2003-01-21 21:14:29 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2003-01-18 02:34:35 +08:00
|
|
|
|
|
|
|
#ifndef OSGPRODUCER_EVENTCALLBACK
|
|
|
|
#define OSGPRODUCER_EVENTCALLBACK 1
|
|
|
|
|
2003-07-19 08:18:07 +08:00
|
|
|
#include <OpenThreads/Mutex>
|
2003-01-17 19:26:16 +08:00
|
|
|
|
|
|
|
#include <Producer/RenderSurface> // For definition of KeySymbol
|
|
|
|
#include <Producer/KeyboardMouse>
|
|
|
|
|
2003-01-18 02:34:35 +08:00
|
|
|
#include <osgProducer/EventAdapter>
|
|
|
|
|
2003-01-17 19:26:16 +08:00
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <osg/Timer>
|
|
|
|
|
2003-01-18 02:34:35 +08:00
|
|
|
namespace osgProducer {
|
|
|
|
|
|
|
|
|
|
|
|
class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseCallback
|
2003-01-17 19:26:16 +08:00
|
|
|
{
|
|
|
|
public:
|
2003-04-05 03:10:37 +08:00
|
|
|
KeyboardMouseCallback(Producer::KeyboardMouse* keyboardMouse, bool &done, bool escapeKeySetsDone=true) :
|
2003-01-17 19:26:16 +08:00
|
|
|
Producer::KeyboardMouseCallback(),
|
2003-04-05 03:10:37 +08:00
|
|
|
_keyboardMouse(keyboardMouse),
|
2003-01-17 19:26:16 +08:00
|
|
|
_mx(0.0f),_my(0.0f),_mbutton(0),
|
2003-03-19 22:27:05 +08:00
|
|
|
_done(done),
|
|
|
|
_escapeKeySetsDone(escapeKeySetsDone)
|
2003-01-17 19:26:16 +08:00
|
|
|
{}
|
|
|
|
|
2003-01-18 02:34:35 +08:00
|
|
|
virtual ~KeyboardMouseCallback() {}
|
2003-01-17 19:26:16 +08:00
|
|
|
|
2003-03-27 18:54:01 +08:00
|
|
|
// override KeyboardMouseCallback methods.
|
2003-05-07 19:13:49 +08:00
|
|
|
virtual void mouseScroll( Producer::KeyboardMouseCallback::ScrollingMotion sm );
|
2003-01-17 19:26:16 +08:00
|
|
|
virtual void mouseMotion( float mx, float my);
|
2003-01-18 18:17:28 +08:00
|
|
|
virtual void passiveMouseMotion( float mx, float my);
|
|
|
|
|
2003-01-17 19:26:16 +08:00
|
|
|
virtual void buttonPress( float mx, float my, unsigned int mbutton );
|
2003-03-28 01:18:59 +08:00
|
|
|
virtual void doubleButtonPress( float mx, float my, unsigned int mbutton);
|
2003-01-17 19:26:16 +08:00
|
|
|
virtual void buttonRelease( float mx, float my, unsigned int mbutton );
|
|
|
|
|
2003-03-27 18:54:01 +08:00
|
|
|
virtual void keyPress( Producer::KeyCharacter key );
|
|
|
|
virtual void keyRelease( Producer::KeyCharacter key );
|
|
|
|
|
|
|
|
virtual void specialKeyPress( Producer::KeyCharacter key);
|
|
|
|
virtual void specialKeyRelease( Producer::KeyCharacter key);
|
|
|
|
|
|
|
|
|
2003-03-28 18:04:58 +08:00
|
|
|
void setEscapeSetDone(bool esc) { _escapeKeySetsDone = esc; }
|
|
|
|
bool getEscapeSetDone() const { return _escapeKeySetsDone; }
|
|
|
|
|
|
|
|
|
2003-03-27 18:54:01 +08:00
|
|
|
// local methods and members
|
2003-01-18 02:34:35 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<EventAdapter> > EventQueue;
|
2003-01-17 19:26:16 +08:00
|
|
|
|
|
|
|
void getEventQueue(EventQueue& queue);
|
|
|
|
|
|
|
|
bool done() { return _done; }
|
|
|
|
float mx() { return _mx; }
|
|
|
|
float my() { return _my; }
|
|
|
|
unsigned int mbutton() { return _mbutton; }
|
|
|
|
|
2003-01-17 22:12:46 +08:00
|
|
|
void setStartTick(osg::Timer_t tick) { _startTick = tick; }
|
|
|
|
|
|
|
|
double getTime() { return _timer.delta_s(_startTick,_timer.tick()); }
|
2003-01-17 19:26:16 +08:00
|
|
|
|
2003-04-05 03:10:37 +08:00
|
|
|
Producer::KeyboardMouse* getKeyboardMouse() { return _keyboardMouse; }
|
|
|
|
const Producer::KeyboardMouse* getKeyboardMouse() const { return _keyboardMouse; }
|
|
|
|
|
2003-04-05 15:19:40 +08:00
|
|
|
EventAdapter* createEventAdapter();
|
|
|
|
|
2003-03-27 18:54:01 +08:00
|
|
|
protected:
|
2003-01-17 19:26:16 +08:00
|
|
|
|
2003-04-05 03:10:37 +08:00
|
|
|
|
|
|
|
Producer::KeyboardMouse* _keyboardMouse;
|
2003-01-17 19:26:16 +08:00
|
|
|
float _mx, _my;
|
|
|
|
unsigned int _mbutton;
|
|
|
|
bool &_done;
|
2003-03-19 22:27:05 +08:00
|
|
|
bool _escapeKeySetsDone;
|
2003-01-17 19:26:16 +08:00
|
|
|
|
2003-01-17 22:12:46 +08:00
|
|
|
osg::Timer_t _startTick;
|
|
|
|
osg::Timer _timer;
|
2003-07-19 08:18:07 +08:00
|
|
|
OpenThreads::Mutex _eventQueueMutex;
|
2003-01-17 19:26:16 +08:00
|
|
|
EventQueue _eventQueue;
|
|
|
|
|
|
|
|
};
|
2003-01-18 02:34:35 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-01-17 19:26:16 +08:00
|
|
|
#endif
|