]> git.mxchange.org Git - flightgear.git/blob - src/Viewer/FGEventHandler.hxx
View can created itself from config properties
[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     void reset();
102 protected:
103     osg::ref_ptr<osg::Node> _node;
104     fgIdleHandler idleHandler;
105     fgKeyHandler keyHandler;
106     fgMouseClickHandler mouseClickHandler;
107     fgMouseMotionHandler mouseMotionHandler;
108     osg::ref_ptr<FGStatsHandler> statsHandler;
109     osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
110     int statsType;
111     int currentModifiers;
112     std::map<int, int> numlockKeyMap;
113     std::map<int, int> noNumlockKeyMap;
114     void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
115     bool resizable;
116     bool mouseWarped;
117     // workaround for osgViewer double scroll events
118     bool scrollButtonPressed;
119     int release_keys[128];
120     void handleStats(osgGA::GUIActionAdapter& us);
121     bool changeStatsCameraRenderOrder;
122     SGPropertyNode_ptr _display, _print;
123 };
124
125 void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
126 void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
127                               double& x, double& y);
128 }
129 #endif