2008-11-18 22:45:57 +00:00
|
|
|
#ifndef FGEVENTHANDLER_H
|
|
|
|
#define FGEVENTHANDLER_H 1
|
2007-05-21 17:50:02 +00:00
|
|
|
|
2007-06-16 09:39:56 +00:00
|
|
|
#include <map>
|
2007-05-21 17:50:02 +00:00
|
|
|
#include <osg/Quat>
|
2008-11-18 22:45:57 +00:00
|
|
|
#include <osgGA/GUIEventHandler>
|
2008-04-20 18:24:52 +00:00
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
2011-10-29 19:58:11 +00:00
|
|
|
#include <simgear/structure/OSGVersion.hxx>
|
2007-05-21 17:50:02 +00:00
|
|
|
|
|
|
|
#include "fg_os.hxx"
|
|
|
|
|
2008-08-01 15:57:29 +00:00
|
|
|
namespace flightgear
|
|
|
|
{
|
2011-10-29 19:58:11 +00:00
|
|
|
class FGStatsHandler : public osgViewer::StatsHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FGStatsHandler()
|
|
|
|
{
|
|
|
|
#if (SG_OSG_VERSION >= 30000)
|
|
|
|
// Adjust font type/size for >=OSG3.
|
|
|
|
// OSG defaults aren't working/available for FG.
|
|
|
|
_font = "Fonts/helvetica_medium.txf";
|
|
|
|
_characterSize = 12.0f;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-11-18 22:45:57 +00:00
|
|
|
class FGEventHandler : public osgGA::GUIEventHandler {
|
2007-05-21 17:50:02 +00:00
|
|
|
public:
|
2008-11-18 22:45:57 +00:00
|
|
|
FGEventHandler();
|
2007-06-16 09:39:56 +00:00
|
|
|
|
2008-11-18 22:45:57 +00:00
|
|
|
virtual ~FGEventHandler() {}
|
2007-05-21 17:50:02 +00:00
|
|
|
|
2008-11-18 22:45:57 +00:00
|
|
|
virtual const char* className() const {return "FGEventHandler"; }
|
|
|
|
#if 0
|
2007-05-21 17:50:02 +00:00
|
|
|
virtual void init(const osgGA::GUIEventAdapter& ea,
|
|
|
|
osgGA::GUIActionAdapter& us);
|
2008-11-18 22:45:57 +00:00
|
|
|
#endif
|
2007-05-21 17:50:02 +00:00
|
|
|
virtual bool handle(const osgGA::GUIEventAdapter& ea,
|
|
|
|
osgGA::GUIActionAdapter& us);
|
|
|
|
|
|
|
|
void setIdleHandler(fgIdleHandler idleHandler)
|
|
|
|
{
|
|
|
|
this->idleHandler = idleHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgIdleHandler getIdleHandler() const
|
|
|
|
{
|
|
|
|
return idleHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setKeyHandler(fgKeyHandler keyHandler)
|
|
|
|
{
|
|
|
|
this->keyHandler = keyHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgKeyHandler getKeyHandler() const
|
|
|
|
{
|
|
|
|
return keyHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
|
|
|
|
{
|
|
|
|
this->mouseClickHandler = mouseClickHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgMouseClickHandler getMouseClickHandler()
|
|
|
|
{
|
|
|
|
return mouseClickHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
|
|
|
|
{
|
|
|
|
this->mouseMotionHandler = mouseMotionHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgMouseMotionHandler getMouseMotionHandler()
|
|
|
|
{
|
|
|
|
return mouseMotionHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getCurrentModifiers() const
|
|
|
|
{
|
|
|
|
return currentModifiers;
|
|
|
|
}
|
2007-08-19 05:29:00 +00:00
|
|
|
|
|
|
|
void setMouseWarped()
|
|
|
|
{
|
|
|
|
mouseWarped = true;
|
|
|
|
}
|
|
|
|
|
2007-07-01 16:39:52 +00:00
|
|
|
/** Whether or not resizing is supported. It might not be when
|
|
|
|
* using multiple displays.
|
|
|
|
*/
|
|
|
|
bool getResizable() { return resizable; }
|
|
|
|
void setResizable(bool _resizable) { resizable = _resizable; }
|
|
|
|
|
2007-05-21 17:50:02 +00:00
|
|
|
protected:
|
|
|
|
osg::ref_ptr<osg::Node> _node;
|
|
|
|
fgIdleHandler idleHandler;
|
|
|
|
fgKeyHandler keyHandler;
|
|
|
|
fgMouseClickHandler mouseClickHandler;
|
|
|
|
fgMouseMotionHandler mouseMotionHandler;
|
2011-10-29 19:58:11 +00:00
|
|
|
osg::ref_ptr<FGStatsHandler> statsHandler;
|
2008-04-20 18:24:52 +00:00
|
|
|
osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
|
2008-04-21 14:18:30 +00:00
|
|
|
int statsType;
|
2007-05-21 17:50:02 +00:00
|
|
|
int currentModifiers;
|
2007-07-01 16:39:52 +00:00
|
|
|
std::map<int, int> numlockKeyMap;
|
2011-08-07 16:24:13 +00:00
|
|
|
std::map<int, int> noNumlockKeyMap;
|
2007-05-21 17:50:02 +00:00
|
|
|
void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
|
2007-07-01 16:39:52 +00:00
|
|
|
bool resizable;
|
2007-08-19 05:29:00 +00:00
|
|
|
bool mouseWarped;
|
2007-08-20 21:38:25 +00:00
|
|
|
// workaround for osgViewer double scroll events
|
|
|
|
bool scrollButtonPressed;
|
2007-11-12 19:29:08 +00:00
|
|
|
int release_keys[128];
|
2008-04-20 18:24:52 +00:00
|
|
|
void handleStats(osgGA::GUIActionAdapter& us);
|
2007-05-21 17:50:02 +00:00
|
|
|
};
|
2008-08-01 15:57:29 +00:00
|
|
|
|
|
|
|
void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
|
|
|
|
void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
|
|
|
|
double& x, double& y);
|
|
|
|
}
|
2007-05-21 17:50:02 +00:00
|
|
|
#endif
|