Converted tabs to four spaces

This commit is contained in:
Robert Osfield 2009-03-11 10:34:29 +00:00
parent 357d465d49
commit c3810e130b
3 changed files with 299 additions and 299 deletions

View File

@ -29,19 +29,19 @@ class MenubarController : public osg::Referenced
{
public:
class WindowAdapter : public osg::Referenced {
public:
WindowAdapter() : osg::Referenced() {}
virtual bool valid() = 0;
virtual void getWindowBounds(CGRect& rect) = 0;
virtual osgViewer::GraphicsWindow* getWindow() = 0;
protected:
virtual ~WindowAdapter() {}
};
class WindowAdapter : public osg::Referenced {
public:
WindowAdapter() : osg::Referenced() {}
virtual bool valid() = 0;
virtual void getWindowBounds(CGRect& rect) = 0;
virtual osgViewer::GraphicsWindow* getWindow() = 0;
protected:
virtual ~WindowAdapter() {}
};
MenubarController();
static MenubarController* instance();
@ -51,11 +51,11 @@ class MenubarController : public osg::Referenced
private:
typedef std::list< osg::ref_ptr< WindowAdapter > > WindowList;
WindowList _list;
bool _menubarShown;
CGRect _availRect;
CGRect _mainScreenBounds;
OpenThreads::Mutex _mutex;
WindowList _list;
bool _menubarShown;
CGRect _availRect;
CGRect _mainScreenBounds;
OpenThreads::Mutex _mutex;
};
@ -64,55 +64,55 @@ class MenubarController : public osg::Referenced
struct DarwinWindowingSystemInterface : public osg::GraphicsContext::WindowingSystemInterface
{
public:
DarwinWindowingSystemInterface();
/** dtor */
~DarwinWindowingSystemInterface();
/** @return a CGDirectDisplayID for a ScreenIdentifier */
CGDirectDisplayID getDisplayID(const osg::GraphicsContext::ScreenIdentifier& si);
/** @return count of attached screens */
virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si) ;
virtual void getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution);
DarwinWindowingSystemInterface();
virtual void enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, osg::GraphicsContext::ScreenSettingsList & resolutionList);
/** dtor */
~DarwinWindowingSystemInterface();
/** return the top left coord of a specific screen in global screen space */
void getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y);
/** implementation of setScreenResolution */
virtual bool setScreenResolution(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) ;
/** @return a CGDirectDisplayID for a ScreenIdentifier */
CGDirectDisplayID getDisplayID(const osg::GraphicsContext::ScreenIdentifier& si);
/** implementation of setScreenRefreshRate */
virtual bool setScreenRefreshRate(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate);
/** returns screen-ndx containing rect x,y,w,h */
unsigned int getScreenContaining(int x, int y, int w, int h);
protected:
template<class PixelBufferImplementation, class GraphicsWindowImplementation>
osg::GraphicsContext* createGraphicsContextImplementation(osg::GraphicsContext::Traits* traits)
{
if (traits->pbuffer)
{
osg::ref_ptr<PixelBufferImplementation> pbuffer = new PixelBufferImplementation(traits);
if (pbuffer->valid()) return pbuffer.release();
else return 0;
}
else
{
osg::ref_ptr<GraphicsWindowImplementation> window = new GraphicsWindowImplementation(traits);
if (window->valid()) return window.release();
else return 0;
}
}
/** @return count of attached screens */
virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si) ;
virtual void getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution);
virtual void enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, osg::GraphicsContext::ScreenSettingsList & resolutionList);
/** return the top left coord of a specific screen in global screen space */
void getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y);
/** implementation of setScreenResolution */
virtual bool setScreenResolution(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) ;
/** implementation of setScreenRefreshRate */
virtual bool setScreenRefreshRate(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate);
/** returns screen-ndx containing rect x,y,w,h */
unsigned int getScreenContaining(int x, int y, int w, int h);
private:
protected:
template<class PixelBufferImplementation, class GraphicsWindowImplementation>
osg::GraphicsContext* createGraphicsContextImplementation(osg::GraphicsContext::Traits* traits)
{
if (traits->pbuffer)
{
osg::ref_ptr<PixelBufferImplementation> pbuffer = new PixelBufferImplementation(traits);
if (pbuffer->valid()) return pbuffer.release();
else return 0;
}
else
{
osg::ref_ptr<GraphicsWindowImplementation> window = new GraphicsWindowImplementation(traits);
if (window->valid()) return window.release();
else return 0;
}
}
private:
CGDisplayCount _displayCount;
CGDirectDisplayID* _displayIds;
@ -145,4 +145,4 @@ struct RegisterWindowingSystemInterfaceProxy
#endif
#endif // __APPLE__
#endif // __APPLE__

