diff --git a/include/osgGA/GUIEventAdapter b/include/osgGA/GUIEventAdapter index f1326bfc0..604f01b8e 100644 --- a/include/osgGA/GUIEventAdapter +++ b/include/osgGA/GUIEventAdapter @@ -35,12 +35,31 @@ public: RELEASE, DRAG, MOVE, - KEYBOARD, + KEYDOWN, + KEYUP, FRAME, RESIZE, NONE }; + enum ModKeyMask { + MOD_LEFT_SHIFT = 0x0001, + MOD_RIGHT_SHIFT = 0x0002, + MOD_LEFT_CTRL = 0x0040, + MOD_RIGHT_CTRL = 0x0080, + MOD_LEFT_ALT = 0x0100, + MOD_RIGHT_ALT = 0x0200, + MOD_LEFT_META = 0x0400, + MOD_RIGHT_META = 0x0800, + MOD_NUM_LOCK = 0x1000, + MOD_CAPS_LOCK = 0x2000, + MOD_CTRL = (MOD_LEFT_CTRL|MOD_RIGHT_CTRL), + MOD_SHIFT = (MOD_LEFT_SHIFT|MOD_RIGHT_SHIFT), + MOD_ALT = (MOD_LEFT_ALT|MOD_RIGHT_ALT), + MOD_META = (MOD_LEFT_META|MOD_RIGHT_META) + }; + + /** Get the EventType of the GUI event.*/ virtual EventType getEventType() const = 0; @@ -71,6 +90,9 @@ public: /** current mouse button state */ virtual unsigned int getButtonMask() const = 0; + /** current modkey state */ + virtual unsigned int getModKeyMask() const = 0; + /** time in seconds of event. */ virtual double time() const = 0; diff --git a/include/osgGLUT/GLUTEventAdapter b/include/osgGLUT/GLUTEventAdapter index 85a286a05..bf12715cc 100644 --- a/include/osgGLUT/GLUTEventAdapter +++ b/include/osgGLUT/GLUTEventAdapter @@ -49,6 +49,9 @@ class OSGGLUT_EXPORT GLUTEventAdapter : public osgGA::GUIEventAdapter /** current mouse button state */ virtual unsigned int getButtonMask() const { return _buttonMask; } + /** current modkey state */ + virtual unsigned int getModKeyMask() const; + /** time in seconds of event. */ virtual double time() const { return _time; } @@ -72,7 +75,8 @@ class OSGGLUT_EXPORT GLUTEventAdapter : public osgGA::GUIEventAdapter void adaptMouse(double t,int button, int state, int x, int y); /** method for adapting keyboard events.*/ - void adaptKeyboard(double t,unsigned char key, int x, int y ); + void adaptKeyboard( double t, unsigned char key, + int x, int y, bool keydown ); /** method for adapting frame events, i.e. idle/display callback.*/ void adaptFrame(double t); diff --git a/include/osgGLUT/Viewer b/include/osgGLUT/Viewer index 3a99215a2..b64599100 100644 --- a/include/osgGLUT/Viewer +++ b/include/osgGLUT/Viewer @@ -113,6 +113,8 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter osg::AnimationPath* getAnimationPath() { return _animationPath.get(); } const osg::AnimationPath* getAnimationPath() const { return _animationPath.get(); } + int mapWindowXYToViewport(int x, int y); + protected: virtual void clear(); @@ -122,10 +124,9 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter virtual void mouseMotion(int x, int y); virtual void mousePassiveMotion(int x, int y); virtual void mouse(int button, int state, int x, int y); - virtual void keyboard(unsigned char key, int x, int y); + virtual void keyboard(int key, int x, int y, bool keydown = true); void setFocusedViewport(unsigned int pos); - int mapWindowXYToViewport(int x, int y); void showStats(unsigned int i); // gwm 24.09.01 pass the viewport to collect sta for each viewport diff --git a/include/osgGLUT/Window b/include/osgGLUT/Window index 1dc3a6105..564f6f471 100644 --- a/include/osgGLUT/Window +++ b/include/osgGLUT/Window @@ -41,8 +41,10 @@ class OSGGLUT_EXPORT Window static void mousePassiveMotionCB(int x, int y); static void mouseCB(int button, int state, int x, int y); static void keyboardCB(unsigned char key, int x, int y ); + static void keyboardUpCB(unsigned char key, int x, int y ); static void specialCB(int key, int x, int y); + static void specialUpCB(int key, int x, int y); static void spaceballMotionCB(int x, int y, int z); static void spaceballRotateCB(int x, int y, int z); static void spaceballButtonCB(int button, int state); @@ -52,9 +54,9 @@ class OSGGLUT_EXPORT Window virtual void mouseMotion(int x, int y); virtual void mousePassiveMotion(int x, int y); virtual void mouse(int button, int state, int x, int y); - virtual void keyboard(unsigned char key, int x, int y); + virtual void keyboard(int key, int x, int y, bool keydown); - virtual void special(int key, int x, int y); + virtual void special(int key, int x, int y, bool keydown); virtual void spaceballMotion(int x, int y, int z); virtual void spaceballRotate(int x, int y, int z); virtual void spaceballButton(int button, int state); diff --git a/src/Demos/osghangglide/GliderManipulator.cpp b/src/Demos/osghangglide/GliderManipulator.cpp index 3cd3470ce..f5cbead50 100644 --- a/src/Demos/osghangglide/GliderManipulator.cpp +++ b/src/Demos/osghangglide/GliderManipulator.cpp @@ -119,7 +119,7 @@ bool GliderManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) return true; } - case(GUIEventAdapter::KEYBOARD): + case(GUIEventAdapter::KEYDOWN): if (ea.getKey()==' ') { flushMouseEventStack(); diff --git a/src/Demos/osgimpostor/TestManipulator.cpp b/src/Demos/osgimpostor/TestManipulator.cpp index 075848ac3..7f8b7f20f 100644 --- a/src/Demos/osgimpostor/TestManipulator.cpp +++ b/src/Demos/osgimpostor/TestManipulator.cpp @@ -134,7 +134,7 @@ bool TestManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) return false; } - case(GUIEventAdapter::KEYBOARD): + case(GUIEventAdapter::KEYDOWN): if (ea.getKey()==' ') { flushMouseEventStack(); diff --git a/src/Demos/osgoccluder/osgoccluder.cpp b/src/Demos/osgoccluder/osgoccluder.cpp index 080a1b1b9..05082c11d 100644 --- a/src/Demos/osgoccluder/osgoccluder.cpp +++ b/src/Demos/osgoccluder/osgoccluder.cpp @@ -91,7 +91,7 @@ bool OccluderEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAct { switch(ea.getEventType()) { - case(osgGA::GUIEventAdapter::KEYBOARD): + case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()=='a') { diff --git a/src/Demos/osgsequence/osgsequence.cpp b/src/Demos/osgsequence/osgsequence.cpp index 8c6183c5c..aa708e622 100644 --- a/src/Demos/osgsequence/osgsequence.cpp +++ b/src/Demos/osgsequence/osgsequence.cpp @@ -31,7 +31,7 @@ public: { bool handled = false; - if (ea.getEventType() == osgGA::GUIEventAdapter::KEYBOARD) + if (ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN) { const char keys[] = "!@#$%^&*()"; for (unsigned int i = 0; i < (sizeof(keys) / sizeof(keys[0])); i++) { diff --git a/src/Demos/osgtext/main.cpp b/src/Demos/osgtext/main.cpp index 2d407c77c..5bc4d485c 100644 --- a/src/Demos/osgtext/main.cpp +++ b/src/Demos/osgtext/main.cpp @@ -463,7 +463,7 @@ protected: } - virtual void keyboard(unsigned char key, int x, int y) + virtual void keyboard(int key, int x, int y) { switch(key) { diff --git a/src/osgGA/AnimationPathManipulator.cpp b/src/osgGA/AnimationPathManipulator.cpp index 9eb0a4138..ac0ef6c52 100644 --- a/src/osgGA/AnimationPathManipulator.cpp +++ b/src/osgGA/AnimationPathManipulator.cpp @@ -65,7 +65,7 @@ bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GU handleFrame( ea.time() ); retval = true; break; - case GUIEventAdapter::KEYBOARD: + case GUIEventAdapter::KEYDOWN: if (ea.getKey()==' ') { home(ea,us); diff --git a/src/osgGA/DriveManipulator.cpp b/src/osgGA/DriveManipulator.cpp index 22fee8d67..f065b0d07 100644 --- a/src/osgGA/DriveManipulator.cpp +++ b/src/osgGA/DriveManipulator.cpp @@ -305,7 +305,7 @@ bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) return true; } - case(GUIEventAdapter::KEYBOARD): + case(GUIEventAdapter::KEYDOWN): { if (ea.getKey()==' ') { diff --git a/src/osgGA/FlightManipulator.cpp b/src/osgGA/FlightManipulator.cpp index 189ea7fab..7072cf7e6 100644 --- a/src/osgGA/FlightManipulator.cpp +++ b/src/osgGA/FlightManipulator.cpp @@ -127,7 +127,7 @@ bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) return true; } - case(GUIEventAdapter::KEYBOARD): + case(GUIEventAdapter::KEYDOWN): if (ea.getKey()==' ') { flushMouseEventStack(); diff --git a/src/osgGA/KeySwitchCameraManipulator.cpp b/src/osgGA/KeySwitchCameraManipulator.cpp index 9f87189cc..0e89d5de7 100644 --- a/src/osgGA/KeySwitchCameraManipulator.cpp +++ b/src/osgGA/KeySwitchCameraManipulator.cpp @@ -22,7 +22,7 @@ void KeySwitchCameraManipulator::addNumberedCameraManipulator(CameraManipulator bool KeySwitchCameraManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa) { - if(ea.getEventType()==GUIEventAdapter::KEYBOARD){ + if(ea.getEventType()==GUIEventAdapter::KEYDOWN){ KeyManipMap::iterator it=_manips.find(ea.getKey()); if(it != _manips.end()){ diff --git a/src/osgGA/StateSetManipulator.cpp b/src/osgGA/StateSetManipulator.cpp index 1c73684bb..d15afb3af 100644 --- a/src/osgGA/StateSetManipulator.cpp +++ b/src/osgGA/StateSetManipulator.cpp @@ -34,7 +34,7 @@ bool StateSetManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa) { if(!_drawState.valid()) return false; - if(ea.getEventType()==GUIEventAdapter::KEYBOARD){ + if(ea.getEventType()==GUIEventAdapter::KEYDOWN){ switch( ea.getKey() ){ diff --git a/src/osgGA/TrackballManipulator.cpp b/src/osgGA/TrackballManipulator.cpp index bfdef6704..4bc9daeb4 100644 --- a/src/osgGA/TrackballManipulator.cpp +++ b/src/osgGA/TrackballManipulator.cpp @@ -135,7 +135,7 @@ bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us return false; } - case(GUIEventAdapter::KEYBOARD): + case(GUIEventAdapter::KEYDOWN): if (ea.getKey()==' ') { flushMouseEventStack(); diff --git a/src/osgGLUT/GLUTEventAdapter.cpp b/src/osgGLUT/GLUTEventAdapter.cpp index 0894ec837..843be0674 100644 --- a/src/osgGLUT/GLUTEventAdapter.cpp +++ b/src/osgGLUT/GLUTEventAdapter.cpp @@ -41,6 +41,22 @@ void GLUTEventAdapter::copyStaticVariables() _my = _s_my; } +unsigned int +GLUTEventAdapter::getModKeyMask() const +{ + int modifiers = glutGetModifiers(); + unsigned int modmask = 0; + if ( modifiers & GLUT_ACTIVE_SHIFT ) { + modmask |= MOD_LEFT_SHIFT | MOD_RIGHT_SHIFT; + } + if ( modifiers & GLUT_ACTIVE_ALT ) { + modmask |= MOD_LEFT_ALT | MOD_RIGHT_ALT; + } + if ( modifiers & GLUT_ACTIVE_CTRL ) { + modmask |= MOD_LEFT_CTRL | MOD_RIGHT_CTRL; + } + return modmask; +} void GLUTEventAdapter::setWindowSize(int Xmin, int Ymin, int Xmax, int Ymax) { @@ -154,9 +170,13 @@ void GLUTEventAdapter::adaptMouse(double time, int button, int state, int x, int /** method for adapting keyboard events.*/ -void GLUTEventAdapter::adaptKeyboard(double time, unsigned char key, int x, int y ) +void GLUTEventAdapter::adaptKeyboard(double time, unsigned char key, int x, int y, bool keydown ) { - _eventType = KEYBOARD; + if ( keydown ) { + _eventType = KEYDOWN; + } else { + _eventType = KEYUP; + } _time = time; _key = key; _s_mx = x; diff --git a/src/osgGLUT/Viewer.cpp b/src/osgGLUT/Viewer.cpp index cd84353d5..109a44275 100644 --- a/src/osgGLUT/Viewer.cpp +++ b/src/osgGLUT/Viewer.cpp @@ -881,10 +881,10 @@ void Viewer::mouse(int button, int state, int x, int y) -void Viewer::keyboard(unsigned char key, int x, int y) +void Viewer::keyboard(int key, int x, int y, bool keydown ) { osg::ref_ptr ea = new GLUTEventAdapter; - ea->adaptKeyboard(clockSeconds(),key,x,y); + ea->adaptKeyboard(clockSeconds(),key,x,y,keydown); for ( EventHandlerList::iterator eh = _viewportList[_focusedViewport]._eventHandlerList.begin(); @@ -901,6 +901,11 @@ void Viewer::keyboard(unsigned char key, int x, int y) return; } + // only keydown handled below + if ( !keydown ) { + return; + } + if (key>='1' && key<='4') { int pos = key-'1'; diff --git a/src/osgGLUT/Window.cpp b/src/osgGLUT/Window.cpp index 4f6f459fa..bd1f8c739 100644 --- a/src/osgGLUT/Window.cpp +++ b/src/osgGLUT/Window.cpp @@ -72,12 +72,14 @@ bool Window::open() glutVisibilityFunc( visibilityCB ); glutDisplayFunc( displayCB ); glutKeyboardFunc( keyboardCB ); + glutKeyboardUpFunc( keyboardUpCB ); glutMouseFunc( mouseCB ); glutMotionFunc( mouseMotionCB ); glutPassiveMotionFunc( mousePassiveMotionCB ); glutSpecialFunc( specialCB ); + glutSpecialUpFunc( specialUpCB ); glutSpaceballMotionFunc( spaceballMotionCB ); glutSpaceballRotateFunc( spaceballRotateCB ); glutSpaceballButtonFunc( spaceballButtonCB ); @@ -138,14 +140,26 @@ void Window::mousePassiveMotionCB(int x, int y) void Window::keyboardCB(unsigned char key, int x, int y) { - s_theWindow->keyboard(key,x,y); + s_theWindow->keyboard((int)key,x,y,true); s_theWindow->check_if_exit(); } -void Window::specialCB(int, int, int) +void Window::keyboardUpCB(unsigned char key, int x, int y) { -// s_theWindow->special(key,x,y); -// s_theWindow->check_if_exit(); + s_theWindow->keyboard((int)key,x,y,false); + s_theWindow->check_if_exit(); +} + +void Window::specialCB(int key, int x, int y) +{ + s_theWindow->special(key,x,y,true); + s_theWindow->check_if_exit(); +} + +void Window::specialUpCB(int key, int x, int y) +{ + s_theWindow->special(key,x,y,false); + s_theWindow->check_if_exit(); } void Window::spaceballMotionCB(int x, int y, int z) @@ -207,8 +221,11 @@ void Window::mouse(int , int , int , int ) } -void Window::keyboard(unsigned char key, int , int ) +void Window::keyboard(int key, int , int, bool keydown ) { + if ( !keydown ) + return; + switch( key ) { case 'f' : @@ -227,10 +244,10 @@ void Window::keyboard(unsigned char key, int , int ) } } -void Window::special(int k, int x, int y) +void Window::special(int k, int x, int y, bool keydown) { // will remap to a straight keyboard event... - keyboard((unsigned char)k, x, y); + keyboard( k * 1000, x, y, keydown); // osg::notify(osg::INFO)<<"info : Window::special() unhandled."<