Skip to content

Commit

Permalink
From Tatsuhiro Nishioka and Stephan Huber, bug fixes and enhancement …
Browse files Browse the repository at this point in the history
…of cursor suppoort.
  • Loading branch information
robertosfield committed Apr 1, 2008
1 parent 31c6115 commit f9f7770
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 19 deletions.
7 changes: 5 additions & 2 deletions include/osgViewer/api/Carbon/GraphicsWindowCarbon
Expand Up @@ -35,7 +35,8 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow
_valid(false),
_initialized(false),
_realized(false),
_ownsWindow(true)
_ownsWindow(true),
_currentCursor(RightArrowCursor)
{
_traits = traits;

Expand Down Expand Up @@ -103,6 +104,7 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow

virtual void setWindowName (const std::string & name);
virtual void useCursor(bool cursorOn);
virtual void setCursor(MouseCursor mouseCursor);

WindowRef getNativeWindowRef() { return _window; }

Expand Down Expand Up @@ -166,7 +168,8 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow


bool _closeRequested;
UInt32 _lastModifierKeys;
UInt32 _lastModifierKeys;
MouseCursor _currentCursor;
};

}
Expand Down
78 changes: 61 additions & 17 deletions src/osgViewer/GraphicsWindowCarbon.cpp
Expand Up @@ -23,6 +23,7 @@
#include <OpenGL/OpenGL.h>

#include <iostream>

using namespace osgViewer;


Expand Down Expand Up @@ -98,6 +99,7 @@ static pascal OSStatus GraphicsWindowEventHandler(EventHandlerCallRef nextHandle
return result;
}


static bool s_quit_requested = false;

// Application eventhandler -- listens for a quit-event
Expand Down Expand Up @@ -219,9 +221,10 @@ class MenubarController : public osg::Referenced
MenubarController() :
osg::Referenced(),
_list(),
_menubarShown(false)
_menubarShown(false),
_mutex()
{
// the following code will query the system for the available ect 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

GDHandle mainScreenDevice;

Expand All @@ -243,10 +246,11 @@ class MenubarController : public osg::Referenced

private:
typedef std::list< osg::observer_ptr< GraphicsWindowCarbon > > WindowList;
WindowList _list;
bool _menubarShown;
Rect _availRect;
CGRect _mainScreenBounds;
WindowList _list;
bool _menubarShown;
Rect _availRect;
CGRect _mainScreenBounds;
OpenThreads::Mutex _mutex;

};

Expand All @@ -260,13 +264,15 @@ MenubarController* MenubarController::instance()

void MenubarController::attachWindow(GraphicsWindowCarbon* win)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
_list.push_back(win);
update();
}


void MenubarController::detachWindow(GraphicsWindowCarbon* win)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
for(WindowList::iterator i = _list.begin(); i != _list.end(); ) {
if ((*i).get() == win)
i = _list.erase(i);
Expand Down Expand Up @@ -620,8 +626,7 @@ bool GraphicsWindowCarbon::realizeImplementation()
_traits->x += screenLeft;
}

//ADEGLI WindowData *windowData = _traits.get() ? dynamic_cast<WindowData*>(_traits->inheritedWindowData.get()) : 0;
WindowData *windowData = ( _traits.get() && _traits->inheritedWindowData.get() ) ? static_cast<osgViewer::GraphicsWindowCarbon::WindowData*>(_traits->inheritedWindowData.get()) : 0; //ADEGLI
WindowData *windowData = ( _traits.get() && _traits->inheritedWindowData.get() ) ? static_cast<osgViewer::GraphicsWindowCarbon::WindowData*>(_traits->inheritedWindowData.get()) : 0;

_ownsWindow = (windowData) ? (windowData->getNativeWindowRef() == NULL) : true;

Expand Down Expand Up @@ -680,12 +685,11 @@ bool GraphicsWindowCarbon::realizeImplementation()


if ( windowData && windowData->getAGLDrawable() ) {
aglSetDrawable(_context, (AGLDrawable)*(windowData->getAGLDrawable()) ); //ADEGLI
// ShowWindow(_window); //ADEGLI

aglSetDrawable(_context, (AGLDrawable)*(windowData->getAGLDrawable()) );

} else {
aglSetDrawable(_context, GetWindowPort(_window)); //ADEGLI
ShowWindow(_window); //ADEGLI
aglSetDrawable(_context, GetWindowPort(_window));
ShowWindow(_window);
MenubarController::instance()->attachWindow(this);
}

Expand All @@ -709,8 +713,8 @@ bool GraphicsWindowCarbon::realizeImplementation()
osg::notify(osg::INFO) << "GraphicsWindowCarbon:: Multi-threaded OpenGL Execution not available" << std::endl;
}
}
//ADEGLI aglSetDrawable(_context, GetWindowPort(_window));
//ADEGLI ShowWindow(_window);

InitCursor();

//enable vsync
if (_traits->vsync) {
Expand Down Expand Up @@ -751,7 +755,9 @@ void GraphicsWindowCarbon::closeImplementation()
_valid = false;
_realized = false;

MenubarController::instance()->detachWindow(this);
// there's a possibility that the MenubarController is destructed already, so prevent a crash:
MenubarController* mbc = MenubarController::instance();
if (mbc) mbc->detachWindow(this);

if (_pixelFormat)
{
Expand Down Expand Up @@ -814,7 +820,8 @@ bool GraphicsWindowCarbon::handleMouseEvent(EventRef theEvent)

WindowRef win;
int fwres = FindWindow(wheresMyMouseGlobal, &win);
if ((fwres != inContent) && (fwres > 0) && (mouseButton >= 1))
// return false when Window is inactive; For enabling click-to-active on window by delegating event to default handler
if (((fwres != inContent) && (fwres > 0) && (mouseButton >= 1)) || !IsWindowActive(win))
{
return false;
}
Expand Down Expand Up @@ -1187,6 +1194,43 @@ void GraphicsWindowCarbon::useCursor(bool cursorOn)
}
}

// FIXME: need to implement all cursor types
// FIXME: I used deprecated functions, but don't know if there are any substitutable newer functions...
void GraphicsWindowCarbon::setCursor(MouseCursor mouseCursor)
{
UInt32 cursor;
if (_currentCursor == mouseCursor)
return;
switch (mouseCursor)
{
case NoCursor:
HideCursor();
_currentCursor = mouseCursor;
return;
case RightArrowCursor:
cursor = kThemeArrowCursor;
break;
case CrosshairCursor:
cursor = kThemeCrossCursor;
break;
case TextCursor:
cursor = kThemeIBeamCursor;
break;
case UpDownCursor:
cursor = kThemeResizeUpDownCursor;
break;
case LeftRightCursor:
cursor = kThemeResizeLeftRightCursor;
break;
default:
cursor = kThemeArrowCursor;
osg::notify(osg::WARN) << "GraphicsWindowCarbon::setCursor doesn't implement cursor: type = " << mouseCursor << std::endl;
}

_currentCursor = mouseCursor;
SetThemeCursor(cursor);
ShowCursor();
}


void GraphicsWindowCarbon::setWindowName (const std::string& name)
Expand Down

0 comments on commit f9f7770

Please sign in to comment.