Adonthell  0.4
input.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 1999/2000/2001 Alexandre Courbot.
3  Copyright (C) 2016 Kai Sterker
4  Part of the Adonthell Project <http://adonthell.nongnu.org>
5 
6  Adonthell is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  Adonthell 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 Adonthell. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 
21 /**
22  * @file input.h
23  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
24  * @author Kai Sterker
25  *
26  * @brief Declares the input class.
27  *
28  *
29  */
30 
31 
32 
33 #ifndef INPUT_H__
34 #define INPUT_H__
35 
36 #include "types.h"
37 #include <string>
38 #include <queue>
39 #include <SDL_keycode.h>
40 
41 /**
42  * Handles keyboard and mouse input.
43  *
44  * @todo Rewrite it!
45  *
46  */
47 class input
48 {
49 public:
50 
51  /**
52  * Initialise the input system.
53  *
54  */
55  static void init();
56 
57  /**
58  * Free resources occupied by the input system.
59  *
60  */
61  static void shutdown();
62 
63  /**
64  * Update the input state.
65  *
66  */
67  static void update();
68 
69  /**
70  * Returns whether a key is currently pushed or not.
71  *
72  * @param key key to test.
73  *
74  * @return true if key is currently pushed, false otherwise.
75  */
76  static bool is_pushed(SDL_Keycode key);
77 #ifdef SWIG
78  static bool is_pushed(char key)
79  {
80  is_pushed((SDL_Keycode)key);
81  }
82 #endif
83 
84  /**
85  * Returns whether a key has been pushed since last function call, false otherwise.
86  *
87  * @param key key to test.
88  *
89  * @return true if the key has been pushed since last call, false otherwise.
90  */
91  static bool has_been_pushed(SDL_Keycode key);
92 #ifdef SWIG
93  static bool has_been_pushed(char key)
94  {
95  has_been_pushed((SDL_Keycode)key);
96  }
97 #endif
98 
99  /**
100  * Returns the code of the next key on the input queue.
101  *
102  *
103  * @return Code of the next key that has been pushed.
104  */
105  static SDL_Keycode get_next_key();
106 
107  /**
108  * Returns the next text input on the input queue encoded as utf8.
109  *
110  *
111  * @return utf8 representation of the next character that has been input.
112  */
113  static std::string get_next_unicode();
114 
115  static void start_text_input();
116  static void stop_text_input();
117  static bool is_text_input() { return text_input; }
118 
119  /**
120  * Totally clears the key queue.
121  *
122  */
123  static void clear_keys_queue();
124 
125 private:
126  static bool text_input;
127 
128  static u_int16 mouse_posx, mouse_posy;
129  static u_int8 * keystate;
130  static u_int8 * p_keystate;
131  static s_int32 keystatelength;
132 #ifndef SWIG
133  static bool mouse_button[3];
134 #endif
135  static std::queue<std::string> input_queue;
136 };
137 
138 #endif
static bool has_been_pushed(SDL_Keycode key)
Returns whether a key has been pushed since last function call, false otherwise.
Definition: input.cc:119
#define s_int32
32 bits long signed integer
Definition: types.h:50
Declares some basic types.
Handles keyboard and mouse input.
Definition: input.h:47
#define u_int16
16 bits long unsigned integer
Definition: types.h:38
static void update()
Update the input state.
Definition: input.cc:64
static SDL_Keycode get_next_key()
Returns the code of the next key on the input queue.
Definition: input.cc:128
#define u_int8
8 bits long unsigned integer
Definition: types.h:35
static void init()
Initialise the input system.
Definition: input.cc:48
static void shutdown()
Free resources occupied by the input system.
Definition: input.cc:59
static bool is_pushed(SDL_Keycode key)
Returns whether a key is currently pushed or not.
Definition: input.cc:110
static void clear_keys_queue()
Totally clears the key queue.
Definition: input.cc:168
static std::string get_next_unicode()
Returns the next text input on the input queue encoded as utf8.
Definition: input.cc:143