Updates to utilise the new Producer keyboard bindings.

This commit is contained in:
Robert Osfield 2003-03-27 10:54:01 +00:00
parent 9d45b526ad
commit fc4fe9c625
3 changed files with 110 additions and 47 deletions

View File

@ -39,18 +39,22 @@ class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseC
virtual ~KeyboardMouseCallback() {}
virtual void keyPress( Producer::KeySymbol key );
virtual void keyRelease( Producer::KeySymbol key );
// override KeyboardMouseCallback methods.
virtual void mouseMotion( float mx, float my);
virtual void passiveMouseMotion( float mx, float my);
virtual void buttonPress( float mx, float my, unsigned int mbutton );
virtual void doubleButtonPress( float mx, float mx, unsigned int mbutton);
virtual void buttonRelease( float mx, float my, unsigned int mbutton );
virtual void keyPress( Producer::KeyCharacter key );
virtual void keyRelease( Producer::KeyCharacter key );
virtual void specialKeyPress( Producer::KeyCharacter key);
virtual void specialKeyRelease( Producer::KeyCharacter key);
// local methods and members
typedef std::vector< osg::ref_ptr<EventAdapter> > EventQueue;
void getEventQueue(EventQueue& queue);
@ -64,7 +68,7 @@ class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseC
double getTime() { return _timer.delta_s(_startTick,_timer.tick()); }
private:
protected:
float _mx, _my;
unsigned int _mbutton;

View File

