Implemented support for float x and y mouse positions, and normalization of
mouse coords in osgGA::GUIEventAdapter, and ported osgGA camera manaipulators to use the new normalized values. Moved osgProducer across to tracking the window dimensions and ensure that the internals values in osgProducer::EventAdapter are kept consistent. Moved the warp pointer in Viewer across to using KeyboardMouse::positionPointer().
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
#include <osg/Math>
|
||||
#include <osgProducer/KeyboardMouseCallback>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <X11/keysym.h>
|
||||
#endif
|
||||
|
||||
#include <float.h>
|
||||
|
||||
using namespace osgProducer;
|
||||
|
||||
@@ -15,8 +11,7 @@ void KeyboardMouseCallback::buttonPress( float mx, float my, unsigned int mbutto
|
||||
_my = my;
|
||||
_mbutton |= (1<<(mbutton-1));
|
||||
|
||||
|
||||
osg::ref_ptr<EventAdapter> event = new EventAdapter;
|
||||
osg::ref_ptr<EventAdapter> event = createEventAdapter();
|
||||
event->adaptButtonPress(getTime(),mx,my,mbutton);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
@@ -30,8 +25,7 @@ void KeyboardMouseCallback::buttonRelease( float mx, float my, unsigned int mbut
|
||||
_my = my;
|
||||
_mbutton &= ~(1<<(mbutton-1));
|
||||
|
||||
|
||||
osg::ref_ptr<EventAdapter> event = new EventAdapter;
|
||||
osg::ref_ptr<EventAdapter> event = createEventAdapter();
|
||||
event->adaptButtonRelease(getTime(),mx,my,mbutton);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
@@ -45,8 +39,7 @@ void KeyboardMouseCallback::doubleButtonPress( float mx, float my, unsigned int
|
||||
_my = my;
|
||||
_mbutton |= (1<<(mbutton-1));
|
||||
|
||||
|
||||
osg::ref_ptr<EventAdapter> event = new EventAdapter;
|
||||
osg::ref_ptr<EventAdapter> event = createEventAdapter();
|
||||
event->adaptButtonPress(getTime(),mx,my,mbutton);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
@@ -57,16 +50,9 @@ void KeyboardMouseCallback::doubleButtonPress( float mx, float my, unsigned int
|
||||
void KeyboardMouseCallback::keyPress( Producer::KeyCharacter key )
|
||||
{
|
||||
|
||||
|
||||
osg::ref_ptr<EventAdapter> event = new EventAdapter;
|
||||
osg::ref_ptr<EventAdapter> event = createEventAdapter();
|
||||
event->adaptKeyPress(getTime(),key);
|
||||
|
||||
//
|
||||
// #ifdef WIN32
|
||||
// if (_escapeKeySetsDone &&
|
||||
// event->getKey()==VK_ESCAPE) _done = true;
|
||||
// #endif
|
||||
|
||||
// check against adapted key symbol.
|
||||
if (_escapeKeySetsDone &&
|
||||
event->getKey()==osgGA::GUIEventAdapter::KEY_Escape) _done = true;
|
||||
@@ -80,7 +66,7 @@ void KeyboardMouseCallback::keyPress( Producer::KeyCharacter key )
|
||||
void KeyboardMouseCallback::keyRelease( Producer::KeyCharacter key )
|
||||
{
|
||||
|
||||
osg::ref_ptr<EventAdapter> event = new EventAdapter;
|
||||
osg::ref_ptr<EventAdapter> event = createEventAdapter();
|
||||
event->adaptKeyRelease(getTime(),key);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
@@ -92,15 +78,9 @@ void KeyboardMouseCallback::specialKeyPress( Producer::KeyCharacter key )
|
||||
{
|
||||
|
||||
|
||||
osg::ref_ptr<EventAdapter> event = new EventAdapter;
|
||||
osg::ref_ptr<EventAdapter> event = createEventAdapter();
|
||||
event->adaptKeyPress(getTime(),key);
|
||||
|
||||
|
||||
// #ifdef WIN32
|
||||
// if (_escapeKeySetsDone &&
|
||||
// event->getKey()==VK_ESCAPE) _done = true;
|
||||
// #endif
|
||||
|
||||
// check against adapted key symbol.
|
||||
if (_escapeKeySetsDone &&
|
||||
event->getKey()==osgGA::GUIEventAdapter::KEY_Escape) _done = true;
|
||||
@@ -114,7 +94,7 @@ void KeyboardMouseCallback::specialKeyPress( Producer::KeyCharacter key )
|
||||
void KeyboardMouseCallback::specialKeyRelease( Producer::KeyCharacter key )
|
||||
{
|
||||
|
||||
osg::ref_ptr<EventAdapter> event = new EventAdapter;
|
||||
osg::ref_ptr<EventAdapter> event = createEventAdapter();
|
||||
event->adaptKeyRelease(getTime(),key);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
@@ -127,7 +107,7 @@ void KeyboardMouseCallback::mouseMotion( float mx, float my)
|
||||
_mx = mx;
|
||||
_my = my;
|
||||
|
||||
osg::ref_ptr<EventAdapter> event = new EventAdapter;
|
||||
osg::ref_ptr<EventAdapter> event = createEventAdapter();
|
||||
event->adaptMouseMotion(getTime(),mx,my);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
@@ -141,7 +121,7 @@ void KeyboardMouseCallback::passiveMouseMotion( float mx, float my)
|
||||
_mx = mx;
|
||||
_my = my;
|
||||
|
||||
osg::ref_ptr<EventAdapter> event = new EventAdapter;
|
||||
osg::ref_ptr<EventAdapter> event = createEventAdapter();
|
||||
event->adaptMouseMotion(getTime(),mx,my);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
@@ -158,3 +138,44 @@ void KeyboardMouseCallback::getEventQueue(EventQueue& queue)
|
||||
_eventQueueMutex.unlock();
|
||||
|
||||
}
|
||||
|
||||
EventAdapter* KeyboardMouseCallback::createEventAdapter()
|
||||
{
|
||||
EventAdapter* ea = new EventAdapter;
|
||||
|
||||
Producer::InputArea* ia = _keyboardMouse->getInputArea();
|
||||
Producer::RenderSurface* rs = _keyboardMouse->getRenderSurface();
|
||||
if (ia)
|
||||
{
|
||||
float minX = FLT_MAX;
|
||||
float minY = FLT_MAX;
|
||||
float maxX = -FLT_MAX;
|
||||
float maxY = -FLT_MAX;
|
||||
int numInputRectangle = ia->getNumInputRectangle();
|
||||
for (int i=0;i<numInputRectangle;++i)
|
||||
{
|
||||
Producer::InputRectangle* ir = ia->getInputRectangle(i);
|
||||
|
||||
minX = osg::minimum(minX,ir->left());
|
||||
minX = osg::minimum(minX,ir->left()+ir->width());
|
||||
|
||||
minY = osg::minimum(minY,ir->bottom());
|
||||
minY = osg::minimum(minY,ir->bottom()+ir->height());
|
||||
|
||||
maxX = osg::maximum(maxX,ir->left());
|
||||
maxX = osg::maximum(maxX,ir->left()+ir->width());
|
||||
|
||||
maxY = osg::maximum(maxY,ir->bottom());
|
||||
maxY = osg::maximum(maxY,ir->bottom()+ir->height());
|
||||
}
|
||||
ea->setWindowSize(minX,minY,maxX,maxY);
|
||||
}
|
||||
else if (rs)
|
||||
{
|
||||
float xMin,yMin,xMax,yMax;
|
||||
rs->getWindowRect(xMin,xMax,yMin,yMax);
|
||||
ea->setWindowSize(xMin,yMin,xMax,yMax);
|
||||
}
|
||||
|
||||
return ea;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user