Enter gsConfirm state when loosing focus
authorunc0rr
Sun, 07 Aug 2011 22:18:51 +0400
changeset 5521 3be9fda5c3c2
parent 5520 7a950ef0cee0
child 5522 5a4bc518c59a
Enter gsConfirm state when loosing focus
hedgewars/hwengine.pas
hedgewars/uWorld.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);
--- 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;