View File

@ -17,38 +17,38 @@ namespace osgDarwin {
static inline CGRect toCGRect(NSRect nsRect)
{
CGRect cgRect;
CGRect cgRect;
cgRect.origin.x = nsRect.origin.x;
cgRect.origin.y = nsRect.origin.y;
cgRect.size.width = nsRect.size.width;
cgRect.size.height = nsRect.size.height;
cgRect.origin.x = nsRect.origin.x;
cgRect.origin.y = nsRect.origin.y;
cgRect.size.width = nsRect.size.width;
cgRect.size.height = nsRect.size.height;
return cgRect;
return cgRect;
}
MenubarController::MenubarController()
: osg::Referenced(),
: osg::Referenced(),
_list(),
_menubarShown(false),
_mutex()
{
// the following code will query the system for the available rect on the main-display (typically the displaying showing the menubar + the dock
// the following code will query the system for the available rect on the main-display (typically the displaying showing the menubar + the dock
NSRect rect = [[[NSScreen screens] objectAtIndex: 0] visibleFrame];
_availRect = toCGRect(rect);
// now we need the rect of the main-display including the menubar and the dock
_mainScreenBounds = CGDisplayBounds( CGMainDisplayID() );
NSRect rect = [[[NSScreen screens] objectAtIndex: 0] visibleFrame];
_availRect = toCGRect(rect);
// now we need the rect of the main-display including the menubar and the dock
_mainScreenBounds = CGDisplayBounds( CGMainDisplayID() );
// NSRect 0/0 is bottom/left, _mainScreenBounds 0/0 is top/left
_availRect.origin.y = _mainScreenBounds.size.height - _availRect.size.height - _availRect.origin.y;
// hide the menubar initially
SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
// NSRect 0/0 is bottom/left, _mainScreenBounds 0/0 is top/left
_availRect.origin.y = _mainScreenBounds.size.height - _availRect.size.height - _availRect.origin.y;
// hide the menubar initially
SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
}
@ -89,16 +89,16 @@ void MenubarController::update()
unsigned int windowsCoveringMenubarArea = 0;
unsigned int windowsIntersectingMainScreen = 0;
for(WindowList::iterator i = _list.begin(); i != _list.end(); ) {
WindowAdapter* wi = (*i).get();
WindowAdapter* wi = (*i).get();
if (wi->valid()) {
CGRect windowBounds;
wi->getWindowBounds(windowBounds);
if (CGRectIntersectsRect(_mainScreenBounds, windowBounds))
wi->getWindowBounds(windowBounds);
if (CGRectIntersectsRect(_mainScreenBounds, windowBounds))
{
++windowsIntersectingMainScreen;
// osg::notify(osg::ALWAYS) << "testing rect " << windowBounds.origin.x << "/" << windowBounds.origin.y << " " << windowBounds.size.width << "x" << windowBounds.size.height << std::endl;
// osg::notify(osg::ALWAYS) << "against " << _availRect.origin.x << "/" << _availRect.origin.y << " " << _availRect.size.width << "x" << _availRect.size.height << std::endl;
// osg::notify(osg::ALWAYS) << "against " << _availRect.origin.x << "/" << _availRect.origin.y << " " << _availRect.size.width << "x" << _availRect.size.height << std::endl;
// the window intersects the main-screen, does it intersect with the menubar/dock?
if (((_availRect.origin.y > _mainScreenBounds.origin.y) && (_availRect.origin.y > windowBounds.origin.y)) ||
((_availRect.origin.x > _mainScreenBounds.origin.x) && (_availRect.origin.x > windowBounds.origin.x)) ||
@ -132,84 +132,84 @@ void MenubarController::update()
/** Helper method to get a double value out of a CFDictionary */
static double getDictDouble (CFDictionaryRef refDict, CFStringRef key)
{
double value;
CFNumberRef number_value = (CFNumberRef) CFDictionaryGetValue(refDict, key);
if (!number_value) // if can't get a number for the dictionary
return -1; // fail
if (!CFNumberGetValue(number_value, kCFNumberDoubleType, &value)) // or if cant convert it
return -1; // fail
return value; // otherwise return the long value
double value;
CFNumberRef number_value = (CFNumberRef) CFDictionaryGetValue(refDict, key);
if (!number_value) // if can't get a number for the dictionary
return -1; // fail
if (!CFNumberGetValue(number_value, kCFNumberDoubleType, &value)) // or if cant convert it
return -1; // fail
return value; // otherwise return the long value
}
/** Helper method to get a long value out of a CFDictionary */
static long getDictLong(CFDictionaryRef refDict, CFStringRef key) // const void* key?
{
long value = 0;
CFNumberRef number_value = (CFNumberRef)CFDictionaryGetValue(refDict, key);
if (!number_value) // if can't get a number for the dictionary
return -1; // fail
if (!CFNumberGetValue(number_value, kCFNumberLongType, &value)) // or if cant convert it
return -1; // fail
return value;
long value = 0;
CFNumberRef number_value = (CFNumberRef)CFDictionaryGetValue(refDict, key);
if (!number_value) // if can't get a number for the dictionary
return -1; // fail
if (!CFNumberGetValue(number_value, kCFNumberLongType, &value)) // or if cant convert it
return -1; // fail
return value;
}
/** ctor, get a list of all attached displays */
DarwinWindowingSystemInterface::DarwinWindowingSystemInterface() :
_displayCount(0),
_displayIds(NULL)
_displayCount(0),
_displayIds(NULL)
{
ProcessSerialNumber sn = { 0, kCurrentProcess };
TransformProcessType(&sn,kProcessTransformToForegroundApplication);
SetFrontProcess(&sn);
if( CGGetActiveDisplayList( 0, NULL, &_displayCount ) != CGDisplayNoErr )
osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: could not get # of screens" << std::endl;
_displayIds = new CGDirectDisplayID[_displayCount];
if( CGGetActiveDisplayList( _displayCount, _displayIds, &_displayCount ) != CGDisplayNoErr )
osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: CGGetActiveDisplayList failed" << std::endl;
}
ProcessSerialNumber sn = { 0, kCurrentProcess };
TransformProcessType(&sn,kProcessTransformToForegroundApplication);
SetFrontProcess(&sn);
if( CGGetActiveDisplayList( 0, NULL, &_displayCount ) != CGDisplayNoErr )
osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: could not get # of screens" << std::endl;
_displayIds = new CGDirectDisplayID[_displayCount];
if( CGGetActiveDisplayList( _displayCount, _displayIds, &_displayCount ) != CGDisplayNoErr )
osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: CGGetActiveDisplayList failed" << std::endl;
}
/** dtor */
DarwinWindowingSystemInterface::~DarwinWindowingSystemInterface()
{
if (osg::Referenced::getDeleteHandler())
{
osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0);
osg::Referenced::getDeleteHandler()->flushAll();
}
if (osg::Referenced::getDeleteHandler())
{
osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0);
osg::Referenced::getDeleteHandler()->flushAll();
}
if (_displayIds) delete[] _displayIds;
_displayIds = NULL;
if (_displayIds) delete[] _displayIds;
_displayIds = NULL;
}
/** @return a CGDirectDisplayID for a ScreenIdentifier */
CGDirectDisplayID DarwinWindowingSystemInterface::getDisplayID(const osg::GraphicsContext::ScreenIdentifier& si) {
if (si.screenNum < static_cast<int>(_displayCount))
return _displayIds[si.screenNum];
else {
osg::notify(osg::WARN) << "GraphicsWindowCarbon :: invalid screen # " << si.screenNum << ", returning main-screen instead" << std::endl;
return _displayIds[0];
}
if (si.screenNum < static_cast<int>(_displayCount))
return _displayIds[si.screenNum];
else {
osg::notify(osg::WARN) << "GraphicsWindowCarbon :: invalid screen # " << si.screenNum << ", returning main-screen instead" << std::endl;
return _displayIds[0];
}
}
/** @return count of attached screens */
unsigned int DarwinWindowingSystemInterface::getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si)
{
return _displayCount;
return _displayCount;
}
void DarwinWindowingSystemInterface::getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution)
{
CGDirectDisplayID id = getDisplayID(si);
resolution.width = CGDisplayPixelsWide(id);
resolution.height = CGDisplayPixelsHigh(id);
resolution.colorDepth = CGDisplayBitsPerPixel(id);
resolution.refreshRate = getDictDouble (CGDisplayCurrentMode(id), kCGDisplayRefreshRate); // Not tested
if (resolution.refreshRate<0) resolution.refreshRate = 0;
CGDirectDisplayID id = getDisplayID(si);
resolution.width = CGDisplayPixelsWide(id);
resolution.height = CGDisplayPixelsHigh(id);
resolution.colorDepth = CGDisplayBitsPerPixel(id);
resolution.refreshRate = getDictDouble (CGDisplayCurrentMode(id), kCGDisplayRefreshRate); // Not tested
if (resolution.refreshRate<0) resolution.refreshRate = 0;
}
@ -240,11 +240,11 @@ void DarwinWindowingSystemInterface::enumerateScreenSettings(const osg::Graphics
/** return the top left coord of a specific screen in global screen space */
void DarwinWindowingSystemInterface::getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y) {
CGRect bounds = CGDisplayBounds( getDisplayID(si) );
x = static_cast<int>(bounds.origin.x);
y = static_cast<int>(bounds.origin.y);
// osg::notify(osg::DEBUG_INFO) << "topleft of screen " << si.screenNum <<" " << bounds.origin.x << "/" << bounds.origin.y << std::endl;
CGRect bounds = CGDisplayBounds( getDisplayID(si) );
x = static_cast<int>(bounds.origin.x);
y = static_cast<int>(bounds.origin.y);
// osg::notify(osg::DEBUG_INFO) << "topleft of screen " << si.screenNum <<" " << bounds.origin.x << "/" << bounds.origin.y << std::endl;
}
@ -252,60 +252,60 @@ void DarwinWindowingSystemInterface::getScreenTopLeft(const osg::GraphicsContext
/** implementation of setScreenResolution */
bool DarwinWindowingSystemInterface::setScreenResolution(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height)
{
CGDirectDisplayID displayID = getDisplayID(screenIdentifier);
// add next line and on following line replace hard coded depth and refresh rate
CGRefreshRate refresh = getDictDouble (CGDisplayCurrentMode(displayID), kCGDisplayRefreshRate);
CFDictionaryRef display_mode_values =
CGDisplayBestModeForParametersAndRefreshRate(
displayID,
CGDisplayBitsPerPixel(displayID),
width, height,
refresh,
NULL);
CGDirectDisplayID displayID = getDisplayID(screenIdentifier);
// add next line and on following line replace hard coded depth and refresh rate
CGRefreshRate refresh = getDictDouble (CGDisplayCurrentMode(displayID), kCGDisplayRefreshRate);
CFDictionaryRef display_mode_values =
CGDisplayBestModeForParametersAndRefreshRate(
displayID,
CGDisplayBitsPerPixel(displayID),
width, height,
refresh,
NULL);
CGDisplaySwitchToMode(displayID, display_mode_values);
return true;
CGDisplaySwitchToMode(displayID, display_mode_values);
return true;
}
/** implementation of setScreenRefreshRate */
bool DarwinWindowingSystemInterface::setScreenRefreshRate(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate) {
boolean_t success(false);
unsigned width, height;
getScreenResolution(screenIdentifier, width, height);
CGDirectDisplayID displayID = getDisplayID(screenIdentifier);
// add next line and on following line replace hard coded depth and refresh rate
CFDictionaryRef display_mode_values =
CGDisplayBestModeForParametersAndRefreshRate(
displayID,
CGDisplayBitsPerPixel(displayID),
width, height,
refreshRate,
&success);
boolean_t success(false);
unsigned width, height;
getScreenResolution(screenIdentifier, width, height);
CGDirectDisplayID displayID = getDisplayID(screenIdentifier);
// add next line and on following line replace hard coded depth and refresh rate
CFDictionaryRef display_mode_values =
CGDisplayBestModeForParametersAndRefreshRate(
displayID,
CGDisplayBitsPerPixel(displayID),
width, height,
refreshRate,
&success);
if (success)
CGDisplaySwitchToMode(displayID, display_mode_values);
return (success != 0);
if (success)
CGDisplaySwitchToMode(displayID, display_mode_values);
return (success != 0);
}
unsigned int DarwinWindowingSystemInterface::getScreenContaining(int x, int y, int w, int h)
{
CGRect rect = CGRectMake(x,y,w,h);
for(unsigned int i = 0; i < _displayCount; ++i) {
CGRect bounds = CGDisplayBounds( getDisplayID(i) );
if (CGRectIntersectsRect(bounds, rect)) {
return i;
}
}
return 0;
CGRect rect = CGRectMake(x,y,w,h);
for(unsigned int i = 0; i < _displayCount; ++i) {
CGRect bounds = CGDisplayBounds( getDisplayID(i) );
if (CGRectIntersectsRect(bounds, rect)) {
return i;
}
}
return 0;
}
@ -313,4 +313,4 @@ unsigned int DarwinWindowingSystemInterface::getScreenContaining(int x, int y, i
}
}

