1 #ifndef FGEVENTHANDLER_H
2 #define FGEVENTHANDLER_H 1
6 #include <osgGA/GUIEventHandler>
7 #include <osgViewer/ViewerEventHandlers>
8 #include <simgear/structure/OSGVersion.hxx>
14 class FGStatsHandler : public osgViewer::StatsHandler
19 #if (SG_OSG_VERSION >= 30000)
20 // Adjust font type/size for >=OSG3.
21 // OSG defaults aren't working/available for FG.
22 _font = "Fonts/helvetica_medium.txf";
23 _characterSize = 12.0f;
28 class FGEventHandler : public osgGA::GUIEventHandler {
32 virtual ~FGEventHandler() {}
34 virtual const char* className() const {return "FGEventHandler"; }
36 virtual void init(const osgGA::GUIEventAdapter& ea,
37 osgGA::GUIActionAdapter& us);
39 virtual bool handle(const osgGA::GUIEventAdapter& ea,
40 osgGA::GUIActionAdapter& us);
42 void setIdleHandler(fgIdleHandler idleHandler)
44 this->idleHandler = idleHandler;
47 fgIdleHandler getIdleHandler() const
52 void setKeyHandler(fgKeyHandler keyHandler)
54 this->keyHandler = keyHandler;
57 fgKeyHandler getKeyHandler() const
62 void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
64 this->mouseClickHandler = mouseClickHandler;
67 fgMouseClickHandler getMouseClickHandler()
69 return mouseClickHandler;
72 void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
74 this->mouseMotionHandler = mouseMotionHandler;
77 fgMouseMotionHandler getMouseMotionHandler()
79 return mouseMotionHandler;
82 int getCurrentModifiers() const
84 return currentModifiers;
92 /** Whether or not resizing is supported. It might not be when
93 * using multiple displays.
95 bool getResizable() { return resizable; }
96 void setResizable(bool _resizable) { resizable = _resizable; }
99 osg::ref_ptr<osg::Node> _node;
100 fgIdleHandler idleHandler;
101 fgKeyHandler keyHandler;
102 fgMouseClickHandler mouseClickHandler;
103 fgMouseMotionHandler mouseMotionHandler;
104 osg::ref_ptr<FGStatsHandler> statsHandler;
105 osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
107 int currentModifiers;
108 std::map<int, int> numlockKeyMap;
109 std::map<int, int> noNumlockKeyMap;
110 void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
113 // workaround for osgViewer double scroll events
114 bool scrollButtonPressed;
115 int release_keys[128];
116 void handleStats(osgGA::GUIActionAdapter& us);
119 void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
120 void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
121 double& x, double& y);