summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2009-11-18 23:07:29 +0000
committerpeter1138 <peter1138@openttd.org>2009-11-18 23:07:29 +0000
commitb0049500a69ba2ddd2739be3d3d502a40ef98919 (patch)
treef0768c1fa0c0de8b79d1424bbf6f16d4dc883e8e /src/video
parent4ade74953243da1675ee58c5384d2b52c72bc32c (diff)
downloadopenttd-b0049500a69ba2ddd2739be3d3d502a40ef98919.tar.xz
(svn r18177) -Fix (r18001): [SDL] Viewport could jump when mouse moved and right button pressed at the same time.
Diffstat (limited to 'src/video')
-rw-r--r--src/video/sdl_v.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index 0e347645e..f9ef164c0 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -365,25 +365,23 @@ static int PollEvent()
{
SDL_Event ev;
- if (_cursor.fix_at != _last_fix_at) {
- _last_fix_at = _cursor.fix_at;
- if (_last_fix_at) {
- /* Move to centre of window */
- SDL_CALL SDL_WarpMouse(_screen.width / 2, _screen.height / 2);
-
- } else {
- /* Restore position */
- SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y);
- }
- }
-
if (!SDL_CALL SDL_PollEvent(&ev)) return -2;
switch (ev.type) {
case SDL_MOUSEMOTION:
if (_cursor.fix_at) {
- int dx = ev.motion.x - _screen.width / 2;
- int dy = ev.motion.y - _screen.height / 2;
+ int dx;
+ int dy;
+ if (_last_fix_at) {
+ dx = ev.motion.x - _screen.width / 2;
+ dy = ev.motion.y - _screen.height / 2;
+ } else {
+ /* Mouse hasn't been warped yet, so our movement is
+ * relative to the old position. */
+ dx = ev.motion.x - _cursor.pos.x;
+ dy = ev.motion.y - _cursor.pos.y;
+ _last_fix_at = true;
+ }
if (dx != 0 || dy != 0) {
_cursor.delta.x = dx;
_cursor.delta.y = dy;
@@ -434,6 +432,13 @@ static int PollEvent()
_right_button_down = false;
}
HandleMouseEvents();
+
+ if (_cursor.fix_at != _last_fix_at) {
+ /* Mouse fixing changed during a mouse button up event, so it
+ * must have been released. */
+ _last_fix_at = false;
+ SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y);
+ }
break;
case SDL_ACTIVEEVENT: