hedgewars/hwengine.pas
changeset 5521 3be9fda5c3c2
parent 5505 a55aab592950
child 5530 25d4118056e1
child 5562 8056d82b4d23
equal deleted inserted replaced
5520:7a950ef0cee0 5521:3be9fda5c3c2
   143 {$WARNINGS OFF}
   143 {$WARNINGS OFF}
   144 // disable "Some fields weren't initialized" warning
   144 // disable "Some fields weren't initialized" warning
   145 const event: TSDL_Event = ();
   145 const event: TSDL_Event = ();
   146 {$WARNINGS ON}
   146 {$WARNINGS ON}
   147 var PrevTime, CurrTime: Longword;
   147 var PrevTime, CurrTime: Longword;
       
   148     prevFocusState: boolean;
   148 begin
   149 begin
   149     PrevTime:= SDL_GetTicks;
   150     PrevTime:= SDL_GetTicks;
   150     while isTerminated = false do
   151     while isTerminated = false do
   151     begin
   152     begin
   152 
   153 
   157 {$IFDEF SDL13}
   158 {$IFDEF SDL13}
   158                     // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
   159                     // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
   159                     KeyPressChat(event.key.keysym.sym);
   160                     KeyPressChat(event.key.keysym.sym);
   160                 SDL_WINDOWEVENT:
   161                 SDL_WINDOWEVENT:
   161                     if event.window.event = SDL_WINDOWEVENT_SHOWN then
   162                     if event.window.event = SDL_WINDOWEVENT_SHOWN then
       
   163                         begin
   162                         cHasFocus:= true;
   164                         cHasFocus:= true;
       
   165                         onFocusStateChanged()
       
   166                         end;
   163 {$ELSE}
   167 {$ELSE}
   164                     KeyPressChat(event.key.keysym.unicode);
   168                     KeyPressChat(event.key.keysym.unicode);
   165                 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then wheelDown:= true;
   169                 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then wheelDown:= true;
   166                 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then wheelUp:= true;
   170                 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then wheelUp:= true;
   167                 SDL_ACTIVEEVENT:
   171                 SDL_ACTIVEEVENT:
   168                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
   172                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
       
   173                         begin
       
   174                         prevFocusState:= cHasFocus;
   169                         cHasFocus:= event.active.gain = 1;
   175                         cHasFocus:= event.active.gain = 1;
       
   176                         if prevFocusState xor cHasFocus then
       
   177                             onFocusStateChanged()
       
   178                         end;
   170 {$ENDIF}
   179 {$ENDIF}
   171                 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
   180                 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
   172                 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
   181                 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
   173                 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true);
   182                 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true);
   174                 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);
   183                 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);