diff --git a/include/osgViewer/api/Cocoa/GraphicsWindowCocoa b/include/osgViewer/api/Cocoa/GraphicsWindowCocoa index 965ce3a1b..dd8b18bf8 100755 --- a/include/osgViewer/api/Cocoa/GraphicsWindowCocoa +++ b/include/osgViewer/api/Cocoa/GraphicsWindowCocoa @@ -25,12 +25,14 @@ @class GraphicsWindowCocoaWindow; @class GraphicsWindowCocoaGLView; @class NSOpenGLContext; +@class NSOpenGLPixelFormat; @class NSWindow; @class NSView; #else class GraphicsWindowCocoaGLView; class GraphicsWindowCocoaWindow; class NSOpenGLContext; +class NSOpenGLPixelFormat; class NSWindow; class NSView; #endif @@ -158,6 +160,7 @@ class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer:: NSOpenGLContext* getContext() { return _context; } GraphicsWindowCocoaWindow* getWindow() { return _window; } + NSOpenGLPixelFormat* getPixelFormat() { return _pixelformat; } void setVSync(bool f); @@ -190,6 +193,7 @@ class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer:: GraphicsWindowCocoaWindow* _window; GraphicsWindowCocoaGLView* _view; NSOpenGLContext* _context; + NSOpenGLPixelFormat* _pixelformat; bool _updateContext; }; diff --git a/src/osgViewer/GraphicsWindowCocoa.mm b/src/osgViewer/GraphicsWindowCocoa.mm index 3c0da1234..eb2b25899 100755 --- a/src/osgViewer/GraphicsWindowCocoa.mm +++ b/src/osgViewer/GraphicsWindowCocoa.mm @@ -673,9 +673,11 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) if (!_win) return; NSString* chars = [theEvent charactersIgnoringModifiers]; - unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], ([theEvent modifierFlags] & NSFunctionKeyMask) ); - // std::cout << "key dn: " <<[chars characterAtIndex:0] << "=" << keyCode << std::endl; - _win->getEventQueue()->keyPress( remapCocoaKey(keyCode), [theEvent timestamp]); + if ((chars) && ([chars length] > 0)) { + unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], ([theEvent modifierFlags] & NSFunctionKeyMask) ); + // std::cout << "key dn: " <<[chars characterAtIndex:0] << "=" << keyCode << std::endl; + _win->getEventQueue()->keyPress( remapCocoaKey(keyCode), [theEvent timestamp]); + } } @@ -684,9 +686,11 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) if (!_win) return; NSString* chars = [theEvent charactersIgnoringModifiers]; - unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], ([theEvent modifierFlags] & NSFunctionKeyMask)); - // std::cout << "key up: " <<[chars characterAtIndex:0] << "=" << keyCode << std::endl; - _win->getEventQueue()->keyRelease( remapCocoaKey(keyCode), [theEvent timestamp]); + if ((chars) && ([chars length] > 0)) { + unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], ([theEvent modifierFlags] & NSFunctionKeyMask)); + // std::cout << "key up: " <<[chars characterAtIndex:0] << "=" << keyCode << std::endl; + _win->getEventQueue()->keyRelease( remapCocoaKey(keyCode), [theEvent timestamp]); + } } @@ -853,6 +857,8 @@ void GraphicsWindowCocoa::init() _ownsWindow = false; _context = NULL; _window = NULL; + _pixelformat = NULL; + _updateContext = false; _valid = _initialized = true; } @@ -973,8 +979,8 @@ bool GraphicsWindowCocoa::realizeImplementation() sharedContext = graphicsHandleCocoa->getNSOpenGLContext(); } - NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ]; - _context = [[NSOpenGLContext alloc] initWithFormat: pixelformat shareContext: sharedContext]; + _pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ]; + _context = [[NSOpenGLContext alloc] initWithFormat: _pixelformat shareContext: sharedContext]; if (!_context) { osg::notify(osg::WARN) << "GraphicsWindowCocoa::realizeImplementation :: could not create context" << std::endl; @@ -1158,7 +1164,8 @@ bool GraphicsWindowCocoa::setWindowDecorationImplementation(bool flag) if (new_win) { [new_win setContentView: [_window contentView]]; setupNSWindow(new_win); - [new_win setTitle: [_window title]]; + NSString* title = (_traits.valid()) ? [NSString stringWithUTF8String: _traits->windowName.c_str()] : @""; + [new_win setTitle: title ]; [_window close]; [_window release]; @@ -1277,9 +1284,8 @@ void GraphicsWindowCocoa::setWindowName (const std::string & name) NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString* title = [NSString stringWithCString: name.c_str() encoding: NSUTF8StringEncoding]; + NSString* title = [NSString stringWithUTF8String: name.c_str()]; [_window setTitle: title]; - [title release]; [pool release]; }