Bläddra i källkod

Merge pull request #672 from kwhatmough/next

Fixes #655. Also fixes setVisible(false) for 2D controls.
Sean Paul Taylor 13 år sedan
förälder
incheckning
48d283d96a
3 ändrade filer med 80 tillägg och 12 borttagningar
  1. 2 1
      gameplay/src/Form.cpp
  2. 61 10
      gameplay/src/PlatformLinux.cpp
  3. 17 1
      gameplay/src/PlatformMacOSX.mm

+ 2 - 1
gameplay/src/Form.cpp

@@ -561,7 +561,8 @@ void Form::draw()
 
 
         GP_ASSERT(_theme);
         GP_ASSERT(_theme);
         _theme->setProjectionMatrix(_projectionMatrix);
         _theme->setProjectionMatrix(_projectionMatrix);
-        Container::draw(_theme->getSpriteBatch(), Rectangle(0, 0, _bounds.width, _bounds.height), _skin != NULL, false, _bounds.height);
+        Container::draw(_theme->getSpriteBatch(), Rectangle(0, 0, _bounds.width, _bounds.height),
+                        true/*WAS _skin!=NULL*/, false, _bounds.height);
         _theme->setProjectionMatrix(_defaultProjectionMatrix);
         _theme->setProjectionMatrix(_defaultProjectionMatrix);
 
 
         // Rebind the default framebuffer and game viewport.
         // Rebind the default framebuffer and game viewport.

+ 61 - 10
gameplay/src/PlatformLinux.cpp

@@ -24,6 +24,9 @@ static double __timeAbsolute;
 static bool __vsync = WINDOW_VSYNC;
 static bool __vsync = WINDOW_VSYNC;
 static float __pitch;
 static float __pitch;
 static float __roll;
 static float __roll;
+static bool __mouseCaptured = false;
+static float __mouseCapturePointX = 0;
+static float __mouseCapturePointY = 0;
 static bool __cursorVisible = true;
 static bool __cursorVisible = true;
 static Display* __display;
 static Display* __display;
 static Window   __window;
 static Window   __window;
@@ -862,25 +865,45 @@ int Platform::enterMessagePump()
         
         
             case MotionNotify:
             case MotionNotify:
                 {
                 {
-                    if (!gameplay::Platform::mouseEventInternal(gameplay::Mouse::MOUSE_MOVE, evt.xmotion.x, evt.xmotion.y, 0))
+                    int x = evt.xmotion.x;
+                    int y = evt.xmotion.y;
+
+                    if (__mouseCaptured)
+                    {
+                        if (x == __mouseCapturePointX && y == __mouseCapturePointY)
+                        {
+                            // Discard the first MotionNotify following capture
+                            // since it contains bogus x,y data.
+                            break;
+                        }
+
+                        // Convert to deltas
+                        x -= __mouseCapturePointX;
+                        y -= __mouseCapturePointY;
+
+                        // Warp mouse back to center of screen.
+                        XWarpPointer(__display, None, __window, 0, 0, 0, 0, __mouseCapturePointX, __mouseCapturePointY);
+                    }
+
+                    if (!gameplay::Platform::mouseEventInternal(gameplay::Mouse::MOUSE_MOVE, x, y, 0))
                     {
                     {
                         if (evt.xmotion.state & Button1Mask)
                         if (evt.xmotion.state & Button1Mask)
                         {
                         {
-                            gameplay::Platform::touchEventInternal(gameplay::Touch::TOUCH_MOVE, evt.xmotion.x, evt.xmotion.y, 0);
+                            gameplay::Platform::touchEventInternal(gameplay::Touch::TOUCH_MOVE, x, y, 0);
                         }
                         }
                         else if (evt.xmotion.state & Button3Mask)
                         else if (evt.xmotion.state & Button3Mask)
                         {
                         {
                             // Update the pitch and roll by adding the scaled deltas.
                             // Update the pitch and roll by adding the scaled deltas.
-                            __roll += (float)(evt.xbutton.x - lx) * ACCELEROMETER_X_FACTOR;
-                            __pitch += -(float)(evt.xbutton.y - ly) * ACCELEROMETER_Y_FACTOR;
+                            __roll += (float)(x - lx) * ACCELEROMETER_X_FACTOR;
+                            __pitch += -(float)(y - ly) * ACCELEROMETER_Y_FACTOR;
 
 
                             // Clamp the values to the valid range.
                             // Clamp the values to the valid range.
                             __roll = max(min(__roll, 90.0f), -90.0f);
                             __roll = max(min(__roll, 90.0f), -90.0f);
                             __pitch = max(min(__pitch, 90.0f), -90.0f);
                             __pitch = max(min(__pitch, 90.0f), -90.0f);
 
 
                             // Update the last X/Y values.
                             // Update the last X/Y values.
-                            lx = evt.xbutton.x;
-                            ly = evt.xbutton.y;
+                            lx = x;
+                            ly = y;
                         }
                         }
                     }
                     }
                 }
                 }
