]> git.mxchange.org Git - flightgear.git/blob - src/Viewer/FGEventHandler.hxx
considering u,v,wbody-fps are the ECEF velocity expressed in body axis, change in...
[flightgear.git] / src / Viewer / 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 <Main/fg_os.hxx>
11
12 namespace flightgear
13 {
14     class FGStatsHandler : public osgViewer::StatsHandler
15     {
16         public:
17             FGStatsHandler()
18             {
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;
23             }
24     };
25
26 class FGEventHandler : public osgGA::GUIEventHandler {
27 public:
28     FGEventHandler();
29     
30     virtual ~FGEventHandler() {}
31     
32     virtual const char* className() const {return "FGEventHandler"; }
33 #if 0
34     virtual void init(const osgGA::GUIEventAdapter& ea,
35                       osgGA::GUIActionAdapter& us);
36 #endif
37     virtual bool handle(const osgGA::GUIEventAdapter& ea,
38                         osgGA::GUIActionAdapter& us);
39
40     void setIdleHandler(fgIdleHandler idleHandler)
41         {
42             this->idleHandler = idleHandler;
43         }
44
45     fgIdleHandler getIdleHandler() const
46         {
47             return idleHandler;
48         }
49
50     void setKeyHandler(fgKeyHandler keyHandler)
51         {
52             this->keyHandler = keyHandler;
53         }
54
55     fgKeyHandler getKeyHandler() const
56         {
57             return keyHandler;
58         }
59
60     void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
61         {
62             this->mouseClickHandler = mouseClickHandler;
63         }
64     
65     fgMouseClickHandler getMouseClickHandler()
66         {
67             return mouseClickHandler;
68         }
69
70     void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
71         {
72             this->mouseMotionHandler = mouseMotionHandler;
73         }
74     
75     fgMouseMotionHandler getMouseMotionHandler()
76         {
77             return mouseMotionHandler;
78         }
79
80     void setChangeStatsCameraRenderOrder(bool c)
81     {
82         changeStatsCameraRenderOrder = c;
83     }
84
85     int getCurrentModifiers() const
86         {
87             return currentModifiers;
88         }
89
90     void setMouseWarped()
91         {
92             mouseWarped = true;
93         }
94
95     /** Whether or not resizing is supported. It might not be when
96      * using multiple displays.
97      */
98     bool getResizable() { return resizable; }
99     void setResizable(bool _resizable) { resizable = _resizable; }
100
101 protected:
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;
109     int statsType;
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);
114     bool resizable;
115     bool mouseWarped;
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;
122 };
123
124 void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
125 void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
126                               double& x, double& y);
127 }
128 #endif