]> git.mxchange.org Git - flightgear.git/blob - src/Main/FGEventHandler.hxx
NavDisplay: fix update lag when switching range or centre.
[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 #include <simgear/structure/OSGVersion.hxx>
9
10 #include "fg_os.hxx"
11
12 namespace flightgear
13 {
14     class FGStatsHandler : public osgViewer::StatsHandler
15     {
16         public:
17             FGStatsHandler()
18             {
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;
24 #endif
25             }
26     };
27
28 class FGEventHandler : public osgGA::GUIEventHandler {
29 public:
30     FGEventHandler();
31     
32     virtual ~FGEventHandler() {}
33     
34     virtual const char* className() const {return "FGEventHandler"; }
35 #if 0
36     virtual void init(const osgGA::GUIEventAdapter& ea,
37                       osgGA::GUIActionAdapter& us);
38 #endif
39     virtual bool handle(const osgGA::GUIEventAdapter& ea,
40                         osgGA::GUIActionAdapter& us);
41
42     void setIdleHandler(fgIdleHandler idleHandler)
43         {
44             this->idleHandler = idleHandler;
45         }
46
47     fgIdleHandler getIdleHandler() const
48         {
49             return idleHandler;
50         }
51
52     void setKeyHandler(fgKeyHandler keyHandler)
53         {
54             this->keyHandler = keyHandler;
55         }
56
57     fgKeyHandler getKeyHandler() const
58         {
59             return keyHandler;
60         }
61
62     void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
63         {
64             this->mouseClickHandler = mouseClickHandler;
65         }
66     
67     fgMouseClickHandler getMouseClickHandler()
68         {
69             return mouseClickHandler;
70         }
71
72     void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
73         {
74             this->mouseMotionHandler = mouseMotionHandler;
75         }
76     
77     fgMouseMotionHandler getMouseMotionHandler()
78         {
79             return mouseMotionHandler;
80         }
81
82     int getCurrentModifiers() const
83         {
84             return currentModifiers;
85         }
86
87     void setMouseWarped()
88         {
89             mouseWarped = true;
90         }
91
92     /** Whether or not resizing is supported. It might not be when
93      * using multiple displays.
94      */
95     bool getResizable() { return resizable; }
96     void setResizable(bool _resizable) { resizable = _resizable; }
97
98 protected:
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;
106     int statsType;
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);
111     bool resizable;
112     bool mouseWarped;
113     // workaround for osgViewer double scroll events
114     bool scrollButtonPressed;
115     int release_keys[128];
116     void handleStats(osgGA::GUIActionAdapter& us);
117 };
118
119 void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
120 void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
121                               double& x, double& y);
122 }
123 #endif