From 897eeadeddacfefd3e2d2fb12325d1aa0c902ad0 Mon Sep 17 00:00:00 2001 From: Christian Ohm Date: Sun, 24 Jan 2010 03:39:44 +0000 Subject: [PATCH] Disable mouse scrolling when mouse leaves the window. Keyboard scrolling still works. Really fixes #1141, and makes the game always behave as mentioned in r9428. git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@9447 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/display.c | 59 ++++++++++++++++++++++++++++----------------------- src/display.h | 1 + src/main.c | 3 +++ 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/display.c b/src/display.c index f377b728f..c9eb4a671 100644 --- a/src/display.c +++ b/src/display.c @@ -210,6 +210,7 @@ static BOOL ignoreRMBC = true; static DROID *psSelectedVtol; static DROID *psDominantSelected; static BOOL bRadarDragging = false; +static bool mouseScroll = true; BOOL rotActive = false; BOOL gameStats = false; @@ -243,6 +244,10 @@ static BOOL bLasSatStruct; static MOUSE_TARGET itemUnderMouse(BASE_OBJECT **ppObjUnderCursor); static BOOL bShakingPermitted = true; +void setMouseScroll(bool scroll) +{ + mouseScroll = scroll; +} void setRadarJump(BOOL val) { @@ -1047,33 +1052,7 @@ void scroll(void) return; } - if(!keyDown(KEY_LCTRL) && !keyDown(KEY_RCTRL)) - { - /* Scroll left */ - if (keyDown(KEY_LEFTARROW) || mouseXPos < BOUNDARY_X) - { - mouseAtLeft = true; - } - - /* Scroll right */ - if ( keyDown(KEY_RIGHTARROW) || mouseXPos > (pie_GetVideoBufferWidth() - BOUNDARY_X) ) - { - mouseAtRight = true; - } - - /* Scroll up */ - if (keyDown(KEY_UPARROW) || (mouseYPos < BOUNDARY_Y)) - { - mouseAtBottom = true; - } - - /* Scroll down */ - if ( keyDown(KEY_DOWNARROW) || mouseYPos > (pie_GetVideoBufferHeight() - BOUNDARY_Y) ) - { - mouseAtTop = true; - } - } - else + if (mouseScroll) { /* Scroll left */ if (mouseXPos < BOUNDARY_X) @@ -1099,6 +1078,32 @@ void scroll(void) mouseAtTop = true; } } + if (!keyDown(KEY_LCTRL) && !keyDown(KEY_RCTRL)) + { + /* Scroll left */ + if (keyDown(KEY_LEFTARROW)) + { + mouseAtLeft = true; + } + + /* Scroll right */ + if (keyDown(KEY_RIGHTARROW)) + { + mouseAtRight = true; + } + + /* Scroll up */ + if (keyDown(KEY_UPARROW)) + { + mouseAtBottom = true; + } + + /* Scroll down */ + if ( keyDown(KEY_DOWNARROW)) + { + mouseAtTop = true; + } + } /* Time to update scroll - change to should be time */ timeDiff = SDL_GetTicks() - scrollRefTime; diff --git a/src/display.h b/src/display.h index ddd67f611..d7116661d 100644 --- a/src/display.h +++ b/src/display.h @@ -48,6 +48,7 @@ extern void processMouseClickInput(void); extern void scroll(void); extern void resetScroll(void); +extern void setMouseScroll(bool); extern BOOL DrawnInLastFrame(SDWORD Frame); diff --git a/src/main.c b/src/main.c index b1b7ba5ff..34d2bb494 100644 --- a/src/main.c +++ b/src/main.c @@ -864,7 +864,10 @@ static void handleActiveEvent(SDL_ActiveEvent * activeEvent) // Ignore focus loss through SDL_APPMOUSEFOCUS, since it mostly happens accidentialy // active.state is a bitflag! Mixed events (eg. APPACTIVE|APPMOUSEFOCUS) will thus not be ignored. if ( activeEvent->state == SDL_APPMOUSEFOCUS ) + { + setMouseScroll(activeEvent->gain); return; + } if ( activeEvent->gain == 1 ) {