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

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