fix coordinate system on ios overlay
authorkoda
Sat, 11 Feb 2012 05:13:56 +0100
changeset 6666 0e2f5b81cbf2
parent 6665 12e809cc5c3f
child 6667 142fe596e75e
fix coordinate system on ios overlay
project_files/HedgewarsMobile/Classes/CGPointUtils.h
project_files/HedgewarsMobile/Classes/OverlayViewController.m
--- a/project_files/HedgewarsMobile/Classes/CGPointUtils.h	Sat Feb 11 04:27:58 2012 +0100
+++ b/project_files/HedgewarsMobile/Classes/CGPointUtils.h	Sat Feb 11 05:13:56 2012 +0100
@@ -24,11 +24,11 @@
 #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)/HW_zoomFactor()
-#define HWY(x) (int)(screen.size.width-x)/HW_zoomFactor() + (IS_IPAD()?40:17.5)*HW_zoomLevel()/HW_zoomFactor()
+#define HWX(x) (int)(x-screen.size.width/2)/HW_zoomFactor()
+#define HWY(x) (int)(screen.size.height-x)/HW_zoomFactor()+(IS_IPAD()?40:17.5)*HW_zoomLevel()/HW_zoomFactor()
 
-#define HWXZ(x) (int)(x-screen.size.height/2)
-#define HWYZ(x) (int)(screen.size.width-x)
+#define HWXZ(x) (int)(x-screen.size.width/2)
+#define HWYZ(x) (int)(screen.size.height-x)
 
 CGFloat distanceBetweenPoints (CGPoint first, CGPoint second);
 CGFloat angleBetweenPoints(CGPoint first, CGPoint second);
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Sat Feb 11 04:27:58 2012 +0100
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Sat Feb 11 05:13:56 2012 +0100
@@ -287,7 +287,7 @@
 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
 // on iphone instead just use the tableViewController directly (and implement manually all animations)
 -(IBAction) showPopover{
-    CGRect screen = [[UIScreen mainScreen] bounds];
+    CGRect screen = [[UIScreen mainScreen] safeBounds];
     isPopoverVisible = YES;
 
     if (IS_IPAD()) {
@@ -299,7 +299,7 @@
             [self.popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
         }
 
-        [self.popoverController presentPopoverFromRect:CGRectMake(screen.size.height / 2, screen.size.width / 2, 1, 1)
+        [self.popoverController presentPopoverFromRect:CGRectMake(screen.size.width / 2, screen.size.height / 2, 1, 1)
                                            inView:self.view
                          permittedArrowDirections:UIPopoverArrowDirectionAny
                                          animated:YES];
@@ -336,10 +336,10 @@
 
     // ignore activity near the dpad and buttons
     CGPoint touchPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
-    CGSize screen = [[UIScreen mainScreen] bounds].size;
+    CGSize screen = [[UIScreen mainScreen] safeBounds].size;
 
-    if ((touchPoint.x < 160 && touchPoint.y > screen.width - 155 ) || 
-        (touchPoint.x > screen.height - 135 && touchPoint.y > screen.width - 140))
+    if ((touchPoint.x < 160 && touchPoint.y > screen.height - 155 ) ||
+        (touchPoint.x > screen.width - 135 && touchPoint.y > screen.height - 140))
         return YES;
     return NO;
 }
@@ -386,14 +386,14 @@
     if ([self shouldIgnoreTouch:allTouches] == YES)
         return;
 
-    CGRect screen = [[UIScreen mainScreen] bounds];
+    CGRect screen = [[UIScreen mainScreen] safeBounds];
     CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
 
     switch ([allTouches count]) {
         case 1:
             // if we're in the menu we just click in the point
             if (HW_isAmmoMenuOpen()) {
-                HW_setCursor(HWXZ(currentPosition.x), HWYZ(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
@@ -479,7 +479,7 @@
     if ([self shouldIgnoreTouch:allTouches] == YES)
         return;
 
-    CGRect screen = [[UIScreen mainScreen] bounds];
+    CGRect screen = [[UIScreen mainScreen] safeBounds];
     int x, y, dx, dy;
     UITouch *touch, *first, *second;