changeset 1492:1608c2a9c2b8

Initial attempt at gravity obstacles on Mac.... doesn't work was trying to debug but XCode 4.0 is crashing, so going to try with 4.2 on Lion.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 25 Dec 2011 02:59:51 +0000
parents d77b8cf25f04
children ac43d9a9eee7
files mac/dw.m
diffstat 1 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Sat Dec 24 18:57:46 2011 +0000
+++ b/mac/dw.m	Sun Dec 25 02:59:51 2011 +0000
@@ -8536,6 +8536,8 @@
 {
     int horz = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_horz"));
     int vert = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_vert"));
+    NSRect visiblerect = [[NSScreen mainScreen] visibleFrame];
+    NSRect totalrect = [[NSScreen mainScreen] frame];
     
     /* Do any gravity calculations */
     if(horz || (vert & 0xf) != DW_GRAV_BOTTOM)
@@ -8557,7 +8559,22 @@
         /* Save the new values */
         *x = newx;
         *y = newy;
-    }            
+    }   
+    /* Adjust the values to avoid Dock/Menubar if requested */
+    if(horz & DW_GRAV_OBSTACLES)
+    {
+        if((horz & 0xf) == DW_GRAV_LEFT)
+            *x += visiblerect.origin.x;
+        else if((horz & 0xf) == DW_GRAV_RIGHT)
+            *x -= (totalrect.origin.x + totalrect.size.width) - (visiblerect.origin.x + visiblerect.size.width);
+    }
+    if(vert & DW_GRAV_OBSTACLES)
+    {
+        if((vert & 0xf) == DW_GRAV_BOTTOM)
+            *y += visiblerect.origin.y;
+        else if((vert & 0xf) == DW_GRAV_RIGHT)
+            *y -= (totalrect.origin.y + totalrect.size.height) - (visiblerect.origin.y + visiblerect.size.height);
+    }
 }
 
 /*