Mana
Loading...
Searching...
No Matches
src
gui
sdlinput.h
Go to the documentation of this file.
1
/* _______ __ __ __ ______ __ __ _______ __ __
2
* / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
3
* / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
4
* / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
5
* / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
6
* /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
7
* \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
8
*
9
* Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson
10
* Copyright (C) 2007-2010 The Mana World Development Team
11
* Copyright (C) 2010-2012 The Mana Developers
12
*
13
* Js_./
14
* Per Larsson a.k.a finalman _RqZ{a<^_aa
15
* Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a//
16
* _Qhm`] _f "'c 1!5m
17
* Visit: http://guichan.darkbits.org )Qk<P ` _: :+' .' "{[
18
* .)j(] .d_/ '-( P . S
19
* License: (BSD) <Td/Z <fP"5(\"??"\a. .L
20
* Redistribution and use in source and _dV>ws?a-?' ._/L #'
21
* binary forms, with or without )4d[#7r, . ' )d`)[
22
* modification, are permitted provided _Q-5'5W..j/?' -?!\)cam'
23
* that the following conditions are met: j<<WP+k/);. _W=j f
24
* 1. Redistributions of source code must .$%w\/]Q . ."' . mj$
25
* retain the above copyright notice, ]E.pYY(Q]>. a J@\
26
* this list of conditions and the j(]1u<sE"L,. . ./^ ]{a
27
* following disclaimer. 4'_uomm\. )L);-4 (3=
28
* 2. Redistributions in binary form must )_]X{Z('a_"a7'<a"a, ]"[
29
* reproduce the above copyright notice, #}<]m7`Za??4,P-"'7. ).m
30
* this list of conditions and the ]d2e)Q(<Q( ?94 b- LQ/
31
* following disclaimer in the <B!</]C)d_, '(<' .f. =C+m
32
* documentation and/or other materials .Z!=J ]e []('-4f _ ) -.)m]'
33
* provided with the distribution. .w[5]' _[ /.)_-"+? _/ <W"
34
* 3. Neither the name of Guichan nor the :$we` _! + _/ . j?
35
* names of its contributors may be used =3)= _f (_yQmWW$#( "
36
* to endorse or promote products derived - W, sQQQQmZQ#Wwa]..
37
* from this software without specific (js, \[QQW$QWW#?!V"".
38
* prior written permission. ]y:.<\.. .
39
* -]n w/ ' [.
40
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT )/ )/ !
41
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY < (; sac , '
42
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, ]^ .- %
43
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF c < r
44
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR aga< <La
45
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 5% )P'-3L
46
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR _bQf` y`..)a
47
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ,J?4P'.P"_(\?d'.,
48
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES _Pa,)!f/<[]/ ?"
49
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT _2-..:. .r+_,.. .
50
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ?a.<%"' " -'.a_ _,
51
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ^
52
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
53
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
55
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
56
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57
*/
58
59
#pragma once
60
61
#include <queue>
62
63
#include <SDL.h>
64
65
#include <guichan/input.hpp>
66
#include <guichan/keyinput.hpp>
67
#include <guichan/mouseinput.hpp>
68
#include <guichan/platform.hpp>
69
70
#include <string>
71
72
namespace
Key
73
{
74
enum
75
{
76
SPACE
=
' '
,
77
TAB
=
'\t'
,
78
ENTER
=
'\n'
,
79
// Negative values, to avoid conflicts with higher character codes.
80
LEFT_ALT
= -1000,
81
RIGHT_ALT
,
82
LEFT_SHIFT
,
83
RIGHT_SHIFT
,
84
LEFT_CONTROL
,
85
RIGHT_CONTROL
,
86
LEFT_META
,
87
RIGHT_META
,
88
LEFT_SUPER
,
89
RIGHT_SUPER
,
90
INSERT
,
91
HOME
,
92
PAGE_UP
,
93
DELETE_KEY
,
94
END
,
95
PAGE_DOWN
,
96
ESCAPE
,
97
CAPS_LOCK
,
98
BACKSPACE
,
99
F1
,
100
F2
,
101
F3
,
102
F4
,
103
F5
,
104
F6
,
105
F7
,
106
F8
,
107
F9
,
108
F10
,
109
F11
,
110
F12
,
111
F13
,
112
F14
,
113
F15
,
114
PRINT_SCREEN
,
115
SCROLL_LOCK
,
116
PAUSE
,
117
NUM_LOCK
,
118
ALT_GR
,
119
LEFT
,
120
RIGHT
,
121
UP
,
122
DOWN
123
};
124
}
125
126
class
TextInput
127
{
128
public
:
129
TextInput
(
const
char
*text)
130
:
mText
(text)
131
{}
132
133
const
std::string &
getText
()
const
{
return
mText
; }
134
135
private
:
136
std::string
mText
;
137
};
138
142
class
SDLInput
:
public
gcn::Input
143
{
144
public
:
145
149
SDLInput
();
150
157
virtual
void
pushInput
(SDL_Event event);
158
164
void
_pollInput
()
override
{ }
165
166
167
// Inherited from Input
168
169
bool
isKeyQueueEmpty
()
override
;
170
171
gcn::KeyInput
dequeueKeyInput
()
override
;
172
173
bool
isMouseQueueEmpty
()
override
;
174
175
gcn::MouseInput
dequeueMouseInput
()
override
;
176
177
bool
isTextQueueEmpty
()
const
;
178
179
TextInput
dequeueTextInput
();
180
181
protected
:
189
static
int
convertMouseButton
(
int
button);
190
198
static
int
convertKeyCharacter
(SDL_Event event);
199
200
std::queue<gcn::KeyInput>
mKeyInputQueue
;
201
std::queue<gcn::MouseInput>
mMouseInputQueue
;
202
std::queue<TextInput>
mTextInputQueue
;
203
204
bool
mMouseDown
=
false
;
205
};
SDLInput
SDL implementation of Input.
Definition
sdlinput.h:143
SDLInput::convertKeyCharacter
static int convertKeyCharacter(SDL_Event event)
Converts an SDL event key to a key value.
Definition
sdlinput.cpp:256
SDLInput::dequeueMouseInput
gcn::MouseInput dequeueMouseInput() override
Definition
sdlinput.cpp:91
SDLInput::pushInput
virtual void pushInput(SDL_Event event)
Pushes an SDL event.
Definition
sdlinput.cpp:132
SDLInput::mMouseDown
bool mMouseDown
Definition
sdlinput.h:204
SDLInput::mKeyInputQueue
std::queue< gcn::KeyInput > mKeyInputQueue
Definition
sdlinput.h:200
SDLInput::isMouseQueueEmpty
bool isMouseQueueEmpty() override
Definition
sdlinput.cpp:86
SDLInput::isTextQueueEmpty
bool isTextQueueEmpty() const
Definition
sdlinput.cpp:106
SDLInput::mMouseInputQueue
std::queue< gcn::MouseInput > mMouseInputQueue
Definition
sdlinput.h:201
SDLInput::dequeueTextInput
TextInput dequeueTextInput()
Definition
sdlinput.cpp:111
SDLInput::isKeyQueueEmpty
bool isKeyQueueEmpty() override
Definition
sdlinput.cpp:66
SDLInput::convertMouseButton
static int convertMouseButton(int button)
Converts a mouse button from SDL to a Guichan mouse button representation.
Definition
sdlinput.cpp:240
SDLInput::dequeueKeyInput
gcn::KeyInput dequeueKeyInput() override
Definition
sdlinput.cpp:71
SDLInput::SDLInput
SDLInput()
Constructor.
SDLInput::_pollInput
void _pollInput() override
Polls all input.
Definition
sdlinput.h:164
SDLInput::mTextInputQueue
std::queue< TextInput > mTextInputQueue
Definition
sdlinput.h:202
TextInput
Definition
sdlinput.h:127
TextInput::mText
std::string mText
Definition
sdlinput.h:136
TextInput::TextInput
TextInput(const char *text)
Definition
sdlinput.h:129
TextInput::getText
const std::string & getText() const
Definition
sdlinput.h:133
Key
Definition
sdlinput.h:73
Key::LEFT_META
@ LEFT_META
Definition
sdlinput.h:86
Key::F2
@ F2
Definition
sdlinput.h:100
Key::F3
@ F3
Definition
sdlinput.h:101
Key::ENTER
@ ENTER
Definition
sdlinput.h:78
Key::PAUSE
@ PAUSE
Definition
sdlinput.h:116
Key::INSERT
@ INSERT
Definition
sdlinput.h:90
Key::TAB
@ TAB
Definition
sdlinput.h:77
Key::F7
@ F7
Definition
sdlinput.h:105
Key::SPACE
@ SPACE
Definition
sdlinput.h:76
Key::LEFT
@ LEFT
Definition
sdlinput.h:119
Key::PAGE_UP
@ PAGE_UP
Definition
sdlinput.h:92
Key::RIGHT_SUPER
@ RIGHT_SUPER
Definition
sdlinput.h:89
Key::PRINT_SCREEN
@ PRINT_SCREEN
Definition
sdlinput.h:114
Key::HOME
@ HOME
Definition
sdlinput.h:91
Key::RIGHT_SHIFT
@ RIGHT_SHIFT
Definition
sdlinput.h:83
Key::LEFT_CONTROL
@ LEFT_CONTROL
Definition
sdlinput.h:84
Key::F10
@ F10
Definition
sdlinput.h:108
Key::RIGHT
@ RIGHT
Definition
sdlinput.h:120
Key::LEFT_SHIFT
@ LEFT_SHIFT
Definition
sdlinput.h:82
Key::F5
@ F5
Definition
sdlinput.h:103
Key::UP
@ UP
Definition
sdlinput.h:121
Key::F9
@ F9
Definition
sdlinput.h:107
Key::ESCAPE
@ ESCAPE
Definition
sdlinput.h:96
Key::LEFT_SUPER
@ LEFT_SUPER
Definition
sdlinput.h:88
Key::F8
@ F8
Definition
sdlinput.h:106
Key::BACKSPACE
@ BACKSPACE
Definition
sdlinput.h:98
Key::RIGHT_ALT
@ RIGHT_ALT
Definition
sdlinput.h:81
Key::F6
@ F6
Definition
sdlinput.h:104
Key::SCROLL_LOCK
@ SCROLL_LOCK
Definition
sdlinput.h:115
Key::DOWN
@ DOWN
Definition
sdlinput.h:122
Key::LEFT_ALT
@ LEFT_ALT
Definition
sdlinput.h:80
Key::F14
@ F14
Definition
sdlinput.h:112
Key::RIGHT_CONTROL
@ RIGHT_CONTROL
Definition
sdlinput.h:85
Key::F1
@ F1
Definition
sdlinput.h:99
Key::RIGHT_META
@ RIGHT_META
Definition
sdlinput.h:87
Key::F13
@ F13
Definition
sdlinput.h:111
Key::F11
@ F11
Definition
sdlinput.h:109
Key::CAPS_LOCK
@ CAPS_LOCK
Definition
sdlinput.h:97
Key::NUM_LOCK
@ NUM_LOCK
Definition
sdlinput.h:117
Key::F15
@ F15
Definition
sdlinput.h:113
Key::F12
@ F12
Definition
sdlinput.h:110
Key::END
@ END
Definition
sdlinput.h:94
Key::ALT_GR
@ ALT_GR
Definition
sdlinput.h:118
Key::F4
@ F4
Definition
sdlinput.h:102
Key::DELETE_KEY
@ DELETE_KEY
Definition
sdlinput.h:93
Key::PAGE_DOWN
@ PAGE_DOWN
Definition
sdlinput.h:95
Generated by
1.9.8