hedgewars/hwengine.pas
changeset 2567 02ff5f9510b5
parent 2428 6800f8aa0184
child 2568 e654cbfb23ba
equal deleted inserted replaced
2565:54296af65fe9 2567:02ff5f9510b5
   161 ///////////////////
   161 ///////////////////
   162 procedure MainLoop;
   162 procedure MainLoop;
   163 var PrevTime,
   163 var PrevTime,
   164     CurrTime: Longword;
   164     CurrTime: Longword;
   165     event: TSDL_Event;
   165     event: TSDL_Event;
       
   166     mouseState, whichMouse: byte;
       
   167     x, y, x_up, y_up, x_down, y_down: LongInt;
       
   168     oldy: LongInt = 240;
   166 begin
   169 begin
   167 PrevTime:= SDL_GetTicks;
   170 PrevTime:= SDL_GetTicks;
   168 repeat
   171 repeat
   169 while SDL_PollEvent(@event) <> 0 do
   172 while SDL_PollEvent(@event) <> 0 do
   170 	case event.type_ of
   173 	case event.type_ of
   171 {$IFDEF IPHONEOS}
   174 {$IFDEF IPHONEOS}
   172 		SDL_MOUSEMOTION: WriteLnToConsole('mouse number ' + inttostr(SDL_SelectMouse(event.motion.which)) + ' over ' + inttostr(SDL_GetNumMice()));
       
   173                 SDL_WINDOWEVENT:
   175                 SDL_WINDOWEVENT:
   174 {$ELSE}
   176 {$ELSE}
   175 		SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode);
   177 		SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode);
   176                 SDL_ACTIVEEVENT:
   178                 SDL_ACTIVEEVENT:
   177 {$ENDIF}
   179 {$ENDIF}
   178                         if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
   180                         if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
   179 				cHasFocus:= event.active.gain = 1;
   181 				cHasFocus:= event.active.gain = 1;
   180 		//SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450));
   182 		//SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450));
   181 {$IFNDEF IPHONEOS}
   183 {$IFDEF IPHONEOS}
       
   184         {*MoveCamera is in uWord.pas -- conflicts with other commands*}
       
   185         {*Keys are in uKeys.pas*}
       
   186                 SDL_MOUSEBUTTONDOWN: begin
       
   187                         mouseState:= SDL_GetMouseState(0, @x, @y);
       
   188                         if x <= 50 then 
       
   189                         begin   
       
   190                                 AddFileLog('Wheel -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   191                                 {* sliding *}
       
   192                                 if oldy - y > 0 then uKeys.wheelUp:= true
       
   193                                 else uKeys.wheelDown:= true;
       
   194                                 {* update value only if movement is consistent *}
       
   195                                // if (y > oldy - 10 ) or (y > oldy + 10 ) then oldy:= y
       
   196                                // oldy:= y;
       
   197                         end;
       
   198 
       
   199                         {* keys *}
       
   200              {*           if (x > 50) then
       
   201                         begin
       
   202                                 AddFileLog('Arrow Key -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   203 
       
   204                                 if (y <= 50)  and (x > 135) and (x <= 185) then uKeys.upKey:= true;
       
   205                                 if (y > 430)  and (x > 135) and (x <= 185) then uKeys.downKey:= true;
       
   206                                 if (x > 270)  and (y > 215) and (y > 265)  then uKeys.rightClick:= true;
       
   207                                 if (x <= 100) and (y > 215) and (y > 265)  then uKeys.leftClick:= true;
       
   208                         end;
       
   209                         
       
   210                         if (y > 430) and (x > 50) and (x <= 135) then
       
   211                         begin
       
   212                                 AddFileLog('Space -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   213                                 uKeys.spaceKey:= true;
       
   214                         end;
       
   215                         if (y > 430) and (x > 185) and (x <= 270) then
       
   216                         begin
       
   217                                 AddFileLog('Enter -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   218                                 uKeys.enterKey:= true;
       
   219                         end;*}
       
   220                 end;
       
   221                 SDL_MOUSEBUTTONUP: begin
       
   222                         mouseState:= SDL_GetMouseState(0, @x, @y);
       
   223                         x_up:= x;
       
   224                         y_up:= y;
       
   225 
       
   226                         {* open ammo menu *}
       
   227                         if (y > 430) and (x > 270) then
       
   228                         begin   
       
   229                                 AddFileLog('Right Click -- x: ' + inttostr(x) + ' y: ' + inttostr(y) );
       
   230                                 uKeys.rightClick:= true;
       
   231                         end;
       
   232                         {* reset zoom *}
       
   233                         if (x > 270) and (y <= 50) then
       
   234                         begin
       
   235                                 AddFileLog('Middle Click -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   236                                 uKeys.middleClick:= true;
       
   237                         end;
       
   238                        
       
   239 
       
   240                 end;
       
   241 {$ELSE}
   182 		SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
   242 		SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
   183 		SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELDUP then uKeys.wheelUp:= true;
   243 		SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELDUP then uKeys.wheelUp:= true;
   184 {$ENDIF}
   244 {$ENDIF}
   185 		SDL_JOYAXIS: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
   245 		SDL_JOYAXIS: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
   186 		SDL_JOYHAT: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
   246 		SDL_JOYHAT: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);