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

Author Topic: Moving the View with the mouse (my solution)  (Read 3041 times)

0 Members and 1 Guest are viewing this topic.

aitgelion

  • Newbie
  • *
  • Posts: 2
    • View Profile
Moving the View with the mouse (my solution)
« on: April 17, 2009, 04:21:50 pm »
After searching the best solution to move (scroll) the View using the mouse (pressing left button) I couldn't find anything that help me, so after spending some time trying, I have some usable solution.
Here it is if someone have the same problem!

Variables involved:
sf::Vector2f mouse(0,0); // global variable holding last position of the mouse
sf::View view; //the View asociated to the window

In the Switch handling the events:
Code: [Select]

while (Window.GetEvent(Event))
        {
            switch(Event.Type) {
                 .................

             case sf::Event::MouseMoved:
           if (!Window.GetInput().IsMouseButtonDown(sf::Mouse::Left)) {
mouse.x=Event.MouseMove.X;
mouse.y=Event.MouseMove.Y;
} else {
view.Move(mouse.x-Window.GetInput().GetMouseX(), mouse.y-Window.GetInput().GetMouseY());
mouse.x=Window.GetInput().GetMouseX();
mouse.y=Window.GetInput().GetMouseY();
}
break;
                       ...................
           }
}



Sure It may be some best aproach to do this, but it works for me!.

P.D.: I'm new so, Hello! ( and sorry for my level of english, I'm triying to improve it hehe)

EDIT: Sorry for posting at the wrong board.

Lord Tim

  • Newbie
  • *
  • Posts: 1
    • View Profile
Moving the View with the mouse (my solution)
« Reply #1 on: August 28, 2009, 05:25:38 am »
How come the MouseMove event coordinates don't go negative? They seem to be absolute, or at least they are on windows.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Moving the View with the mouse (my solution)
« Reply #2 on: August 28, 2009, 04:31:31 pm »
The mouse coordinates are relative to the client area.

 

anything