From 49696d776a5a3f69e89ecd758b47bcb2c04f3979 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 17 Dec 2007 10:24:20 +0000 Subject: [PATCH] From Stephan Huber, "attached you'll find an updated carbon-implementation, which implements the missing functionality for setWindowName and useCursor " --- .../osgViewer/api/Carbon/GraphicsWindowCarbon | 3 ++ src/osgViewer/GraphicsWindowCarbon.cpp | 47 +++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/include/osgViewer/api/Carbon/GraphicsWindowCarbon b/include/osgViewer/api/Carbon/GraphicsWindowCarbon index 7b5cd3eed..fa5c18aff 100644 --- a/include/osgViewer/api/Carbon/GraphicsWindowCarbon +++ b/include/osgViewer/api/Carbon/GraphicsWindowCarbon @@ -101,6 +101,9 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow virtual void resizedImplementation(int x, int y, int width, int height); + virtual void setWindowName (const std::string & name); + virtual void useCursor(bool cursorOn); + WindowRef getNativeWindowRef() { return _window; } bool handleMouseEvent(EventRef theEvent); diff --git a/src/osgViewer/GraphicsWindowCarbon.cpp b/src/osgViewer/GraphicsWindowCarbon.cpp index 49970a8e7..d5b24400f 100644 --- a/src/osgViewer/GraphicsWindowCarbon.cpp +++ b/src/osgViewer/GraphicsWindowCarbon.cpp @@ -603,9 +603,9 @@ bool GraphicsWindowCarbon::realizeImplementation() if (!_traits) return false; setWindowDecoration(_traits->windowDecoration); + useCursor(_traits->useCursor); // move the window to the right screen - OSXCarbonWindowingSystemInterface* wsi = dynamic_cast(osg::GraphicsContext::getWindowingSystemInterface()); int screenLeft(0), screenTop(0); if (wsi) { @@ -646,10 +646,7 @@ bool GraphicsWindowCarbon::realizeImplementation() installEventHandler(); // set the window title - if (!_traits->windowName.empty()) { - CFStringRef windowtitle = CFStringCreateWithBytes( kCFAllocatorDefault, (const UInt8*)(_traits->windowName.c_str()), _traits->windowName.length(),kCFStringEncodingUTF8, false ); - SetWindowTitleWithCFString( _window, windowtitle ); - } + setWindowName(_traits->windowName); // create the context AGLContext sharedContextCarbon = NULL; @@ -1128,6 +1125,46 @@ void GraphicsWindowCarbon::grabFocusIfPointerInWindow() } +void GraphicsWindowCarbon::useCursor(bool cursorOn) +{ + + if (_traits.valid()) + _traits->useCursor = cursorOn; + OSXCarbonWindowingSystemInterface* 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)); + CGDisplayErr err = kCGErrorSuccess; + switch (cursorOn) + { + case true: + err = CGDisplayShowCursor(displayId); + break; + case false: + err = CGDisplayHideCursor(displayId); + break; + } + if (err != kCGErrorSuccess) { + osg::notify(osg::WARN) << "GraphicsWindowCarbon::useCursor failed with " << err << std::endl; + } +} + + + +void GraphicsWindowCarbon::setWindowName (const std::string& name) +{ + _traits->windowName = name; + if (!_traits->windowName.empty()) + { + CFStringRef windowtitle = CFStringCreateWithBytes( kCFAllocatorDefault, (const UInt8*)(_traits->windowName.c_str()), _traits->windowName.length(),kCFStringEncodingUTF8, false ); + SetWindowTitleWithCFString( _window, windowtitle ); + CFRelease(windowtitle); + } +} + void GraphicsWindowCarbon::transformMouseXY(float& x, float& y) {