SFML community forums

Help => Window => Topic started by: dewyatt on June 14, 2008, 11:35:11 am

Title: Mouse cursor enter/leave
Post by: dewyatt on June 14, 2008, 11:35:11 am
It seems there isn't any event for the mouse cursor entering/leaving the window (in windowed mode).
Is there another way to detect this?
Or should I post this in feature requests?
I'm using CEGUI and having such notification would be nice (not required).
Title: Mouse cursor enter/leave
Post by: Laurent on June 14, 2008, 12:32:19 pm
I can't see any situation where this event would be useful, even more for an internal GUI. Can you tell me what you (or CEGUI) would use it for ?
Title: Mouse cursor enter/leave
Post by: dewyatt on June 14, 2008, 01:14:33 pm
Well to quote the cegui wiki:
Quote

 bool injectMouseLeaves( void )

This function informs CEGUI that the mouse cursor has left the system application window which CEGUI considers it's rendering area. This is useful if running in windowed mode to inform widgets that the mouse has actually left the CEGUI display completely (otherwise it may not get to know, since under some systems no more mouse events are generated for a OS window once the mouse has left it).

But the real reason I wanted this feature:
When dragging a CEGUI window around, if the mouse leaves the application window, the CEGUI window still acts as if the mouse button is held down (though it may not be) and the window is being dragged.
In other words, you can drag a window until the mouse is outside of the application, release the mouse button, then bring the mouse back in on the opposite side of the application and the window will 'jump' there and still drag around until you press+release the mouse button.

If I could be notified that the mouse left the application window then I'm sure I could find a way to inform CEGUI that the window is no longer being dragged.
There may be a way around this but I haven't been able to find any yet.
Title: Mouse cursor enter/leave
Post by: Laurent on June 14, 2008, 01:35:38 pm
Ok, I see. I need to check how to implement this on every OS.
Title: Mouse cursor enter/leave
Post by: dewyatt on June 14, 2008, 01:50:46 pm
Great, thanks!
No rush, it's not exactly a high priority thing.

And thanks for SFML, I'm glad I switched from HGE.  :)
Title: Mouse cursor enter/leave
Post by: Laurent on June 14, 2008, 02:49:46 pm
Quote
I'm glad I switched from HGE

Interesting :)
As far as I know HGE is a more complete game engine, why did you switch ?
Title: Mouse cursor enter/leave
Post by: dewyatt on June 14, 2008, 03:43:46 pm
The main reason is that SFML is cross-platform (yay!).
Another reason is that the HGE community seems to be pretty dead.
Lastly, I like SFML's code (interface+implementation) more than HGEs.
It seems well thought-out.
Title: Mouse cursor enter/leave
Post by: Laurent on June 14, 2008, 04:52:41 pm
Ok I see. Thanks a lot for your feedback ;)
Title: Mouse cursor enter/leave
Post by: quasius on June 16, 2008, 02:52:45 am
I'll second this as a (hopefully) easy-to-implement feature I'd like to see, for the same reason.  (I'm using CEGUI as well and have the same issue.)
Title: Mouse cursor enter/leave
Post by: Laurent on June 16, 2008, 03:12:37 am
Yep, it should be implemented soon after the 1.3 release ;)
Title: sfml gui
Post by: Caspin on June 18, 2008, 04:22:14 pm
I"ve been planning (dreading) to implement my own gui system for my current game.  It's had to more than simple as a level editor is integrated with the game.
A friend of mine recently point me to cegui.  I don't know how I missed this gem.  I was wonder how difficult it was to get cegui to work with sfml.

Did you write an SFML renderer?

Are you using the standard OpenGL renderer and having sfml to preserve it's state?

Did you run into any snags?

In effect I'm looking for a tutorial on how you chose to bring up cegui with sfml.

-caspin
Title: Mouse cursor enter/leave
Post by: dewyatt on June 21, 2008, 05:04:03 am
Using CEGUI in SFML is easy, you just use CEGUI::OpenGLRenderer.
Here's a screenshot:
http://i107.photobucket.com/albums/m300/silentdae/sfmlCEGUI.jpg
The tutorials on the CEGUI website apply to SFML as well.
http://www.cegui.org.uk/wiki/index.php/Tutorials

Here's a quick introduction though:
This part isn't SFML specific.
If you haven't already, download the SDK.
You may need to copy CEGUI-SDK\RendererModules\OpenGLGUIRenderer\*.h to CEGUI-SDK\include.

If you're not linking to the static CEGUI libs, you'll want to copy some DLLs to your app folder:
CEGUIBase.dll
CEGUIDevILImageCodec.dll
CEGUIExpatParser.dll
CEGUIFalagardWRBase.dll
CEGUISILLYImageCodec.dll
OpenGLGUIRenderer.dll
SILLY.dll

Plus the debug (CEGUIBase_d.dll, etc) versions as well.
The code from the screenshot was:
Code: [Select]

CEGUI::OpenGLRenderer* CEGUIRenderer = new OpenGLRenderer(0);
CEGUI::System* CEGUISystem = new System(CEGUIRenderer);
CEGUI::Window* RootWindow;

SchemeManager::getSingleton().loadScheme("WindowsLook.scheme");
FontManager::getSingleton().createFont("DejaVuSans-10.font");

CEGUISystem->setDefaultMouseCursor("WindowsLook", "MouseArrow");
CEGUISystem->setDefaultTooltip("WindowsLook/Tooltip");

