SFML community forums

Help => Window => Topic started by: Prominence256 on January 26, 2011, 02:42:50 am

Title: Screen Savers and Event::MouseMoved
Post by: Prominence256 on January 26, 2011, 02:42:50 am
I'm trying to make a simple Windows screen saver. My only issue is closing it when the mouse moves. This is my code:
Code: [Select]
case Event::MouseMoved:
app.Close();
break;
The problem is that this closes the window as soon as it opens. Is there any way to fix this?
Title: Screen Savers and Event::MouseMoved
Post by: JAssange on January 26, 2011, 03:15:03 am
You need to check for movement larger than a certain amount at once to filter out small jitters just like real screensavers do.
Title: Screen Savers and Event::MouseMoved
Post by: Prominence256 on January 26, 2011, 04:08:04 am
I tried using an IntRect and checking if it contains the current mouse coordinates but that didn't work. Here's what I did:
Code: [Select]
IntRect box;
box.Left   = app.GetInput().GetMouseX() - 16;
box.Right  = app.GetInput().GetMouseX() + 16;
box.Top    = app.GetInput().GetMouseY() - 16;
box.Bottom = app.GetInput().GetMouseY() + 16;
Code: [Select]
case Event::MouseMoved:
int mx = app.GetInput().GetMouseX();
int my = app.GetInput().GetMouseY();
if (!box.Contains(mx, my))
app.Close();
break;
And it still immediately closed.
Title: Screen Savers and Event::MouseMoved
Post by: tntexplosivesltd on January 26, 2011, 07:21:03 am
Can you show your complete code?
Title: Screen Savers and Event::MouseMoved
Post by: JAssange on January 26, 2011, 12:31:50 pm
You should store OldMouseX and OldMouseY and compare against them.
Title: Screen Savers and Event::MouseMoved
Post by: Prominence256 on January 26, 2011, 10:29:54 pm
I found the problem. The issue was that OldMouseX and Y were only assigned values once, and that time happened to be before the window had finished loading so they were always set to 0. The odds of you actually putting the mouse in the top left corner are pretty low, that's why it always closed.