From fc4fe9c625c0aef2c27549cdb3df332b2380cbd5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 27 Mar 2003 10:54:01 +0000 Subject: [PATCH] Updates to utilise the new Producer keyboard bindings. --- include/osgProducer/KeyboardMouseCallback | 18 ++-- src/osgProducer/KeyboardMouseCallback.cpp | 113 ++++++++++++++++------ src/osgProducer/ViewerEventHandler.cpp | 26 +++-- 3 files changed, 110 insertions(+), 47 deletions(-) diff --git a/include/osgProducer/KeyboardMouseCallback b/include/osgProducer/KeyboardMouseCallback index 23d7f3ea4..66ee95191 100644 --- a/include/osgProducer/KeyboardMouseCallback +++ b/include/osgProducer/KeyboardMouseCallback @@ -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 > 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; diff --git a/src/osgProducer/KeyboardMouseCallback.cpp b/src/osgProducer/KeyboardMouseCallback.cpp index 8ada3102a..5bcf76d69 100644 --- a/src/osgProducer/KeyboardMouseCallback.cpp +++ b/src/osgProducer/KeyboardMouseCallback.cpp @@ -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 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 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 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 event = new EventAdapter; + event->adaptKeyRelease(getTime(),key); + + _eventQueueMutex.lock(); + _eventQueue.push_back(event); + _eventQueueMutex.unlock(); +} + +void KeyboardMouseCallback::specialKeyPress( Producer::KeyCharacter key ) +{ + + + osg::ref_ptr 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 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 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 event = new EventAdapter; - event->adaptButtonRelease(getTime(),mx,my,mbutton); - - _eventQueueMutex.lock(); - _eventQueue.push_back(event); - _eventQueueMutex.unlock(); -} - void KeyboardMouseCallback::getEventQueue(EventQueue& queue) { queue.clear(); diff --git a/src/osgProducer/ViewerEventHandler.cpp b/src/osgProducer/ViewerEventHandler.cpp index f3882a331..cb2807600 100644 --- a/src/osgProducer/ViewerEventHandler.cpp +++ b/src/osgProducer/ViewerEventHandler.cpp @@ -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;