Mana
Loading...
Searching...
No Matches
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
125
127{
128public:
129 TextInput(const char *text)
130 : mText(text)
131 {}
132
133 const std::string &getText() const { return mText; }
134
135private:
136 std::string mText;
137};
138
142class SDLInput : public gcn::Input
143{
144public:
145
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
180
181protected:
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};
SDL implementation of Input.
Definition sdlinput.h:143
static int convertKeyCharacter(SDL_Event event)
Converts an SDL event key to a key value.
Definition sdlinput.cpp:256
gcn::MouseInput dequeueMouseInput() override
Definition sdlinput.cpp:91
virtual void pushInput(SDL_Event event)
Pushes an SDL event.
Definition sdlinput.cpp:132
bool mMouseDown
Definition sdlinput.h:204
std::queue< gcn::KeyInput > mKeyInputQueue
Definition sdlinput.h:200
bool isMouseQueueEmpty() override
Definition sdlinput.cpp:86
bool isTextQueueEmpty() const
Definition sdlinput.cpp:106
std::queue< gcn::MouseInput > mMouseInputQueue
Definition sdlinput.h:201
TextInput dequeueTextInput()
Definition sdlinput.cpp:111
bool isKeyQueueEmpty() override
Definition sdlinput.cpp:66
static int convertMouseButton(int button)
Converts a mouse button from SDL to a Guichan mouse button representation.
Definition sdlinput.cpp:240
gcn::KeyInput dequeueKeyInput() override
Definition sdlinput.cpp:71
SDLInput()
Constructor.
void _pollInput() override
Polls all input.
Definition sdlinput.h:164
std::queue< TextInput > mTextInputQueue
Definition sdlinput.h:202
std::string mText
Definition sdlinput.h:136
TextInput(const char *text)
Definition sdlinput.h:129
const std::string & getText() const
Definition sdlinput.h:133
Definition sdlinput.h:73
@ LEFT_META
Definition sdlinput.h:86
@ F2
Definition sdlinput.h:100
@ F3
Definition sdlinput.h:101
@ ENTER
Definition sdlinput.h:78
@ PAUSE
Definition sdlinput.h:116
@ INSERT
Definition sdlinput.h:90
@ TAB
Definition sdlinput.h:77
@ F7
Definition sdlinput.h:105
@ SPACE
Definition sdlinput.h:76
@ LEFT
Definition sdlinput.h:119
@ PAGE_UP
Definition sdlinput.h:92
@ RIGHT_SUPER
Definition sdlinput.h:89
@ PRINT_SCREEN
Definition sdlinput.h:114
@ HOME
Definition sdlinput.h:91
@ RIGHT_SHIFT
Definition sdlinput.h:83
@ LEFT_CONTROL
Definition sdlinput.h:84
@ F10
Definition sdlinput.h:108
@ RIGHT
Definition sdlinput.h:120
@ LEFT_SHIFT
Definition sdlinput.h:82
@ F5
Definition sdlinput.h:103
@ UP
Definition sdlinput.h:121
@ F9
Definition sdlinput.h:107
@ ESCAPE
Definition sdlinput.h:96
@ LEFT_SUPER
Definition sdlinput.h:88
@ F8
Definition sdlinput.h:106
@ BACKSPACE
Definition sdlinput.h:98
@ RIGHT_ALT
Definition sdlinput.h:81
@ F6
Definition sdlinput.h:104
@ SCROLL_LOCK
Definition sdlinput.h:115
@ DOWN
Definition sdlinput.h:122
@ LEFT_ALT
Definition sdlinput.h:80
@ F14
Definition sdlinput.h:112
@ RIGHT_CONTROL
Definition sdlinput.h:85
@ F1
Definition sdlinput.h:99
@ RIGHT_META
Definition sdlinput.h:87
@ F13
Definition sdlinput.h:111
@ F11
Definition sdlinput.h:109
@ CAPS_LOCK
Definition sdlinput.h:97
@ NUM_LOCK
Definition sdlinput.h:117
@ F15
Definition sdlinput.h:113
@ F12
Definition sdlinput.h:110
@ END
Definition sdlinput.h:94
@ ALT_GR
Definition sdlinput.h:118
@ F4
Definition sdlinput.h:102
@ DELETE_KEY
Definition sdlinput.h:93
@ PAGE_DOWN
Definition sdlinput.h:95