1 #ifndef FGEVENTHANDLER_H
2 #define FGEVENTHANDLER_H 1
6 #include <osgGA/GUIEventHandler>
7 #include <osgViewer/ViewerEventHandlers>
8 #include <simgear/structure/OSGVersion.hxx>
10 #include <Main/fg_os.hxx>
14 class FGStatsHandler : public osgViewer::StatsHandler
19 // Adjust font type/size for >=OSG3.
20 // OSG defaults aren't working/available for FG.
21 _font = "Fonts/helvetica_medium.txf";
22 _characterSize = 12.0f;
26 class FGEventHandler : public osgGA::GUIEventHandler {
30 virtual ~FGEventHandler() {}
32 virtual const char* className() const {return "FGEventHandler"; }
34 virtual void init(const osgGA::GUIEventAdapter& ea,
35 osgGA::GUIActionAdapter& us);
37 virtual bool handle(const osgGA::GUIEventAdapter& ea,
38 osgGA::GUIActionAdapter& us);
40 void setIdleHandler(fgIdleHandler idleHandler)
42 this->idleHandler = idleHandler;
45 fgIdleHandler getIdleHandler() const
50 void setKeyHandler(fgKeyHandler keyHandler)
52 this->keyHandler = keyHandler;
55 fgKeyHandler getKeyHandler() const
60 void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
62 this->mouseClickHandler = mouseClickHandler;
65 fgMouseClickHandler getMouseClickHandler()
67 return mouseClickHandler;
70 void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
72 this->mouseMotionHandler = mouseMotionHandler;
75 fgMouseMotionHandler getMouseMotionHandler()
77 return mouseMotionHandler;
80 void setChangeStatsCameraRenderOrder(bool c)
82 changeStatsCameraRenderOrder = c;
85 int getCurrentModifiers() const
87 return currentModifiers;
95 /** Whether or not resizing is supported. It might not be when
96 * using multiple displays.
98 bool getResizable() { return resizable; }
99 void setResizable(bool _resizable) { resizable = _resizable; }
102 osg::ref_ptr<osg::Node> _node;
103 fgIdleHandler idleHandler;
104 fgKeyHandler keyHandler;
105 fgMouseClickHandler mouseClickHandler;
106 fgMouseMotionHandler mouseMotionHandler;
107 osg::ref_ptr<FGStatsHandler> statsHandler;
108 osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
110 int currentModifiers;
111 std::map<int, int> numlockKeyMap;
112 std::map<int, int> noNumlockKeyMap;
113 void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
116 // workaround for osgViewer double scroll events
117 bool scrollButtonPressed;
118 int release_keys[128];
119 void handleStats(osgGA::GUIActionAdapter& us);
120 bool changeStatsCameraRenderOrder;
121 SGPropertyNode_ptr _display, _print;
124 void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
125 void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
126 double& x, double& y);