Revision: 34450
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34450
Author:   merwin
Date:     2011-01-22 06:46:40 +0000 (Sat, 22 Jan 2011)
Log Message:
-----------
WIP toward better cursor-grab implementation on Mac, plus various minor fixes

Modified Paths:
--------------
    branches/merwin-tablet-2/intern/ghost/GHOST_Rect.h
    branches/merwin-tablet-2/intern/ghost/intern/GHOST_SystemCocoa.h
    branches/merwin-tablet-2/intern/ghost/intern/GHOST_SystemCocoa.mm
    branches/merwin-tablet-2/intern/ghost/intern/GHOST_Window.cpp
    branches/merwin-tablet-2/intern/ghost/intern/GHOST_WindowCocoa.mm
    branches/merwin-tablet-2/source/blender/windowmanager/intern/wm_cursors.c

Modified: branches/merwin-tablet-2/intern/ghost/GHOST_Rect.h
===================================================================
--- branches/merwin-tablet-2/intern/ghost/GHOST_Rect.h  2011-01-22 06:41:34 UTC 
(rev 34449)
+++ branches/merwin-tablet-2/intern/ghost/GHOST_Rect.h  2011-01-22 06:46:40 UTC 
(rev 34450)
@@ -66,21 +66,16 @@
                : m_l(r.m_l), m_t(r.m_t), m_r(r.m_r), m_b(r.m_b) {}
        
        /**
-        * Destructor.
-        */
-       virtual ~GHOST_Rect() {};
-
-       /**
         * Access to rectangle width.
         * @return      width of the rectangle
         */
-       virtual inline GHOST_TInt32 getWidth() const;
+       inline GHOST_TInt32 getWidth() const;
 
        /**
         * Access to rectangle height.
         * @return      height of the rectangle
         */
-       virtual inline GHOST_TInt32 getHeight() const;
+       inline GHOST_TInt32 getHeight() const;
 
        /**
         * Sets all members of the rectangle.
@@ -89,49 +84,50 @@
         * @param       r       requested right coordinate of the rectangle
         * @param       b       requested bottom coordinate of the rectangle
         */
-       virtual inline void set(GHOST_TInt32 l, GHOST_TInt32 t, GHOST_TInt32 r, 
GHOST_TInt32 b);
+       inline void set(GHOST_TInt32 l, GHOST_TInt32 t, GHOST_TInt32 r, 
GHOST_TInt32 b);
 
        /**
         * Returns whether this rectangle is empty.
         * Empty rectangles are rectangles that have width==0 and/or height==0.
         * @return      boolean value (true==empty rectangle)
         */
-       virtual inline bool isEmpty() const;
+       inline bool isEmpty() const;
 
        /**
         * Returns whether this rectangle is valid.
         * Valid rectangles are rectangles that have m_l <= m_r and m_t <= m_b. 
Thus, emapty rectangles are valid.
         * @return      boolean value (true==valid rectangle)
         */
-       virtual inline bool isValid() const;
+       inline bool isValid() const;
 
        /**
         * Grows (or shrinks the rectangle).
         * The method avoids negative insets making the rectangle invalid
         * @param       i       The amount of offset given to each extreme 
(negative values shrink the rectangle).
         */
-       virtual void inset(GHOST_TInt32 i);
+       void inset(GHOST_TInt32 i);
 
        /**
         * Does a union of the rectangle given and this rectangle.
         * The result is stored in this rectangle.
         * @param       r       The rectangle that is input for the union 
operation.
         */
-       virtual inline void unionRect(const GHOST_Rect& r);
+       inline void unionRect(const GHOST_Rect& r);
 
        /**
         * Grows the rectangle to included a point.
         * @param       x       The x-coordinate of the point.
         * @param       y       The y-coordinate of the point.
         */
-       virtual inline void unionPoint(GHOST_TInt32 x, GHOST_TInt32 y);
+       inline void unionPoint(GHOST_TInt32 x, GHOST_TInt32 y);
 
        /**
-        * Grows the rectangle to included a point.
-        * @param       x       The x-coordinate of the point.
-        * @param       y       The y-coordinate of the point.
+        * Wraps x and y to lie inside this rect.
+        * @param x The x-coordinate of the point.
+        * @param y The y-coordinate of the point.
+        * @param ofs The margin of safety; point will stay at least this far 
from any edge.
         */
-       virtual inline void wrapPoint(GHOST_TInt32 &x, GHOST_TInt32 &y, 
GHOST_TInt32 ofs);
+       inline void wrapPoint(GHOST_TInt32& x, GHOST_TInt32& y, GHOST_TInt32 
ofs = 0) const;
 
        /**
         * Returns whether the point is inside this rectangle.
@@ -140,14 +136,14 @@
         * @param y y-coordinate of point to test.
         * @return boolean value (true if point is inside).
         */
