1 #ifndef FGEVENTHANDLER_H
2 #define FGEVENTHANDLER_H 1
6 #include <osgGA/GUIEventHandler>
7 #include <osgViewer/ViewerEventHandlers>
13 class FGEventHandler : public osgGA::GUIEventHandler {
17 virtual ~FGEventHandler() {}
19 virtual const char* className() const {return "FGEventHandler"; }
21 virtual void init(const osgGA::GUIEventAdapter& ea,
22 osgGA::GUIActionAdapter& us);
24 virtual bool handle(const osgGA::GUIEventAdapter& ea,
25 osgGA::GUIActionAdapter& us);
27 void setIdleHandler(fgIdleHandler idleHandler)
29 this->idleHandler = idleHandler;
32 fgIdleHandler getIdleHandler() const
37 void setDrawHandler(fgDrawHandler drawHandler)
39 this->drawHandler = drawHandler;
42 fgDrawHandler getDrawHandler() const
47 void setWindowResizeHandler(fgWindowResizeHandler windowResizeHandler)
49 this->windowResizeHandler = windowResizeHandler;
52 fgWindowResizeHandler getWindowResizeHandler() const
54 return windowResizeHandler;
57 void setKeyHandler(fgKeyHandler keyHandler)
59 this->keyHandler = keyHandler;
62 fgKeyHandler getKeyHandler() const
67 void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
69 this->mouseClickHandler = mouseClickHandler;
72 fgMouseClickHandler getMouseClickHandler()
74 return mouseClickHandler;
77 void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
79 this->mouseMotionHandler = mouseMotionHandler;
82 fgMouseMotionHandler getMouseMotionHandler()
84 return mouseMotionHandler;
87 int getCurrentModifiers() const
89 return currentModifiers;
97 /** Whether or not resizing is supported. It might not be when
98 * using multiple displays.
100 bool getResizable() { return resizable; }
101 void setResizable(bool _resizable) { resizable = _resizable; }
104 osg::ref_ptr<osg::Node> _node;
105 fgIdleHandler idleHandler;
106 fgDrawHandler drawHandler;
107 fgWindowResizeHandler windowResizeHandler;
108 fgKeyHandler keyHandler;
109 fgMouseClickHandler mouseClickHandler;
110 fgMouseMotionHandler mouseMotionHandler;
111 osg::ref_ptr<osgViewer::StatsHandler> statsHandler;
112 osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
114 int currentModifiers;
115 std::map<int, int> numlockKeyMap;
116 void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
119 // workaround for osgViewer double scroll events
120 bool scrollButtonPressed;
121 int release_keys[128];
122 void handleStats(osgGA::GUIActionAdapter& us);
125 void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
126 void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
127 double& x, double& y);