Continuously scroll map with two fingers

This commit is contained in:
pelya
2014-11-10 17:57:43 +02:00
parent a43e0fb4e7
commit a7c2766411
4 changed files with 23 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ bool _left_button_down; ///< Is left mouse button pressed?
bool _left_button_clicked; ///< Is left mouse button clicked?
bool _right_button_down; ///< Is right mouse button pressed?
bool _right_button_clicked; ///< Is right mouse button clicked?
Point _right_button_down_pos; ///< Pos of right mouse button click, for drag and drop
DrawPixelInfo _screen;
bool _screen_disable_anim = false; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)

View File

@@ -64,6 +64,7 @@ extern bool _left_button_down;
extern bool _left_button_clicked;
extern bool _right_button_down;
extern bool _right_button_clicked;
extern Point _right_button_down_pos;
extern DrawPixelInfo _screen;
extern bool _screen_disable_anim; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)

View File

@@ -596,6 +596,8 @@ int VideoDriver_SDL::PollEvent()
case SDL_BUTTON_RIGHT:
_right_button_down = true;
_right_button_clicked = true;
_right_button_down_pos.x = ev.motion.x;
_right_button_down_pos.y = ev.motion.y;
break;
case SDL_BUTTON_WHEELUP: _cursor.wheel--; break;

View File

@@ -2774,6 +2774,24 @@ static void HandleAutoscroll()
#undef scrollspeed
}
/**
* Perform small continuous scrolling with right button press and drag.
*/
static void HandleContinuousScroll()
{
#define scrollspeed 0.05f
if (_scrolling_viewport && _right_button_down) {
Window *w = FindWindowFromPt(_right_button_down_pos.x, _right_button_down_pos.y);
if (w == NULL || w->flags & WF_DISABLE_VP_SCROLL) return;
ViewPort *vp = IsPtInWindowViewport(w, _right_button_down_pos.x, _right_button_down_pos.y);
if (vp == NULL) return;
w->viewport->dest_scrollpos_x += ScaleByZoom(scrollspeed * (_right_button_down_pos.x - _cursor.pos.x), vp->zoom);
w->viewport->dest_scrollpos_y += ScaleByZoom(scrollspeed * (_right_button_down_pos.y - _cursor.pos.y), vp->zoom);
}
#undef scrollspeed
}
enum MouseClick {
MC_NONE = 0,
MC_LEFT,
@@ -3093,6 +3111,7 @@ void InputLoop()
/* HandleMouseEvents was already called for this tick */
HandleMouseEvents();
HandleAutoscroll();
HandleContinuousScroll();
}
/**