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

Author Topic: Relative mouse position delta in sf::Event::MouseMoveEvent  (Read 14554 times)

0 Members and 1 Guest are viewing this topic.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Relative mouse position delta in sf::Event::MouseMoveEvent
« on: December 10, 2008, 12:09:43 am »
So there is no to keep track of the last position.

Good for dragging objects or the viewport.

Regards
-Martin

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
Relative mouse position delta in sf::Event::MouseMoveEvent
« Reply #1 on: December 10, 2008, 06:11:59 am »
Just do it yourself.

The SFML is supposed to be minimalistic.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Relative mouse position delta in sf::Event::MouseMoveEvent
« Reply #2 on: December 10, 2008, 02:58:49 pm »
I could derive from RenderWindow to keep track, and access it everywhere  :roll: , other ways involve adding a "Last Mouse Position" variables in a lot of places and really error-prone.

It's a commodity, I know, but it's useful.

You can't say this lib is minimalistic thou... it's really big.
It's easy to learn, easy to understand, pretty verbose, well documented... but it's far from minimal.

Compare it with "raw" SDL... You'll know what I mean (loading yourself the audio buffer, accessing pixels, no loading of images other than BMP... that's minimalistic)


Adding two variables to the event struct doesn't bloat the code.

Regards
-Martín

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Relative mouse position delta in sf::Event::MouseMoveEvent
« Reply #3 on: December 10, 2008, 03:07:30 pm »
The problem with a delta is that it will sometimes be wrong, when the mouse leaves and re-enter the window.
Laurent Gomila - SFML developer

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Relative mouse position delta in sf::Event::MouseMoveEvent
« Reply #4 on: December 11, 2008, 06:59:30 pm »
It can be worked with a flag.
The first time of a MouseMove event, as there is no saved last position, it could be flagged, and the delta would be (0,0).

After the first MouseMove, the flag is cleared and the last position saved.
Next time a proper delta is sent in the event.

If the cursor exits the window (I'm sure there is a way to know in every platform), the flag would be set and then again (0,0) will be the delta in the  next event.

When I have more time I'll give it a try myself and post the code if it works.

Regards
-Martín