From 0d347352cf47dc834e720d204862acbd3f66e966 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 21 Sep 2010 10:28:50 +0000 Subject: [PATCH] From David Guthrie, "The cocoa version of the window for Mac OS X doesn't implement the requestWarpPointer function, but it turns out that the code from the Carbon version of the window is the same because it uses the windowing interface, so it this version, based on 2.8.3 GraphicsWindowCocoa, I copied the function over. The trunk version it also missing the function and the code looks to be very similar, so I assume it will transfer simply enough. " --- .../osgViewer/api/Cocoa/GraphicsWindowCocoa | 1 + src/osgViewer/GraphicsWindowCocoa.mm | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/osgViewer/api/Cocoa/GraphicsWindowCocoa b/include/osgViewer/api/Cocoa/GraphicsWindowCocoa index dd8b18bf8..076fedb84 100644 --- a/include/osgViewer/api/Cocoa/GraphicsWindowCocoa +++ b/include/osgViewer/api/Cocoa/GraphicsWindowCocoa @@ -126,6 +126,7 @@ class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer:: virtual bool setWindowRectangleImplementation(int x, int y, int width, int height); virtual void setWindowName (const std::string & name); + virtual void requestWarpPointer(float x,float y); virtual void useCursor(bool cursorOn); virtual void setCursor(MouseCursor mouseCursor); diff --git a/src/osgViewer/GraphicsWindowCocoa.mm b/src/osgViewer/GraphicsWindowCocoa.mm index 8af1f154c..08e84d361 100644 --- a/src/osgViewer/GraphicsWindowCocoa.mm +++ b/src/osgViewer/GraphicsWindowCocoa.mm @@ -1289,6 +1289,29 @@ void GraphicsWindowCocoa::setWindowName (const std::string & name) [pool release]; } +// ---------------------------------------------------------------------------------------------------------- +// requestWarpPointer +// ---------------------------------------------------------------------------------------------------------- +void GraphicsWindowCocoa::requestWarpPointer(float x,float y) +{ + + DarwinWindowingSystemInterface* wsi = dynamic_cast(osg::GraphicsContext::getWindowingSystemInterface()); + if (wsi == NULL) { + osg::notify(osg::WARN) << "GraphicsWindowCarbon::useCursor :: could not get OSXCarbonWindowingSystemInterface" << std::endl; + return; + } + + CGDirectDisplayID displayId = wsi->getDisplayID((*_traits)); + + CGPoint point; + point.x = x + _traits->x; + point.y = y + _traits->y; + CGDisplayMoveCursorToPoint(displayId, point); + + getEventQueue()->mouseWarped(x,y); +} + + // ---------------------------------------------------------------------------------------------------------- // useCursor