@ -9,7 +9,52 @@
using namespace osgProducer;
void KeyboardMouseCallback::keyPress( Producer::KeySymbol key )
void KeyboardMouseCallback::buttonPress( float mx, float my, unsigned int mbutton )
{
_mx = mx;
_my = my;
_mbutton |= (1<<(mbutton-1));
osg::ref_ptr<EventAdapter> event = new EventAdapter;
event->adaptButtonPress(getTime(),mx,my,mbutton);
_eventQueueMutex.lock();
_eventQueue.push_back(event);
_eventQueueMutex.unlock();
}
void KeyboardMouseCallback::buttonRelease( float mx, float my, unsigned int mbutton )
{
_mx = mx;
_my = my;
_mbutton &= ~(1<<(mbutton-1));
osg::ref_ptr<EventAdapter> event = new EventAdapter;
event->adaptButtonRelease(getTime(),mx,my,mbutton);
_eventQueueMutex.lock();
_eventQueue.push_back(event);
_eventQueueMutex.unlock();
}
void KeyboardMouseCallback::doubleButtonPress( float mx, float my, unsigned int mbutton )
{
_mx = mx;
_my = my;
_mbutton |= (1<<(mbutton-1));
osg::ref_ptr<EventAdapter> event = new EventAdapter;
event->adaptButtonPress(getTime(),mx,my,mbutton);
_eventQueueMutex.lock();
_eventQueue.push_back(event);
_eventQueueMutex.unlock();
}
void KeyboardMouseCallback::keyPress( Producer::KeyCharacter key )
{
@ -32,7 +77,41 @@ void KeyboardMouseCallback::keyPress( Producer::KeySymbol key )
_eventQueueMutex.unlock();
}
void KeyboardMouseCallback::keyRelease( Producer::KeySymbol key )
void KeyboardMouseCallback::keyRelease( Producer::KeyCharacter key )
{
osg::ref_ptr<EventAdapter> event = new EventAdapter;
event->adaptKeyRelease(getTime(),key);
_eventQueueMutex.lock();
_eventQueue.push_back(event);
_eventQueueMutex.unlock();
}
void KeyboardMouseCallback::specialKeyPress( Producer::KeyCharacter key )
{
osg::ref_ptr<EventAdapter> event = new EventAdapter;
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;
_eventQueueMutex.lock();
_eventQueue.push_back(event);
_eventQueueMutex.unlock();
}
void KeyboardMouseCallback::specialKeyRelease( Producer::KeyCharacter key )
{
osg::ref_ptr<EventAdapter> event = new EventAdapter;
@ -71,36 +150,6 @@ void KeyboardMouseCallback::passiveMouseMotion( float mx, float my)
}
void KeyboardMouseCallback::buttonPress( float mx, float my, unsigned int mbutton )
{
_mx = mx;
_my = my;
_mbutton |= (1<<(mbutton-1));
osg::ref_ptr<EventAdapter> event = new EventAdapter;
event->adaptButtonPress(getTime(),mx,my,mbutton);
_eventQueueMutex.lock();
_eventQueue.push_back(event);
_eventQueueMutex.unlock();
}
void KeyboardMouseCallback::buttonRelease( float mx, float my, unsigned int mbutton )
{
_mx = mx;
_my = my;
_mbutton &= ~(1<<(mbutton-1));
osg::ref_ptr<EventAdapter> event = new EventAdapter;
event->adaptButtonRelease(getTime(),mx,my,mbutton);
_eventQueueMutex.lock();
_eventQueue.push_back(event);
_eventQueueMutex.unlock();
}
void KeyboardMouseCallback::getEventQueue(EventQueue& queue)
{
queue.clear();

View File

@ -24,6 +24,11 @@ public:
_viewport = new osg::Viewport(0,0,1280,1024);
_stateset->setAttribute(_viewport.get());
//createHelpText();
createStatsText();
//_helpInitialized = false;
}
void setArraySize(unsigned int size) { _fs.resize(size); }
@ -173,6 +178,7 @@ void DrawCallback::createHelpText()
osgText::Text* text = new osgText::Text;
text->setFont("fonts/arial.ttf");
text->setColor(colorDescription);
text->setFontSize(characterSize,characterSize);
text->setCharacterSize(characterSize);
text->setPosition(posDescription);
text->setMaximumWidth(maxWidthOfDisplayRegion);
@ -198,6 +204,7 @@ void DrawCallback::createHelpText()
osgText::Text* text = new osgText::Text;
text->setFont("fonts/arial.ttf");
text->setColor(colorOption);
text->setFontSize(characterSize,characterSize);
text->setCharacterSize(characterSize);
text->setPosition(posOption);
text->setAlignment(osgText::Text::BASE_LINE);
@ -224,6 +231,7 @@ void DrawCallback::createHelpText()
osgText::Text* text = new osgText::Text;
text->setFont("fonts/arial.ttf");
text->setColor(colorExplanation);
text->setFontSize(characterSize,characterSize);
text->setCharacterSize(characterSize);
text->setPosition(posExplanation);
text->setMaximumWidth(maxWidth);
@ -328,13 +336,15 @@ void DrawCallback::displayStats()
_frameRateLabelText->draw(*(osh->getState()));
unsigned int lindex = (_index + 1) % _fs.size();
double timeForFrames = (_fs[_index]._startOfFrame-_fs[lindex]._startOfFrame);
double timePerFrame = timeForFrames/(double)(_fs.size()-1);
char frameRateText[128];
sprintf(frameRateText,"%4.2f",1.0/timePerFrame);
_frameRateCounterText->setText(frameRateText);
if (_fs.size()>1)
{
unsigned int lindex = (_index + 1) % _fs.size();
double timeForFrames = (_fs[_index]._startOfFrame-_fs[lindex]._startOfFrame);
double timePerFrame = timeForFrames/(double)(_fs.size()-1);
char frameRateText[128];
sprintf(frameRateText,"%4.2f",1.0/timePerFrame);
_frameRateCounterText->setText(frameRateText);
}
_frameRateCounterText->draw(*(osh->getState()));
@ -513,7 +523,7 @@ void DrawCallback::createStatsText()
_frameRateCounterText->setCharacterSize(characterSize);
_frameRateCounterText->setPosition(pos);
_frameRateCounterText->setAlignment(osgText::Text::BASE_LINE);
_frameRateCounterText->setText("0 Hz.");
_frameRateCounterText->setText("01234567890");
/* _statsLabelList;
_updateTimeText;