]> git.mxchange.org Git - flightgear.git/blob - src/Main/FGManipulator.hxx
make isatty() available for stdout/stderr (hope it works on MS Windows)
[flightgear.git] / src / Main / FGManipulator.hxx
1 #ifndef FGMANIPULATOR_H
2 #define FGMANIPULATOR_H 1
3
4 #include <map>
5 #include <osg/Quat>
6 #include <osgGA/MatrixManipulator>
7 #include <osgViewer/ViewerEventHandlers>
8
9 #include "fg_os.hxx"
10
11 namespace flightgear
12 {
13 class FGManipulator : public osgGA::MatrixManipulator {
14 public:
15     FGManipulator();
16     
17     virtual ~FGManipulator() {}
18     
19     virtual const char* className() const {return "FGManipulator"; }
20
21     /** set the position of the matrix manipulator using a 4x4 Matrix.*/
22     virtual void setByMatrix(const osg::Matrixd& matrix);
23
24     virtual void setByInverseMatrix(const osg::Matrixd& matrix)
25         { setByMatrix(osg::Matrixd::inverse(matrix)); }
26
27     /** get the position of the manipulator as 4x4 Matrix.*/
28     virtual osg::Matrixd getMatrix() const;
29
30     /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
31     virtual osg::Matrixd getInverseMatrix() const;
32
33     virtual void setNode(osg::Node* node);
34     
35     const osg::Node* getNode() const;
36
37     osg::Node* getNode();
38
39     virtual void init(const osgGA::GUIEventAdapter& ea,
40                       osgGA::GUIActionAdapter& us);
41
42     virtual bool handle(const osgGA::GUIEventAdapter& ea,
43                         osgGA::GUIActionAdapter& us);
44
45     void setIdleHandler(fgIdleHandler idleHandler)
46         {
47             this->idleHandler = idleHandler;
48         }
49
50     fgIdleHandler getIdleHandler() const
51         {
52             return idleHandler;
53         }
54
55     void setDrawHandler(fgDrawHandler drawHandler)
56         {
57             this->drawHandler = drawHandler;
58         }
59
60     fgDrawHandler getDrawHandler() const
61         {
62             return drawHandler;
63         }
64
65     void setWindowResizeHandler(fgWindowResizeHandler windowResizeHandler)
66         {
67             this->windowResizeHandler = windowResizeHandler;
68         }
69     
70     fgWindowResizeHandler getWindowResizeHandler() const
71         {
72             return windowResizeHandler;
73         }
74
75     void setKeyHandler(fgKeyHandler keyHandler)
76         {
77             this->keyHandler = keyHandler;
78         }
79
80     fgKeyHandler getKeyHandler() const
81         {
82             return keyHandler;
83         }
84
85     void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
86         {
87             this->mouseClickHandler = mouseClickHandler;
88         }
89     
90     fgMouseClickHandler getMouseClickHandler()
91         {
92             return mouseClickHandler;
93         }
94
95     void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
96         {
97             this->mouseMotionHandler = mouseMotionHandler;
98         }
99     
100     fgMouseMotionHandler getMouseMotionHandler()
101         {
102             return mouseMotionHandler;
103         }
104
105     int getCurrentModifiers() const
106         {
107             return currentModifiers;
108         }
109
110     void setMouseWarped()
111         {
112             mouseWarped = true;
113         }
114
115     void setPosition(const osg::Vec3d position) { this->position = position; }
116     void setAttitude(const osg::Quat attitude) { this->attitude = attitude; }
117
118     /** Whether or not resizing is supported. It might not be when
119      * using multiple displays.
120      */
121     bool getResizable() { return resizable; }
122     void setResizable(bool _resizable) { resizable = _resizable; }
123
124 protected:
125     osg::ref_ptr<osg::Node> _node;
126     fgIdleHandler idleHandler;
127     fgDrawHandler drawHandler;
128     fgWindowResizeHandler windowResizeHandler;
129     fgKeyHandler keyHandler;
130     fgMouseClickHandler mouseClickHandler;
131     fgMouseMotionHandler mouseMotionHandler;
132     osg::ref_ptr<osgViewer::StatsHandler> statsHandler;
133     osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
134     int statsType;
135     int currentModifiers;
136     std::map<int, int> numlockKeyMap;
137     osg::Vec3d position;
138     osg::Quat attitude;
139     void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
140     bool resizable;
141     bool mouseWarped;
142     // workaround for osgViewer double scroll events
143     bool scrollButtonPressed;
144     int release_keys[128];
145     void handleStats(osgGA::GUIActionAdapter& us);
146 };
147
148 void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
149 void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
150                               double& x, double& y);
151 }
152 #endif