Added a workaround for computing the time of an event.

This commit is contained in:
Robert Osfield 2007-01-05 13:01:08 +00:00
parent 3d1c971bca
commit 23ac972d4e
2 changed files with 45 additions and 17 deletions

View File

@ -44,7 +44,8 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
_nullCursor(0),
_currentCursor(0),
_initialized(false),
_realized(false)
_realized(false),
_timeOfLastCheckEvents(-1.0)
{
_traits = traits;
@ -129,6 +130,8 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
bool _initialized;
bool _realized;
double _timeOfLastCheckEvents;
};
}

View File

@ -612,6 +612,11 @@ void GraphicsWindowX11::checkEvents()
{
if (!_realized) return;
double baseTime = _timeOfLastCheckEvents;
double eventTime = baseTime;
double resizeTime = eventTime;
_timeOfLastCheckEvents = getEventQueue()->getTime();
int windowX = _traits->x;
int windowY = _traits->y;
int windowWidth = _traits->width;
@ -619,6 +624,8 @@ void GraphicsWindowX11::checkEvents()
bool destroyWindowRequested = false;
Time firstEventTime = 0;
// osg::notify(osg::NOTICE)<<"Check events"<<std::endl;
while( XPending(_display) )
{
@ -666,6 +673,8 @@ void GraphicsWindowX11::checkEvents()
windowWidth != ev.xconfigure.width ||
windowHeight != ev.xconfigure.height)
{
resizeTime = eventTime;
windowX = ev.xconfigure.x;
windowY = ev.xconfigure.y;
windowWidth = ev.xconfigure.width;
@ -687,20 +696,20 @@ void GraphicsWindowX11::checkEvents()
if (windowWidth != watt.width || windowHeight != watt.height)
{
resizeTime = eventTime;
windowWidth = watt.width;
windowHeight = watt.height;
}
_traits->width = watt.width;
_traits->height = watt.height;
break;
}
case MotionNotify :
{
osg::notify(osg::INFO)<<"MotionNotify time="<<ev.xmotion.time<<std::endl;
if (firstEventTime==0) firstEventTime = ev.xmotion.time;
Time relativeTime = ev.xmotion.time - firstEventTime;
eventTime = baseTime + static_cast<double>(relativeTime)*0.001;
int wx, wy;
Window win = 0L;
@ -750,7 +759,7 @@ void GraphicsWindowX11::checkEvents()
float mx = wx;
float my = wy;
transformMouseXY(mx, my);
getEventQueue()->mouseMotion(mx, my);
getEventQueue()->mouseMotion(mx, my, eventTime);
// osg::notify(osg::NOTICE)<<"MotionNotify wx="<<wx<<" wy="<<wy<<" mx="<<mx<<" my="<<my<<std::endl;
@ -759,62 +768,78 @@ void GraphicsWindowX11::checkEvents()
case ButtonPress :
{
if (firstEventTime==0) firstEventTime = ev.xmotion.time;
Time relativeTime = ev.xmotion.time - firstEventTime;
eventTime = baseTime + static_cast<double>(relativeTime)*0.001;
if( ev.xbutton.button == Button4 )
{
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_UP);
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_UP, eventTime);
}
else if( ev.xbutton.button == Button5)
{
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_DOWN);
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_DOWN, eventTime);
}
else
{
float mx = ev.xbutton.x;
float my = ev.xmotion.y;
transformMouseXY(mx, my);
getEventQueue()->mouseButtonPress(mx, my, ev.xbutton.button);
getEventQueue()->mouseButtonPress(mx, my, ev.xbutton.button, eventTime);
}
break;
}
case ButtonRelease :
{
if (firstEventTime==0) firstEventTime = ev.xmotion.time;
Time relativeTime = ev.xmotion.time - firstEventTime;
eventTime = baseTime + static_cast<double>(relativeTime)*0.001;
if( ev.xbutton.button == Button4 )
{
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_UP);
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_UP, eventTime);
}
else if( ev.xbutton.button == Button5)
{
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_DOWN);
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_DOWN, eventTime);
}
else
{
float mx = ev.xbutton.x;
float my = ev.xmotion.y;
transformMouseXY(mx, my);
getEventQueue()->mouseButtonRelease(mx, my, ev.xbutton.button);
getEventQueue()->mouseButtonRelease(mx, my, ev.xbutton.button, eventTime);
}
break;
}
case KeyPress:
{
if (firstEventTime==0) firstEventTime = ev.xmotion.time;
Time relativeTime = ev.xmotion.time - firstEventTime;
eventTime = baseTime + static_cast<double>(relativeTime)*0.001;
int keySymbol = 0;
unsigned int modifierMask = 0;
adaptKey(ev.xkey, keySymbol, modifierMask);
getEventQueue()->keyPress(keySymbol);
getEventQueue()->keyPress(keySymbol, eventTime);
getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask);
break;
}
case KeyRelease:
{
if (firstEventTime==0) firstEventTime = ev.xmotion.time;
Time relativeTime = ev.xmotion.time - firstEventTime;
eventTime = baseTime + static_cast<double>(relativeTime)*0.001;
int keySymbol = 0;
unsigned int modifierMask = 0;
adaptKey(ev.xkey, keySymbol, modifierMask);
getEventQueue()->keyRelease(keySymbol);
getEventQueue()->keyRelease(keySymbol, eventTime);
getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask);
break;
}
@ -832,7 +857,7 @@ void GraphicsWindowX11::checkEvents()
windowHeight != _traits->height)
{
resized(windowX, windowY, windowWidth, windowHeight);
getEventQueue()->windowResize(windowX, windowY, windowWidth, windowHeight);
getEventQueue()->windowResize(windowX, windowY, windowWidth, windowHeight, resizeTime);
}
if (destroyWindowRequested)