# HG changeset patch # User unc0rr # Date 1168188796 0 # Node ID 806c3b55500d8918b0717a8bc6158b2a5384c6da # Parent 96b428ac11f2e3968786780801a4bfff9c75e088 Release mouse when keyboard focus lost diff -r 96b428ac11f2 -r 806c3b55500d hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Thu Jan 04 18:54:24 2007 +0000 +++ b/hedgewars/SDLh.pas Sun Jan 07 16:53:16 2007 +0000 @@ -55,10 +55,13 @@ SDL_RLEACCEL = $00004000; SDL_NOEVENT = 0; + SDL_ACTIVEEVENT = 1; SDL_KEYDOWN = 2; SDL_KEYUP = 3; SDL_QUITEV = 12; + SDL_APPINPUTFOCUS = 2; + SDL_INIT_VIDEO = $00000020; SDL_INIT_AUDIO = $00000010; @@ -158,6 +161,12 @@ unicode: Word; end; + TSDL_ActiveEvent = record + type_: byte; + gain: byte; + state: byte; + end; + TSDL_KeyboardEvent = record type_: Byte; which: Byte; @@ -172,6 +181,7 @@ TSDL_Event = record case Byte of SDL_NOEVENT: (type_: byte); + SDL_ACTIVEEVENT: (active: TSDL_ActiveEvent); SDL_KEYDOWN, SDL_KEYUP: (key: TSDL_KeyboardEvent); SDL_QUITEV: (quit: TSDL_QuitEvent); end; diff -r 96b428ac11f2 -r 806c3b55500d hedgewars/hwengine.dpr --- a/hedgewars/hwengine.dpr Thu Jan 04 18:54:24 2007 +0000 +++ b/hedgewars/hwengine.dpr Sun Jan 07 16:53:16 2007 +0000 @@ -135,6 +135,8 @@ end; gsConsole: KeyPressConsole(event.key.keysym.sym); end; + SDL_ACTIVEEVENT: if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then + cHasFocus:= event.active.gain = 1; SDL_QUITEV: isTerminated:= true end; CurrTime:= SDL_GetTicks; diff -r 96b428ac11f2 -r 806c3b55500d hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Thu Jan 04 18:54:24 2007 +0000 +++ b/hedgewars/uMisc.pas Sun Jan 07 16:53:16 2007 +0000 @@ -71,6 +71,7 @@ cInitVolume : integer = 128; cVolumeDelta : integer = 0; cTimerInterval : Longword = 5; + cHasFocus : boolean = true; var cSendEmptyPacketTime : LongWord = 2000; diff -r 96b428ac11f2 -r 806c3b55500d hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Thu Jan 04 18:54:24 2007 +0000 +++ b/hedgewars/uWorld.pas Sun Jan 07 16:53:16 2007 +0000 @@ -402,7 +402,7 @@ if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33; if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76; prevPoint:= CursorPoint; - SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); + if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); exit end; @@ -440,13 +440,15 @@ CursorPoint.Y:= cScreenHeight - EdgesDist end; end else - begin + if cHasFocus then + begin WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; WorldDy:= WorldDy - CursorPoint.Y + prevPoint.Y; CursorPoint.X:= (cScreenWidth shr 1); CursorPoint.Y:= (cScreenHeight shr 1); - end; -SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); + end; + +if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); prevPoint:= CursorPoint; if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater; if WorldDy > 2048 then WorldDy:= 2048;