summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2009-11-07 21:41:41 +0000
committerpeter1138 <peter1138@openttd.org>2009-11-07 21:41:41 +0000
commit723c19571f8ca64f2d495abef42f5ccc29dbe35a (patch)
tree45473996870b7525ef2adb388b264b656a9c343b
parent98d24c34e66c43e95ed5d6e21d9e5f3475b49e62 (diff)
downloadopenttd-723c19571f8ca64f2d495abef42f5ccc29dbe35a.tar.xz
(svn r18001) -Codechange: [SDL] When the mouse cursor is locked into position when scrolling a viewport, warp the mouse pointer to the centre of the window. This gives maximum freedom of movement. The pointer position is restored when the lock is removed. Visually the mouse cursor stays where it was.
-rw-r--r--src/video/sdl_v.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index 477314e0d..984556237 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -29,6 +29,8 @@ static FVideoDriver_SDL iFVideoDriver_SDL;
static SDL_Surface *_sdl_screen;
static bool _all_modes;
+/** Flag used to determine if _cursor.fix_at has changed. */
+static bool _last_fix_at;
/** Whether the drawing is/may be done in a separate thread. */
static bool _draw_threaded;
@@ -363,17 +365,29 @@ 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 - _cursor.pos.x;
- int dy = ev.motion.y - _cursor.pos.y;
+ int dx = ev.motion.x - _screen.width / 2;
+ int dy = ev.motion.y - _screen.height / 2;
if (dx != 0 || dy != 0) {
_cursor.delta.x += dx;
_cursor.delta.y += dy;
- SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y);
+ SDL_CALL SDL_WarpMouse(_screen.width / 2, _screen.height / 2);
}
} else {
_cursor.delta.x = ev.motion.x - _cursor.pos.x;