@@ -992,13 +1015,31 @@ bool Platform::hasMouse()
 
 
 void Platform::setMouseCaptured(bool captured)
 void Platform::setMouseCaptured(bool captured)
 {
 {
-    // TODO
+    if (captured != __mouseCaptured)
+    {
+        if (captured)
+        {
+            // Hide the cursor and warp it to the center of the screen
+            __mouseCapturePointX = getDisplayWidth() / 2;
+            __mouseCapturePointY = getDisplayHeight() / 2;
+
+            setCursorVisible(false);
+            XWarpPointer(__display, None, __window, 0, 0, 0, 0, __mouseCapturePointX, __mouseCapturePointY);
+        }
+        else
+        {
+            // Restore cursor
+            XWarpPointer(__display, None, __window, 0, 0, 0, 0, __mouseCapturePointX, __mouseCapturePointY);
+            setCursorVisible(true);
+        }
+
+        __mouseCaptured = captured;
+    }
 }
 }
 
 
 bool Platform::isMouseCaptured()
 bool Platform::isMouseCaptured()
 {
 {
-    // TODO
-    return false;
+    return __mouseCaptured;
 }
 }
 
 
 void Platform::setCursorVisible(bool visible)
 void Platform::setCursorVisible(bool visible)
@@ -1007,7 +1048,17 @@ void Platform::setCursorVisible(bool visible)
     {
     {
         if (visible)
         if (visible)
         {
         {
-            XDefineCursor(__display, __window, None);
+            Cursor invisibleCursor;
+            Pixmap bitmapNoData;
+            XColor black;
+            static char noData[] = {0, 0, 0, 0, 0, 0, 0, 0};
+            black.red = black.green = black.blue = 0;
+            bitmapNoData = XCreateBitmapFromData(__display, __window, noData, 8, 8);
+            invisibleCursor = XCreatePixmapCursor(__display, bitmapNoData, bitmapNoData, &black, &black, 0, 0);
+
+            XDefineCursor(__display, __window, invisibleCursor);
+            XFreeCursor(__display, invisibleCursor);
+            XFreePixmap(__display, bitmapNoData);
         }
         }
         else
         else
         {
         {

+ 17 - 1
gameplay/src/PlatformMacOSX.mm

@@ -48,6 +48,7 @@ static char* __title = NULL;
 static bool __fullscreen = false;
 static bool __fullscreen = false;
 static void* __attachToWindow = NULL;
 static void* __attachToWindow = NULL;
 static bool __mouseCaptured = false;
 static bool __mouseCaptured = false;
+static bool __mouseCapturedFirstPass = false;
 static CGPoint __mouseCapturePoint;
 static CGPoint __mouseCapturePoint;
 static bool __cursorVisible = true;
 static bool __cursorVisible = true;
 static View* __view = NULL;
 static View* __view = NULL;
@@ -848,8 +849,17 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
 {
 {
     NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
     NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
     
     
+    float y;
     if (__mouseCaptured)
     if (__mouseCaptured)
     {
     {
+        if (__mouseCapturedFirstPass)
+        {
+            // Discard the first mouseMoved event following transition into capture
+            // since it contains bogus x,y data.
+            __mouseCapturedFirstPass = false;
+            return;
+        }
+
         point.x = [event deltaX];
         point.x = [event deltaX];
         point.y = [event deltaY];
         point.y = [event deltaY];
 
 
@@ -859,9 +869,14 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
         centerPoint.x = rect.origin.x + (rect.size.width / 2);
         centerPoint.x = rect.origin.x + (rect.size.width / 2);
         centerPoint.y = rect.origin.y + (rect.size.height / 2);
         centerPoint.y = rect.origin.y + (rect.size.height / 2);
         CGDisplayMoveCursorToPoint(CGDisplayPrimaryDisplay(NULL), centerPoint);
         CGDisplayMoveCursorToPoint(CGDisplayPrimaryDisplay(NULL), centerPoint);
+        y = point.y;
+    }
+    else
+    {
+        y = __height - point.y;
     }
     }
     
     
-    gameplay::Platform::mouseEventInternal(Mouse::MOUSE_MOVE, point.x, __height - point.y, 0);
+    gameplay::Platform::mouseEventInternal(Mouse::MOUSE_MOVE, point.x, y, 0);
 }
 }
 
 
 - (void) mouseDragged: (NSEvent*) event
 - (void) mouseDragged: (NSEvent*) event
@@ -1609,6 +1624,7 @@ void Platform::setMouseCaptured(bool captured)
         if (captured)
         if (captured)
         {
         {
             [NSCursor hide];
             [NSCursor hide];
+            __mouseCapturedFirstPass = true;
         }
         }
         else
         else
         {   
         {