]> git.mxchange.org Git - flightgear.git/blob - src/Input/FGMouseInput.hxx
replay system: protect from recording multiple records for identical time
[flightgear.git] / src / Input / FGMouseInput.hxx
1 // FGMouseInput.hxx -- handle user input from mouse devices
2 //
3 // Written by Torsten Dreyer, started August 2009
4 // Based on work from David Megginson, started May 2001.
5 //
6 // Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
7 // Copyright (C) 2001 David Megginson, david@megginson.com
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22 //
23 // $Id$
24
25
26 #ifndef _FGMOUSEINPUT_HXX
27 #define _FGMOUSEINPUT_HXX
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif
32
33 #include "FGCommonInput.hxx"
34 #include "FGButton.hxx"
35
36 #include <map>
37 #include <list>
38 #include <simgear/structure/subsystem_mgr.hxx>
39 #include <simgear/scene/util/SGPickCallback.hxx>
40 #include <Viewer/renderer.hxx>
41
42 /**
43   * List of currently pressed mouse button events
44   */
45 class ActivePickCallbacks : public std::map<int, std::list<SGSharedPtr<SGPickCallback> > > {
46 public:
47   void update( double dt );
48   void init( int b, const osgGA::GUIEventAdapter* ea );
49 };
50
51
52 ////////////////////////////////////////////////////////////////////////
53 // The Mouse Input Class
54 ////////////////////////////////////////////////////////////////////////
55 class FGMouseInput : public SGSubsystem,FGCommonInput {
56 public:
57   FGMouseInput();
58   virtual ~FGMouseInput();
59
60   virtual void init();
61   virtual void update( double dt );
62
63   static const int MAX_MICE = 1;
64   static const int MAX_MOUSE_BUTTONS = 8;
65
66 private:
67   void doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea);
68   void doMouseMotion (int x, int y);
69   static FGMouseInput * mouseInput;
70   static void mouseClickHandler(int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter*);
71   static void mouseMotionHandler(int x, int y);
72
73   ActivePickCallbacks activePickCallbacks;
74   /**
75    * Settings for a mouse mode.
76    */
77   struct mouse_mode {
78     mouse_mode ();
79     virtual ~mouse_mode ();
80     int cursor;
81     bool constrained;
82     bool pass_through;
83     FGButton * buttons;
84     binding_list_t x_bindings[KEYMOD_MAX];
85     binding_list_t y_bindings[KEYMOD_MAX];
86   };
87
88
89   /**
90    * Settings for a mouse.
91    */
92   struct mouse {
93     mouse ();
94     virtual ~mouse ();
95     int x;
96     int y;
97     int save_x;
98     int save_y;
99     SGPropertyNode_ptr mode_node;
100     SGPropertyNode_ptr mouse_button_nodes[MAX_MOUSE_BUTTONS];
101     int nModes;
102     int current_mode;
103     double timeout;
104     mouse_mode * modes;
105   };
106
107   // 
108   // Map of all known cursor names
109   // This used to contain all the Glut cursors, but those are
110   // not defined by other toolkits.  It now supports only the cursor
111   // images we actually use, in the interest of portability.  Someday,
112   // it would be cool to write an OpenGL cursor renderer, with the
113   // cursors defined as textures referenced in the property tree.  This
114   // list could then be eliminated. -Andy
115   //
116   const static struct MouseCursorMap {
117     const char * name;
118     int cursor;
119   } mouse_cursor_map[];
120
121   mouse bindings[MAX_MICE];
122   
123   bool haveWarped;
124
125   SGPropertyNode_ptr xSizeNode;
126   SGPropertyNode_ptr ySizeNode;
127   SGPropertyNode_ptr xAccelNode;
128   SGPropertyNode_ptr yAccelNode;
129   SGPropertyNode_ptr hideCursorNode;
130   SGPropertyNode_ptr cursorTimeoutNode;
131 };
132
133 #endif