-       virtual inline bool isInside(GHOST_TInt32 x, GHOST_TInt32 y) const;
+       inline bool isInside(GHOST_TInt32 x, GHOST_TInt32 y) const;
 
        /**
         * Returns whether the rectangle is inside this rectangle.
         * @param       r       rectangle to test.
         * @return      visibility (not, partially or fully visible).
         */
-       virtual GHOST_TVisibility getVisibility(GHOST_Rect& r) const;
+       GHOST_TVisibility getVisibility(GHOST_Rect& r) const;
 
        /**
         * Sets rectangle members.
@@ -155,7 +151,7 @@
         * @param       cx      requested center x-coordinate of the rectangle
         * @param       cy      requested center y-coordinate of the rectangle
         */
-       virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy);
+       void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy);
 
        /**
         * Sets rectangle members.
@@ -166,7 +162,7 @@
         * @param       w       requested width of the rectangle
         * @param       h       requested height of the rectangle
         */
-       virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy, GHOST_TInt32 
w, GHOST_TInt32 h);
+       void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy, GHOST_TInt32 w, 
GHOST_TInt32 h);
 
        /**
         * Clips a rectangle.
@@ -175,7 +171,7 @@
         * @param       r       the rectangle to clip
         * @return      whether clipping has occurred
         */
-       virtual bool clip(GHOST_Rect& r) const;
+       bool clip(GHOST_Rect& r) const;
 
        /** Left coordinate of the rectangle */
        GHOST_TInt32 m_l;
@@ -234,11 +230,11 @@
        if (y < m_t) m_t = y;
        if (y > m_b) m_b = y;
 }
-#include <stdio.h>
-inline void GHOST_Rect::wrapPoint(GHOST_TInt32 &x, GHOST_TInt32 &y, 
GHOST_TInt32 ofs)
+
+inline void GHOST_Rect::wrapPoint(GHOST_TInt32& x, GHOST_TInt32& y, 
GHOST_TInt32 ofs) const
 {
-       GHOST_TInt32 w= getWidth();
-       GHOST_TInt32 h= getHeight();
+       const GHOST_TInt32 w= getWidth();
+       const GHOST_TInt32 h= getHeight();
 
        /* highly unlikely but avoid eternal loop */
        if(w-ofs*2 <= 0 || h-ofs*2 <= 0)
@@ -249,6 +245,27 @@
        while(y+ofs > m_b)              y-= h-(ofs*2);
 }
 
+#if 0
+#include <stdio.h>
+inline void GHOST_Rect::wrapPoint(GHOST_TInt32& x, GHOST_TInt32& y, 
GHOST_TInt32 ofs) const
+{
+       const GHOST_TInt32 left = m_l + ofs;
+       const GHOST_TInt32 right = m_r - ofs;
+       const GHOST_TInt32 top = m_t + ofs;
+       const GHOST_TInt32 bottom = m_b - ofs;
+       printf("H %d..%d -> %d..%d\n", m_l, m_r, left, right);
+       printf("V %d..%d -> %d..%d\n", m_t, m_b, top, bottom);
+
+       const GHOST_TInt32 width = right - left;
+       const GHOST_TInt32 height = bottom - top;
+
+       printf("point (%d,%d)", x, y);
+       x = (x - left) % width + left;
+       y = (y - top) % height + top;
+       printf(" -> (%d,%d)\n", x, y);
+}
+#endif
+
 inline bool GHOST_Rect::isInside(GHOST_TInt32 x, GHOST_TInt32 y) const
 {
        return (x >= m_l) && (x <= m_r) && (y >= m_t) && (y <= m_b);

Modified: branches/merwin-tablet-2/intern/ghost/intern/GHOST_SystemCocoa.h
===================================================================
--- branches/merwin-tablet-2/intern/ghost/intern/GHOST_SystemCocoa.h    
2011-01-22 06:41:34 UTC (rev 34449)
+++ branches/merwin-tablet-2/intern/ghost/intern/GHOST_SystemCocoa.h    
2011-01-22 06:46:40 UTC (rev 34450)
@@ -42,6 +42,7 @@
 
 
 #include "GHOST_System.h"
+#include "GHOST_TabletManagerCocoa.h"
 
 class GHOST_EventCursor;
 class GHOST_EventKey;
@@ -314,6 +315,8 @@
        
        /** Multitouch gesture in progress, useful to distinguish trackpad from 
mouse scroll events */
        bool m_isGestureInProgress;
+
+       GHOST_TabletManagerCocoa m_tabletManager;
 };
 
 #endif // _GHOST_SYSTEM_COCOA_H_

