WE HAVE TOUCH INPUT
authorkoda
Tue, 20 Oct 2009 17:55:11 +0000
changeset 2567 02ff5f9510b5
parent 2565 54296af65fe9
child 2568 e654cbfb23ba
WE HAVE TOUCH INPUT
hedgewars/SDLh.pas
hedgewars/hwengine.pas
hedgewars/uKeys.pas
hedgewars/uStore.pas
hedgewars/uWorld.pas
--- a/hedgewars/SDLh.pas	Tue Oct 20 11:49:10 2009 +0000
+++ b/hedgewars/SDLh.pas	Tue Oct 20 17:55:11 2009 +0000
@@ -126,6 +126,20 @@
 {$ENDIF}
 {*end sdl_event binding*}
 
+{$IFDEF SDL13}
+{*#define SDL_BUTTON(X)		(1 << ((X)-1))
+#define SDL_BUTTON_LEFT		1
+#define SDL_BUTTON_MIDDLE	2
+#define SDL_BUTTON_RIGHT	3
+#define SDL_BUTTON_X1		4
+#define SDL_BUTTON_X2		5
+#define SDL_BUTTON_LMASK	SDL_BUTTON(SDL_BUTTON_LEFT)
+#define SDL_BUTTON_MMASK	SDL_BUTTON(SDL_BUTTON_MIDDLE)
+#define SDL_BUTTON_RMASK	SDL_BUTTON(SDL_BUTTON_RIGHT)
+#define SDL_BUTTON_X1MASK	SDL_BUTTON(SDL_BUTTON_X1)
+#define SDL_BUTTON_X2MASK	SDL_BUTTON(SDL_BUTTON_X2)*}
+{$ENDIF}
+
 	RMask = $000000FF;
 	GMask = $0000FF00;
 	BMask = $00FF0000;
--- a/hedgewars/hwengine.pas	Tue Oct 20 11:49:10 2009 +0000
+++ b/hedgewars/hwengine.pas	Tue Oct 20 17:55:11 2009 +0000
@@ -163,13 +163,15 @@
 var PrevTime,
     CurrTime: Longword;
     event: TSDL_Event;
+    mouseState, whichMouse: byte;
+    x, y, x_up, y_up, x_down, y_down: LongInt;
+    oldy: LongInt = 240;
 begin
 PrevTime:= SDL_GetTicks;
 repeat
 while SDL_PollEvent(@event) <> 0 do
 	case event.type_ of
 {$IFDEF IPHONEOS}
-		SDL_MOUSEMOTION: WriteLnToConsole('mouse number ' + inttostr(SDL_SelectMouse(event.motion.which)) + ' over ' + inttostr(SDL_GetNumMice()));
                 SDL_WINDOWEVENT:
 {$ELSE}
 		SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode);
@@ -178,7 +180,65 @@
                         if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
 				cHasFocus:= event.active.gain = 1;
 		//SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450));
