1 /*
2  * CRRCsim - the Charles River Radio Control Club Flight Simulator Project
3  *
4  * Copyright (C) 2005, 2008 Jens Wilhelm Wulf (original author)
5  * Copyright (C) 2005, 2006, 2009 Jan Reucker
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2
9  * as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
23 
24 #ifndef MOUSE_KBD_H
25 # define MOUSE_KBD_H
26 
27 #include <SDL.h>
28 
29 #include "defines.h"
30 #include "mod_misc/SimpleXMLTransfer.h"
31 #include "mod_inputdev/inputdev.h"
32 
33 
34 
35 /**
36  * This class holds information about bindings of certain inputs, like
37  * axes/buttons of a mouse/joystick or keyboard actions.
38  *
39  * It also contains the number of the joystick.
40  */
41 class TInputDev
42 {
43   public:
44 
45    enum { NUM_BUTTONACTION=8 };
46    enum { NOTHING=0, RESUME=1, PAUSE=2, RESET=3, INCTHROTTLE=4, DECTHROTTLE=5, ZOOMIN=6, ZOOMOUT=7 };
47 
48    enum { NUM_ZOMCONTROL=2 };
49    enum { KEYBOARD=0, MOUSE=1};
50 
51    TInputDev();
52 
53    int mouse_bind_x;
54    int mouse_bind_y;
55    int mouse_bind_l;
56    int mouse_bind_m;
57    int mouse_bind_r;
58    int mouse_bind_u;
59    int mouse_bind_d;
60 
61    int joystick_bind_b[MAXJOYBUTTON + 1];  // joystick buttons
62    int joystick_n;                         // sdl joystick num
63 
64    char** AxisStringsXML;
65    char** AxisStringsGUI;
66    char** InputMethodStrings;//for XML
67    char** InputMethodStringsGUI;// The same but possibly translated
68    char** ActionButtonStrings;//for XML
69    char** ActionButtonStringsGUI;
70    char** MixerStringsXML;
71    char** MixerStringsGUI;
72    char** ZoomControlStrings;//for XML
73    char** ZoomControlStringsGUI;
74    /**
75     * What input device controls the field of view
76     */
77    int zoom_control;
78 
79    /**
80     * Loads configuration from <code>cfgfile</code>
81     */
82    void init(SimpleXMLTransfer* cfgfile);
83 
84    /**
85     * Writes current configuration back into <code>cfgfile</code>
86     */
87    void putBackIntoCfg(SimpleXMLTransfer* cfgfile);
88 
89    /**
90     * Tries to open the joystick joystick_n. If a joystick is
91     * already open, it will be closed before trying to open
92     * the new joystick.
93     *
94     * \return empty string on success, error message on failure
95     */
96    std::string openJoystick();
97 
98    /**
99     * Sets joystick_n to joy_n and tries to open this joystick.
100     * If a joystick is already open, it will be closed before trying
101     * to open the new joystick.
102     *
103     * \param joy_n number of the joystick to open
104     * \return empty string on success, error message on failure
105     */
106    std::string openJoystick(int joy_n);
107 
108    /**
109     * Closes joystick if it has been opened before.
110     */
111    void closeJoystick();
112 
113    /**
114     * Get the number of axes of the current joystick.
115     * Joystick must have been opened before!
116     * \return Number of axes, 0 if joystick is inactive.
117     */
118    int getJoystickNumAxes();
119 
120    /**
121     * Get the number of buttons of the current joystick.
122     * Joystick must have been opened before!
123     * \return Number of buttons, 0 if joystick is inactive.
124     */
125    int getJoystickNumButtons();
126 
127   private:
128    int  getValAxis  (std::string asString, int nDefault);
129    int  getValButton(std::string asString, int nDefault);
130 
131    SDL_Joystick* joy;
132 };
133 
134 #endif
135