fix panning when zoomed (finally)
authorkoda
Sat, 31 Jul 2010 10:39:20 +0200
changeset 3680 aaf832c6fbd7
parent 3678 00428183300f
child 3693 09892cdb8f95
fix panning when zoomed (finally)
.hgeol
hedgewars/CCHandlers.inc
hedgewars/CMakeLists.txt
hedgewars/PascalExports.pas
hedgewars/uMisc.pas
hedgewars/uWorld.pas
project_files/HedgewarsMobile/Classes/CGPointUtils.h
project_files/HedgewarsMobile/Classes/OverlayViewController.m
project_files/HedgewarsMobile/Classes/PascalImports.h
--- a/.hgeol	Sat Jul 31 08:19:56 2010 +0200
+++ b/.hgeol	Sat Jul 31 10:39:20 2010 +0200
@@ -1,6 +1,7 @@
 [patterns]
 **.h = native
 **.c = native
+**.m = native
 **.cpp = native
 **.lua = native
 **.txt = native
--- a/hedgewars/CCHandlers.inc	Sat Jul 31 08:19:56 2010 +0200
+++ b/hedgewars/CCHandlers.inc	Sat Jul 31 10:39:20 2010 +0200
@@ -824,13 +824,13 @@
 
 procedure chChat(var s: shortstring);
 begin
-s:= s; // avoid compiler hint
-GameState:= gsChat;
-KeyPressChat(27)
+    s:= s; // avoid compiler hint
+    GameState:= gsChat;
+    KeyPressChat(27)
 end;
 
 procedure chHistory(var s: shortstring);
 begin
-s:= s; // avoid compiler hint
-uChat.showAll:= not uChat.showAll
+    s:= s; // avoid compiler hint
+    uChat.showAll:= not uChat.showAll
 end;
--- a/hedgewars/CMakeLists.txt	Sat Jul 31 08:19:56 2010 +0200
+++ b/hedgewars/CMakeLists.txt	Sat Jul 31 10:39:20 2010 +0200
@@ -74,6 +74,7 @@
 	GearDrawing.inc
 	HHHandlers.inc
 	SinTable.inc
+	ArgParsers.inc
 	options.inc
 	${CMAKE_CURRENT_BINARY_DIR}/config.inc
 	)
--- a/hedgewars/PascalExports.pas	Sat Jul 31 08:19:56 2010 +0200
+++ b/hedgewars/PascalExports.pas	Sat Jul 31 10:39:20 2010 +0200
@@ -54,6 +54,17 @@
         followGear:= CurrentHedgehog^.Gear;
 end;
 
+function HW_zoomFactor: GLfloat; cdecl; export;
+begin
+    exit( ZoomValue / cDefaultZoomLevel );
+end;
+
+function HW_zoomLevel: LongInt; cdecl; export;
+begin
+    writelntoconsole(inttostr(trunc((ZoomValue - cDefaultZoomLevel) / cZoomDelta) ));
+    exit( trunc((ZoomValue - cDefaultZoomLevel) / cZoomDelta) );
+end;
+
 procedure HW_ammoMenu; cdecl; export;
 begin
     rightClick:= true;
--- a/hedgewars/uMisc.pas	Sat Jul 31 08:19:56 2010 +0200
+++ b/hedgewars/uMisc.pas	Sat Jul 31 10:39:20 2010 +0200
@@ -257,12 +257,12 @@
 begin
 // obsolete? written in WriteLnToConsole() anyway
 // {$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF}
-WriteLnToConsole(Msg);
-if isFatalError then
+    WriteLnToConsole(Msg);
+    if isFatalError then
     begin
-    SendIPC('E' + GetLastConsoleLine);
-    SDL_Quit;
-    halt(1)
+        SendIPC('E' + GetLastConsoleLine);
+        SDL_Quit;
+        halt(1)
     end
 end;
 
--- a/hedgewars/uWorld.pas	Sat Jul 31 08:19:56 2010 +0200
+++ b/hedgewars/uWorld.pas	Sat Jul 31 10:39:20 2010 +0200
@@ -1019,15 +1019,16 @@
 
 if (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not fastUntilLag) then
     if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then
-        begin
+    begin
         FollowGear:= nil;
         prevPoint:= CursorPoint;
         exit
-        end
-        else begin
+    end
+    else
+    begin
         CursorPoint.X:= (prevPoint.X * 7 + hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100 + WorldDx) div 8;
         CursorPoint.Y:= (prevPoint.Y * 7 + cScreenHeight - (hwRound(FollowGear^.Y) + WorldDy)) div 8;
