Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Mouse leaving the window causes button issue  (Read 5820 times)

0 Members and 1 Guest are viewing this topic.

wademcgillis

  • Newbie
  • *
  • Posts: 36
    • View Profile
Mouse leaving the window causes button issue
« on: May 10, 2010, 03:44:32 pm »
I hold down the left mouse button and move the mouse outside an SFML window, then I release the left mouse button. When I move the mouse back into the window, Input.IsMouseButtonDown(sf::Mouse::Left) returns true!

Why?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Mouse leaving the window causes button issue
« Reply #1 on: May 10, 2010, 05:40:06 pm »
Because the mouse release event is never notified, as it happens outside the window. This is a limitation of how input work in SFML.
Laurent Gomila - SFML developer

wademcgillis

  • Newbie
  • *
  • Posts: 36
    • View Profile
Mouse leaving the window causes button issue
« Reply #2 on: May 10, 2010, 06:31:14 pm »
But the window is still in focus.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Mouse leaving the window causes button issue
« Reply #3 on: May 10, 2010, 06:54:36 pm »
A window can receive a mouse event outside its area only if you previously called SetCapture on it (on Windows), which SFML doesn't.
Laurent Gomila - SFML developer

wademcgillis

  • Newbie
  • *
  • Posts: 36
    • View Profile
Mouse leaving the window causes button issue
« Reply #4 on: May 10, 2010, 08:17:22 pm »
How disappointing.

Maybe I should make programs that don't use the mouse.

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Mouse leaving the window causes button issue
« Reply #5 on: May 11, 2010, 04:18:24 am »
Quote from: "wademcgillis"
Maybe I should make programs that don't use the mouse.


How about fullscreen mode? :)

( to Laurent: )
What about a function that does collect data about each key/mosebutton status every time it is called? (Only for those users who want to be sure about button status' :)) Or is it possible at all?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Mouse leaving the window causes button issue
« Reply #6 on: May 11, 2010, 07:52:53 am »
Quote
What about a function that does collect data about each key/mosebutton status every time it is called?

I already thought about it, but input states would then no longer be related to windows, which raises a lot of new questions and problems.
For example, what would GetMouseX() return, screen coordinates? And what do you expect from key states? Should windows that are out of focus be notified as well?
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Mouse leaving the window causes button issue
« Reply #7 on: May 11, 2010, 09:09:43 am »
Can't you emit an event when the mouse exits the window area ?


Code: [Select]
-> when mouse go out :
  -> if any mouse button down :
    -> "emit" release event
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Mouse leaving the window causes button issue
« Reply #8 on: May 11, 2010, 11:23:01 am »
What if the button is still down when the cursor comes back into the window? ;)
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Mouse leaving the window causes button issue
« Reply #9 on: May 11, 2010, 01:13:03 pm »
Emit a "button is pressed" when mouse enter window's area ?

I don't know if this is clean or not from implementation point of view...
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Mouse leaving the window causes button issue
« Reply #10 on: May 11, 2010, 01:34:01 pm »
It would be ugly to implement, and I would have to do it for every state (checking every key, every mouse button, every joystick button and axis, ...).
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Mouse leaving the window causes button issue
« Reply #11 on: May 11, 2010, 01:35:47 pm »
Well, indeed, that seems not a good idea  :roll:
SFML / OS X developer

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Mouse leaving the window causes button issue
« Reply #12 on: May 11, 2010, 02:36:17 pm »
So mix the two ideas: If the mouse enters the window area, and the window is focused, sf::Input checks all the key states and coordinates and such. Internally. All the troubles with GetMouseX() and notifications etc. are gone (as I can see). But correct me, if I'm wrong ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Mouse leaving the window causes button issue
« Reply #13 on: May 11, 2010, 03:12:43 pm »
This is exactly what I had in mind when I wrote my previous answer
Quote
It would be ugly to implement, and I would have to do it for every state (checking every key, every mouse button, every joystick button and axis, ...).
Laurent Gomila - SFML developer

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Mouse leaving the window causes button issue
« Reply #14 on: May 11, 2010, 03:25:06 pm »
Ooops, sorry then.... :)