From 3c414c79621a16c6d0072d8ed3d022f14243f1ae Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 24 Jan 2012 17:47:04 +0000 Subject: [PATCH] Fixed indentation and spaces at ends of lines. --- src/osgViewer/GraphicsWindowCocoa.mm | 422 +++++++++++++-------------- 1 file changed, 211 insertions(+), 211 deletions(-) diff --git a/src/osgViewer/GraphicsWindowCocoa.mm b/src/osgViewer/GraphicsWindowCocoa.mm index 73cf980ca..ed03f2b81 100644 --- a/src/osgViewer/GraphicsWindowCocoa.mm +++ b/src/osgViewer/GraphicsWindowCocoa.mm @@ -4,8 +4,8 @@ * * Created by Stephan Huber on 27.06.08. * Copyright 2008 Stephan Maximilian Huber, digital mind. All rights reserved. - * - * Some code borrowed from the implementation of CocoaViewer, + * + * Some code borrowed from the implementation of CocoaViewer, * Created by Eric Wing on 11/12/06. and ported by Martin Lavery 7/06/07 * * Other snippets are borrowed from the Cocoa-implementation of the SDL-lib @@ -47,8 +47,8 @@ class CocoaKeyboardMap { _keymap[9] = osgGA::GUIEventAdapter::KEY_Tab; _keymap[32] = osgGA::GUIEventAdapter::KEY_Space; _keymap[127] = osgGA::GUIEventAdapter::KEY_BackSpace; - - + + _keymap[NSHomeFunctionKey] = osgGA::GUIEventAdapter::KEY_Home; _keymap[NSEndFunctionKey] = osgGA::GUIEventAdapter::KEY_End; _keymap[NSPageUpFunctionKey] = osgGA::GUIEventAdapter::KEY_Page_Up; @@ -57,9 +57,9 @@ class CocoaKeyboardMap { _keymap[NSRightArrowFunctionKey] = osgGA::GUIEventAdapter::KEY_Right; _keymap[NSUpArrowFunctionKey] = osgGA::GUIEventAdapter::KEY_Up; _keymap[NSDownArrowFunctionKey] = osgGA::GUIEventAdapter::KEY_Down; - + _keymap[NSDeleteFunctionKey] = osgGA::GUIEventAdapter::KEY_Delete; - + _keymap[NSF1FunctionKey] = osgGA::GUIEventAdapter::KEY_F1; _keymap[NSF2FunctionKey] = osgGA::GUIEventAdapter::KEY_F2; _keymap[NSF3FunctionKey] = osgGA::GUIEventAdapter::KEY_F3; @@ -69,7 +69,7 @@ class CocoaKeyboardMap { _keymap[NSF7FunctionKey] = osgGA::GUIEventAdapter::KEY_F7; _keymap[NSF8FunctionKey] = osgGA::GUIEventAdapter::KEY_F8; _keymap[NSF9FunctionKey] = osgGA::GUIEventAdapter::KEY_F9; - + _keymap[NSF10FunctionKey] = osgGA::GUIEventAdapter::KEY_F10; _keymap[NSF11FunctionKey] = osgGA::GUIEventAdapter::KEY_F11; _keymap[NSF12FunctionKey] = osgGA::GUIEventAdapter::KEY_F12; @@ -80,7 +80,7 @@ class CocoaKeyboardMap { _keymap[NSF17FunctionKey] = osgGA::GUIEventAdapter::KEY_F17; _keymap[NSF18FunctionKey] = osgGA::GUIEventAdapter::KEY_F18; _keymap[NSF19FunctionKey] = osgGA::GUIEventAdapter::KEY_F19; - + _keymap[NSF20FunctionKey] = osgGA::GUIEventAdapter::KEY_F20; _keymap[NSF21FunctionKey] = osgGA::GUIEventAdapter::KEY_F21; _keymap[NSF22FunctionKey] = osgGA::GUIEventAdapter::KEY_F22; @@ -91,22 +91,22 @@ class CocoaKeyboardMap { _keymap[NSF27FunctionKey] = osgGA::GUIEventAdapter::KEY_F27; _keymap[NSF28FunctionKey] = osgGA::GUIEventAdapter::KEY_F28; _keymap[NSF29FunctionKey] = osgGA::GUIEventAdapter::KEY_F29; - + _keymap[NSF30FunctionKey] = osgGA::GUIEventAdapter::KEY_F30; _keymap[NSF31FunctionKey] = osgGA::GUIEventAdapter::KEY_F31; _keymap[NSF32FunctionKey] = osgGA::GUIEventAdapter::KEY_F32; _keymap[NSF33FunctionKey] = osgGA::GUIEventAdapter::KEY_F33; _keymap[NSF34FunctionKey] = osgGA::GUIEventAdapter::KEY_F34; _keymap[NSF35FunctionKey] = osgGA::GUIEventAdapter::KEY_F35; - - + + _keypadmap['='] = osgGA::GUIEventAdapter::KEY_KP_Equal; _keypadmap['*'] = osgGA::GUIEventAdapter::KEY_KP_Multiply; _keypadmap['+'] = osgGA::GUIEventAdapter::KEY_KP_Add; _keypadmap['-'] = osgGA::GUIEventAdapter::KEY_KP_Subtract; _keypadmap['.'] = osgGA::GUIEventAdapter::KEY_KP_Decimal; _keypadmap['/'] = osgGA::GUIEventAdapter::KEY_KP_Divide; - + _keypadmap['0'] = osgGA::GUIEventAdapter::KEY_KP_0; _keypadmap['1'] = osgGA::GUIEventAdapter::KEY_KP_1; _keypadmap['2'] = osgGA::GUIEventAdapter::KEY_KP_2; @@ -118,18 +118,18 @@ class CocoaKeyboardMap { _keypadmap['8'] = osgGA::GUIEventAdapter::KEY_KP_8; _keypadmap['9'] = osgGA::GUIEventAdapter::KEY_KP_9; } - + ~CocoaKeyboardMap() { } - + unsigned int remapKey(unsigned int key, bool pressedOnKeypad = false) { if (pressedOnKeypad) { - KeyMap::iterator itr = _keypadmap.find(key); + KeyMap::iterator itr = _keypadmap.find(key); if (itr == _keypadmap.end()) return key; else return itr->second; } - + KeyMap::iterator itr = _keymap.find(key); if (itr == _keymap.end()) return key; else return itr->second; @@ -146,50 +146,50 @@ class CocoaKeyboardMap { static unsigned int remapCocoaKey(unsigned int key, unsigned int modifiers) { static CocoaKeyboardMap s_CocoaKeyboardMap; - + bool pressedOnKeypad = modifiers & NSNumericPadKeyMask; if (modifiers & NSFunctionKeyMask) pressedOnKeypad = false; - + //std::cout << std::hex << "remap " << key << " keypad: " << pressedOnKeypad << " modifiers: " << modifiers << std::endl; - + return s_CocoaKeyboardMap.remapKey(key, pressedOnKeypad); } -std::ostream& operator<<(std::ostream& os, const NSRect& rect) +std::ostream& operator<<(std::ostream& os, const NSRect& rect) { os << rect.origin.x << "/" << rect.origin.y << " " << rect.size.width << "x" << rect.size.height; return os; } // ---------------------------------------------------------------------------------------------------------- -// Cocoa uses a coordinate system where its origin is in the bottom left corner, +// Cocoa uses a coordinate system where its origin is in the bottom left corner, // osg and quartz uses top left for the origin // // these 2 methods convets rects between the different coordinate systems // ---------------------------------------------------------------------------------------------------------- -static NSRect convertFromQuartzCoordinates(const NSRect& rect) +static NSRect convertFromQuartzCoordinates(const NSRect& rect) { NSRect frame = [[[NSScreen screens] objectAtIndex: 0] frame]; float y = frame.size.height - rect.origin.y - rect.size.height; NSRect converted = NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height); - + // std::cout << "converting from Quartz " << rect << " to " << converted << " using screen rect " << frame << std::endl; - + return converted; } static NSRect convertToQuartzCoordinates(const NSRect& rect) { NSRect frame = [[[NSScreen screens] objectAtIndex: 0] frame]; - + float y = frame.size.height - (rect.origin.y + rect.size.height); NSRect converted = NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height); - + // std::cout << "converting To Quartz " << rect << " to " << converted << " using screen rect " << frame << std::endl; - + return converted; } @@ -199,7 +199,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) // the app-delegate, handling quit-requests // ---------------------------------------------------------------------------------------------------------- -@interface CocoaAppDelegate : NSObject +@interface CocoaAppDelegate : NSObject { } @@ -268,7 +268,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) BOOL _isUsingCtrlClick, _isUsingOptionClick; unsigned int _cachedModifierFlags; BOOL _handleTabletEvents; - + } - (void)setGraphicsWindowCocoa: (osgViewer::GraphicsWindowCocoa*) win; @@ -313,7 +313,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) @end -@implementation GraphicsWindowCocoaGLView +@implementation GraphicsWindowCocoaGLView -(void) setGraphicsWindowCocoa: (osgViewer::GraphicsWindowCocoa*) win @@ -323,17 +323,17 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) - (BOOL)acceptsFirstResponder { - return YES; + return YES; } - (BOOL)becomeFirstResponder { - return YES; + return YES; } - (BOOL)resignFirstResponder { - return YES; + return YES; } @@ -346,64 +346,64 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) - (void) handleModifiers: (NSEvent*)theEvent { DEBUG_OUT("handling modifiers"); - - if ((!_win) || (!_win->getEventQueue())) + + if ((!_win) || (!_win->getEventQueue())) return; // no event queue in place - + unsigned int flags = [theEvent modifierFlags]; - - if (flags == _cachedModifierFlags) + + if (flags == _cachedModifierFlags) return; - - const unsigned int masks[] = { + + const unsigned int masks[] = { NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask, NSCommandKeyMask, NSAlphaShiftKeyMask }; - - const unsigned int keys[] = { - osgGA::GUIEventAdapter::KEY_Shift_L, + + const unsigned int keys[] = { + osgGA::GUIEventAdapter::KEY_Shift_L, osgGA::GUIEventAdapter::KEY_Control_L, osgGA::GUIEventAdapter::KEY_Alt_L, osgGA::GUIEventAdapter::KEY_Super_L, osgGA::GUIEventAdapter::KEY_Caps_Lock }; - + // std::cout << "flags: " << flags << " cached: " << _cachedModifierFlags << std::endl; - + for(unsigned int i = 0; i < 5; ++i) { - + if ((flags & masks[i]) && !(_cachedModifierFlags & masks[i])) { _win->getEventQueue()->keyPress(keys[i], _win->getEventQueue()->getTime(), keys[i]); - + // we don't get a key up for the caps lock so emulate it. if (i == 4) _win->getEventQueue()->keyRelease(keys[i], _win->getEventQueue()->getTime(), keys[i]); } - + if (!(flags & masks[i]) && (_cachedModifierFlags & masks[i])) { if (i == 4) { // emulate a key down for caps-lock. _win->getEventQueue()->keyPress(keys[i], _win->getEventQueue()->getTime(), keys[i]); } - + _win->getEventQueue()->keyRelease(keys[i], _win->getEventQueue()->getTime(), keys[i]); } } - + _cachedModifierFlags = flags; - + } - (void)flagsChanged:(NSEvent *)theEvent { [self handleModifiers: theEvent]; } -- (void) mouseMoved:(NSEvent*)theEvent +- (void) mouseMoved:(NSEvent*)theEvent { NSPoint converted_point = [self getLocalPoint: theEvent]; DEBUG_OUT("Mouse moved" << converted_point.x << "/" << converted_point.y); @@ -433,7 +433,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) { [self doLeftMouseButtonDown:theEvent]; } - + if ([theEvent subtype] == NSTabletPointEventSubtype) { _handleTabletEvents = true; [self handleTabletEvents:theEvent]; @@ -444,10 +444,10 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) - (void) mouseDragged:(NSEvent*)theEvent { if (!_win) return; - - NSPoint converted_point = [self getLocalPoint: theEvent]; + + NSPoint converted_point = [self getLocalPoint: theEvent]; _win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y); - + if (_handleTabletEvents) [self handleTabletEvents:theEvent]; } @@ -484,7 +484,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) - (void) rightMouseDragged:(NSEvent*)theEvent { if (!_win) return; - + NSPoint converted_point = [self getLocalPoint: theEvent]; _win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y); } @@ -517,16 +517,16 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) - (void) otherMouseDragged:(NSEvent*)theEvent { if (!_win) return; - - NSPoint converted_point = [self getLocalPoint: theEvent]; + + NSPoint converted_point = [self getLocalPoint: theEvent]; _win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y); - + } // "otherMouse" seems to capture middle button and any other buttons beyond (4th, etc). - (void) otherMouseUp:(NSEvent*)theEvent { - + // Button 0 is left // Button 1 is right // Button 2 is middle @@ -540,7 +540,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) else // buttonNumber should be 3,4,5,etc; must map to 4,5,6,etc in osgViewer { // I don't think osgViewer does anything for these additional buttons, - // but just in case, pass them along. But as a Cocoa programmer, you might + // but just in case, pass them along. But as a Cocoa programmer, you might // think about things you can do natively here instead of passing the buck. [self doExtraMouseButtonUp:theEvent buttonNumber:[theEvent buttonNumber]]; } @@ -648,7 +648,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) - (void) scrollWheel:(NSEvent*)theEvent { if (!_win) return; - + // Unfortunately, it turns out mouseScroll2D doesn't actually do anything. // The camera manipulators don't seem to implement any code that utilize the scroll values. // This this call does nothing. @@ -657,17 +657,17 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) -- (void)keyDown:(NSEvent *)theEvent +- (void)keyDown:(NSEvent *)theEvent { if (!_win) return; - - NSString* unmodified_chars = [theEvent charactersIgnoringModifiers]; + + NSString* unmodified_chars = [theEvent charactersIgnoringModifiers]; if ([theEvent modifierFlags] && NSShiftKeyMask) { unmodified_chars = [unmodified_chars lowercaseString]; } - - NSString* chars = [theEvent characters]; - + + NSString* chars = [theEvent characters]; + if ((chars) && ([chars length] > 0)) { unsigned int unmodified_keyCode = remapCocoaKey([unmodified_chars characterAtIndex:0], [theEvent modifierFlags] ); unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], [theEvent modifierFlags] ); @@ -677,22 +677,22 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) } -- (void)keyUp:(NSEvent *)theEvent -{ +- (void)keyUp:(NSEvent *)theEvent +{ if (!_win) return; - - NSString* unmodified_chars = [theEvent charactersIgnoringModifiers]; + + NSString* unmodified_chars = [theEvent charactersIgnoringModifiers]; if ([theEvent modifierFlags] && NSShiftKeyMask) { unmodified_chars = [unmodified_chars lowercaseString]; } - - NSString* chars = [theEvent characters]; - + + NSString* chars = [theEvent characters]; + if ((chars) && ([chars length] > 0)) { unsigned int unmodified_keyCode = remapCocoaKey([unmodified_chars characterAtIndex:0], [theEvent modifierFlags] ); unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], [theEvent modifierFlags] ); //std::cout << std::hex << "key up: " <<[chars characterAtIndex:0] << "=" << keyCode << " unmodified: " << unmodified_keyCode << std::endl; - + _win->getEventQueue()->keyRelease( keyCode, _win->getEventQueue()->getTime(), unmodified_keyCode); } } @@ -707,11 +707,11 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) -(void)handleTabletEvents:(NSEvent *)theEvent { if (!_win) return; - + float pressure = [theEvent pressure]; _win->getEventQueue()->penPressure(pressure); NSPoint tilt = [theEvent tilt]; - + _win->getEventQueue()->penOrientation (tilt.x, tilt.y, [theEvent rotation]); } @@ -719,7 +719,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) - (void)tabletProximity:(NSEvent *)theEvent { if (!_win) return; - + osgGA::GUIEventAdapter::TabletPointerType pt(osgGA::GUIEventAdapter::UNKNOWN); switch ([theEvent pointingDeviceType]) { case NSPenPointingDevice: @@ -734,7 +734,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) default: break; } - _win->getEventQueue()->penProximity(pt, [theEvent isEnteringProximity]); + _win->getEventQueue()->penProximity(pt, [theEvent isEnteringProximity]); } @@ -788,22 +788,22 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) { if (_inDidMove) return; _inDidMove = true; - + GraphicsWindowCocoaWindow* nswin = _win->getWindow(); NSRect bounds = [nswin contentRectForFrameRect: [nswin frame] ]; - + // convert to quartz-coordinate-system bounds = convertToQuartzCoordinates(bounds); - + // std::cout << "windowdidmove: " << bounds.origin.x << " " << bounds.origin.y << " " << bounds.size.width << " " << bounds.size.height << std::endl; - + _win->adaptResize(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height); //_win->getEventQueue()->windowResize(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height, _win->getEventQueue()->getTime()); _win->requestRedraw(); _inDidMove = false; } -- (BOOL)windowShouldClose:(id)window +- (BOOL)windowShouldClose:(id)window { return _win->requestClose(); } @@ -826,20 +826,20 @@ namespace osgViewer { class CocoaWindowAdapter : public MenubarController::WindowAdapter { public: CocoaWindowAdapter(GraphicsWindowCocoa* win) : MenubarController::WindowAdapter(), _win(win) {} - + virtual bool valid() { return (_win.valid() && _win->valid()); } - - virtual void getWindowBounds(CGRect& rect) + + virtual void getWindowBounds(CGRect& rect) { NSRect nsrect = [_win->getWindow() frame]; nsrect = convertToQuartzCoordinates(nsrect); - + rect.origin.x = nsrect.origin.x; rect.origin.y = nsrect.origin.y; rect.size.width = nsrect.size.width; rect.size.height = nsrect.size.height; } - + virtual osgViewer::GraphicsWindow* getWindow() {return _win.get(); } private: osg::observer_ptr _win; @@ -862,7 +862,7 @@ void GraphicsWindowCocoa::init() _context = NULL; _window = NULL; _pixelformat = NULL; - + _updateContext = false; _valid = _initialized = true; } @@ -877,11 +877,11 @@ void GraphicsWindowCocoa::setupNSWindow(NSWindow* win) { [win setReleasedWhenClosed:NO]; - [win setDisplaysWhenScreenProfileChanges:YES]; + [win setDisplaysWhenScreenProfileChanges:YES]; GraphicsWindowCocoaDelegate* delegate = [[GraphicsWindowCocoaDelegate alloc] initWith: this]; [win setDelegate: delegate ]; //[delegate autorelease]; - + [win makeKeyAndOrderFront:nil]; [win setAcceptsMouseMovedEvents: YES]; @@ -895,44 +895,44 @@ void GraphicsWindowCocoa::setupNSWindow(NSWindow* win) bool GraphicsWindowCocoa::realizeImplementation() { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - + unsigned int style(NSBorderlessWindowMask); - + if (_traits->windowDecoration) { style = NSClosableWindowMask | NSMiniaturizableWindowMask | NSTitledWindowMask; - + // supportsResize works only with windows with titlebar - if (_traits->supportsResize) + if (_traits->supportsResize) style |= NSResizableWindowMask; } - + DarwinWindowingSystemInterface* wsi = dynamic_cast(osg::GraphicsContext::getWindowingSystemInterface()); int screenLeft(0), screenTop(0); if (wsi) { wsi->getScreenTopLeft((*_traits), screenLeft, screenTop); } - + NSRect rect = NSMakeRect(_traits->x + screenLeft, _traits->y + screenTop, _traits->width, _traits->height); - + _ownsWindow = true; - + // should we create a NSView only?? WindowData* windowData = _traits->inheritedWindowData ? dynamic_cast(_traits->inheritedWindowData.get()) : NULL; - if (windowData) + if (windowData) { if (windowData->createOnlyView()) _ownsWindow = false; _checkForEvents = windowData->checkForEvents(); - - } - + + } + OSG_DEBUG << "GraphicsWindowCocoa::realizeImplementation / ownsWindow: " << _ownsWindow << " checkForEvents: " << _checkForEvents << std::endl; - if (_ownsWindow) + if (_ownsWindow) { _window = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO]; - + if (!_window) { OSG_WARN << "GraphicsWindowCocoa::realizeImplementation :: could not create window" << std::endl; return false; @@ -940,19 +940,19 @@ bool GraphicsWindowCocoa::realizeImplementation() rect = convertFromQuartzCoordinates(rect); [_window setFrameOrigin: rect.origin]; - } - + } + NSOpenGLPixelFormatAttribute attr[32]; int i = 0; - + attr[i++] = NSOpenGLPFADepthSize; attr[i++] = static_cast(_traits->depth); if (_traits->doubleBuffer) { attr[i++] = NSOpenGLPFADoubleBuffer; } - - if (_traits->alpha) { + + if (_traits->alpha) { attr[i++] = NSOpenGLPFAAlphaSize; attr[i++] = static_cast(_traits->alpha); } @@ -961,7 +961,7 @@ bool GraphicsWindowCocoa::realizeImplementation() attr[i++] = NSOpenGLPFAStencilSize; attr[i++] = static_cast(_traits->stencil); } - + if (_traits->sampleBuffers) { attr[i++] = NSOpenGLPFASampleBuffers; @@ -970,30 +970,30 @@ bool GraphicsWindowCocoa::realizeImplementation() attr[i++] = static_cast(_traits->samples); } - + attr[i++] = NSOpenGLPFAAccelerated; attr[i] = static_cast(0); - + // create the context NSOpenGLContext* sharedContext = NULL; - + GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast(_traits->sharedContext); - if (graphicsHandleCocoa) + if (graphicsHandleCocoa) { sharedContext = graphicsHandleCocoa->getNSOpenGLContext(); } - + _pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ]; _context = [[NSOpenGLContext alloc] initWithFormat: _pixelformat shareContext: sharedContext]; - + if (!_context) { OSG_WARN << "GraphicsWindowCocoa::realizeImplementation :: could not create context" << std::endl; return false; } - + // set graphics handle for shared usage setNSOpenGLContext(_context); - + GraphicsWindowCocoaGLView* theView = [[ GraphicsWindowCocoaGLView alloc ] initWithFrame:[ _window frame ] ]; [theView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable) ]; [theView setGraphicsWindowCocoa: this]; @@ -1005,26 +1005,26 @@ bool GraphicsWindowCocoa::realizeImplementation() [_window setContentView: theView]; setupNSWindow(_window); [theView release]; - + MenubarController::instance()->attachWindow( new CocoaWindowAdapter(this) ); } - else + else { windowData->setCreatedNSView(theView); } [pool release]; - - + + useCursor(_traits->useCursor); setWindowName(_traits->windowName); setSyncToVBlank(_traits->vsync); - + MenubarController::instance()->update(); - + // Cocoa's origin is bottom/left: getEventQueue()->getCurrentEventState()->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS); - + _valid = _initialized = _realized = true; return _valid; } @@ -1039,27 +1039,27 @@ void GraphicsWindowCocoa::closeImplementation() { _valid = false; _realized = false; - + // there's a possibility that the MenubarController is destructed already, so prevent a crash: MenubarController* mbc = MenubarController::instance(); if (mbc) mbc->detachWindow(this); - + if (_view) { [_view setGraphicsWindowCocoa: NULL]; } - + if (_window) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - + // we have to close + release the window in the main-thread - + [_window performSelectorOnMainThread: @selector(close) withObject:NULL waitUntilDone: YES]; [_window performSelectorOnMainThread: @selector(release) withObject:NULL waitUntilDone: YES]; [pool release]; } - + _window = NULL; - _view = NULL; + _view = NULL; } @@ -1072,9 +1072,9 @@ bool GraphicsWindowCocoa:: makeCurrentImplementation() if (_updateContext) { [_context update]; - _updateContext = false; + _updateContext = false; } - + [_context makeCurrentContext]; return true; } @@ -1103,15 +1103,15 @@ void GraphicsWindowCocoa::swapBuffersImplementation() // ---------------------------------------------------------------------------------------------------------- // checkEvents -// process all pending events +// process all pending events // ---------------------------------------------------------------------------------------------------------- void GraphicsWindowCocoa::checkEvents() { if (!_checkForEvents) return; - + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - + while(1) { /* NOTE: It may be better to use something like @@ -1120,7 +1120,7 @@ void GraphicsWindowCocoa::checkEvents() run while tracking events. However, it should be noted that NSEventTrackingRunLoopMode is in the common set of modes so it may not effectively make much of a difference. - */ + */ NSEvent *event = [ NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] @@ -1129,16 +1129,16 @@ void GraphicsWindowCocoa::checkEvents() if(!event) break; [NSApp sendEvent: event]; - } - + } + if (_closeRequested) getEventQueue()->closeWindow(); - + if (s_quit_requested) { getEventQueue()->quitApplication(); s_quit_requested = false; } - + [pool release]; } @@ -1147,28 +1147,28 @@ void GraphicsWindowCocoa::checkEvents() // ---------------------------------------------------------------------------------------------------------- // setWindowDecorationImplementation // -// unfortunately there's no way to change the decoration of a window, so we create an new one +// unfortunately there's no way to change the decoration of a window, so we create an new one // and swap the content // ---------------------------------------------------------------------------------------------------------- bool GraphicsWindowCocoa::setWindowDecorationImplementation(bool flag) { if (!_realized || !_ownsWindow) return false; - + NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init]; - + unsigned int style(NSBorderlessWindowMask); - + if (flag) { style = NSClosableWindowMask | NSMiniaturizableWindowMask | NSTitledWindowMask; - + // supportsResize works only with windows with titlebar - if (_traits->supportsResize) + if (_traits->supportsResize) style |= NSResizableWindowMask; } NSRect rect = [_window contentRectForFrameRect: [_window frame] ]; GraphicsWindowCocoaWindow* new_win = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO]; - + if (new_win) { [new_win setContentView: [_window contentView]]; setupNSWindow(new_win); @@ -1180,9 +1180,9 @@ bool GraphicsWindowCocoa::setWindowDecorationImplementation(bool flag) _window = new_win; [_window makeKeyAndOrderFront: nil]; } - + [localPool release]; - + return true; } @@ -1212,11 +1212,11 @@ void GraphicsWindowCocoa::grabFocusIfPointerInWindow() void GraphicsWindowCocoa::resizedImplementation(int x, int y, int width, int height) { - DEBUG_OUT("resized implementation" << x << " " << y << " " << width << " " << height); + DEBUG_OUT("resized implementation" << x << " " << y << " " << width << " " << height); GraphicsContext::resizedImplementation(x, y, width, height); - + _updateContext = true; - + MenubarController::instance()->update(); getEventQueue()->windowResize(x,y,width, height, getEventQueue()->getTime()); } @@ -1231,9 +1231,9 @@ bool GraphicsWindowCocoa::setWindowRectangleImplementation(int x, int y, int wid { if (!_ownsWindow) return false; - + NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init]; - + DarwinWindowingSystemInterface* wsi = dynamic_cast(osg::GraphicsContext::getWindowingSystemInterface()); int screenLeft(0), screenTop(0); if (wsi) { @@ -1243,19 +1243,19 @@ bool GraphicsWindowCocoa::setWindowRectangleImplementation(int x, int y, int wid NSRect rect = NSMakeRect(x+screenLeft,y+screenTop,width, height); rect = convertFromQuartzCoordinates(rect); - + [_window setFrame: [NSWindow frameRectForContentRect: rect styleMask: [_window styleMask]] display: YES]; [_context update]; MenubarController::instance()->update(); - + [localPool release]; - + return true; } // ---------------------------------------------------------------------------------------------------------- -// +// // ---------------------------------------------------------------------------------------------------------- void GraphicsWindowCocoa::adaptResize(int x, int y, int w, int h) @@ -1264,17 +1264,17 @@ void GraphicsWindowCocoa::adaptResize(int x, int y, int w, int h) DarwinWindowingSystemInterface* wsi = dynamic_cast(osg::GraphicsContext::getWindowingSystemInterface()); int screenLeft(0), screenTop(0); if (wsi) { - + // get the screen containing the window unsigned int screenNdx = wsi->getScreenContaining(x,y,w,h); - + // update traits _traits->screenNum = screenNdx; - + // get top left of screen wsi->getScreenTopLeft((*_traits), screenLeft, screenTop); } - + resized(x-screenLeft,y-screenTop,w,h); getEventQueue()->windowResize(x-screenLeft, y-screenTop, w, h, getEventQueue()->getTime()); } @@ -1287,12 +1287,12 @@ void GraphicsWindowCocoa::adaptResize(int x, int y, int w, int h) void GraphicsWindowCocoa::setWindowName (const std::string & name) { if (_traits.valid()) _traits->windowName = name; - + if (!_ownsWindow) return; - + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - + NSString* title = [NSString stringWithUTF8String: name.c_str()]; [_window setTitle: title]; [pool release]; @@ -1335,7 +1335,7 @@ void GraphicsWindowCocoa::useCursor(bool cursorOn) OSG_WARN << "GraphicsWindowCarbon::useCursor :: could not get OSXCarbonWindowingSystemInterface" << std::endl; return; } - + CGDirectDisplayID displayId = wsi->getDisplayID((*_traits)); CGDisplayErr err = kCGErrorSuccess; @@ -1358,38 +1358,38 @@ void GraphicsWindowCocoa::useCursor(bool cursorOn) void GraphicsWindowCocoa::setCursor(MouseCursor mouseCursor) { if (_currentCursor == mouseCursor) { - return; + return; } - + NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init]; - switch (mouseCursor) + switch (mouseCursor) { case NoCursor: [NSCursor hide]; break; - + case LeftArrowCursor: case RightArrowCursor: [[NSCursor arrowCursor] set]; break; - + case TextCursor: [[NSCursor IBeamCursor] set]; break; - + case CrosshairCursor: [[NSCursor crosshairCursor] set]; break; - + default: - OSG_INFO << "GraphicsWindowCocoa::setCursor :: unsupported MouseCursor: " << mouseCursor << std::endl; + OSG_INFO << "GraphicsWindowCocoa::setCursor :: unsupported MouseCursor: " << mouseCursor << std::endl; } - + if (_currentCursor == NoCursor) { - [NSCursor unhide]; + [NSCursor unhide]; } - + _currentCursor = mouseCursor; [localPool release]; } @@ -1399,7 +1399,7 @@ void GraphicsWindowCocoa::setCursor(MouseCursor mouseCursor) // setSyncToVBlank // ---------------------------------------------------------------------------------------------------------- -void GraphicsWindowCocoa::setSyncToVBlank(bool f) +void GraphicsWindowCocoa::setSyncToVBlank(bool f) { if (_traits.valid()) _traits->vsync = f; GLint VBL(f?1:0); @@ -1411,7 +1411,7 @@ void GraphicsWindowCocoa::setSyncToVBlank(bool f) // d'tor // ---------------------------------------------------------------------------------------------------------- -GraphicsWindowCocoa::~GraphicsWindowCocoa() +GraphicsWindowCocoa::~GraphicsWindowCocoa() { close(); } @@ -1431,58 +1431,58 @@ struct CocoaWindowingSystemInterface : public DarwinWindowingSystemInterface { } - void initAsStandaloneApplication() + void initAsStandaloneApplication() { _init(); static bool s_inited = false; if (s_inited) return; s_inited = true; - + OSG_INFO << "CocoaWindowingSystemInterface::initAsStandaloneApplication " << std::endl; - + ProcessSerialNumber psn; if (!GetCurrentProcess(&psn)) { TransformProcessType(&psn, kProcessTransformToForegroundApplication); SetFrontProcess(&psn); } - + NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init]; - + if (NSApp == nil) { [NSApplication sharedApplication]; } - + [NSApp setDelegate: [[CocoaAppDelegate alloc] init] ]; - + createApplicationMenus(); - + [NSApp finishLaunching]; - + [localPool release]; } - - virtual osg::GraphicsContext* createGraphicsContext(osg::GraphicsContext::Traits* traits) + + virtual osg::GraphicsContext* createGraphicsContext(osg::GraphicsContext::Traits* traits) { _init(); - if (!traits->pbuffer) + if (!traits->pbuffer) { GraphicsWindowCocoa::WindowData* windowData = traits->inheritedWindowData ? dynamic_cast(traits->inheritedWindowData.get()) : NULL; - - if (!windowData || (windowData && windowData->poseAsStandaloneApp())) + + if (!windowData || (windowData && windowData->poseAsStandaloneApp())) { initAsStandaloneApplication(); } } - + return createGraphicsContextImplementation(traits); } - - virtual ~CocoaWindowingSystemInterface() + + virtual ~CocoaWindowingSystemInterface() { } - + private: NSString *getApplicationName(void) { @@ -1493,39 +1493,39 @@ private: dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); if (dict) appName = [dict objectForKey: @"CFBundleName"]; - + if (![appName length]) appName = [[NSProcessInfo processInfo] processName]; return appName; } - - void createApplicationMenus(void) + + void createApplicationMenus(void) { NSString *appName; NSString *title; NSMenu *appleMenu; NSMenuItem *menuItem; - + /* Create the main menu bar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; /* Create the application menu */ appName = getApplicationName(); appleMenu = [[NSMenu alloc] initWithTitle:@""]; - + /* Add menu items */ title = [@"About " stringByAppendingString:appName]; [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; [appleMenu addItem:[NSMenuItem separatorItem]]; - + NSMenu* service_menu = [[NSMenu alloc] init]; NSMenuItem* service_menu_item = [[NSMenuItem alloc] initWithTitle:@"Services" action:nil keyEquivalent:@""]; [service_menu_item setSubmenu: service_menu]; [appleMenu addItem: service_menu_item]; [NSApp setServicesMenu: service_menu]; - + [appleMenu addItem:[NSMenuItem separatorItem]]; title = [@"Hide " stringByAppendingString:appName]; @@ -1540,7 +1540,7 @@ private: title = [@"Quit " stringByAppendingString:appName]; [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@/*"q"*/"q"]; - + /* Put menu into the menubar */ menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; [menuItem setSubmenu:appleMenu];