]> git.mxchange.org Git - flightgear.git/blob - src/Input/FGMouseInput.hxx
MSVC9 fix
[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 <Main/renderer.hxx>
41 /**
42   * List of currently pressed mouse button events
43   */
44 class ActivePickCallbacks : public std::map<int, std::list<SGSharedPtr<SGPickCallback> > > {
45 public:
46   void update( double dt );
47   void init( int b, const osgGA::GUIEventAdapter* ea );
48 };
49
50
51 ////////////////////////////////////////////////////////////////////////
52 // The Mouse Input Class
53 ////////////////////////////////////////////////////////////////////////
54 class FGMouseInput : public SGSubsystem,FGCommonInput {
55 public:
56   FGMouseInput();
57   virtual ~FGMouseInput();
58
59   virtual void init();
60   virtual void update( double dt );
61
62   static const int MAX_MICE = 1;
63   static const int MAX_MOUSE_BUTTONS = 8;
64
65 private:
66   void doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea);
67   void doMouseMotion (int x, int y);
68   static FGMouseInput * mouseInput;
69   static void mouseClickHandler(int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter*);
70   static void mouseMotionHandler(int x, int y);
71
72   ActivePickCallbacks activePickCallbacks;
73   /**
74    * Settings for a mouse mode.
75    */
76   struct mouse_mode {
77     mouse_mode ();
78     virtual ~mouse_mode ();
79     int cursor;
80     bool constrained;
81     bool pass_through;
82     FGButton * buttons;
83     binding_list_t x_bindings[KEYMOD_MAX];
84     binding_list_t y_bindings[KEYMOD_MAX];
85   };
86
87
88   /**
89    * Settings for a mouse.
90    */
91   struct mouse {
92     mouse ();
93     virtual ~mouse ();
94     int x;
95     int y;
96     int save_x;
97     int save_y;
98     SGPropertyNode_ptr mode_node;
99     SGPropertyNode_ptr mouse_button_nodes[MAX_MOUSE_BUTTONS];
100     int nModes;
101     int current_mode;
102     double timeout;
103     mouse_mode * modes;
104   };
105
106   // 
107   // Map of all known cursor names
108   // This used to contain all the Glut cursors, but those are
109   // not defined by other toolkits.  It now supports only the cursor
110   // images we actually use, in the interest of portability.  Someday,
111   // it would be cool to write an OpenGL cursor renderer, with the
112   // cursors defined as textures referenced in the property tree.  This
113   // list could then be eliminated. -Andy
114   //
115   const static struct MouseCursorMap {
116     const char * name;
117     int cursor;
118   } mouse_cursor_map[];
119
120   mouse bindings[MAX_MICE];
121 };
122
123 #endif