-{$IFNDEF IPHONEOS}
+{$IFDEF IPHONEOS}
+        {*MoveCamera is in uWord.pas -- conflicts with other commands*}
+        {*Keys are in uKeys.pas*}
+                SDL_MOUSEBUTTONDOWN: begin
+                        mouseState:= SDL_GetMouseState(0, @x, @y);
+                        if x <= 50 then 
+                        begin   
+                                AddFileLog('Wheel -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
+                                {* sliding *}
+                                if oldy - y > 0 then uKeys.wheelUp:= true
+                                else uKeys.wheelDown:= true;
+                                {* update value only if movement is consistent *}
+                               // if (y > oldy - 10 ) or (y > oldy + 10 ) then oldy:= y
+                               // oldy:= y;
+                        end;
+
+                        {* keys *}
+             {*           if (x > 50) then
+                        begin
+                                AddFileLog('Arrow Key -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
+
+                                if (y <= 50)  and (x > 135) and (x <= 185) then uKeys.upKey:= true;
+                                if (y > 430)  and (x > 135) and (x <= 185) then uKeys.downKey:= true;
+                                if (x > 270)  and (y > 215) and (y > 265)  then uKeys.rightClick:= true;
+                                if (x <= 100) and (y > 215) and (y > 265)  then uKeys.leftClick:= true;
+                        end;
+                        
+                        if (y > 430) and (x > 50) and (x <= 135) then
+                        begin
+                                AddFileLog('Space -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
+                                uKeys.spaceKey:= true;
+                        end;
+                        if (y > 430) and (x > 185) and (x <= 270) then
+                        begin
+                                AddFileLog('Enter -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
+                                uKeys.enterKey:= true;
+                        end;*}
+                end;
+                SDL_MOUSEBUTTONUP: begin
+                        mouseState:= SDL_GetMouseState(0, @x, @y);
+                        x_up:= x;
+                        y_up:= y;
+
+                        {* open ammo menu *}
+                        if (y > 430) and (x > 270) then
+                        begin   
+                                AddFileLog('Right Click -- x: ' + inttostr(x) + ' y: ' + inttostr(y) );
+                                uKeys.rightClick:= true;
+                        end;
+                        {* reset zoom *}
+                        if (x > 270) and (y <= 50) then
+                        begin
+                                AddFileLog('Middle Click -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
+                                uKeys.middleClick:= true;
+                        end;
+                       
+
+                end;
+{$ELSE}
 		SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
 		SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELDUP then uKeys.wheelUp:= true;
 {$ENDIF}
--- a/hedgewars/uKeys.pas	Tue Oct 20 11:49:10 2009 +0000
+++ b/hedgewars/uKeys.pas	Tue Oct 20 17:55:11 2009 +0000
@@ -22,8 +22,9 @@
 {$INCLUDE options.inc}
 
 type TBinds = array[0..cKeyMaxIndex] of shortstring;
+type TKeyboardState = array[0..cKeyMaxIndex] of Byte;
 
-function KeyNameToCode(name: string): word;
+function  KeyNameToCode(name: string): word;
 procedure ProcessKbd;
 procedure ResetKbd;
 procedure FreezeEnterKey;
@@ -41,7 +42,19 @@
 var hideAmmoMenu: boolean;
 	wheelUp: boolean = false;
 	wheelDown: boolean = false;
+{$IFDEF IPHONEOS}
+        leftClick: boolean = false;
+        middleClick: boolean = false;
+        rightClick: boolean = false;
 
+upKey: boolean = false;
+downKey: boolean = false;
+rightKey: boolean = false;
+leftKey: boolean = false;
+
+spaceKey: boolean = false;
+enterKey: boolean = false;
+{$ENDIF}
 	ControllerNumControllers: Integer;
     ControllerEnabled: Integer;
     ControllerNumAxes: array[0..5] of Integer;
@@ -56,7 +69,6 @@
 implementation
 uses SDLh, uTeams, uConsole, uMisc, uStore;
 const KeyNumber = 1024;
-type TKeyboardState = array[0..cKeyMaxIndex] of Byte;
 
 var tkbd, tkbdn: TKeyboardState;
     KeyNames: array [0..cKeyMaxIndex] of string[15];
@@ -111,6 +123,33 @@
 tkbdn[5]:= ord(wheelUp);
 wheelUp:= false;
 wheelDown:= false;
+{$IFDEF IPHONEOS}
+tkbdn[1]:= ord(leftClick);
+tkbdn[2]:= ord(middleClick);
+tkbdn[3]:= ord(rightClick);
+leftClick:= false;
+middleClick:= false;
+rightClick:= false;
+
+{*
+//sdl1.3 for these keys is messed up
+tkbdn[273]:= ord(upKey);
+tkbdn[274]:= ord(downKey);
+tkbdn[275]:= ord(rightKey);
+tkbdn[276]:= ord(leftKey);
+
+tkbdn[32]:= ord(spaceKey);
+tkbdn[13]:= ord(enterKey);
+
+upKey:= false;
+downKey:= false;
+rightKey:= false;
+leftKey:= false;
+
+spaceKey:= false;
+enterKey:= false;
+*}
+{$ENDIF}
 
 // Controller(s)
 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
@@ -162,10 +201,10 @@
 
 {$IFDEF SDL13}
 pkbd:= SDL_GetKeyboardState(@j);
-k    := SDL_GetMouseState(0, nil, nil);
+k:= SDL_GetMouseState(0, nil, nil);
 {$ELSE}
 pkbd:= SDL_GetKeyState(@j);
-k    := SDL_GetMouseState(nil, nil);
+k:= SDL_GetMouseState(nil, nil);
 {$ENDIF}
 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(j) + ')', true);
 
@@ -187,6 +226,32 @@
 tkbdn[5]:= ord(wheelUp);
 wheelUp:= false;
 wheelDown:= false;
+{$IFDEF IPHONEOS}
+tkbdn[1]:= ord(leftClick);
+tkbdn[2]:= ord(middleClick);
+tkbdn[3]:= ord(rightClick);
+leftClick:= false;
+middleClick:= false;
+rightClick:= false;
+
+{*
+tkbdn[273]:= ord(upKey);
+tkbdn[274]:= ord(downKey);
+tkbdn[275]:= ord(rightKey);
+tkbdn[276]:= ord(leftKey);
+
+tkbdn[32]:= ord(spaceKey);
+tkbdn[13]:= ord(enterKey);
+
+upKey:= false;
+downKey:= false;
+rightKey:= false;
+leftKey:= false;
+
+spaceKey:= false;
+enterKey:= false;
+*}
+{$ENDIF}
 
 // Controller(s)
 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
@@ -305,7 +370,7 @@
 procedure FreezeEnterKey;
 begin
 tkbd[13]:= 1;
-tkbd[271]:= 1
+tkbd[271]:= 1;
 end;
 
 var Controller: array [0..5] of PSDLJoystick;
--- a/hedgewars/uStore.pas	Tue Oct 20 11:49:10 2009 +0000
+++ b/hedgewars/uStore.pas	Tue Oct 20 17:55:11 2009 +0000
@@ -589,7 +589,7 @@
 
 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
 begin
-DrawTexture(X - Source^.w div 2, Top, Source)
+DrawTexture(X - Source^.w shr 1, Top, Source)
 end;
 
 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
--- a/hedgewars/uWorld.pas	Tue Oct 20 11:49:10 2009 +0000
+++ b/hedgewars/uWorld.pas	Tue Oct 20 17:55:11 2009 +0000
@@ -319,6 +319,8 @@
     tdx, tdy: Double;
     grp: TCapGroup;
     s: string[15];
+    x,y: LongInt;
+    offset: LongInt;
 begin
 if ZoomValue < zoom then
 	begin
@@ -338,6 +340,11 @@
 //glPushMatrix;
 //glScalef(1.0, 1.0, 1.0);
 
+{$IFDEF IPHONEOS}
+{* see the code in MainLoop *}
+SDL_GetMouseState(0, @x, @y);
+if (x > 100) and (x < 220) and (y > 200) and (y < 280) then
+{$ENDIF}
 if not isPaused then MoveCamera;
 
 if not cReducedQuality then
@@ -388,7 +395,7 @@
 
 // Waves
 DrawWaves( 1, 25, - cWaveHeight);
-DrawWaves(-1, 50, - (cWaveHeight div 2));
+DrawWaves(-1, 50, - (cWaveHeight shr 1));
 DrawWaves( 1, 75, 0);
 
 
@@ -399,6 +406,11 @@
 {$WARNINGS ON}
 SetScale(2.0);
 
+{$IFDEF IPHONEOS}
+offset:= 465;
+{$ELSE}
+offset:= 48;
+{$ENDIF}
 // Turn time
 if TurnTimeLeft <> 0 then
    begin
@@ -406,16 +418,17 @@
    if i>99 then t:= 112
       else if i>9 then t:= 96
                   else t:= 80;
-   DrawSprite(sprFrame, -cScreenWidth div 2 + t, cScreenHeight - 48, 1);
+   DrawSprite(sprFrame, -cScreenWidth div 2 + t, cScreenHeight - offset, 1);
    while i > 0 do
          begin
          dec(t, 32);
-         DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, cScreenHeight - 48, i mod 10);
+         DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, cScreenHeight - offset, i mod 10);
          i:= i div 10
          end;
-   DrawSprite(sprFrame, -cScreenWidth div 2 + t - 4, cScreenHeight - 48, 0);
+   DrawSprite(sprFrame, -cScreenWidth div 2 + t - 4, cScreenHeight - offset, 0);
    end;
 
+{$IFNDEF IPHONEOS}
 // Timetrial
 if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then
 	begin
@@ -459,9 +472,14 @@
 	// left frame
 	DrawSprite(sprFrame, -cScreenWidth div 2 + t - 4, 8, 0);
 	end;
-   
+{$ENDIF}
+
 // Captions
+{$IFDEF IPHONEOS}
+i:= 53;
+{$ELSE}
 if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then i:= 48 else i:= 8;
+{$ENDIF}
 
 for grp:= Low(TCapGroup) to High(TCapGroup) do
     with Captions[grp] do
@@ -497,10 +515,15 @@
       end;
 
 // Lag alert
-if isInLag then DrawSprite(sprLag, 32 - cScreenWidth div 2, 32, (RealTicks shr 7) mod 12);
+if isInLag then DrawSprite(sprLag, 32 - (cScreenWidth shr 1), 32, (RealTicks shr 7) mod 12);
 
 // Wind bar
-DrawSprite(sprWindBar, cScreenWidth div 2 - 180, cScreenHeight - 30, 0);
+{$IFDEF IPHONEOS}
+offset:= 450;
+{$ELSE}
+offset:= 30;
+{$ENDIF}
+DrawSprite(sprWindBar, (cScreenWidth shr 1) - 180, cScreenHeight - offset, 0);
 if WindBarWidth > 0 then
    begin
    {$WARNINGS OFF}
@@ -509,7 +532,7 @@
    r.y:= 0;
    r.w:= WindBarWidth;
    r.h:= 13;
-   DrawSpriteFromRect(sprWindR, r, cScreenWidth div 2 - 103, cScreenHeight - 28, 13, 0);
+   DrawSpriteFromRect(sprWindR, r, (cScreenWidth shr 1) - 103, cScreenHeight - offset - 2, 13, 0);
    end else
  if WindBarWidth < 0 then
    begin
@@ -519,7 +542,7 @@
    r.y:= 0;
    r.w:= - WindBarWidth;
    r.h:= 13;
-   DrawSpriteFromRect(sprWindL, r, cScreenWidth div 2 - 106 + WindBarWidth, cScreenHeight - 28, 13, 0);
+   DrawSpriteFromRect(sprWindL, r, (cScreenWidth shr 1) - 106 + WindBarWidth, cScreenHeight - offset - 2, 13, 0);
    end;
 
 // AmmoMenu
@@ -529,10 +552,13 @@
 if isCursorVisible and bShowAmmoMenu then
    DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
 
+{$IFNDEF IPHONEOS}
+{* do not draw the chat because a) no input b) too little space*}
 DrawChat;
+{$ENDIF}
 
-if fastUntilLag then DrawCentered(0, cScreenHeight div 2, SyncTexture);
-if isPaused then DrawCentered(0, cScreenHeight div 2, PauseTexture);
+if fastUntilLag then DrawCentered(0, (cScreenHeight shr 1), SyncTexture);
+if isPaused then DrawCentered(0, (cScreenHeight shr 1), PauseTexture);
 
 inc(Frames);
 if cShowFPS then
@@ -550,7 +576,7 @@
       SDL_FreeSurface(tmpSurface)
       end;
    if fpsTexture <> nil then
-      DrawTexture(cScreenWidth div 2 - 50, 10, fpsTexture);
+      DrawTexture((cScreenWidth shr 1) - 50, 10, fpsTexture);
    end;
 
 inc(SoundTimerTicks, Lag);
@@ -615,7 +641,7 @@
 {$ELSE}
 	SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y);
 {$ENDIF}
-	CursorPoint.X:= CursorPoint.X - cScreenWidth div 2;
+	CursorPoint.X:= CursorPoint.X - (cScreenWidth shr 1);
 	CursorPoint.Y:= cScreenHeight - CursorPoint.Y;
 	end;
 
@@ -690,7 +716,7 @@
       end;
 
 prevPoint:= CursorPoint;
-if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
+if cHasFocus then SDL_WarpMouse(CursorPoint.X + (cScreenWidth shr 1), cScreenHeight - CursorPoint.Y);
 if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024;
 if WorldDy < wdy then WorldDy:= wdy;
 if WorldDx < - LAND_WIDTH - 1024 then WorldDx:= - LAND_WIDTH - 1024;