From ae930d431c1998fa620f1e82b3753efc8d4f6b6a Mon Sep 17 00:00:00 2001 From: Ryan Flegel Date: Fri, 21 May 2004 23:37:56 +0000 Subject: [PATCH] - made some changes for joystick in menu. better? SVN-Revision: 1296 --- src/defines.h | 3 +++ src/menu.cpp | 14 ++++++++++++-- src/menu.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/defines.h b/src/defines.h index a33d976d2..1c2d9b161 100644 --- a/src/defines.h +++ b/src/defines.h @@ -39,6 +39,9 @@ enum Direction { LEFT = 0, RIGHT = 1 }; #define UP 0 #define DOWN 1 +/* Joystick menu delay */ +#define JOYSTICK_MENU_DELAY 500 + /* Dying types: */ /* ---- NO 0 */ diff --git a/src/menu.cpp b/src/menu.cpp index 1de8a7ff4..f9fc8ae4c 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -326,6 +326,8 @@ Menu::Menu() arrange_left = 0; active_item = 0; effect.init(false); + + joystick_timer.init(true); } void Menu::set_pos(int x, int y, float rw, float rh) @@ -818,10 +820,18 @@ Menu::event(SDL_Event& event) case SDL_JOYAXISMOTION: if(event.jaxis.axis == joystick_keymap.y_axis) { - if (event.jaxis.value > 1024) + if (event.jaxis.value > joystick_keymap.dead_zone && !joystick_timer.started()) + { menuaction = MENU_ACTION_DOWN; - else if (event.jaxis.value < -1024) + joystick_timer.start(JOYSTICK_MENU_DELAY); + } + else if (event.jaxis.value < -joystick_keymap.dead_zone && !joystick_timer.started()) + { menuaction = MENU_ACTION_UP; + joystick_timer.start(JOYSTICK_MENU_DELAY); + } + else + joystick_timer.stop(); } break; case SDL_JOYBUTTONDOWN: diff --git a/src/menu.h b/src/menu.h index fa1ddf5b6..4ac921dd8 100644 --- a/src/menu.h +++ b/src/menu.h @@ -179,6 +179,7 @@ private: /* input implementation variables */ int delete_character; char mn_input_char; + Timer joystick_timer; public: Timer effect; -- 2.11.0