]> git.mxchange.org Git - flightgear.git/blob - src/Main/FGEventHandler.hxx
Push aspect-ratio handling into CameraGroup, so renderer doesn't need to resize viewp...
[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 setKeyHandler(fgKeyHandler keyHandler)
38         {
39             this->keyHandler = keyHandler;
40         }
41
42     fgKeyHandler getKeyHandler() const
43         {
44             return keyHandler;
45         }
46
47     void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
48         {
49             this->mouseClickHandler = mouseClickHandler;
50         }
51     
52     fgMouseClickHandler getMouseClickHandler()
53         {
54             return mouseClickHandler;
55         }
56
57     void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
58         {
59             this->mouseMotionHandler = mouseMotionHandler;
60         }
61     
62     fgMouseMotionHandler getMouseMotionHandler()
63         {
64             return mouseMotionHandler;
65         }
66
67     int getCurrentModifiers() const
68         {
69             return currentModifiers;
70         }
71
72     void setMouseWarped()
73         {
74             mouseWarped = true;
75         }
76
77     /** Whether or not resizing is supported. It might not be when
78      * using multiple displays.
79      */
80     bool getResizable() { return resizable; }
81     void setResizable(bool _resizable) { resizable = _resizable; }
82
83 protected:
84     osg::ref_ptr<osg::Node> _node;
85     fgIdleHandler idleHandler;
86     fgKeyHandler keyHandler;
87     fgMouseClickHandler mouseClickHandler;
88     fgMouseMotionHandler mouseMotionHandler;
89     osg::ref_ptr<osgViewer::StatsHandler> statsHandler;
90     osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
91     int statsType;
92     int currentModifiers;
93     std::map<int, int> numlockKeyMap;
94     std::map<int, int> noNumlockKeyMap;
95     void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
96     bool resizable;
97     bool mouseWarped;
98     // workaround for osgViewer double scroll events
99     bool scrollButtonPressed;
100     int release_keys[128];
101     void handleStats(osgGA::GUIActionAdapter& us);
102 };
103
104 void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
105 void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
106                               double& x, double& y);
107 }
108 #endif