File: input.h

package info (click to toggle)
warzone2100 2.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 104,520 kB
  • ctags: 37,273
  • sloc: ansic: 194,169; yacc: 6,307; sh: 4,753; lex: 1,943; makefile: 1,507; cpp: 836; perl: 139
file content (235 lines) | stat: -rw-r--r-- 6,815 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
	This file is part of Warzone 2100.
	Copyright (C) 1999-2004  Eidos Interactive
	Copyright (C) 2005-2010  Warzone 2100 Project

	Warzone 2100 is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	Warzone 2100 is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Warzone 2100; if not, write to the Free Software
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*! \file input.h
 * \brief Prototypes for the keyboard and mouse input funcitons.
 */
#ifndef _input_h
#define _input_h

/* Check the header files have been included from frame.h if they
 * are used outside of the framework library.
 */
#if !defined(_frame_h) && !defined(FRAME_LIB_INCLUDE)
#error Framework header files MUST be included from Frame.h ONLY.
#endif

#include <SDL.h>
#include "types.h"
#include "lib/framework/utf.h"

/** Defines for all the key codes used. */
typedef enum _key_code
{
	KEY_ESC			=SDLK_ESCAPE,
	KEY_1			=SDLK_1,
	KEY_2			=SDLK_2,
	KEY_3			=SDLK_3,
	KEY_4			=SDLK_4,
	KEY_5			=SDLK_5,
	KEY_6			=SDLK_6,
	KEY_7			=SDLK_7,
	KEY_8			=SDLK_8,
	KEY_9			=SDLK_9,
	KEY_0			=SDLK_0,
	KEY_MINUS		=SDLK_MINUS,
	KEY_EQUALS		=SDLK_EQUALS,
	KEY_BACKSPACE		=SDLK_BACKSPACE,
	KEY_TAB			=SDLK_TAB,
	KEY_Q			=SDLK_q,
	KEY_W			=SDLK_w,
	KEY_E			=SDLK_e,
	KEY_R			=SDLK_r,
	KEY_T			=SDLK_t,
	KEY_Y			=SDLK_y,
	KEY_U			=SDLK_u,
	KEY_I			=SDLK_i,
	KEY_O			=SDLK_o,
	KEY_P			=SDLK_p,
	KEY_LBRACE		=SDLK_LEFTBRACKET,
	KEY_RBRACE		=SDLK_RIGHTBRACKET,
	KEY_RETURN		=SDLK_RETURN,
	KEY_LCTRL		=SDLK_LCTRL,
	KEY_A			=SDLK_a,
	KEY_S			=SDLK_s,
	KEY_D			=SDLK_d,
	KEY_F			=SDLK_f,
	KEY_G			=SDLK_g,
	KEY_H			=SDLK_h,
	KEY_J			=SDLK_j,
	KEY_K			=SDLK_k,
	KEY_L			=SDLK_l,
	KEY_SEMICOLON		=SDLK_SEMICOLON,
	KEY_QUOTE		=SDLK_QUOTE,
	KEY_BACKQUOTE		=SDLK_BACKQUOTE,
	KEY_LSHIFT		=SDLK_LSHIFT,
	KEY_LMETA		=SDLK_LMETA,
	KEY_LSUPER		=SDLK_LSUPER,
	KEY_BACKSL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_RALT,
	KEY_HOME		=SDLK_HOME,
	KEY_UPARROW		=SDLK_UP,
	KEY_PAGEUP		=SDLK_PAGEUP,
	KEY_LEFTARROW		=SDLK_LEFT,
	KEY_RIGHTARROW		=SDLK_RIGHT,
	KEY_END			=SDLK_END,
	KEY_DOWNARROW		=SDLK_DOWN,
	KEY_PAGEDOWN		=SDLK_PAGEDOWN,
	KEY_INSERT		=SDLK_INSERT,
	KEY_DELETE		=SDLK_DELETE,
	KEY_KPENTER		=SDLK_KP_ENTER,

	KEY_IGNORE		=5190
} KEY_CODE;

/** The largest possible scan code. */
#define KEY_MAXSCAN SDLK_LAST

/** Tell the input system that we have lost the focus. */
extern void inputLooseFocus(void);

extern void inputHandleKeyEvent(SDL_KeyboardEvent*);
extern void inputHandleMouseMotionEvent(SDL_MouseMotionEvent*);
extern void inputHandleMouseButtonEvent(SDL_MouseButtonEvent*);

/** Converts the key code into an ascii string. */
extern void keyScanToString(KEY_CODE code, char *ascii, UDWORD maxStringSize);

/** Initialise the input module. */
extern void inputInitialise(void);

/** This returns true if the key is currently depressed. */
extern bool keyDown(KEY_CODE code);

/** This returns true if the key went from being up to being down this frame. */
extern bool keyPressed(KEY_CODE code);

/** This returns true if the key went from being down to being up this frame. */
extern bool keyReleased(KEY_CODE code);

typedef enum _mouse_key_code
{
	MOUSE_LMB = SDL_BUTTON_LEFT,
	MOUSE_MMB = SDL_BUTTON_MIDDLE,
	MOUSE_RMB = SDL_BUTTON_RIGHT,
	MOUSE_WUP = SDL_BUTTON_WHEELUP,
	MOUSE_WDN = SDL_BUTTON_WHEELDOWN
} MOUSE_KEY_CODE;

/** Return the current X position of the mouse. */
extern Uint16 mouseX(void) WZ_DECL_PURE;

/** Return the current Y position of the mouse. */
extern Uint16 mouseY(void) WZ_DECL_PURE;

/** This returns true if the mouse key is currently depressed. */
extern bool mouseDown(MOUSE_KEY_CODE code);

/** This returns true if the mouse key was double clicked. */
extern bool mouseDClicked(MOUSE_KEY_CODE code);

/** This returns true if the mouse key went from being up to being down this frame. */
extern bool mousePressed(MOUSE_KEY_CODE code);

/** This returns true if the mouse key went from being down to being up this frame. */
extern bool mouseReleased(MOUSE_KEY_CODE code);

/** Check for a mouse drag, return the drag start coords if dragging. */
extern bool mouseDrag(MOUSE_KEY_CODE code, UDWORD *px, UDWORD *py);

/** Warps the mouse to the given position. */
extern void SetMousePos(Uint16 x, Uint16 y);

/* The input buffer can contain normal character codes and these control codes */
#define INPBUF_LEFT		0x010000
#define INPBUF_RIGHT	0x020000
#define INPBUF_UP		0x030000
#define INPBUF_DOWN		0x040000
#define INPBUF_HOME		0x050000
#define INPBUF_END		0x060000
#define INPBUF_INS		0x070000
#define INPBUF_DEL		0x080000
#define INPBUF_PGUP		0x090000
#define INPBUF_PGDN		0x0a0000

/* Some defines for keys that map into the normal character space */
#define INPBUF_BKSPACE		0x000008
#define INPBUF_TAB		0x000009
#define INPBUF_CR		0x00000D
#define INPBUF_ESC		0x00001b

/** Return the next key press or 0 if no key in the buffer.
 * The key returned will have been remapped to the correct ascii code for the
 * US layout (approximately) key map.
 * All key presses are buffered up (including auto repeat).
 * @param unicode is filled (unless NULL) with the unicode character corresponding
 * to the key press (using the user's native layout).
 */
extern UDWORD inputGetKey(utf_32_char *unicode);

/** Clear the input buffer. */
extern void inputClearBuffer(void);

#endif