CEGUI::WindowManager& WindowMgr = WindowManager::getSingleton();

RootWindow = WindowMgr.createWindow("WindowsLook/Static");
RootWindow->setProperty("FrameEnabled", "false");
CEGUISystem->setGUISheet(RootWindow);

CEGUI::Window* Dialog = WindowMgr.createWindow("WindowsLook/FrameWindow");
Dialog->setMinSize(UVector2(UDim(0, 400),UDim(0, 300)));
Dialog->setText("Window");
RootWindow->addChildWindow(Dialog);

That's all before your render loop.
Then, in your render loop add:
Code: [Select]

CEGUI::System::getSingleton().renderGUI();

Before your call to SFML's Window::Display().

To run that, you'll also need to have these files (from CEGUI-SDK/Samples/datafiles) in your app folder:
WindowsLook.scheme
WindowsLookWidgets.scheme
WindowsLook.tga
WindowsLook.imageset
DejaVuSans-10.font
DejaVuSans.ttf
WindowsLook.looknfeel

You'll also want to inject inputs into CEGUI.
Here's some code for that:
Code: [Select]

while (Window.GetEvent(Event))
{
switch (Event.Type)
{
case sf::Event::KeyPressed:
CEGUI::System::getSingleton().injectKeyDown(Event.Key.Code);
CEGUI::System::getSingleton().injectChar(Event.Text.Unicode);
break;
case sf::Event::KeyReleased:
CEGUI::System::getSingleton().injectKeyUp(Event.Key.Code);
break;
case sf::Event::MouseMoved:
CEGUI::System::getSingleton().injectMousePosition(Window.GetInput().GetMouseX(), Window.GetInput().GetMouseY());
break;
case sf::Event::MouseButtonPressed:
switch (Event.MouseButton.Button)
{
case sf::Mouse::Left:
CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
break;
case sf::Mouse::Middle:
CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);
break;
case sf::Mouse::Right:
CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
break;
}
break;
case sf::Event::MouseButtonReleased:
switch (Event.MouseButton.Button)
{
case sf::Mouse::Left:
CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
break;
case sf::Mouse::Middle:
CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);
break;
case sf::Mouse::Right:
CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
break;
}
break;
case sf::Event::MouseWheelMoved:
CEGUI::System::getSingleton().injectMouseWheelChange(Event.MouseWheel.Delta);
break;
}
}

Finally, I think that's all.
It takes a bit to get it all set up but it's worth it.
Sure beats writing your own GUI.
Title: Mouse cursor enter/leave
Post by: Laurent on June 21, 2008, 05:41:37 am
Why don't you put this tutorial on the wiki ? It would be useful to a many users ;)
Title: Mouse cursor enter/leave
Post by: dewyatt on June 21, 2008, 05:50:11 am
Quote from: "Laurent"
Why don't you put this tutorial on the wiki ? It would be useful to a many users ;)

Oh yeah, that would be a good idea.
Will do.
Title: Mouse cursor enter/leave
Post by: dewyatt on June 21, 2008, 03:40:18 pm
Okay, here's the wiki tutorial:
http://sfml-dev.org/wiki/en/tutorials/CEGUI

If someone with the privileges can move the image+example off the external servers, I'd appreciate it.
Title: Mouse cursor enter/leave
Post by: Laurent on June 21, 2008, 05:45:03 pm
You can upload an image with the "add picture" button when editing the page.
Title: Mouse cursor enter/leave
Post by: dewyatt on June 21, 2008, 07:03:21 pm
I tried that but it looks like you have ACL enabled or something.
The Media Manager doesn't provide any upload option for me.
Title: Mouse cursor enter/leave
Post by: MadMartin on July 17, 2008, 10:08:19 am
Hi Laurent,

any news on this topic? Don't want to hurry you, I'm just curious  :wink:

Btw I also switched from HGE for the same reasons dewyatt mentioned. Its nice and well designed, but I like the design behind SFML even more. Is marvellous! Just wanted to say that...

greets
Martin
Title: Mouse cursor enter/leave
Post by: Laurent on July 17, 2008, 10:25:16 am
Quote
any news on this topic? Don't want to hurry you, I'm just curious

No, sorry. I noticed that these events were not supported directly by the OS (at least Windows), and didn't investigate further yet.

Quote
Btw I also switched from HGE for the same reasons dewyatt mentioned. Its nice and well designed, but I like the design behind SFML even more. Is marvellous! Just wanted to say that...

Thank you :)
Title: Mouse cursor enter/leave
Post by: MadMartin on July 17, 2008, 11:05:16 am
Ever heard of TrackMouseEvent and WM_MOUSELEAVE? I've never tried it, but I think it could be capable enough. When the mouse reenters the window, it probably just would be a WM_MOUSEMOVE.

So far for the Windows part...
Title: Mouse cursor enter/leave
Post by: Laurent on July 17, 2008, 11:13:56 am
Quote from: "MadMartin"
Ever heard of TrackMouseEvent and WM_MOUSELEAVE? I've never tried it, but I think it could be capable enough. When the mouse reenters the window, it probably just would be a WM_MOUSEMOVE.

So far for the Windows part...

That's exactly what I was planning to do.
Title: Mouse cursor enter/leave
Post by: MadMartin on July 17, 2008, 11:30:24 am
Ah, ok, just thought this information would be interesting for you :wink: