Changed firebutton, parameters in uTouch might need to be tweaked some more hedgeroid
authorXeli
Fri, 16 Sep 2011 17:36:05 +0200
branchhedgeroid
changeset 5828 667fb58d7f18
parent 5826 2a2cce052b4d
child 5932 5164d17b6374
Changed firebutton, parameters in uTouch might need to be tweaked some more
hedgewars/uTouch.pas
hedgewars/uWorld.pas
--- a/hedgewars/uTouch.pas	Wed Sep 14 18:43:16 2011 +0200
+++ b/hedgewars/uTouch.pas	Fri Sep 16 17:36:05 2011 +0200
@@ -60,7 +60,12 @@
 const
     clicktime = 200;
     nilFingerId = High(SDL_FingerId);
+
 var
+    fireButtonLeft, fireButtonRight, fireButtonTop, fireButtonBottom : LongInt;
+        
+
+
     leftButtonBoundary  : LongInt;
     rightButtonBoundary : LongInt;
     topButtonBoundary   : LongInt;
@@ -138,6 +143,7 @@
         begin
             aiming:= false;
             stopFiring:= true;
+            moveCursor:= false;
             pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^);
             baseZoomValue := ZoomValue
         end;
@@ -148,42 +154,46 @@
 var
     finger, secondFinger: PTouch_Finger;
     currentPinchDelta, zoom : hwFloat;
+    tmpX, tmpY: LongInt;
 begin
     finger:= findFinger(pointerId);
-
-    finger^.x := convertToCursor(cScreenWidth, x);
-    finger^.y := convertToCursor(cScreenHeight, y);
+    tmpX := convertToCursor(cScreenWidth, x);
+    tmpY := convertToCursor(cScreenHeight, y);
 
-    case pointerCount of
-       1:
-           begin
-               if aiming then 
-               begin
-                   aim(finger^);
-                   exit
-               end;
-               if moveCursor then
-                   if invertCursor then
-                   begin
-                       CursorPoint.X := CursorPoint.X - convertToCursor(cScreenWidth,dx);
-                       CursorPoint.Y := CursorPoint.Y + convertToCursor(cScreenWidth,dy);
-                   end
-                   else
-                   begin
-                       CursorPoint.X := CursorPoint.X + convertToCursor(cScreenWidth,dx);
-                       CursorPoint.Y := CursorPoint.Y - convertToCursor(cScreenWidth,dy);
-                   end;
-           end;
-       2:
-           begin
-               secondFinger := getSecondFinger(finger^);
-               currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
-               zoom := currentPinchDelta/cScreenWidth;
-               ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
-               if ZoomValue < cMaxZoomLevel then ZoomValue := cMaxZoomLevel;
-               if ZoomValue > cMinZoomLevel then ZoomValue := cMinZoomLevel;
-            end;
-    end; //end case pointerCount of
+    if moveCursor then
+    begin
+        if invertCursor then
+        begin
+            CursorPoint.X := CursorPoint.X + (finger^.x - tmpX);
+            CursorPoint.Y := CursorPoint.Y - (finger^.y - tmpY);
+        end
+        else
+        begin
+            CursorPoint.X := CursorPoint.X - (finger^.x - tmpX);
+            CursorPoint.Y := CursorPoint.Y + (finger^.y - tmpY);
+        end;
+        finger^.x := tmpX;
+        finger^.y := tmpY;
+        exit //todo change into switch rather than ugly ifs
+    end;
+    
+    finger^.x := tmpX;
+    finger^.y := tmpY;
+    
+    if aiming then 
+    begin
+        aim(finger^);
+        exit
+    end;
+    if pointerCount = 2 then
+    begin
+       secondFinger := getSecondFinger(finger^);
+       currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
+       zoom := currentPinchDelta/cScreenWidth;
+       ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
+       if ZoomValue < cMaxZoomLevel then ZoomValue := cMaxZoomLevel;
+       if ZoomValue > cMinZoomLevel then ZoomValue := cMinZoomLevel;
+    end;
 end;
 
 procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId);
@@ -402,10 +412,7 @@
 
 function isOnFireButton(finger: Touch_Finger): boolean;
 begin
-    printFinger(finger);
-    WriteToConsole(Format('%d %d ',[round((-cScreenWidth+20)/0.8), round((cScreenHeight+55)/0.8)]));
-    WriteToConsole(Format('%d, %d',[cScreenWidth, cScreenHeight]));
-    isOnFireButton:= (finger.x < 205) and (finger.y > 420);
+    isOnFireButton:= (finger.x <= fireButtonRight) and (finger.x >= fireButtonLeft) and (finger.y <= fireButtonBottom) and (finger.y >= fireButtonTop);
 end;
 
 function isOnCrosshair(finger: Touch_Finger): boolean;
@@ -464,7 +471,7 @@
 
 procedure initModule;
 var
-    index: Longword;
+    index, uRenderCoordScaleX, uRenderCoordScaleY: Longword;
 begin
     movingCrosshair := false;
     stopFiring:= false;
@@ -478,6 +485,13 @@
     setLength(fingers, 4);
     for index := 0 to High(fingers) do 
         fingers[index].id := nilFingerId;
+
+
+    uRenderCoordScaleX := Round(cScreenWidth/0.8 * 2);
+    fireButtonLeft := Round(cScreenWidth*0.01);
+    fireButtonRight := Round(fireButtonLeft + (spritesData[sprFireButton].Width*0.4));
+    fireButtonBottom := Round(cScreenHeight*0.99);
+    fireButtonTop := fireButtonBottom - Round(spritesData[sprFireButton].Height*0.4);
 end;
 
 begin
--- a/hedgewars/uWorld.pas	Wed Sep 14 18:43:16 2011 +0200
+++ b/hedgewars/uWorld.pas	Fri Sep 16 17:36:05 2011 +0200
@@ -913,9 +913,10 @@
 // Captions
 DrawCaptions;
 
-// Draw buttons
-SetScale(0.8);
-DrawSprite(sprFireButton, round((-cScreenWidth+20)/0.8),round((cScreenHeight+55)/0.8),0);
+// Draw buttons Related to the Touch interface
+//SetScale(0.8);
+//DrawSprite(sprFireButton, round(-cScreenWidth/0.8),round(cScreenHeight/0.8), 0);
+DrawTexture(Round(-cScreenWidth*0.5 + cScreenHeight*0.02),Round((cScreenHeight*0.98)-(spritesData[sprFireButton].Height*0.4) ),spritesData[sprFireButton].Texture, 0.4);
 SetScale(cDefaultZoomLevel);
 
 // Teams Healths