From Olaf Flebbe, "an implementation of GraphicsWindow::setCursor for WIN32."
This commit is contained in:
parent
85c8797bc4
commit
36d50301cf
@ -78,6 +78,9 @@ class GraphicsWindowWin32 : public osgViewer::GraphicsWindow
|
||||
/** Switch on/off the cursor.*/
|
||||
virtual void useCursor(bool /*cursorOn*/);
|
||||
|
||||
/** Set mouse cursor to a specific shape.*/
|
||||
virtual void setCursor(MouseCursor cursor);
|
||||
|
||||
/** Handle a native (Win32) windowing event as received from the system */
|
||||
virtual LRESULT handleNativeWindowingEvent( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
|
||||
|
||||
@ -119,15 +122,20 @@ class GraphicsWindowWin32 : public osgViewer::GraphicsWindow
|
||||
|
||||
void transformMouseXY(float& x, float& y);
|
||||
|
||||
HCURSOR getOrCreateCursor(MouseCursor mouseShape);
|
||||
|
||||
HWND _hwnd;
|
||||
HDC _hdc;
|
||||
HGLRC _hglrc;
|
||||
HCURSOR _currentCursor;
|
||||
|
||||
WNDPROC _windowProcedure;
|
||||
|
||||
double _timeOfLastCheckEvents;
|
||||
|
||||
|
||||
|
||||
|
||||
int _screenOriginX;
|
||||
int _screenOriginY;
|
||||
unsigned int _screenWidth;
|
||||
@ -146,6 +154,8 @@ class GraphicsWindowWin32 : public osgViewer::GraphicsWindow
|
||||
bool _closeWindow;
|
||||
bool _destroyWindow;
|
||||
bool _destroying;
|
||||
|
||||
std::map<MouseCursor,HCURSOR> _mouseCursorMap;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1021,6 +1021,7 @@ GraphicsWindowWin32::GraphicsWindowWin32( osg::GraphicsContext::Traits* traits )
|
||||
_destroying(false)
|
||||
{
|
||||
_traits = traits;
|
||||
setCursor( LeftArrowCursor);
|
||||
|
||||
init();
|
||||
|
||||
@ -1772,6 +1773,89 @@ void GraphicsWindowWin32::useCursor( bool cursorOn )
|
||||
_traits->useCursor = cursorOn;
|
||||
}
|
||||
|
||||
void GraphicsWindowWin32::setCursor( MouseCursor mouseCursor )
|
||||
{
|
||||
HCURSOR newCursor = getOrCreateCursor( mouseCursor);
|
||||
if (newCursor == _currentCursor) return;
|
||||
|
||||
_currentCursor = newCursor;
|
||||
_traits->useCursor = (_currentCursor != NULL);
|
||||
}
|
||||
|
||||
HCURSOR GraphicsWindowWin32::getOrCreateCursor(MouseCursor mouseCursor)
|
||||
{
|
||||
std::map<MouseCursor,HCURSOR>::iterator i = _mouseCursorMap.find(mouseCursor);
|
||||
if (i != _mouseCursorMap.end()) return i->second;
|
||||
|
||||
switch (mouseCursor) {
|
||||
case NoCursor:
|
||||
_mouseCursorMap[mouseCursor] = NULL;
|
||||
break;
|
||||
case RightArrowCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_ARROW);
|
||||
break;
|
||||
case LeftArrowCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_ARROW);
|
||||
break;
|
||||
case InfoCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_SIZEALL);
|
||||
break;
|
||||
case DestroyCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_NO );
|
||||
break;
|
||||
case HelpCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_HELP );
|
||||
break;
|
||||
case CycleCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_NO );
|
||||
break;
|
||||
case SprayCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_SIZEALL );
|
||||
break;
|
||||
case WaitCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_WAIT);
|
||||
break;
|
||||
case TextCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_IBEAM );
|
||||
break;
|
||||
case CrosshairCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_CROSS );
|
||||
break;
|
||||
case UpDownCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_SIZENS );
|
||||
break;
|
||||
case LeftRightCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_SIZEWE );
|
||||
break;
|
||||
case TopSideCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_UPARROW );
|
||||
break;
|
||||
case BottomSideCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_UPARROW );
|
||||
break;
|
||||
case LeftSideCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_SIZEWE);
|
||||
break;
|
||||
case RightSideCursor:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_SIZEWE );
|
||||
break;
|
||||
case TopLeftCorner:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_SIZENWSE );
|
||||
break;
|
||||
case TopRightCorner:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_SIZENESW );
|
||||
break;
|
||||
case BottomRightCorner:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_SIZENWSE );
|
||||
break;
|
||||
case BottomLeftCorner:
|
||||
_mouseCursorMap[mouseCursor] = LoadCursor( NULL, IDC_SIZENESW );
|
||||
break;
|
||||
}
|
||||
|
||||
return _mouseCursorMap[mouseCursor];
|
||||
}
|
||||
|
||||
void GraphicsWindowWin32::adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask )
|
||||
{
|
||||
modifierMask = 0;
|
||||
@ -2044,9 +2128,10 @@ LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, W
|
||||
///////////////////
|
||||
case WM_SETCURSOR :
|
||||
///////////////////
|
||||
|
||||
if (_traits->useCursor) return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||
::SetCursor(NULL);
|
||||
if (_traits->useCursor)
|
||||
::SetCursor( _currentCursor);
|
||||
else
|
||||
::SetCursor(NULL);
|
||||
return TRUE;
|
||||
|
||||
/////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user