- Timestamp:
- 03/11/09 11:34:29 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
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 };
