Added ProducerEventCallback class to manager the conversion of producer events
into GUIEventAdapter versions.
This commit is contained in:
parent
1c602035ef
commit
097030766d
@ -2,6 +2,7 @@ TOPDIR = ../../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
ProducerEventCallback.cpp\
|
||||
ProducerEventAdapter.cpp\
|
||||
osgproducer.cpp\
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
unsigned int ProducerEventAdapter::_s_accumulatedButtonMask = 0;
|
||||
|
||||
int ProducerEventAdapter::_s_button = 0;
|
||||
int ProducerEventAdapter::_s_modKeyMask = 0;
|
||||
int ProducerEventAdapter::_s_Xmin = 0;
|
||||
int ProducerEventAdapter::_s_Xmax = 1280;
|
||||
int ProducerEventAdapter::_s_Ymin = 0;
|
||||
@ -19,6 +20,7 @@ ProducerEventAdapter::ProducerEventAdapter()
|
||||
_mx = -1; // set to 'invalid' position value.
|
||||
_my = -1; // set to 'invalid' position value.
|
||||
_buttonMask = 0; // default to no mouse buttons being pressed.
|
||||
_modKeyMask = 0; // default to no mouse buttons being pressed.
|
||||
_time = 0.0f; // default to no time has been set.
|
||||
|
||||
copyStaticVariables();
|
||||
@ -29,6 +31,7 @@ ProducerEventAdapter::ProducerEventAdapter()
|
||||
void ProducerEventAdapter::copyStaticVariables()
|
||||
{
|
||||
_buttonMask = _s_accumulatedButtonMask;
|
||||
_modKeyMask = _s_modKeyMask;
|
||||
_button = _s_button;
|
||||
_Xmin = _s_Xmin;
|
||||
_Xmax = _s_Xmax;
|
||||
@ -138,7 +141,7 @@ void ProducerEventAdapter::adaptMouseMotion(double time, float x, float y)
|
||||
|
||||
|
||||
/** method for adapting keyboard events.*/
|
||||
void ProducerEventAdapter::adaptKeyPess( double time, Producer::KeySymbol key)
|
||||
void ProducerEventAdapter::adaptKeyPress( double time, Producer::KeySymbol key)
|
||||
{
|
||||
_eventType = KEYDOWN;
|
||||
_time = time;
|
||||
|
@ -49,6 +49,7 @@ class ProducerEventAdapter : public osgGA::GUIEventAdapter
|
||||
/** time in seconds of event. */
|
||||
virtual double time() const { return _time; }
|
||||
|
||||
virtual unsigned int getModKeyMask() const { return _modKeyMask; }
|
||||
|
||||
/** static method for setting window dimensions.*/
|
||||
static void setWindowSize(int Xmin, int Ymin, int Xmax, int Ymax);
|
||||
@ -68,13 +69,14 @@ class ProducerEventAdapter : public osgGA::GUIEventAdapter
|
||||
void adaptButtonRelease(double t,float x, float y, unsigned int button);
|
||||
|
||||
/** method for adapting keyboard events.*/
|
||||
void adaptKeyPess( double t, Producer::KeySymbol key);
|
||||
void adaptKeyPress( double t, Producer::KeySymbol key);
|
||||
|
||||
void adaptKeyRelease( double t, Producer::KeySymbol key);
|
||||
|
||||
/** method for adapting frame events, i.e. idle/display callback.*/
|
||||
void adaptFrame(double t);
|
||||
|
||||
|
||||
void copyStaticVariables();
|
||||
|
||||
protected:
|
||||
@ -88,6 +90,7 @@ class ProducerEventAdapter : public osgGA::GUIEventAdapter
|
||||
int _mx;
|
||||
int _my;
|
||||
unsigned int _buttonMask;
|
||||
unsigned int _modKeyMask;
|
||||
double _time;
|
||||
|
||||
// used to accumulate the button mask state, it represents
|
||||
@ -106,7 +109,7 @@ class ProducerEventAdapter : public osgGA::GUIEventAdapter
|
||||
static int _s_Ymax;
|
||||
static int _s_mx;
|
||||
static int _s_my;
|
||||
|
||||
static int _s_modKeyMask;
|
||||
|
||||
};
|
||||
|
||||
|
89
src/Demos/osgproducer/ProducerEventCallback.cpp
Normal file
89
src/Demos/osgproducer/ProducerEventCallback.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include "ProducerEventCallback.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <X11/keysym.h>
|
||||
#endif
|
||||
|
||||
|
||||
void ProducerEventCallback::keyPress( Producer::KeySymbol key )
|
||||
{
|
||||
|
||||
switch( key )
|
||||
{
|
||||
#ifdef XK_MISCELLANY // XWindows keydefs
|
||||
case XK_Escape:
|
||||
_done = true;
|
||||
break;
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
case VK_ESCAPE:
|
||||
_done = true;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
|
||||
event->adaptKeyPress(getTime(),key);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
_eventQueue.push_back(event);
|
||||
_eventQueueMutex.unlock();
|
||||
}
|
||||
|
||||
void ProducerEventCallback::keyRelease( Producer::KeySymbol key )
|
||||
{
|
||||
|
||||
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
|
||||
event->adaptKeyRelease(getTime(),key);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
_eventQueue.push_back(event);
|
||||
_eventQueueMutex.unlock();
|
||||
}
|
||||
|
||||
void ProducerEventCallback::mouseMotion( float mx, float my)
|
||||
{
|
||||
_mx = mx;
|
||||
_my = my;
|
||||
|
||||
|
||||
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
|
||||
event->adaptMouseMotion(getTime(),mx,my);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
_eventQueue.push_back(event);
|
||||
_eventQueueMutex.unlock();
|
||||
|
||||
}
|
||||
|
||||
void ProducerEventCallback::buttonPress( float mx, float my, unsigned int mbutton )
|
||||
{
|
||||
_mx = mx;
|
||||
_my = my;
|
||||
_mbutton |= (1<<(mbutton-1));
|
||||
|
||||
|
||||
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
|
||||
event->adaptButtonPress(getTime(),mx,my,mbutton);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
_eventQueue.push_back(event);
|
||||
_eventQueueMutex.unlock();
|
||||
}
|
||||
|
||||
void ProducerEventCallback::buttonRelease( float mx, float my, unsigned int mbutton )
|
||||
{
|
||||
_mx = mx;
|
||||
_my = my;
|
||||
_mbutton &= ~(1<<(mbutton-1));
|
||||
|
||||
|
||||
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
|
||||
event->adaptButtonRelease(getTime(),mx,my,mbutton);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
_eventQueue.push_back(event);
|
||||
_eventQueueMutex.unlock();
|
||||
}
|
57
src/Demos/osgproducer/ProducerEventCallback.h
Normal file
57
src/Demos/osgproducer/ProducerEventCallback.h
Normal file
@ -0,0 +1,57 @@
|
||||
//C++
|
||||
#ifndef PRODUCEREVENTCALLBACK
|
||||
#define PRODUCEREVENTCALLBACK
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Producer/RenderSurface> // For definition of KeySymbol
|
||||
#include <Producer/KeyboardMouse>
|
||||
#include <Producer/Mutex>
|
||||
|
||||
#include "ProducerEventAdapter.h"
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Timer>
|
||||
|
||||
class ProducerEventCallback : public Producer::KeyboardMouseCallback
|
||||
{
|
||||
public:
|
||||
ProducerEventCallback(bool &done) :
|
||||
Producer::KeyboardMouseCallback(),
|
||||
_mx(0.0f),_my(0.0f),_mbutton(0),
|
||||
_done(done)
|
||||
{}
|
||||
|
||||
virtual ~ProducerEventCallback();
|
||||
|
||||
virtual void keyPress( Producer::KeySymbol key );
|
||||
|
||||
virtual void keyRelease( Producer::KeySymbol key );
|
||||
|
||||
virtual void mouseMotion( float mx, float my);
|
||||
|
||||
virtual void buttonPress( float mx, float my, unsigned int mbutton );
|
||||
|
||||
virtual void buttonRelease( float mx, float my, unsigned int mbutton );
|
||||
|
||||
typedef std::vector< osg::ref_ptr<ProducerEventAdapter> > EventQueue;
|
||||
|
||||
void getEventQueue(EventQueue& queue);
|
||||
|
||||
bool done() { return _done; }
|
||||
float mx() { return _mx; }
|
||||
float my() { return _my; }
|
||||
unsigned int mbutton() { return _mbutton; }
|
||||
|
||||
double getTime() { return 0.0f; }
|
||||
|
||||
private:
|
||||
|
||||
float _mx, _my;
|
||||
unsigned int _mbutton;
|
||||
bool &_done;
|
||||
|
||||
osg::Timer _timer;
|
||||
Producer::Mutex _eventQueueMutex;
|
||||
EventQueue _eventQueue;
|
||||
|
||||
};
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user