]> git.mxchange.org Git - flightgear.git/blob - src/Viewer/FGEventHandler.hxx
Move viewer-related sources to separate folder.
[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 #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     void setChangeStatsCameraRenderOrder(bool c)
83     {
84         changeStatsCameraRenderOrder = c;
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     fgKeyHandler keyHandler;
107     fgMouseClickHandler mouseClickHandler;
108     fgMouseMotionHandler mouseMotionHandler;
109     osg::ref_ptr<FGStatsHandler> statsHandler;
110     osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
111     int statsType;
112     int currentModifiers;
113     std::map<int, int> numlockKeyMap;
114     std::map<int, int> noNumlockKeyMap;
115     void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
116     bool resizable;
117     bool mouseWarped;
118     // workaround for osgViewer double scroll events
119     bool scrollButtonPressed;
120     int release_keys[128];
121     void handleStats(osgGA::GUIActionAdapter& us);
122     bool changeStatsCameraRenderOrder;
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