-        end;
+    end;
 
 wdy:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine - cVisibleWater;
 if WorldDy < wdy then WorldDy:= wdy;
@@ -1035,7 +1036,7 @@
 if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then exit;
 
 if AMxShift < AMWidth then
-    begin
+begin
 {$IFDEF IPHONEOS}
     if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth;
     if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset;
@@ -1050,50 +1051,56 @@
     prevPoint:= CursorPoint;
     if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
     exit
-    end;
+end;
 
 if isCursorVisible then
-    begin
+begin
     if (not CurrentTeam^.ExtDriven) and (GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
-        begin
+    begin
         SendIPCXY('P', CursorPoint.X - WorldDx, cScreenHeight - CursorPoint.Y - WorldDy);
         PrevSentPointTime:= GameTicks
+    end;
+    EdgesDist:= cCursorEdgesDist
+end
+else
+    EdgesDist:= cGearScrEdgesDist;
+
+// this generates the border around the screen that moves the camera when cursor is near it
+if isCursorVisible or (FollowGear <> nil) then
+begin
+    if CursorPoint.X < - cScreenWidth div 2 + EdgesDist then
+    begin
+        WorldDx:= WorldDx - CursorPoint.X - cScreenWidth div 2 + EdgesDist;
+        CursorPoint.X:= - cScreenWidth div 2 + EdgesDist
+    end
+    else
+        if CursorPoint.X > cScreenWidth div 2 - EdgesDist then
+        begin
+            WorldDx:= WorldDx - CursorPoint.X + cScreenWidth div 2 - EdgesDist;
+            CursorPoint.X:= cScreenWidth div 2 - EdgesDist
         end;
+    if CursorPoint.Y < EdgesDist then
+    begin
+        WorldDy:= WorldDy + CursorPoint.Y - EdgesDist;
+        CursorPoint.Y:= EdgesDist
+    end
+    else
+        if CursorPoint.Y > cScreenHeight - EdgesDist then
+        begin
+           WorldDy:= WorldDy + CursorPoint.Y - cScreenHeight + EdgesDist;
+           CursorPoint.Y:= cScreenHeight - EdgesDist
+        end;
+end
+else
+    if cHasFocus then
+    begin
+        WorldDx:= WorldDx - CursorPoint.X + prevPoint.X;
+        WorldDy:= WorldDy + CursorPoint.Y - prevPoint.Y;
+        CursorPoint.X:= 0;
+        CursorPoint.Y:= cScreenHeight div 2;
     end;
 
-if isCursorVisible or (FollowGear <> nil) then
-   begin
-   if isCursorVisible then EdgesDist:= cCursorEdgesDist
-                      else EdgesDist:= cGearScrEdgesDist;
-   if CursorPoint.X < - cScreenWidth div 2 + EdgesDist then
-         begin
-         WorldDx:= WorldDx - CursorPoint.X - cScreenWidth div 2 + EdgesDist;
-         CursorPoint.X:= - cScreenWidth div 2 + EdgesDist
-         end else
-      if CursorPoint.X > cScreenWidth div 2 - EdgesDist then
-         begin
-         WorldDx:= WorldDx - CursorPoint.X + cScreenWidth div 2 - EdgesDist;
-         CursorPoint.X:= cScreenWidth div 2 - EdgesDist
-         end;
-      if CursorPoint.Y < EdgesDist then
-         begin
-         WorldDy:= WorldDy + CursorPoint.Y - EdgesDist;
-         CursorPoint.Y:= EdgesDist
-         end else
-      if CursorPoint.Y > cScreenHeight - EdgesDist then
-         begin
-         WorldDy:= WorldDy + CursorPoint.Y - cScreenHeight + EdgesDist;
-         CursorPoint.Y:= cScreenHeight - EdgesDist
-         end;
-   end else
-   if cHasFocus then
-      begin
-      WorldDx:= WorldDx - CursorPoint.X + prevPoint.X;
-      WorldDy:= WorldDy + CursorPoint.Y - prevPoint.Y;
-      CursorPoint.X:= 0;
-      CursorPoint.Y:= cScreenHeight div 2;
-      end;
-
+// this moves the camera according to CursorPoint X and Y
 prevPoint:= CursorPoint;
 if cHasFocus then SDL_WarpMouse(CursorPoint.X + (cScreenWidth shr 1), cScreenHeight - CursorPoint.Y);
 if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024;
--- a/project_files/HedgewarsMobile/Classes/CGPointUtils.h	Sat Jul 31 08:19:56 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/CGPointUtils.h	Sat Jul 31 10:39:20 2010 +0200
@@ -9,12 +9,16 @@
 
 #import <CoreGraphics/CoreGraphics.h>
 
-#define degreesToRadian(x)  (M_PI * x / 180.0)
-#define radiansToDegrees(x) (180.0 * x / M_PI)
+#define degreesToRadians(x) ( M_PI * x / 180.0)
+#define radiansToDegrees(x) (180.0 * x / M_PI )
 
-#define HWX(x) (int)(x-screen.size.height/2)
-#define HWY(x) (int)(screen.size.width-x)
+// 40 is not a good value for iphone but works for ipad
+#define HWX(x) (int)(x-screen.size.height/2)/HW_zoomFactor()
+#define HWY(x) (int)(screen.size.width-x)/HW_zoomFactor() + 40*HW_zoomLevel()/HW_zoomFactor()
+
+#define HWXZ(x) (int)(x-screen.size.height/2)
+#define HWYZ(x) (int)(screen.size.width-x)
 
 CGFloat distanceBetweenPoints (CGPoint first, CGPoint second);
 CGFloat angleBetweenPoints(CGPoint first, CGPoint second);
-CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint lin2End);
+CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End);
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Sat Jul 31 08:19:56 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Sat Jul 31 10:39:20 2010 +0200
@@ -43,13 +43,13 @@
     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
     switch (orientation) {
         case UIDeviceOrientationLandscapeLeft:
-            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
-            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
+            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
+            self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
             HW_setLandscape(YES);
             break;
         case UIDeviceOrientationLandscapeRight:
-            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
-            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
+            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
+            self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
             HW_setLandscape(YES);
             break;
         /*
@@ -90,12 +90,12 @@
     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
     switch (orientation) {
         case UIDeviceOrientationLandscapeLeft:
-            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
-            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
+            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
+            self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
             break;
         case UIDeviceOrientationLandscapeRight:
-            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
-            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
+            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
+            self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
             break;
         default:
             break;
@@ -360,7 +360,7 @@
         case 1:
             // if we're in the menu we just click in the point
             if (HW_isAmmoOpen()) {
-                HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
+                HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y));
                 // this click doesn't need any wrapping because the ammoMenu already limits the cursor
                 HW_click();
             } else 
@@ -462,20 +462,26 @@
             touch = [[allTouches allObjects] objectAtIndex:0];
             CGPoint currentPosition = [touch locationInView:self.view];
 
-            if (HW_isAmmoOpen() || HW_isWeaponRequiringClick()) {
-                // moves the cursor around
-                HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
-            } else {
-                // panning \o/
-                dx = startingPoint.x - currentPosition.x;
-                dy = currentPosition.y - startingPoint.y;
-                HW_getCursor(&x, &y);
-                // momentum (or something like that)
-                if (abs(dx) > 40) dx *= log(abs(dx)/4);
-                if (abs(dy) > 40) dy *= log(abs(dy)/4);
-                HW_setCursor(x + dx, y + dy);
-                startingPoint = currentPosition;
-            }
+            if (HW_isAmmoOpen()) {
+                // no zoom consideration for this
+                HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y));
+            } else
+                if (HW_isWeaponRequiringClick()) {
+                    // moves the cursor around wrt zoom
+                    HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
+                } else {
+                    // panning \o/
+                    dx = startingPoint.x - currentPosition.x;
+                    dy = currentPosition.y - startingPoint.y;
+                    HW_getCursor(&x, &y);
+                    // momentum (or something like that)
+                    /*if (abs(dx) > 40)
+                        dx *= log(abs(dx)/4);
+                    if (abs(dy) > 40)
+                        dy *= log(abs(dy)/4);*/
+                    HW_setCursor(x + dx/HW_zoomFactor(), y + dy/HW_zoomFactor());
+                    startingPoint = currentPosition;
+                }
             break;
         case 2:
             first = [[allTouches allObjects] objectAtIndex:0];
--- a/project_files/HedgewarsMobile/Classes/PascalImports.h	Sat Jul 31 08:19:56 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/PascalImports.h	Sat Jul 31 10:39:20 2010 +0200
@@ -58,6 +58,9 @@
 
     void HW_setPianoSound(int snd);
     
+    float HW_zoomFactor(void);
+    int HW_zoomLevel(void);
+    
     BOOL HW_isAmmoOpen(void);
     BOOL HW_isPaused(void);
     BOOL HW_isWeaponRequiringClick(void);