Modified: branches/merwin-tablet-2/intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
--- branches/merwin-tablet-2/intern/ghost/intern/GHOST_SystemCocoa.mm   
2011-01-22 06:41:34 UTC (rev 34449)
+++ branches/merwin-tablet-2/intern/ghost/intern/GHOST_SystemCocoa.mm   
2011-01-22 06:46:40 UTC (rev 34450)
@@ -927,7 +927,14 @@
                                                if ([event deviceID] == 
m_tablet_mouse_id)
                                                        handleMouseEvent(event);
                                                else
+                                                       {
                                                        
handleTabletEvent(event);
+
+                                                       GHOST_WindowCocoa* 
window = (GHOST_WindowCocoa*)
+                                                               
m_windowManager->getWindowAssociatedWithOSWindow((void*)[event window]);
+
+                                                       
m_tabletManager.convertEvent(event, window);
+                                                       }
                                                break;
                                        case NSTabletProximityEventSubtype:
                                                // I think only LMB down/up 
sends this.
@@ -945,6 +952,12 @@
                                
                        case NSTabletProximity:
                                handleTabletProximity(event);
+
+                               if ([event isEnteringProximity])
+                                       m_tabletManager.pickupTool(event);
+                               else
+                                       m_tabletManager.dropTool();
+
                                break;
 
                        case NSTabletPoint:
@@ -1538,13 +1551,24 @@
                return GHOST_kFailure;
        }
 
+       // these support "continuous grab" feature and
+       // take advantage of MacOS support for fractional coordinates
+       static NSPoint effectiveCursorPos;
+               // while *visible* cursor may be wrapped inside a view, the 
*effective* cursor
+               // is free to extend beyond the view, even beyond the screen.
+       static NSPoint prevCursorPos;
+               // used for tracking precise cursor deltas
+               // errors from [event deltaX] and its vertical friend 
accumulate quickly!
+
        switch ([event type])
     {
                case NSLeftMouseDown:
                case NSRightMouseDown:
                case NSOtherMouseDown:
                        printf("mouse button %d down\n", [event buttonNumber]);
-                       [NSEvent setMouseCoalescingEnabled:NO];
+                       effectiveCursorPos = [event locationInWindow]; // 
similar role to grabInitPos
+                       prevCursorPos = effectiveCursorPos; // set this 
initially, so we have something to delta from
+//                     [NSEvent setMouseCoalescingEnabled:NO]; // start hi-fi 
event stream
                        pushEvent(new GHOST_EventButton([event timestamp]*1000, 
GHOST_kEventButtonDown, window, convertButton([event buttonNumber])));
                        break;
 
@@ -1552,7 +1576,7 @@
                case NSRightMouseUp:
                case NSOtherMouseUp:
                        printf("mouse button %d up\n", [event buttonNumber]);
-                       [NSEvent setMouseCoalescingEnabled:YES];
+//                     [NSEvent setMouseCoalescingEnabled:YES]; // stop hi-fi 
event stream
                        pushEvent(new GHOST_EventButton([event timestamp]*1000, 
GHOST_kEventButtonUp, window, convertButton([event buttonNumber])));
                        break;
 
@@ -1561,6 +1585,12 @@
                case NSOtherMouseDragged:
                case NSMouseMoved:
 //                     printf("move ");
+
+                       {
+                       CGPoint screenPos = CGEventGetLocation([event CGEvent]);
+                       printf("screen position: %.2f %.2f\n", screenPos.x, 
screenPos.y);
+                       }
+
                        if (false) { // display some useful mouse info
                                NSPoint mousePos = [event locationInWindow];
                                float event_dx = [event deltaX];
@@ -1570,6 +1600,7 @@
                                        printf("[hi-fi] ");
                                printf("<%.2f,%.2f> to (%.2f,%.2f)\n", 
event_dx, event_dy, mousePos.x, mousePos.y);
                        }
+
                        switch (window->getCursorGrabMode()) {
                                case GHOST_kGrabHide: //Cursor hidden grab 
operation : no cursor move
                                {
@@ -1586,51 +1617,78 @@
                                        break;
                                case GHOST_kGrabWrap: //Wrap cursor at 
area/window boundaries
                                {
-                                       NSPoint mousePos = [event 
locationInWindow];
-                                       GHOST_TInt32 x_mouse= mousePos.x;
-                                       GHOST_TInt32 y_mouse= mousePos.y;
-                                       GHOST_TInt32 x_accum, y_accum, x_cur, 
y_cur;
-                                       GHOST_Rect bounds, windowBounds, 
correctedBounds;
+                                       printf("-- gangsta wrap --\n");
 
-                                       /* fallback to window bounds */
-                                       
if(window->getCursorGrabBounds(bounds)==GHOST_kFailure)
+                                       NSPoint visibleCursorPos = [event 
locationInWindow];
+
+                                       // get good screen coordinates
+                                       /*

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to