From Daniel Sjölie, updates to the GUIEventAdapter and GLUTEventAdapter to handle

key and key down, modifiers and funcion keys.
This commit is contained in:
Robert Osfield 2003-01-14 14:25:56 +00:00
parent a03fff8c57
commit 59969be08d
18 changed files with 99 additions and 28 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -119,7 +119,7 @@ bool GliderManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
return true;
}
case(GUIEventAdapter::KEYBOARD):
case(GUIEventAdapter::KEYDOWN):
if (ea.getKey()==' ')
{
flushMouseEventStack();

View File

@ -134,7 +134,7 @@ bool TestManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
return false;
}
case(GUIEventAdapter::KEYBOARD):
case(GUIEventAdapter::KEYDOWN):
if (ea.getKey()==' ')
{
flushMouseEventStack();

View File

@ -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')
{

View File

@ -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++) {

View File

@ -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)
{

View File

@ -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);

View File

@ -305,7 +305,7 @@ bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
return true;
}
case(GUIEventAdapter::KEYBOARD):
case(GUIEventAdapter::KEYDOWN):
{
if (ea.getKey()==' ')
{

View File

@ -127,7 +127,7 @@ bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
return true;
}
case(GUIEventAdapter::KEYBOARD):
case(GUIEventAdapter::KEYDOWN):
if (ea.getKey()==' ')
{
flushMouseEventStack();

View File

@ -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()){

View File

@ -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() ){

View File

@ -135,7 +135,7 @@ bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us
return false;
}
case(GUIEventAdapter::KEYBOARD):
case(GUIEventAdapter::KEYDOWN):
if (ea.getKey()==' ')
{
flushMouseEventStack();

View File

@ -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;

View File

@ -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<GLUTEventAdapter> 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';

View File

@ -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."<<std::endl;
}