]> git.mxchange.org Git - flightgear.git/blob - src/Main/FGEventHandler.hxx
#389: NumPad keys not working when NumLock is off
[flightgear.git] / src / Main / FGEventHandler.hxx
1 #ifndef FGEVENTHANDLER_H
2 #define FGEVENTHANDLER_H 1
3
4 #include <map>
5 #include <osg/Quat>
6 #include <osgGA/GUIEventHandler>
7 #include <osgViewer/ViewerEventHandlers>
8
9 #include "fg_os.hxx"
10
11 namespace flightgear
12 {
13 class FGEventHandler : public osgGA::GUIEventHandler {
14 public:
15     FGEventHandler();
16     
17     virtual ~FGEventHandler() {}
18     
19     virtual const char* className() const {return "FGEventHandler"; }
20 #if 0
21     virtual void init(const osgGA::GUIEventAdapter& ea,
22                       osgGA::GUIActionAdapter& us);
23 #endif
24     virtual bool handle(const osgGA::GUIEventAdapter& ea,
25                         osgGA::GUIActionAdapter& us);
26
27     void setIdleHandler(fgIdleHandler idleHandler)
28         {
29             this->idleHandler = idleHandler;
30         }
31
32     fgIdleHandler getIdleHandler() const
33         {
34             return idleHandler;
35         }
36
37     void setDrawHandler(fgDrawHandler drawHandler)
38         {
39             this->drawHandler = drawHandler;
40         }
41
42     fgDrawHandler getDrawHandler() const
43         {
44             return drawHandler;
45         }
46
47     void setWindowResizeHandler(fgWindowResizeHandler windowResizeHandler)
48         {
49             this->windowResizeHandler = windowResizeHandler;
50         }
51     
52     fgWindowResizeHandler getWindowResizeHandler() const
53         {
54             return windowResizeHandler;
55         }
56
57     void setKeyHandler(fgKeyHandler keyHandler)
58         {
59             this->keyHandler = keyHandler;
60         }
61
62     fgKeyHandler getKeyHandler() const
63         {
64             return keyHandler;
65         }
66
67     void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
68         {
69             this->mouseClickHandler = mouseClickHandler;
70         }
71     
72     fgMouseClickHandler getMouseClickHandler()
73         {
74             return mouseClickHandler;
75         }
76
77     void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
78         {
79             this->mouseMotionHandler = mouseMotionHandler;
80         }
81     
82     fgMouseMotionHandler getMouseMotionHandler()
83         {
84             return mouseMotionHandler;
85         }
86
87     int getCurrentModifiers() const
88         {
89             return currentModifiers;
90         }
91
92     void setMouseWarped()
93         {
94             mouseWarped = true;
95         }
96
97     /** Whether or not resizing is supported. It might not be when
98      * using multiple displays.
99      */
100     bool getResizable() { return resizable; }
101     void setResizable(bool _resizable) { resizable = _resizable; }
102
103 protected:
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;
113     int statsType;
114     int currentModifiers;
115     std::map<int, int> numlockKeyMap;
116     std::map<int, int> noNumlockKeyMap;
117     void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
118     bool resizable;
119     bool mouseWarped;
120     // workaround for osgViewer double scroll events
121     bool scrollButtonPressed;
122     int release_keys[128];
123     void handleStats(osgGA::GUIActionAdapter& us);
124 };
125
126 void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
127 void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
128                               double& x, double& y);
129 }
130 #endif