2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
19 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "input/gameinputhandler.hpp"
27 #include "input/joystick.hpp"
29 GameInputHandler::GameInputHandler() {
30 clear_all_keypresses();
34 void GameInputHandler::clear_all_keypresses() {
43 alternate_status
= false;
48 void GameInputHandler::keyrelease(int gfxlib_keycode
) {
49 for (unsigned i
= 0; i
!= KeysNum
; ++i
) {
50 KeyAssignment
const &key
= get_key(Keys(i
));
51 if (gfxlib_keycode
== key
.gfxlib_keycode
) {
52 this->*key
.ptr
= false;
58 void GameInputHandler::keypress(int gfxlib_keycode
) {
59 for (unsigned i
= 0; i
!= KeysNum
; ++i
) {
60 KeyAssignment
const &key
= get_key(Keys(i
));
61 if (gfxlib_keycode
== key
.gfxlib_keycode
) {
62 this->*key
.ptr
= true;
68 char const *GameInputHandler::get_key_name(Keys keyindex
) {
69 return get_key_name_from_keycode(get_key(keyindex
).gfxlib_keycode
);
73 int &GameInputHandler::get_key_variable(Keys keyindex
) {
74 return get_key(keyindex
).gfxlib_keycode
;
78 bool GameInputHandler::up() {
79 return up_k
|| Joystick::up();
83 bool GameInputHandler::down() {
84 return down_k
|| Joystick::down();
88 bool GameInputHandler::left() {
89 return left_k
|| Joystick::left();
93 bool GameInputHandler::right() {
94 return right_k
|| Joystick::right();
98 bool GameInputHandler::fire1() {
99 return fire1_k
|| Joystick::fire1();
103 bool GameInputHandler::fire2() {
104 return fire2_k
|| Joystick::fire2();
107 bool GameInputHandler::restart() {
108 bool ret
= restart_k
;
113 void GameInputHandler::set_restart() {