View File

@ -142,8 +142,8 @@ static unsigned int remapCocoaKey(unsigned int key, bool pressedOnKeypad = false
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;
os << rect.origin.x << "/" << rect.origin.y << " " << rect.size.width << "x" << rect.size.height;
return os;
}
// ----------------------------------------------------------------------------------------------------------
@ -157,10 +157,10 @@ 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;
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;
}
@ -169,10 +169,10 @@ 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;
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;
}
@ -244,7 +244,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect)
osgViewer::GraphicsWindowCocoa* _win;
BOOL _isUsingCtrlClick, _isUsingOptionClick;
unsigned int _cachedModifierFlags;
BOOL _handleTabletEvents;
BOOL _handleTabletEvents;
}
- (void)setGraphicsWindowCocoa: (osgViewer::GraphicsWindowCocoa*) win;
@ -361,7 +361,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect)
}
- (void)flagsChanged:(NSEvent *)theEvent {
[self handleModifiers: theEvent];
[self handleModifiers: theEvent];
}
- (void) mouseMoved:(NSEvent*)theEvent
@ -392,11 +392,11 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect)
{
[self doLeftMouseButtonDown:theEvent];
}
if ([theEvent subtype] == NSTabletPointEventSubtype) {
_handleTabletEvents = true;
[self handleTabletEvents:theEvent];
}
if ([theEvent subtype] == NSTabletPointEventSubtype) {
_handleTabletEvents = true;
[self handleTabletEvents:theEvent];
}
}
@ -404,9 +404,9 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect)
{
NSPoint converted_point = [self getLocalPoint: theEvent];
_win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y);
if (_handleTabletEvents)
[self handleTabletEvents:theEvent];
if (_handleTabletEvents)
[self handleTabletEvents:theEvent];
}
@ -430,7 +430,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect)
{
[self doLeftMouseButtonUp:theEvent];
}
_handleTabletEvents = false;
_handleTabletEvents = false;
}
- (void) rightMouseDown:(NSEvent*)theEvent
@ -448,7 +448,7 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect)
- (void) rightMouseUp:(NSEvent*)theEvent
{
[self doRightMouseButtonUp:theEvent];
_handleTabletEvents = false;
_handleTabletEvents = false;
}
// "otherMouse" seems to capture middle button and any other buttons beyond (4th, etc).
@ -637,37 +637,37 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect)
- (void)tabletPoint:(NSEvent *)theEvent
{
//_handleTabletEvents = YES;
//[self handleTabletEvents:theEvent];
//_handleTabletEvents = YES;
//[self handleTabletEvents:theEvent];
}
-(void)handleTabletEvents:(NSEvent *)theEvent
{
float pressure = [theEvent pressure];
_win->getEventQueue()->penPressure(pressure);
NSPoint tilt = [theEvent tilt];
_win->getEventQueue()->penOrientation (tilt.x, tilt.y, [theEvent rotation]);
float pressure = [theEvent pressure];
_win->getEventQueue()->penPressure(pressure);
NSPoint tilt = [theEvent tilt];
_win->getEventQueue()->penOrientation (tilt.x, tilt.y, [theEvent rotation]);
}
- (void)tabletProximity:(NSEvent *)theEvent
{
osgGA::GUIEventAdapter::TabletPointerType pt(osgGA::GUIEventAdapter::UNKNOWN);
switch ([theEvent pointingDeviceType]) {
case NSPenPointingDevice:
pt = osgGA::GUIEventAdapter::PEN;
break;
case NSCursorPointingDevice:
pt = osgGA::GUIEventAdapter::PUCK;
break;
case NSEraserPointingDevice:
pt = osgGA::GUIEventAdapter::ERASER;
break;
default:
break;
}
_win->getEventQueue()->penProximity(pt, [theEvent isEnteringProximity]);
osgGA::GUIEventAdapter::TabletPointerType pt(osgGA::GUIEventAdapter::UNKNOWN);
switch ([theEvent pointingDeviceType]) {
case NSPenPointingDevice:
pt = osgGA::GUIEventAdapter::PEN;
break;
case NSCursorPointingDevice:
pt = osgGA::GUIEventAdapter::PUCK;
break;
case NSEraserPointingDevice:
pt = osgGA::GUIEventAdapter::ERASER;
break;
default:
break;
}
_win->getEventQueue()->penProximity(pt, [theEvent isEnteringProximity]);
}
@ -761,7 +761,7 @@ public:
CocoaWindowAdapter(GraphicsWindowCocoa* win) : MenubarController::WindowAdapter(), _win(win) {}
virtual bool valid() { return (_win.valid() && _win->valid()); }
virtual void getWindowBounds(CGRect& rect)
{
NSRect nsrect = [_win->getWindow() frame];
@ -772,7 +772,7 @@ public:
rect.size.width = nsrect.size.width;
rect.size.height = nsrect.size.height;
}
virtual osgViewer::GraphicsWindow* getWindow() {return _win.get(); }
private:
osg::observer_ptr<GraphicsWindowCocoa> _win;
@ -807,11 +807,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];
@ -835,17 +835,17 @@ bool GraphicsWindowCocoa::realizeImplementation()
if (_traits->supportsResize)
style |= NSResizableWindowMask;
}
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(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);
NSRect rect = NSMakeRect(_traits->x + screenLeft, _traits->y + screenTop, _traits->width, _traits->height);
_window = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO];
_window = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO];
if (!_window) {
osg::notify(osg::WARN) << "GraphicsWindowCocoa::realizeImplementation :: could not create window" << std::endl;
return false;
@ -853,8 +853,8 @@ bool GraphicsWindowCocoa::realizeImplementation()
rect = convertFromQuartzCoordinates(rect);
[_window setFrameOrigin: rect.origin];
NSOpenGLPixelFormatAttribute attr[32];
NSOpenGLPixelFormatAttribute attr[32];
int i = 0;
attr[i++] = NSOpenGLPFADepthSize;
@ -901,25 +901,25 @@ bool GraphicsWindowCocoa::realizeImplementation()
sharedContext = pixelbuffer->getContext();
}
}
NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ];
NSOpenGLPixelFormat* 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;
return false;
}
GraphicsWindowCocoaGLView* theView = [[ GraphicsWindowCocoaGLView alloc ] initWithFrame:[ _window frame ] ];
GraphicsWindowCocoaGLView* theView = [[ GraphicsWindowCocoaGLView alloc ] initWithFrame:[ _window frame ] ];
[theView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable) ];
[theView setGraphicsWindowCocoa: this];
[theView setOpenGLContext:_context];
[_window setContentView: theView];
[_window setContentView: theView];
setupNSWindow(_window);
[theView release];
[pool release];
MenubarController::instance()->attachWindow( new CocoaWindowAdapter(this) );
useCursor(_traits->useCursor);
@ -950,7 +950,7 @@ void GraphicsWindowCocoa::closeImplementation()
MenubarController* mbc = MenubarController::instance();
if (mbc) mbc->detachWindow(this);
[_window close];
[_window close];
[_window release];
}
@ -961,8 +961,8 @@ void GraphicsWindowCocoa::closeImplementation()
bool GraphicsWindowCocoa:: makeCurrentImplementation()
{
[_context makeCurrentContext];
return true;
[_context makeCurrentContext];
return true;
}
@ -972,8 +972,8 @@ bool GraphicsWindowCocoa:: makeCurrentImplementation()
bool GraphicsWindowCocoa::releaseContextImplementation()
{
[NSOpenGLContext clearCurrentContext];
return true;
[NSOpenGLContext clearCurrentContext];
return true;
}
@ -983,7 +983,7 @@ bool GraphicsWindowCocoa::releaseContextImplementation()
void GraphicsWindowCocoa::swapBuffersImplementation()
{
[_context flushBuffer];
[_context flushBuffer];
}
@ -993,7 +993,7 @@ void GraphicsWindowCocoa::swapBuffersImplementation()
// ----------------------------------------------------------------------------------------------------------
void GraphicsWindowCocoa::checkEvents()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
while(1)
{
@ -1012,7 +1012,7 @@ void GraphicsWindowCocoa::checkEvents()
if(!event)
break;
[[NSApplication sharedApplication] sendEvent: event];
}
}
if (_closeRequested)
getEventQueue()->closeWindow();
@ -1022,7 +1022,7 @@ void GraphicsWindowCocoa::checkEvents()
s_quit_requested = false;
}
[pool release];
[pool release];
}
@ -1037,7 +1037,7 @@ void GraphicsWindowCocoa::checkEvents()
bool GraphicsWindowCocoa::setWindowDecorationImplementation(bool flag)
{
if (!_realized) return false;
unsigned int style(NSBorderlessWindowMask);
if (flag) {
@ -1047,8 +1047,8 @@ bool GraphicsWindowCocoa::setWindowDecorationImplementation(bool flag)
if (_traits->supportsResize)
style |= NSResizableWindowMask;
}
NSRect rect = [_window contentRectForFrameRect: [_window frame] ];
GraphicsWindowCocoaWindow* new_win = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO];
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]];
@ -1061,7 +1061,7 @@ bool GraphicsWindowCocoa::setWindowDecorationImplementation(bool flag)
[_window makeKeyAndOrderFront: nil];
}
return true;
return true;
}
@ -1070,7 +1070,7 @@ bool GraphicsWindowCocoa::setWindowDecorationImplementation(bool flag)
// ----------------------------------------------------------------------------------------------------------
void GraphicsWindowCocoa::grabFocus()
{
[_window makeKeyAndOrderFront: nil];
[_window makeKeyAndOrderFront: nil];
}
@ -1079,7 +1079,7 @@ void GraphicsWindowCocoa::grabFocus()
// ----------------------------------------------------------------------------------------------------------
void GraphicsWindowCocoa::grabFocusIfPointerInWindow()
{
osg::notify(osg::INFO) << "GraphicsWindowCocoa :: grabFocusIfPointerInWindow not implemented yet " << std::endl;
osg::notify(osg::INFO) << "GraphicsWindowCocoa :: grabFocusIfPointerInWindow not implemented yet " << std::endl;
}
@ -1089,12 +1089,12 @@ void GraphicsWindowCocoa::grabFocusIfPointerInWindow()
void GraphicsWindowCocoa::resizedImplementation(int x, int y, int width, int height)
{
std::cout << "resized implementation" << x << " " << y << " " << width << " " << height << std::endl;
GraphicsContext::resizedImplementation(x, y, width, height);
std::cout << "resized implementation" << x << " " << y << " " << width << " " << height << std::endl;
GraphicsContext::resizedImplementation(x, y, width, height);
[_context update];
MenubarController::instance()->update();
getEventQueue()->windowResize(x,y,width, height, getEventQueue()->getTime());
getEventQueue()->windowResize(x,y,width, height, getEventQueue()->getTime());
}
@ -1105,7 +1105,7 @@ void GraphicsWindowCocoa::resizedImplementation(int x, int y, int width, int hei
// ----------------------------------------------------------------------------------------------------------
bool GraphicsWindowCocoa::setWindowRectangleImplementation(int x, int y, int width, int height)
{
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());
int screenLeft(0), screenTop(0);
if (wsi) {
wsi->getScreenTopLeft((*_traits), screenLeft, screenTop);
@ -1130,21 +1130,21 @@ bool GraphicsWindowCocoa::setWindowRectangleImplementation(int x, int y, int wid
void GraphicsWindowCocoa::adaptResize(int x, int y, int w, int h)
{
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(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
// 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);
resized(x-screenLeft,y-screenTop,w,h);
}
@ -1154,11 +1154,11 @@ void GraphicsWindowCocoa::adaptResize(int x, int y, int w, int h)
void GraphicsWindowCocoa::setWindowName (const std::string & name)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString* title = [NSString stringWithCString: name.c_str() encoding: NSUTF8StringEncoding];
[_window setTitle: title];
[title release];
[_window setTitle: title];
[title release];
[pool release];
}
@ -1169,7 +1169,7 @@ void GraphicsWindowCocoa::setWindowName (const std::string & name)
void GraphicsWindowCocoa::useCursor(bool cursorOn)
{
if (_traits.valid())
if (_traits.valid())
_traits->useCursor = cursorOn;
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());
if (wsi == NULL) {
@ -1200,7 +1200,7 @@ void GraphicsWindowCocoa::useCursor(bool cursorOn)
void GraphicsWindowCocoa::setCursor(MouseCursor mouseCursor)
{
switch (mouseCursor)
switch (mouseCursor)
{
case NoCursor:
@ -1232,7 +1232,7 @@ void GraphicsWindowCocoa::setCursor(MouseCursor mouseCursor)
void GraphicsWindowCocoa::setVSync(bool f)
{
GLint VBL(f?1:0);
[_context setValues:&VBL forParameter:NSOpenGLCPSwapInterval];
[_context setValues:&VBL forParameter:NSOpenGLCPSwapInterval];
}
@ -1253,25 +1253,25 @@ GraphicsWindowCocoa::~GraphicsWindowCocoa()
// ----------------------------------------------------------------------------------------------------------
struct CocoaWindowingSystemInterface : public DarwinWindowingSystemInterface {
CocoaWindowingSystemInterface()
: DarwinWindowingSystemInterface()
{
localPool = [[NSAutoreleasePool alloc] init];
CocoaWindowingSystemInterface()
: DarwinWindowingSystemInterface()
{
localPool = [[NSAutoreleasePool alloc] init];
[[NSApplication sharedApplication] setDelegate: [[CocoaAppDelegate alloc] init] ];
}
virtual osg::GraphicsContext* createGraphicsContext(osg::GraphicsContext::Traits* traits)
{
return createGraphicsContextImplementation<PixelBufferCocoa, GraphicsWindowCocoa>(traits);
}
virtual ~CocoaWindowingSystemInterface()
{
[localPool release];
}
NSAutoreleasePool *localPool;
}
virtual osg::GraphicsContext* createGraphicsContext(osg::GraphicsContext::Traits* traits)
{
return createGraphicsContextImplementation<PixelBufferCocoa, GraphicsWindowCocoa>(traits);
}
virtual ~CocoaWindowingSystemInterface()
{
[localPool release];
}
NSAutoreleasePool *localPool;
};