FlightGear next
FGEventHandler.hxx
Go to the documentation of this file.
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 <Main/fg_os.hxx>
10
11namespace flightgear
12{
13 class FGStatsHandler : public osgViewer::StatsHandler
14 {
15 public:
17 {
18 // Adjust font type/size for >=OSG3.
19 // OSG defaults aren't working/available for FG.
20 _font = "Fonts/helvetica_medium.txf";
21 _characterSize = 12.0f;
22 }
23 };
24
25class FGEventHandler : public osgGA::GUIEventHandler {
26public:
28
29 virtual ~FGEventHandler() {}
30
31 virtual const char* className() const {return "FGEventHandler"; }
32#if 0
33 virtual void init(const osgGA::GUIEventAdapter& ea,
34 osgGA::GUIActionAdapter& us);
35#endif
36 bool handle(const osgGA::GUIEventAdapter& ea,
37 osgGA::GUIActionAdapter& us) override;
38
40 {
41 this->idleHandler = idleHandler;
42 }
43
45 {
46 return idleHandler;
47 }
48
50 {
51 this->keyHandler = keyHandler;
52 }
53
55 {
56 return keyHandler;
57 }
58
60 {
61 this->mouseClickHandler = mouseClickHandler;
62 }
63
68
73
78
83
85 {
86 return currentModifiers;
87 }
88
90 {
91 mouseWarped = true;
92 }
93
97 bool getResizable() { return resizable; }
98 void setResizable(bool _resizable) { resizable = _resizable; }
99
100 void reset();
101 void clear();
102
103 // Wrapper for osgViewer::GraphicsWindow::setWindowRectangle() that takes
104 // coordinates excluding window furniture.
105 //
106 void setWindowRectangleInteriorWithCorrection(osgViewer::GraphicsWindow* window, int x, int y, int width, int height);
107
108 static int translateKey(const osgGA::GUIEventAdapter& ea);
109 static int translateModifiers(const osgGA::GUIEventAdapter& ea);
110protected:
111 osg::ref_ptr<osg::Node> _node;
116 osg::ref_ptr<FGStatsHandler> statsHandler;
117 osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
120
121 void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
124 // workaround for osgViewer double scroll events
126 int release_keys[128];
127 void handleStats(osgGA::GUIActionAdapter& us);
129 SGPropertyNode_ptr _display, _print;
130private:
131 bool m_setWindowRectangle_called = false;
132 int m_setWindowRectangle_called_x = 0;
133 int m_setWindowRectangle_called_y = 0;
134 int m_setWindowRectangle_delta_x = 0;
135 int m_setWindowRectangle_delta_y = 0;
136
137 enum WindowType
138 {
139 WindowType_NONE,
140 WindowType_MAIN,
141 WindowType_SVIEW
142 };
143 WindowType
144 eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us,
145 int& x, int& y);
146
147 bool isMainWindow(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
148
149};
150
151bool eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
152}
153#endif
void setIdleHandler(fgIdleHandler idleHandler)
void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
osg::ref_ptr< osg::Node > _node
static int translateModifiers(const osgGA::GUIEventAdapter &ea)
osg::ref_ptr< osgGA::GUIEventAdapter > statsEvent
fgMouseClickHandler getMouseClickHandler()
fgIdleHandler getIdleHandler() const
void handleStats(osgGA::GUIActionAdapter &us)
bool getResizable()
Whether or not resizing is supported.
void setChangeStatsCameraRenderOrder(bool c)
void setWindowRectangleInteriorWithCorrection(osgViewer::GraphicsWindow *window, int x, int y, int width, int height)
virtual const char * className() const
fgMouseClickHandler mouseClickHandler
static int translateKey(const osgGA::GUIEventAdapter &ea)
osg::ref_ptr< FGStatsHandler > statsHandler
fgMouseMotionHandler getMouseMotionHandler()
void handleKey(const osgGA::GUIEventAdapter &ea, int &key, int &modifiers)
void setKeyHandler(fgKeyHandler keyHandler)
void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
fgKeyHandler getKeyHandler() const
bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us) override
fgMouseMotionHandler mouseMotionHandler
void setResizable(bool _resizable)
void(* fgKeyHandler)(int key, int keymod, int mousex, int mousey)
Definition fg_os.hxx:72
void(* fgMouseClickHandler)(int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter *)
Definition fg_os.hxx:73
void(* fgIdleHandler)()
Definition fg_os.hxx:68
void(* fgMouseMotionHandler)(int x, int y, const osgGA::GUIEventAdapter *)
Definition fg_os.hxx:74
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
Definition Addon.cxx:53
bool eventToWindowCoords(const osgGA::GUIEventAdapter *ea, double &x, double &y)