Changeset 9895
- Timestamp:
- 03/11/09 11:34:29 (4 years ago)
- Location:
- OpenSceneGraph/trunk/src/osgViewer
- Files:
-
- 3 modified
-
DarwinUtils.h (modified) (3 diffs)
-
DarwinUtils.mm (modified) (9 diffs)
-
GraphicsWindowCocoa.mm (modified) (39 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgViewer/DarwinUtils.h
r9879 r9895 30 30 31 31 public: 32 class WindowAdapter : public osg::Referenced {33 34 public:35 WindowAdapter() : osg::Referenced() {}36 37 virtual bool valid() = 0;38 virtual void getWindowBounds(CGRect& rect) = 0;39 virtual osgViewer::GraphicsWindow* getWindow() = 0;40 41 protected:42 virtual ~WindowAdapter() {}43 };44 32 class WindowAdapter : public osg::Referenced { 33 34 public: 35 WindowAdapter() : osg::Referenced() {} 36 37 virtual bool valid() = 0; 38 virtual void getWindowBounds(CGRect& rect) = 0; 39 virtual osgViewer::GraphicsWindow* getWindow() = 0; 40 41 protected: 42 virtual ~WindowAdapter() {} 43 }; 44 45 45 MenubarController(); 46 46 static MenubarController* instance(); … … 52 52 private: 53 53 typedef std::list< osg::ref_ptr< WindowAdapter > > WindowList; 54 WindowList _list;55 bool _menubarShown;56 CGRect _availRect;57 CGRect _mainScreenBounds;58 OpenThreads::Mutex _mutex;54 WindowList _list; 55 bool _menubarShown; 56 CGRect _availRect; 57 CGRect _mainScreenBounds; 58 OpenThreads::Mutex _mutex; 59 59 60 60 }; … … 65 65 { 66 66 public: 67 DarwinWindowingSystemInterface(); 68 69 /** dtor */ 70 ~DarwinWindowingSystemInterface(); 71 72 /** @return a CGDirectDisplayID for a ScreenIdentifier */ 73 CGDirectDisplayID getDisplayID(const osg::GraphicsContext::ScreenIdentifier& si); 74 75 /** @return count of attached screens */ 76 virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si) ; 77 78 virtual void getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution); 67 DarwinWindowingSystemInterface(); 79 68 80 virtual void enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, osg::GraphicsContext::ScreenSettingsList & resolutionList); 69 /** dtor */ 70 ~DarwinWindowingSystemInterface(); 81 71 82 /** return the top left coord of a specific screen in global screen space */ 83 void getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y); 84 85 /** implementation of setScreenResolution */ 86 virtual bool setScreenResolution(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) ; 72 /** @return a CGDirectDisplayID for a ScreenIdentifier */ 73 CGDirectDisplayID getDisplayID(const osg::GraphicsContext::ScreenIdentifier& si); 87 74 88 /** implementation of setScreenRefreshRate */ 89 virtual bool setScreenRefreshRate(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate); 90 91 92 /** returns screen-ndx containing rect x,y,w,h */ 93 unsigned int getScreenContaining(int x, int y, int w, int h); 94 95 protected: 96 97 template<class PixelBufferImplementation, class GraphicsWindowImplementation> 98 osg::GraphicsContext* createGraphicsContextImplementation(osg::GraphicsContext::Traits* traits) 99 { 100 if (traits->pbuffer) 101 { 102 osg::ref_ptr<PixelBufferImplementation> pbuffer = new PixelBufferImplementation(traits); 103 if (pbuffer->valid()) return pbuffer.release(); 104 else return 0; 105 } 106 else 107 { 108 osg::ref_ptr<GraphicsWindowImplementation> window = new GraphicsWindowImplementation(traits); 109 if (window->valid()) return window.release(); 110 else return 0; 111 } 112 } 113 75 /** @return count of attached screens */ 76 virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si) ; 77 78 virtual void getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution); 79 80 virtual void enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, osg::GraphicsContext::ScreenSettingsList & resolutionList); 81 82 /** return the top left coord of a specific screen in global screen space */ 83 void getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y); 84 85 /** implementation of setScreenResolution */ 86 virtual bool setScreenResolution(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) ; 87 88 /** implementation of setScreenRefreshRate */ 89 virtual bool setScreenRefreshRate(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate); 90 91 92 /** returns screen-ndx containing rect x,y,w,h */ 93 unsigned int getScreenContaining(int x, int y, int w, int h); 114 94 115 private: 95 protected: 96 97 template<class PixelBufferImplementation, class GraphicsWindowImplementation> 98 osg::GraphicsContext* createGraphicsContextImplementation(osg::GraphicsContext::Traits* traits) 99 { 100 if (traits->pbuffer) 101 { 102 osg::ref_ptr<PixelBufferImplementation> pbuffer = new PixelBufferImplementation(traits); 103 if (pbuffer->valid()) return pbuffer.release(); 104 else return 0; 105 } 106 else 107 { 108 osg::ref_ptr<GraphicsWindowImplementation> window = new GraphicsWindowImplementation(traits); 109 if (window->valid()) return window.release(); 110 else return 0; 111 } 112 } 113 114 115 private: 116 116 CGDisplayCount _displayCount; 117 117 CGDirectDisplayID* _displayIds; -
OpenSceneGraph/trunk/src/osgViewer/DarwinUtils.mm
r9879 r9895 18 18 static inline CGRect toCGRect(NSRect nsRect) 19 19 { 20 CGRect cgRect;21 22 cgRect.origin.x = nsRect.origin.x;23 cgRect.origin.y = nsRect.origin.y;24 cgRect.size.width = nsRect.size.width;25 cgRect.size.height = nsRect.size.height;26 27 return cgRect;20 CGRect cgRect; 21 22 cgRect.origin.x = nsRect.origin.x; 23 cgRect.origin.y = nsRect.origin.y; 24 cgRect.size.width = nsRect.size.width; 25 cgRect.size.height = nsRect.size.height; 26 27 return cgRect; 28 28 } 29 29 30 30 31 31 MenubarController::MenubarController() 32 : osg::Referenced(),32 : osg::Referenced(), 33 33 _list(), 34 34 _menubarShown(false), 35 35 _mutex() 36 36 { 37 // the following code will query the system for the available rect on the main-display (typically the displaying showing the menubar + the dock38 39 NSRect rect = [[[NSScreen screens] objectAtIndex: 0] visibleFrame];40 _availRect = toCGRect(rect);41 42 // now we need the rect of the main-display including the menubar and the dock43 _mainScreenBounds = CGDisplayBounds( CGMainDisplayID() );44 45 46 // NSRect 0/0 is bottom/left, _mainScreenBounds 0/0 is top/left47 _availRect.origin.y = _mainScreenBounds.size.height - _availRect.size.height - _availRect.origin.y;48 49 50 // hide the menubar initially51 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);37 // the following code will query the system for the available rect on the main-display (typically the displaying showing the menubar + the dock 38 39 NSRect rect = [[[NSScreen screens] objectAtIndex: 0] visibleFrame]; 40 _availRect = toCGRect(rect); 41 42 // now we need the rect of the main-display including the menubar and the dock 43 _mainScreenBounds = CGDisplayBounds( CGMainDisplayID() ); 44 45 46 // NSRect 0/0 is bottom/left, _mainScreenBounds 0/0 is top/left 47 _availRect.origin.y = _mainScreenBounds.size.height - _availRect.size.height - _availRect.origin.y; 48 49 50 // hide the menubar initially 51 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); 52 52 } 53 53 … … 90 90 unsigned int windowsIntersectingMainScreen = 0; 91 91 for(WindowList::iterator i = _list.begin(); i != _list.end(); ) { 92 WindowAdapter* wi = (*i).get();92 WindowAdapter* wi = (*i).get(); 93 93 if (wi->valid()) { 94 94 CGRect windowBounds; 95 wi->getWindowBounds(windowBounds);96 97 if (CGRectIntersectsRect(_mainScreenBounds, windowBounds))95 wi->getWindowBounds(windowBounds); 96 97 if (CGRectIntersectsRect(_mainScreenBounds, windowBounds)) 98 98 { 99 99 ++windowsIntersectingMainScreen; 100 100 // osg::notify(osg::ALWAYS) << "testing rect " << windowBounds.origin.x << "/" << windowBounds.origin.y << " " << windowBounds.size.width << "x" << windowBounds.size.height << std::endl; 101 // osg::notify(osg::ALWAYS) << "against " << _availRect.origin.x << "/" << _availRect.origin.y << " " << _availRect.size.width << "x" << _availRect.size.height << std::endl;101 // osg::notify(osg::ALWAYS) << "against " << _availRect.origin.x << "/" << _availRect.origin.y << " " << _availRect.size.width << "x" << _availRect.size.height << std::endl; 102 102 // the window intersects the main-screen, does it intersect with the menubar/dock? 103 103 if (((_availRect.origin.y > _mainScreenBounds.origin.y) && (_availRect.origin.y > windowBounds.origin.y)) || … … 133 133 static double getDictDouble (CFDictionaryRef refDict, CFStringRef key) 134 134 { 135 double value;136 CFNumberRef number_value = (CFNumberRef) CFDictionaryGetValue(refDict, key);137 if (!number_value) // if can't get a number for the dictionary138 return -1; // fail139 if (!CFNumberGetValue(number_value, kCFNumberDoubleType, &value)) // or if cant convert it140 return -1; // fail141 return value; // otherwise return the long value135 double value; 136 CFNumberRef number_value = (CFNumberRef) CFDictionaryGetValue(refDict, key); 137 if (!number_value) // if can't get a number for the dictionary 138 return -1; // fail 139 if (!CFNumberGetValue(number_value, kCFNumberDoubleType, &value)) // or if cant convert it 140 return -1; // fail 141 return value; // otherwise return the long value 142 142 } 143 143 … … 145 145 static long getDictLong(CFDictionaryRef refDict, CFStringRef key) // const void* key? 146 146 { 147 long value = 0;148 CFNumberRef number_value = (CFNumberRef)CFDictionaryGetValue(refDict, key);149 if (!number_value) // if can't get a number for the dictionary150 return -1; // fail151 if (!CFNumberGetValue(number_value, kCFNumberLongType, &value)) // or if cant convert it152 return -1; // fail153 return value;147 long value = 0; 148 CFNumberRef number_value = (CFNumberRef)CFDictionaryGetValue(refDict, key); 149 if (!number_value) // if can't get a number for the dictionary 150 return -1; // fail 151 if (!CFNumberGetValue(number_value, kCFNumberLongType, &value)) // or if cant convert it 152 return -1; // fail 153 return value; 154 154 } 155 155 … … 158 158 /** ctor, get a list of all attached displays */ 159 159 DarwinWindowingSystemInterface::DarwinWindowingSystemInterface() : 160 _displayCount(0),161 _displayIds(NULL)162 { 163 ProcessSerialNumber sn = { 0, kCurrentProcess };164 TransformProcessType(&sn,kProcessTransformToForegroundApplication);165 SetFrontProcess(&sn);166 167 if( CGGetActiveDisplayList( 0, NULL, &_displayCount ) != CGDisplayNoErr )168 osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: could not get # of screens" << std::endl;169 170 _displayIds = new CGDirectDisplayID[_displayCount];171 if( CGGetActiveDisplayList( _displayCount, _displayIds, &_displayCount ) != CGDisplayNoErr )172 osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: CGGetActiveDisplayList failed" << std::endl;173 174 }160 _displayCount(0), 161 _displayIds(NULL) 162 { 163 ProcessSerialNumber sn = { 0, kCurrentProcess }; 164 TransformProcessType(&sn,kProcessTransformToForegroundApplication); 165 SetFrontProcess(&sn); 166 167 if( CGGetActiveDisplayList( 0, NULL, &_displayCount ) != CGDisplayNoErr ) 168 osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: could not get # of screens" << std::endl; 169 170 _displayIds = new CGDirectDisplayID[_displayCount]; 171 if( CGGetActiveDisplayList( _displayCount, _displayIds, &_displayCount ) != CGDisplayNoErr ) 172 osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: CGGetActiveDisplayList failed" << std::endl; 173 174 } 175 175 176 176 /** dtor */ 177 177 DarwinWindowingSystemInterface::~DarwinWindowingSystemInterface() 178 178 { 179 if (osg::Referenced::getDeleteHandler())180 {181 osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0);182 osg::Referenced::getDeleteHandler()->flushAll();183 }184 185 if (_displayIds) delete[] _displayIds;186 _displayIds = NULL;179 if (osg::Referenced::getDeleteHandler()) 180 { 181 osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0); 182 osg::Referenced::getDeleteHandler()->flushAll(); 183 } 184 185 if (_displayIds) delete[] _displayIds; 186 _displayIds = NULL; 187 187 } 188 188 189 189 /** @return a CGDirectDisplayID for a ScreenIdentifier */ 190 190 CGDirectDisplayID DarwinWindowingSystemInterface::getDisplayID(const osg::GraphicsContext::ScreenIdentifier& si) { 191 if (si.screenNum < static_cast<int>(_displayCount))192 return _displayIds[si.screenNum];193 else {194 osg::notify(osg::WARN) << "GraphicsWindowCarbon :: invalid screen # " << si.screenNum << ", returning main-screen instead" << std::endl;195 return _displayIds[0];196 }191 if (si.screenNum < static_cast<int>(_displayCount)) 192 return _displayIds[si.screenNum]; 193 else { 194 osg::notify(osg::WARN) << "GraphicsWindowCarbon :: invalid screen # " << si.screenNum << ", returning main-screen instead" << std::endl; 195 return _displayIds[0]; 196 } 197 197 } 198 198 … … 200 200 unsigned int DarwinWindowingSystemInterface::getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si) 201 201 { 202 return _displayCount;202 return _displayCount; 203 203 } 204 204 205 205 void DarwinWindowingSystemInterface::getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution) 206 206 { 207 CGDirectDisplayID id = getDisplayID(si);208 resolution.width = CGDisplayPixelsWide(id);209 resolution.height = CGDisplayPixelsHigh(id);210 resolution.colorDepth = CGDisplayBitsPerPixel(id);211 resolution.refreshRate = getDictDouble (CGDisplayCurrentMode(id), kCGDisplayRefreshRate); // Not tested212 if (resolution.refreshRate<0) resolution.refreshRate = 0;207 CGDirectDisplayID id = getDisplayID(si); 208 resolution.width = CGDisplayPixelsWide(id); 209 resolution.height = CGDisplayPixelsHigh(id); 210 resolution.colorDepth = CGDisplayBitsPerPixel(id); 211 resolution.refreshRate = getDictDouble (CGDisplayCurrentMode(id), kCGDisplayRefreshRate); // Not tested 212 if (resolution.refreshRate<0) resolution.refreshRate = 0; 213 213 } 214 214 … … 241 241 /** return the top left coord of a specific screen in global screen space */ 242 242 void DarwinWindowingSystemInterface::getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y) { 243 CGRect bounds = CGDisplayBounds( getDisplayID(si) );244 x = static_cast<int>(bounds.origin.x);245 y = static_cast<int>(bounds.origin.y);246 247 // osg::notify(osg::DEBUG_INFO) << "topleft of screen " << si.screenNum <<" " << bounds.origin.x << "/" << bounds.origin.y << std::endl;243 CGRect bounds = CGDisplayBounds( getDisplayID(si) ); 244 x = static_cast<int>(bounds.origin.x); 245 y = static_cast<int>(bounds.origin.y); 246 247 // osg::notify(osg::DEBUG_INFO) << "topleft of screen " << si.screenNum <<" " << bounds.origin.x << "/" << bounds.origin.y << std::endl; 248 248 } 249 249 … … 253 253 bool DarwinWindowingSystemInterface::setScreenResolution(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) 254 254 { 255 CGDirectDisplayID displayID = getDisplayID(screenIdentifier);256 257 // add next line and on following line replace hard coded depth and refresh rate258 CGRefreshRate refresh = getDictDouble (CGDisplayCurrentMode(displayID), kCGDisplayRefreshRate);259 CFDictionaryRef display_mode_values =260 CGDisplayBestModeForParametersAndRefreshRate(261 displayID,262 CGDisplayBitsPerPixel(displayID),263 width, height,264 refresh,265 NULL);266 267 268 CGDisplaySwitchToMode(displayID, display_mode_values);269 return true;255 CGDirectDisplayID displayID = getDisplayID(screenIdentifier); 256 257 // add next line and on following line replace hard coded depth and refresh rate 258 CGRefreshRate refresh = getDictDouble (CGDisplayCurrentMode(displayID), kCGDisplayRefreshRate); 259 CFDictionaryRef display_mode_values = 260 CGDisplayBestModeForParametersAndRefreshRate( 261 displayID, 262 CGDisplayBitsPerPixel(displayID), 263 width, height, 264 refresh, 265 NULL); 266 267 268 CGDisplaySwitchToMode(displayID, display_mode_values); 269 return true; 270 270 } 271 271 272 272 /** implementation of setScreenRefreshRate */ 273 273 bool DarwinWindowingSystemInterface::setScreenRefreshRate(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate) { 274 275 boolean_t success(false);276 unsigned width, height;277 getScreenResolution(screenIdentifier, width, height);278 279 CGDirectDisplayID displayID = getDisplayID(screenIdentifier);280 281 // add next line and on following line replace hard coded depth and refresh rate282 CFDictionaryRef display_mode_values =283 CGDisplayBestModeForParametersAndRefreshRate(284 displayID,285 CGDisplayBitsPerPixel(displayID),286 width, height,287 refreshRate,288 &success);289 290 291 if (success)292 CGDisplaySwitchToMode(displayID, display_mode_values);293 294 return (success != 0);274 275 boolean_t success(false); 276 unsigned width, height; 277 getScreenResolution(screenIdentifier, width, height); 278 279 CGDirectDisplayID displayID = getDisplayID(screenIdentifier); 280 281 // add next line and on following line replace hard coded depth and refresh rate 282 CFDictionaryRef display_mode_values = 283 CGDisplayBestModeForParametersAndRefreshRate( 284 displayID, 285 CGDisplayBitsPerPixel(displayID), 286 width, height, 287 refreshRate, 288 &success); 289 290 291 if (success) 292 CGDisplaySwitchToMode(displayID, display_mode_values); 293 294 return (success != 0); 295 295 } 296 296 … … 298 298 unsigned int DarwinWindowingSystemInterface::getScreenContaining(int x, int y, int w, int h) 299 299 { 300 CGRect rect = CGRectMake(x,y,w,h);301 for(unsigned int i = 0; i < _displayCount; ++i) {302 CGRect bounds = CGDisplayBounds( getDisplayID(i) );303 if (CGRectIntersectsRect(bounds, rect)) {304 return i;305 }306 }307 308 return 0;309 } 310 311 312 313 314 315 316 } 300 CGRect rect = CGRectMake(x,y,w,h); 301 for(unsigned int i = 0; i < _displayCount; ++i) { 302 CGRect bounds = CGDisplayBounds( getDisplayID(i) ); 303 if (CGRectIntersectsRect(bounds, rect)) { 304 return i; 305 } 306 } 307 308 return 0; 309 } 310 311 312 313 314 315 316 } -
OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCocoa.mm
r9879 r9895 143 143 std::ostream& operator<<(std::ostream& os, const NSRect& rect) 144 144 { 145 os << rect.origin.x << "/" << rect.origin.y << " " << rect.size.width << "x" << rect.size.height;146 return os;145 os << rect.origin.x << "/" << rect.origin.y << " " << rect.size.width << "x" << rect.size.height; 146 return os; 147 147 } 148 148 … … 158 158 NSRect frame = [[[NSScreen screens] objectAtIndex: 0] frame]; 159 159 float y = frame.size.height - rect.origin.y - rect.size.height; 160 NSRect converted = NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height);161 162 // std::cout << "converting from Quartz " << rect << " to " << converted << " using screen rect " << frame << std::endl;163 160 NSRect converted = NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height); 161 162 // std::cout << "converting from Quartz " << rect << " to " << converted << " using screen rect " << frame << std::endl; 163 164 164 return converted; 165 165 } … … 170 170 171 171 float y = frame.size.height - (rect.origin.y + rect.size.height); 172 NSRect converted = NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height);173 174 // std::cout << "converting To Quartz " << rect << " to " << converted << " using screen rect " << frame << std::endl;175 172 NSRect converted = NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height); 173 174 // std::cout << "converting To Quartz " << rect << " to " << converted << " using screen rect " << frame << std::endl; 175 176 176 return converted; 177 177 } … … 245 245 BOOL _isUsingCtrlClick, _isUsingOptionClick; 246 246 unsigned int _cachedModifierFlags; 247 BOOL _handleTabletEvents;247 BOOL _handleTabletEvents; 248 248 249 249 } … … 362 362 363 363 - (void)flagsChanged:(NSEvent *)theEvent { 364 [self handleModifiers: theEvent];364 [self handleModifiers: theEvent]; 365 365 } 366 366 … … 393 393 [self doLeftMouseButtonDown:theEvent]; 394 394 } 395 396 if ([theEvent subtype] == NSTabletPointEventSubtype) {397 _handleTabletEvents = true;398 [self handleTabletEvents:theEvent];399 }395 396 if ([theEvent subtype] == NSTabletPointEventSubtype) { 397 _handleTabletEvents = true; 398 [self handleTabletEvents:theEvent]; 399 } 400 400 } 401 401 … … 405 405 NSPoint converted_point = [self getLocalPoint: theEvent]; 406 406 _win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y); 407 408 if (_handleTabletEvents)409 [self handleTabletEvents:theEvent];407 408 if (_handleTabletEvents) 409 [self handleTabletEvents:theEvent]; 410 410 } 411 411 … … 431 431 [self doLeftMouseButtonUp:theEvent]; 432 432 } 433 _handleTabletEvents = false;433 _handleTabletEvents = false; 434 434 } 435 435 … … 449 449 { 450 450 [self doRightMouseButtonUp:theEvent]; 451 _handleTabletEvents = false;451 _handleTabletEvents = false; 452 452 } 453 453 … … 638 638 - (void)tabletPoint:(NSEvent *)theEvent 639 639 { 640 //_handleTabletEvents = YES;641 //[self handleTabletEvents:theEvent];640 //_handleTabletEvents = YES; 641 //[self handleTabletEvents:theEvent]; 642 642 } 643 643 644 644 -(void)handleTabletEvents:(NSEvent *)theEvent 645 645 { 646 float pressure = [theEvent pressure];647 _win->getEventQueue()->penPressure(pressure);648 NSPoint tilt = [theEvent tilt];649 650 _win->getEventQueue()->penOrientation (tilt.x, tilt.y, [theEvent rotation]);646 float pressure = [theEvent pressure]; 647 _win->getEventQueue()->penPressure(pressure); 648 NSPoint tilt = [theEvent tilt]; 649 650 _win->getEventQueue()->penOrientation (tilt.x, tilt.y, [theEvent rotation]); 651 651 } 652 652 … … 654 654 - (void)tabletProximity:(NSEvent *)theEvent 655 655 { 656 osgGA::GUIEventAdapter::TabletPointerType pt(osgGA::GUIEventAdapter::UNKNOWN);657 switch ([theEvent pointingDeviceType]) {658 case NSPenPointingDevice:659 pt = osgGA::GUIEventAdapter::PEN;660 break;661 case NSCursorPointingDevice:662 pt = osgGA::GUIEventAdapter::PUCK;663 break;664 case NSEraserPointingDevice:665 pt = osgGA::GUIEventAdapter::ERASER;666 break;667 default:668 break;669 }670 _win->getEventQueue()->penProximity(pt, [theEvent isEnteringProximity]);656 osgGA::GUIEventAdapter::TabletPointerType pt(osgGA::GUIEventAdapter::UNKNOWN); 657 switch ([theEvent pointingDeviceType]) { 658 case NSPenPointingDevice: 659 pt = osgGA::GUIEventAdapter::PEN; 660 break; 661 case NSCursorPointingDevice: 662 pt = osgGA::GUIEventAdapter::PUCK; 663 break; 664 case NSEraserPointingDevice: 665 pt = osgGA::GUIEventAdapter::ERASER; 666 break; 667 default: 668 break; 669 } 670 _win->getEventQueue()->penProximity(pt, [theEvent isEnteringProximity]); 671 671 } 672 672 … … 762 762 763 763 virtual bool valid() { return (_win.valid() && _win->valid()); } 764 764 765 765 virtual void getWindowBounds(CGRect& rect) 766 766 { … … 773 773 rect.size.height = nsrect.size.height; 774 774 } 775 775 776 776 virtual osgViewer::GraphicsWindow* getWindow() {return _win.get(); } 777 777 private: … … 808 808 809 809 [win setReleasedWhenClosed:NO]; 810 [win setDisplaysWhenScreenProfileChanges:YES]; 810 [win setDisplaysWhenScreenProfileChanges:YES]; 811 811 GraphicsWindowCocoaDelegate* delegate = [[GraphicsWindowCocoaDelegate alloc] initWith: this]; 812 812 [win setDelegate: delegate ]; 813 813 //[delegate autorelease]; 814 814 815 815 [win makeKeyAndOrderFront:nil]; 816 816 [win setAcceptsMouseMovedEvents: YES]; … … 836 836 style |= NSResizableWindowMask; 837 837 } 838 838 839 839 DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface()); 840 840 int screenLeft(0), screenTop(0); … … 843 843 } 844 844 845 NSRect rect = NSMakeRect(_traits->x + screenLeft, _traits->y + screenTop, _traits->width, _traits->height);846 847 _window = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO];848 845 NSRect rect = NSMakeRect(_traits->x + screenLeft, _traits->y + screenTop, _traits->width, _traits->height); 846 847 _window = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO]; 848 849 849 if (!_window) { 850 850 osg::notify(osg::WARN) << "GraphicsWindowCocoa::realizeImplementation :: could not create window" << std::endl; … … 854 854 rect = convertFromQuartzCoordinates(rect); 855 855 [_window setFrameOrigin: rect.origin]; 856 857 NSOpenGLPixelFormatAttribute attr[32];856 857 NSOpenGLPixelFormatAttribute attr[32]; 858 858 int i = 0; 859 859 … … 902 902 } 903 903 } 904 905 NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ];904 905 NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ]; 906 906 _context = [[NSOpenGLContext alloc] initWithFormat: pixelformat shareContext: sharedContext]; 907 907 … … 910 910 return false; 911 911 } 912 GraphicsWindowCocoaGLView* theView = [[ GraphicsWindowCocoaGLView alloc ] initWithFrame:[ _window frame ] ];912 GraphicsWindowCocoaGLView* theView = [[ GraphicsWindowCocoaGLView alloc ] initWithFrame:[ _window frame ] ]; 913 913 [theView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable) ]; 914 914 [theView setGraphicsWindowCocoa: this]; 915 915 [theView setOpenGLContext:_context]; 916 [_window setContentView: theView];917 916 [_window setContentView: theView]; 917 918 918 setupNSWindow(_window); 919 919 920 920 [theView release]; 921 921 [pool release]; 922 922 923 923 MenubarController::instance()->attachWindow( new CocoaWindowAdapter(this) ); 924 924 … … 951 951 if (mbc) mbc->detachWindow(this); 952 952 953 [_window close];953 [_window close]; 954 954 [_window release]; 955 955 } … … 962 962 bool GraphicsWindowCocoa:: makeCurrentImplementation() 963 963 { 964 [_context makeCurrentContext];965 return true;964 [_context makeCurrentContext]; 965 return true; 966 966 } 967 967 … … 973 973 bool GraphicsWindowCocoa::releaseContextImplementation() 974 974 { 975 [NSOpenGLContext clearCurrentContext];976 return true;975 [NSOpenGLContext clearCurrentContext]; 976 return true; 977 977 } 978 978 … … 984 984 void GraphicsWindowCocoa::swapBuffersImplementation() 985 985 { 986 [_context flushBuffer];986 [_context flushBuffer]; 987 987 } 988 988 … … 994 994 void GraphicsWindowCocoa::checkEvents() 995 995 { 996 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];996 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 997 997 998 998 while(1) … … 1013 1013 break; 1014 1014 [[NSApplication sharedApplication] sendEvent: event]; 1015 } 1015 } 1016 1016 1017 1017 if (_closeRequested) … … 1023 1023 } 1024 1024 1025 [pool release];1025 [pool release]; 1026 1026 } 1027 1027 … … 1038 1038 { 1039 1039 if (!_realized) return false; 1040 1040 1041 1041 unsigned int style(NSBorderlessWindowMask); 1042 1042 … … 1048 1048 style |= NSResizableWindowMask; 1049 1049 } 1050 NSRect rect = [_window contentRectForFrameRect: [_window frame] ];1051 GraphicsWindowCocoaWindow* new_win = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO];1050 NSRect rect = [_window contentRectForFrameRect: [_window frame] ]; 1051 GraphicsWindowCocoaWindow* new_win = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO]; 1052 1052 1053 1053 if (new_win) { … … 1062 1062 } 1063 1063 1064 return true;1064 return true; 1065 1065 } 1066 1066 … … 1071 1071 void GraphicsWindowCocoa::grabFocus() 1072 1072 { 1073 [_window makeKeyAndOrderFront: nil];1073 [_window makeKeyAndOrderFront: nil]; 1074 1074 } 1075 1075 … … 1080 1080 void GraphicsWindowCocoa::grabFocusIfPointerInWindow() 1081 1081 { 1082 osg::notify(osg::INFO) << "GraphicsWindowCocoa :: grabFocusIfPointerInWindow not implemented yet " << std::endl;1082 osg::notify(osg::INFO) << "GraphicsWindowCocoa :: grabFocusIfPointerInWindow not implemented yet " << std::endl; 1083 1083 } 1084 1084 … … 1090 1090 void GraphicsWindowCocoa::resizedImplementation(int x, int y, int width, int height) 1091 1091 { 1092 std::cout << "resized implementation" << x << " " << y << " " << width << " " << height << std::endl;1093 GraphicsContext::resizedImplementation(x, y, width, height);1092 std::cout << "resized implementation" << x << " " << y << " " << width << " " << height << std::endl; 1093 GraphicsContext::resizedImplementation(x, y, width, height); 1094 1094 1095 1095 [_context update]; 1096 1096 MenubarController::instance()->update(); 1097 getEventQueue()->windowResize(x,y,width, height, getEventQueue()->getTime());1097 getEventQueue()->windowResize(x,y,width, height, getEventQueue()->getTime()); 1098 1098 } 1099 1099 … … 1106 1106 bool GraphicsWindowCocoa::setWindowRectangleImplementation(int x, int y, int width, int height) 1107 1107 { 1108 DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());1108 DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface()); 1109 1109 int screenLeft(0), screenTop(0); 1110 1110 if (wsi) { … … 1131 1131 { 1132 1132 1133 DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());1133 DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface()); 1134 1134 int screenLeft(0), screenTop(0); 1135 1135 if (wsi) { 1136 1137 // get the screen containing the window1138 unsigned int screenNdx = wsi->getScreenContaining(x,y,w,h);1139 1140 // update traits1141 _traits->screenNum = screenNdx;1142 1143 // get top left of screen1136 1137 // get the screen containing the window 1138 unsigned int screenNdx = wsi->getScreenContaining(x,y,w,h); 1139 1140 // update traits 1141 _traits->screenNum = screenNdx; 1142 1143 // get top left of screen 1144 1144 wsi->getScreenTopLeft((*_traits), screenLeft, screenTop); 1145 1145 } 1146 1147 resized(x-screenLeft,y-screenTop,w,h);1146 1147 resized(x-screenLeft,y-screenTop,w,h); 1148 1148 } 1149 1149 … … 1155 1155 void GraphicsWindowCocoa::setWindowName (const std::string & name) 1156 1156 { 1157 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];1157 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 1158 1158 1159 1159 NSString* title = [NSString stringWithCString: name.c_str() encoding: NSUTF8StringEncoding]; 1160 [_window setTitle: title];1161 [title release];1160 [_window setTitle: title]; 1161 [title release]; 1162 1162 [pool release]; 1163 1163 } … … 1170 1170 void GraphicsWindowCocoa::useCursor(bool cursorOn) 1171 1171 { 1172 if (_traits.valid())1172 if (_traits.valid()) 1173 1173 _traits->useCursor = cursorOn; 1174 1174 DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface()); … … 1201 1201 void GraphicsWindowCocoa::setCursor(MouseCursor mouseCursor) 1202 1202 { 1203 switch (mouseCursor)1203 switch (mouseCursor) 1204 1204 { 1205 1205 … … 1233 1233 { 1234 1234 GLint VBL(f?1:0); 1235 [_context setValues:&VBL forParameter:NSOpenGLCPSwapInterval];1235 [_context setValues:&VBL forParameter:NSOpenGLCPSwapInterval]; 1236 1236 } 1237 1237 … … 1254 1254 1255 1255 struct CocoaWindowingSystemInterface : public DarwinWindowingSystemInterface { 1256 1257 CocoaWindowingSystemInterface()1258 :DarwinWindowingSystemInterface()1259 {1260 localPool = [[NSAutoreleasePool alloc] init];1256 1257 CocoaWindowingSystemInterface() 1258 : DarwinWindowingSystemInterface() 1259 { 1260 localPool = [[NSAutoreleasePool alloc] init]; 1261 1261 [[NSApplication sharedApplication] setDelegate: [[CocoaAppDelegate alloc] init] ]; 1262 }1263 1264 virtual osg::GraphicsContext* createGraphicsContext(osg::GraphicsContext::Traits* traits)1265 {1266 return createGraphicsContextImplementation<PixelBufferCocoa, GraphicsWindowCocoa>(traits);1267 }1268 1269 virtual ~CocoaWindowingSystemInterface()1270 {1271 [localPool release];1272 }1273 1274 NSAutoreleasePool *localPool;1262 } 1263 1264 virtual osg::GraphicsContext* createGraphicsContext(osg::GraphicsContext::Traits* traits) 1265 { 1266 return createGraphicsContextImplementation<PixelBufferCocoa, GraphicsWindowCocoa>(traits); 1267 } 1268 1269 virtual ~CocoaWindowingSystemInterface() 1270 { 1271 [localPool release]; 1272 } 1273 1274 NSAutoreleasePool *localPool; 1275 1275 1276 1276 };
