From e3e9be75b0a19fe7ffcdf0d1cb46a95e9559cf96 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Wed, 29 Sep 2010 23:06:26 +0000 Subject: [PATCH] Unification of button system for the three current console ports. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1630 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/global.h | 102 +++++++++++------------ src/hotkeys.c | 34 +++++++- src/input.c | 216 +++++++++++++++++-------------------------------- src/keyboard.c | 145 ++++++++++++++++++--------------- 4 files changed, 238 insertions(+), 259 deletions(-) diff --git a/src/global.h b/src/global.h index eb5252f9..98a8d62e 100644 --- a/src/global.h +++ b/src/global.h @@ -966,64 +966,64 @@ GFX2_GLOBAL SDL_Joystick* Joystick; #define JOYSTICK_THRESHOLD (4096) /// Button definitions for the gp2x - #define GP2X_BUTTON_UP (0) - #define GP2X_BUTTON_DOWN (4) - #define GP2X_BUTTON_LEFT (2) - #define GP2X_BUTTON_RIGHT (6) - #define GP2X_BUTTON_UPLEFT (1) - #define GP2X_BUTTON_UPRIGHT (7) - #define GP2X_BUTTON_DOWNLEFT (3) - #define GP2X_BUTTON_DOWNRIGHT (5) - #define GP2X_BUTTON_CLICK (18) - #define GP2X_BUTTON_A (12) - #define GP2X_BUTTON_B (13) - #define GP2X_BUTTON_Y (14) - #define GP2X_BUTTON_X (15) - #define GP2X_BUTTON_L (10) - #define GP2X_BUTTON_R (11) - #define GP2X_BUTTON_START (8) - #define GP2X_BUTTON_SELECT (9) - #define GP2X_BUTTON_VOLUP (16) - #define GP2X_BUTTON_VOLDOWN (17) + #define JOY_BUTTON_UP (0) + #define JOY_BUTTON_DOWN (4) + #define JOY_BUTTON_LEFT (2) + #define JOY_BUTTON_RIGHT (6) + #define JOY_BUTTON_UPLEFT (1) + #define JOY_BUTTON_UPRIGHT (7) + #define JOY_BUTTON_DOWNLEFT (3) + #define JOY_BUTTON_DOWNRIGHT (5) + #define JOY_BUTTON_CLICK (18) + #define JOY_BUTTON_A (12) + #define JOY_BUTTON_B (13) + #define JOY_BUTTON_Y (14) + #define JOY_BUTTON_X (15) + #define JOY_BUTTON_L (10) + #define JOY_BUTTON_R (11) + #define JOY_BUTTON_START (8) + #define JOY_BUTTON_SELECT (9) + #define JOY_BUTTON_VOLUP (16) + #define JOY_BUTTON_VOLDOWN (17) - #define KEY_ESC (KEY_JOYBUTTON+GP2X_BUTTON_X) + #define KEY_ESC (KEY_JOYBUTTON+JOY_BUTTON_X) #elif defined(__WIZ__) /// Button definitions for the Wiz - #define WIZ_BUTTON_UP (0) - #define WIZ_BUTTON_DOWN (4) - #define WIZ_BUTTON_LEFT (2) - #define WIZ_BUTTON_RIGHT (6) - #define WIZ_BUTTON_UPLEFT (1) - #define WIZ_BUTTON_UPRIGHT (7) - #define WIZ_BUTTON_DOWNLEFT (3) - #define WIZ_BUTTON_DOWNRIGHT (5) - #define WIZ_BUTTON_L (10) - #define WIZ_BUTTON_R (11) - #define WIZ_BUTTON_A (12) - #define WIZ_BUTTON_B (13) - #define WIZ_BUTTON_X (14) - #define WIZ_BUTTON_Y (15) - #define WIZ_BUTTON_MENU (8) - #define WIZ_BUTTON_SELECT (9) - #define WIZ_BUTTON_VOLUP (16) - #define WIZ_BUTTON_VOLDOWN (17) + #define JOY_BUTTON_UP (0) + #define JOY_BUTTON_DOWN (4) + #define JOY_BUTTON_LEFT (2) + #define JOY_BUTTON_RIGHT (6) + #define JOY_BUTTON_UPLEFT (1) + #define JOY_BUTTON_UPRIGHT (7) + #define JOY_BUTTON_DOWNLEFT (3) + #define JOY_BUTTON_DOWNRIGHT (5) + #define JOY_BUTTON_L (10) + #define JOY_BUTTON_R (11) + #define JOY_BUTTON_A (12) + #define JOY_BUTTON_B (13) + #define JOY_BUTTON_X (14) + #define JOY_BUTTON_Y (15) + #define JOY_BUTTON_MENU (8) + #define JOY_BUTTON_SELECT (9) + #define JOY_BUTTON_VOLUP (16) + #define JOY_BUTTON_VOLDOWN (17) - #define KEY_ESC (KEY_JOYBUTTON+WIZ_BUTTON_X) + #define KEY_ESC (KEY_JOYBUTTON+JOY_BUTTON_X) #elif __CAANOO__ /// Button definitions for the Caanoo - #define CAANOO_BUTTON_A (0) - #define CAANOO_BUTTON_X (1) - #define CAANOO_BUTTON_B (2) - #define CAANOO_BUTTON_Y (3) - #define CAANOO_BUTTON_L (4) - #define CAANOO_BUTTON_R (5) - #define CAANOO_BUTTON_HOME (6) - #define CAANOO_BUTTON_HOLD (7) - #define CAANOO_BUTTON_I (8) - #define CAANOO_BUTTON_II (9) - #define CAANOO_BUTTON_JOY (10) + #define JOY_BUTTON_A (0) + #define JOY_BUTTON_X (1) + #define JOY_BUTTON_B (2) + #define JOY_BUTTON_Y (3) + #define JOY_BUTTON_L (4) + #define JOY_BUTTON_R (5) + #define JOY_BUTTON_HOME (6) + #define JOY_BUTTON_HOLD (7) + #define JOY_BUTTON_I (8) + #define JOY_BUTTON_II (9) + #define JOY_BUTTON_JOY (10) - #define KEY_ESC (KEY_JOYBUTTON+CAANOO_BUTTON_HOME) + #define KEY_ESC (KEY_JOYBUTTON+JOY_BUTTON_HOME) #else /// /// This is the key identifier for ESC. When hard-coding keyboard shortcuts diff --git a/src/hotkeys.c b/src/hotkeys.c index a82cad80..bdf65ba4 100644 --- a/src/hotkeys.c +++ b/src/hotkeys.c @@ -884,7 +884,16 @@ T_Key_config ConfigKey[NB_SHORTCUTS] = { "", true, SDLK_u, // U - 0}, + // Secondary shortcut is button I on the Caanoo, L on the Wiz, unset on others + #if defined (__CAANOO__) + (KEY_JOYBUTTON+JOY_BUTTON_I) + #elif defined (__WIZ__) + (KEY_JOYBUTTON+JOY_BUTTON_L) + #else + 0 + #endif + // -- + }, {103, "Redo", "Redo the last undone action.", @@ -892,7 +901,16 @@ T_Key_config ConfigKey[NB_SHORTCUTS] = { "", true, SDLK_u|MOD_SHIFT, // Shift + U - 0}, + // Secondary shortcut is button II on the Caanoo, R on the Wiz, unset on others + #if defined (__CAANOO__) + (KEY_JOYBUTTON+JOY_BUTTON_II) + #elif defined (__WIZ__) + (KEY_JOYBUTTON+JOY_BUTTON_R) + #else + 0 + #endif + // -- + }, {133, "Kill", "Kills the current page. It actually", @@ -924,7 +942,17 @@ T_Key_config ConfigKey[NB_SHORTCUTS] = { "confirmation is asked.", false, SDLK_q, // Q (A en AZERTY) - 0}, + // Secondary shortcut is button Home on the Caanoo, Menu on the Wiz, unset on others + #if defined (__CAANOO__) + (KEY_JOYBUTTON+JOY_BUTTON_HOME) + #elif defined (__WIZ__) + (KEY_JOYBUTTON+JOY_BUTTON_MENU) + #else + 0 + #endif + // -- + + }, {107, "Palette menu", "Opens a menu which allows you to", diff --git a/src/input.c b/src/input.c index 3451f501..abf71622 100644 --- a/src/input.c +++ b/src/input.c @@ -88,29 +88,29 @@ short Mouse_virtual_height; #if defined(__GP2X__) #define JOYSTICK_THRESHOLD (4096) - short Joybutton_shift=GP2X_BUTTON_L; - short Joybutton_control=GP2X_BUTTON_R; - short Joybutton_alt=GP2X_BUTTON_CLICK; - short Joybutton_left_click=GP2X_BUTTON_B; - short Joybutton_right_click=GP2X_BUTTON_Y; + short Joybutton_shift= JOY_BUTTON_L; + short Joybutton_control= JOY_BUTTON_R; + short Joybutton_alt= JOY_BUTTON_CLICK; + short Joybutton_left_click= JOY_BUTTON_B; + short Joybutton_right_click=JOY_BUTTON_Y; #elif defined(__WIZ__) #define JOYSTICK_THRESHOLD (4096) - short Joybutton_shift=WIZ_BUTTON_X; - short Joybutton_control=WIZ_BUTTON_SELECT; - short Joybutton_alt=WIZ_BUTTON_Y; - short Joybutton_left_click=WIZ_BUTTON_A; - short Joybutton_right_click=WIZ_BUTTON_B; + short Joybutton_shift= JOY_BUTTON_X; + short Joybutton_control= JOY_BUTTON_SELECT; + short Joybutton_alt= JOY_BUTTON_Y; + short Joybutton_left_click= JOY_BUTTON_A; + short Joybutton_right_click=JOY_BUTTON_B; #elif defined(__CAANOO__) #define JOYSTICK_THRESHOLD (4096) - short Joybutton_shift=CAANOO_BUTTON_L; - short Joybutton_control=CAANOO_BUTTON_R; - short Joybutton_alt=CAANOO_BUTTON_Y; - short Joybutton_left_click=CAANOO_BUTTON_A; - short Joybutton_right_click=CAANOO_BUTTON_B; + short Joybutton_shift= JOY_BUTTON_L; + short Joybutton_control= JOY_BUTTON_R; + short Joybutton_alt= JOY_BUTTON_Y; + short Joybutton_left_click= JOY_BUTTON_A; + short Joybutton_right_click=JOY_BUTTON_B; #else // Default : Any joystick on a computer platform /// @@ -537,106 +537,53 @@ int Handle_joystick_press(SDL_JoyButtonEvent event) Input_new_mouse_K=2; return Move_cursor_with_constraints(); } - #if defined(__GP2X__) switch(event.button) { - case GP2X_BUTTON_UP: + #ifdef JOY_BUTTON_UP + case JOY_BUTTON_UP: Directional_up=1; break; - case GP2X_BUTTON_UPRIGHT: + #endif + #ifdef JOY_BUTTON_UPRIGHT + case JOY_BUTTON_UPRIGHT: Directional_up_right=1; break; - case GP2X_BUTTON_RIGHT: + #endif + #ifdef JOY_BUTTON_RIGHT + case JOY_BUTTON_RIGHT: Directional_right=1; break; - case GP2X_BUTTON_DOWNRIGHT: + #endif + #ifdef JOY_BUTTON_DOWNRIGHT + case JOY_BUTTON_DOWNRIGHT: Directional_down_right=1; break; - case GP2X_BUTTON_DOWN: + #endif + #ifdef JOY_BUTTON_DOWN + case JOY_BUTTON_DOWN: Directional_down=1; break; - case GP2X_BUTTON_DOWNLEFT: + #endif + #ifdef JOY_BUTTON_DOWNLEFT + case JOY_BUTTON_DOWNLEFT: Directional_down_left=1; break; - case GP2X_BUTTON_LEFT: + #endif + #ifdef JOY_BUTTON_LEFT + case JOY_BUTTON_LEFT: Directional_left=1; break; - case GP2X_BUTTON_UPLEFT: + #endif + #ifdef JOY_BUTTON_UPLEFT + case JOY_BUTTON_UPLEFT: Directional_up_left=1; break; - + #endif + default: break; - } - #elif __WIZ__ - switch(event.button) - { - case WIZ_BUTTON_UP: - Directional_up=1; - break; - case WIZ_BUTTON_UPRIGHT: - Directional_up_right=1; - break; - case WIZ_BUTTON_RIGHT: - Directional_right=1; - break; - case WIZ_BUTTON_DOWNRIGHT: - Directional_down_right=1; - break; - case WIZ_BUTTON_DOWN: - Directional_down=1; - break; - case WIZ_BUTTON_DOWNLEFT: - Directional_down_left=1; - case WIZ_BUTTON_LEFT: - Directional_left=1; - break; - case WIZ_BUTTON_UPLEFT: - Directional_up_left=1; - break; - case WIZ_BUTTON_MENU: - { - SDL_Event Event; - Event.type = SDL_QUIT; - SDL_PushEvent(&Event); - } - break; - case WIZ_BUTTON_L: - if(!Windows_open) - Button_Undo(); - break; - case WIZ_BUTTON_R: - if(!Windows_open) - Button_Redo(); - break; - default: - break; - } - #elif __CAANOO__ - switch(event.button) - { - case CAANOO_BUTTON_HOME: - { - SDL_Event Event; - - Event.type = SDL_QUIT; - SDL_PushEvent(&Event); - } - break; - - case CAANOO_BUTTON_I: - if(!Windows_open) - Button_Undo(); - break; - case CAANOO_BUTTON_II: - if(!Windows_open) - Button_Redo(); - break; - - default: - break; } - #endif + Key = (KEY_JOYBUTTON+event.button)|Key_modifiers(SDL_GetModState()); // TODO: systeme de répétition @@ -671,63 +618,52 @@ int Handle_joystick_release(SDL_JoyButtonEvent event) return Move_cursor_with_constraints(); } - #if defined(__GP2X__) switch(event.button) { - case GP2X_BUTTON_UP: - Directional_up=0; + #ifdef JOY_BUTTON_UP + case JOY_BUTTON_UP: + Directional_up=1; break; - case GP2X_BUTTON_UPRIGHT: - Directional_up_right=0; + #endif + #ifdef JOY_BUTTON_UPRIGHT + case JOY_BUTTON_UPRIGHT: + Directional_up_right=1; break; - case GP2X_BUTTON_RIGHT: - Directional_right=0; + #endif + #ifdef JOY_BUTTON_RIGHT + case JOY_BUTTON_RIGHT: + Directional_right=1; break; - case GP2X_BUTTON_DOWNRIGHT: - Directional_down_right=0; + #endif + #ifdef JOY_BUTTON_DOWNRIGHT + case JOY_BUTTON_DOWNRIGHT: + Directional_down_right=1; break; - case GP2X_BUTTON_DOWN: - Directional_down=0; + #endif + #ifdef JOY_BUTTON_DOWN + case JOY_BUTTON_DOWN: + Directional_down=1; break; - case GP2X_BUTTON_DOWNLEFT: - Directional_down_left=0; + #endif + #ifdef JOY_BUTTON_DOWNLEFT + case JOY_BUTTON_DOWNLEFT: + Directional_down_left=1; break; - case GP2X_BUTTON_LEFT: - Directional_left=0; + #endif + #ifdef JOY_BUTTON_LEFT + case JOY_BUTTON_LEFT: + Directional_left=1; break; - case GP2X_BUTTON_UPLEFT: - Directional_up_left=0; + #endif + #ifdef JOY_BUTTON_UPLEFT + case JOY_BUTTON_UPLEFT: + Directional_up_left=1; + break; + #endif + + default: break; } - #elif defined(__WIZ__) - switch(event.button) - { - case WIZ_BUTTON_UP: - Directional_up=0; - break; - case WIZ_BUTTON_UPRIGHT: - Directional_up_right=0; - break; - case WIZ_BUTTON_RIGHT: - Directional_right=0; - break; - case WIZ_BUTTON_DOWNRIGHT: - Directional_down_right=0; - break; - case WIZ_BUTTON_DOWN: - Directional_down=0; - break; - case WIZ_BUTTON_DOWNLEFT: - Directional_down_left=0; - break; - case WIZ_BUTTON_LEFT: - Directional_left=0; - break; - case WIZ_BUTTON_UPLEFT: - Directional_up_left=0; - break; - } - #endif return Move_cursor_with_constraints(); } diff --git a/src/keyboard.c b/src/keyboard.c index 80266b0c..d3d22f5a 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -466,78 +466,93 @@ const char * Key_name(word key) key=key & ~(MOD_CTRL|MOD_ALT|MOD_SHIFT); -#if defined(__GP2X__) - if (key>=KEY_JOYBUTTON && key<=KEY_JOYBUTTON+18) + // 99 is only a sanity check + if (key>=KEY_JOYBUTTON && key<=KEY_JOYBUTTON+99) { char *button_name; switch(key-KEY_JOYBUTTON) - { - case GP2X_BUTTON_UP: button_name="[UP]"; break; - case GP2X_BUTTON_DOWN: button_name="[DOWN]"; break; - case GP2X_BUTTON_LEFT: button_name="[LEFT]"; break; - case GP2X_BUTTON_RIGHT: button_name="[RIGHT]"; break; - case GP2X_BUTTON_UPLEFT: button_name="[UP-LEFT]"; break; - case GP2X_BUTTON_UPRIGHT: button_name="[UP-RIGHT]"; break; - case GP2X_BUTTON_DOWNLEFT: button_name="[DOWN-LEFT]"; break; - case GP2X_BUTTON_DOWNRIGHT: button_name="[DOWN-RIGHT]"; break; - case GP2X_BUTTON_CLICK: button_name="[CLICK]"; break; - case GP2X_BUTTON_A: button_name="[A]"; break; - case GP2X_BUTTON_B: button_name="[B]"; break; - case GP2X_BUTTON_X: button_name="[X]"; break; - case GP2X_BUTTON_Y: button_name="[Y]"; break; - case GP2X_BUTTON_L: button_name="[L]"; break; - case GP2X_BUTTON_R: button_name="[R]"; break; - case GP2X_BUTTON_START: button_name="[START]"; break; - case GP2X_BUTTON_SELECT: button_name="[SELECT]"; break; - case GP2X_BUTTON_VOLUP: button_name="[VOL UP]"; break; - case GP2X_BUTTON_VOLDOWN: button_name="[VOL DOWN]"; break; - default: sprintf(buffer+strlen(buffer), "[B%d]", key);return buffer; - } - strcat(buffer,button_name); -#elif defined(__WIZ__) - if (Key>=KEY_JOYBUTTON && Key<=KEY_JOYBUTTON+17) - { - char *button_name; - switch(Key-KEY_JOYBUTTON) { - case WIZ_BUTTON_A: button_name="[A]"; break; - case WIZ_BUTTON_X: button_name="[X]"; break; - case WIZ_BUTTON_B: button_name="[B]"; break; - case WIZ_BUTTON_Y: button_name="[Y]"; break; - case WIZ_BUTTON_L: button_name="[L]"; break; - case WIZ_BUTTON_R: button_name="[R]"; break; - case WIZ_BUTTON_MENU: button_name="[MENU]"; break; - case WIZ_BUTTON_SELECT: button_name="[SELECT]"; break; - case WIZ_BUTTON_VOLUP: button_name="[VOL UP]"; break; - case WIZ_BUTTON_VOLDOWN: button_name="[VOL DOWN]"; break; - default: sprintf(buffer+strlen(buffer), "[B%d]", Key);return buffer; + #ifdef JOY_BUTTON_UP + case JOY_BUTTON_UP: button_name="[UP]"; break; + #endif + #ifdef JOY_BUTTON_DOWN + case JOY_BUTTON_DOWN: button_name="[DOWN]"; break; + #endif + #ifdef JOY_BUTTON_LEFT + case JOY_BUTTON_LEFT: button_name="[LEFT]"; break; + #endif + #ifdef JOY_BUTTON_RIGHT + case JOY_BUTTON_RIGHT: button_name="[RIGHT]"; break; + #endif + #ifdef JOY_BUTTON_UPLEFT + case JOY_BUTTON_UPLEFT: button_name="[UP-LEFT]"; break; + #endif + #ifdef JOY_BUTTON_UPRIGHT + case JOY_BUTTON_UPRIGHT: button_name="[UP-RIGHT]"; break; + #endif + #ifdef JOY_BUTTON_DOWNLEFT + case JOY_BUTTON_DOWNLEFT: button_name="[DOWN-LEFT]"; break; + #endif + #ifdef JOY_BUTTON_DOWNRIGHT + case JOY_BUTTON_DOWNRIGHT: button_name="[DOWN-RIGHT]"; break; + #endif + #ifdef JOY_BUTTON_CLICK + case JOY_BUTTON_CLICK: button_name="[CLICK]"; break; + #endif + #ifdef JOY_BUTTON_A + case JOY_BUTTON_A: button_name="[A]"; break; + #endif + #ifdef JOY_BUTTON_B + case JOY_BUTTON_B: button_name="[B]"; break; + #endif + #ifdef JOY_BUTTON_X + case JOY_BUTTON_X: button_name="[X]"; break; + #endif + #ifdef JOY_BUTTON_Y + case JOY_BUTTON_Y: button_name="[Y]"; break; + #endif + #ifdef JOY_BUTTON_L + case JOY_BUTTON_L: button_name="[L]"; break; + #endif + #ifdef JOY_BUTTON_R + case JOY_BUTTON_R: button_name="[R]"; break; + #endif + #ifdef JOY_BUTTON_START + case JOY_BUTTON_START: button_name="[START]"; break; + #endif + #ifdef JOY_BUTTON_SELECT + case JOY_BUTTON_SELECT: button_name="[SELECT]"; break; + #endif + #ifdef JOY_BUTTON_VOLUP + case JOY_BUTTON_VOLUP: button_name="[VOL UP]"; break; + #endif + #ifdef JOY_BUTTON_VOLDOWN + case JOY_BUTTON_VOLDOWN: button_name="[VOL DOWN]"; break; + #endif + #ifdef JOY_BUTTON_MENU + case JOY_BUTTON_MENU: button_name="[MENU]"; break; + #endif + #ifdef JOY_BUTTON_HOME + case JOY_BUTTON_HOME: button_name="[HOME]"; break; + #endif + #ifdef JOY_BUTTON_HOLD + case JOY_BUTTON_HOLD: button_name="[HOLD]"; break; + #endif + #ifdef JOY_BUTTON_I + case JOY_BUTTON_I: button_name="[BUTTON I]"; break; + #endif + #ifdef JOY_BUTTON_II + case JOY_BUTTON_II: button_name="[BUTTON II]"; break; + #endif + #ifdef JOY_BUTTON_JOY + case JOY_BUTTON_JOY: button_name="[THUMB JOY]"; break; + #endif + + default: sprintf(buffer+strlen(buffer), "[B%d]", key-KEY_JOYBUTTON);return buffer; } strcat(buffer,button_name); -#elif defined(__CAANOO__) - if (Key>=KEY_JOYBUTTON && Key<=KEY_JOYBUTTON+10) - { - char *button_name; - switch(Key-KEY_JOYBUTTON) - { - case CAANOO_BUTTON_A: button_name="[A]"; break; - case CAANOO_BUTTON_X: button_name="[X]"; break; - case CAANOO_BUTTON_B: button_name="[B]"; break; - case CAANOO_BUTTON_Y: button_name="[Y]"; break; - case CAANOO_BUTTON_L: button_name="[L]"; break; - case CAANOO_BUTTON_R: button_name="[R]"; break; - case CAANOO_BUTTON_HOME: button_name="[HOME]"; break; - case CAANOO_BUTTON_HOLD: button_name="[HOLD]"; break; - case CAANOO_BUTTON_I: button_name="[BUTTON I]"; break; - case CAANOO_BUTTON_II: button_name="[BUTTON II]"; break; - case CAANOO_BUTTON_JOY: button_name="[THUMB JOY]"; break; - default: sprintf(buffer+strlen(buffer), "[B%d]", Key);return buffer; - } - strcat(buffer,button_name); -#else - { - sprintf(buffer+strlen(buffer), "[B%d]", key-KEY_JOYBUTTON); -#endif + return buffer; }