# HG changeset patch # User unc0rr # Date 1312741131 -14400 # Node ID 3be9fda5c3c29915372a913c4834bba0ff54276a # Parent 7a950ef0cee0412233e48343837d9f4d41b1742c Enter gsConfirm state when loosing focus diff -r 7a950ef0cee0 -r 3be9fda5c3c2 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Sun Aug 07 13:32:28 2011 -0400 +++ b/hedgewars/hwengine.pas Sun Aug 07 22:18:51 2011 +0400 @@ -145,6 +145,7 @@ const event: TSDL_Event = (); {$WARNINGS ON} var PrevTime, CurrTime: Longword; + prevFocusState: boolean; begin PrevTime:= SDL_GetTicks; while isTerminated = false do @@ -159,14 +160,22 @@ KeyPressChat(event.key.keysym.sym); SDL_WINDOWEVENT: if event.window.event = SDL_WINDOWEVENT_SHOWN then + begin cHasFocus:= true; + onFocusStateChanged() + end; {$ELSE} KeyPressChat(event.key.keysym.unicode); SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then wheelDown:= true; SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then wheelUp:= true; SDL_ACTIVEEVENT: if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then + begin + prevFocusState:= cHasFocus; cHasFocus:= event.active.gain = 1; + if prevFocusState xor cHasFocus then + onFocusStateChanged() + end; {$ENDIF} SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); diff -r 7a950ef0cee0 -r 3be9fda5c3c2 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Sun Aug 07 13:32:28 2011 -0400 +++ b/hedgewars/uWorld.pas Sun Aug 07 22:18:51 2011 +0400 @@ -33,6 +33,7 @@ procedure HideMission; procedure ShakeCamera(amount: LongWord); procedure MoveCamera; +procedure onFocusStateChanged; implementation uses @@ -51,7 +52,8 @@ uTextures, uRender, uCaptions, - uCursor + uCursor, + uCommands ; var cWaveWidth, cWaveHeight: LongInt; @@ -1312,6 +1314,14 @@ WorldDy:= WorldDy - amount + LongInt(getRandom(1 + amount * 2)); end; + +procedure onFocusStateChanged; +begin +if (not cHasFocus) and (GameState <> gsConfirm) then + ParseCommand('quit', true) +end; + + procedure initModule; begin fpsTexture:= nil;