README.md edited online with Bitbucket
[gdash.git] / src / input / gameinputhandler.cpp
blob69a3f20407fba3eb25a7fb22a4f85f794d901f64
1 /*
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.
24 #include "config.h"
26 #include "input/gameinputhandler.hpp"
27 #include "input/joystick.hpp"
29 GameInputHandler::GameInputHandler() {
30 clear_all_keypresses();
34 void GameInputHandler::clear_all_keypresses() {
35 up_k = false;
36 down_k = false;
37 left_k = false;
38 right_k = false;
39 fire1_k = false;
40 fire2_k = false;
41 suicide = false;
42 fast_forward = false;
43 alternate_status = false;
44 restart_k = 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;
109 restart_k = false;
110 return ret;
113 void GameInputHandler::set_restart() {
114 restart_k = true;