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:
@@ -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;
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user