File: handler_keyboard.h

package info (click to toggle)
tecnoballz 0.93.1-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 4,528 kB
  • sloc: cpp: 29,390; xml: 425; makefile: 301; ansic: 171; sh: 38
file content (232 lines) | stat: -rw-r--r-- 6,085 bytes parent folder | download | duplicates (5)
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
/**
 * @file handler_keyboard.h
 * @brief Handler of the keyboard and mouse
 * @date 2012-10-13 
 * @copyright 1991-2014 TLK Games
 * @author Bruno Ethvignot
 * @version $Revision: 24 $
 */
/*
 * copyright (c) 1991-2014 TLK Games all rights reserved
 * $Id: handler_keyboard.h 24 2014-09-28 15:30:04Z bruno.ethvignot@gmail.com $
 *
 * TecnoballZ 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 3 of the License, or
 * (at your option) any later version.
 *
 * TecnoballZ 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 this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */
#ifndef __HANDLER_KEYBOARD__
#define __HANDLER_KEYBOARD__

#include "../include/tecnoballz.h"

class handler_keyboard:public virtual tecnoballz
  {
  public:
    static const Sint32 NULL_YCOORD = -10240;

  private:
#ifdef TECNOBALLZ_GP2X
    /* GP2X button codes, as received through SDL joystick events */
    typedef enum
    {
      GP2X_BUTTON_UP,
      GP2X_BUTTON_UPLEFT,
      GP2X_BUTTON_LEFT,
      GP2X_BUTTON_DOWNLEFT,
      GP2X_BUTTON_DOWN,
      GP2X_BUTTON_DOWNRIGHT,
      GP2X_BUTTON_RIGHT,
      GP2X_BUTTON_UPRIGHT,
      GP2X_BUTTON_START,
      GP2X_BUTTON_SELECT,
      GP2X_BUTTON_R,
      GP2X_BUTTON_L,
      GP2X_BUTTON_A,
      GP2X_BUTTON_B,
      GP2X_BUTTON_Y,
      GP2X_BUTTON_X,
      GP2X_BUTTON_VOLUP,
      GP2X_BUTTON_VOLDOWN,
      GP2X_BUTTON_CLICK,
      GP2X_NUM_BUTTONS
    } GP2X_BUTTONS_CODE;
    /* The current state of all the GP2X buttons is stored in
     * this array - used to handle multi-key actions */
    static bool gp2x_buttons[GP2X_NUM_BUTTONS];
#endif
#ifdef TECNOBALLZ_PSP
    /* PSP button codes, as received through SDL joystick events */
    typedef enum
    {
      PSP_BUTTON_Y,
      PSP_BUTTON_B,
      PSP_BUTTON_A,
      PSP_BUTTON_X,
      PSP_BUTTON_L,
      PSP_BUTTON_R,
      PSP_BUTTON_DOWN,
      PSP_BUTTON_LEFT,
      PSP_BUTTON_UP,
      PSP_BUTTON_RIGHT,
      PSP_BUTTON_SELECT,
      PSP_BUTTON_START,
      PSP_NUM_BUTTONS
    } PSP_BUTTONS_CODE;
    static bool psp_buttons[PSP_NUM_BUTTONS];
#endif

    typedef enum
    {
      IJOY_LEFT = 1,
      IJOY_RIGHT,
      IJOY_TOP,
      IJOY_DOWN,
      IJOY_FIRE,
      IJOY_RELEASE,
      IJOY_GIGABLITZ,
      IJOY_OPTION
    }
    JOYCODE_ENUM;

  public:
    typedef enum
    {
      COMMAND_KEY_PAUSE,
      QUIT_TECNOBALLZ,
      QUIT_TO_MAIN_MENU,
      CAUSE_GAME_OVER,
      TOGGLE_AUDIO,
      TOGGLE_SOUND,
      TOGGLE_MUSIC,
      TOGGLE_FULLSCREEN,
      TOGGLE_POPUP_MENU,
      DISABLE_TIMER,
      VOLUME_DOWN,
      VOLUME_UP,
      NUMOF_COMMAND_KEYS
    }
    COMAND_KEYS_ENUM;

    typedef enum
    {
      K_LEFT,
      K_RIGHT,
      K_UP,
      K_DOWN,
      K_RELEASE_BALL,
      K_FIRE,
      K_GIGABLITZ,
      K_VOLUME_UP,
      K_VOLUME_DOWN,
      K_MAXOF
    } KEY_CODES_ENUM;

  private:
    static bool last_command_keys[NUMOF_COMMAND_KEYS];
    static bool command_keys[NUMOF_COMMAND_KEYS];
    /** Predefinded keys to control the paddle */
    static Uint32 key_codes[K_MAXOF];
    static handler_keyboard *keyboard_singleton;

  private:
    /** True if grabs mouse and keyboard input */
    bool is_grab_input;
    /** Number of available joysticks */
    Uint32 numof_joysticks;
    SDL_Joystick **sdl_joysticks;
    bool joy_fire;
    bool joy_release;
    bool joy_gigablitz;
    bool joy_option;
    bool joy_left;
    bool joy_right;
    bool joy_top;
    bool joy_down;

    Uint32 joy_code_down;
    Uint32 joy_code_down_prev;
    Uint32 joy_up;
    Sint32 input_joy_tempo;

    Sint32 mouse_x_offset;
    Sint32 mouse_y_offset;

    /* x and y coordinates of the mouse pointer */
    Sint32 mouse_x_coord;
    Sint32 mouse_y_coord;

    bool is_left_button_down;
    bool is_right_button_down;
    bool is_middle_button_down;
    bool is_left_button_released;
    bool is_right_button_released;

    /* keyboard input delay */
    Sint32 key_delay;
    Uint32 key_code_down;
    Uint32 previous_key_code_down;
    Uint32 code_keyup;
    /* cursor position into input string */
    Sint32 string_cursor_pos;
    /* input string size */
    Sint32 string_input_size;
    /* pointer to the current input string */
    char *current_input_string;

    bool is_key_waiting;
    Sint32 wait_key_pressed;
  private:
    handler_keyboard ();
#ifdef TECNOBALLZ_HANDHELD_CONSOLE
    void handle_console_buttons (SDL_Event * event);
#endif
  public:
    ~handler_keyboard ();
    static handler_keyboard *get_instance ();

    void set_grab_input (bool mode);
    void read_events ();
    void clear_command_keys ();
    bool command_is_pressed (Uint32 code, bool clear = false);
    bool is_left_button ();
    bool is_right_button ();
    bool is_gigablitz_or_tilt ();
    //bool is_right_left_buttons ();
    bool is_left_button_up (Sint32 * off_x, Sint32 * off_y);
    bool is_right_button_up (Sint32 * off_x, Sint32 * off_y);
    Sint32 get_mouse_x_offset ();
    Sint32 get_mouse_y_offset ();
    Sint32 get_mouse_x ();
    Sint32 get_mouse_y ();
    bool key_is_pressed (Sint32 code);
    bool key_is_released (Sint32 code);
    bool control_is_pressed (Uint32 code);
    void set_input_string (char *str, Uint32 size);
    Sint32 get_input_cursor_pos ();
    void stop_string_input ();
    Uint32 get_key_down_code ();
    bool wait_key ();

  private:
    void toggle_popup_menu ();
    void toggle_pause ();
    void init_joysticks ();
    void set_joy (Uint32 code);
    void clr_joy (Uint32 code);
    void input_string ();
    void input_string (Uint32 code);
    void set_key_code_down (Uint32 code);
    void set_keycode_up (Uint32 code);
  };
#endif