From bce77ebd5f818899777a216a309e5b1c5ac1c373 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Thu, 22 Apr 2004 14:11:57 +0000 Subject: [PATCH] Improved the control key code a bit, in order to make it possible to write the keys right in the first dialog display (still to be done). SVN-Revision: 632 --- src/menu.cpp | 99 +++++++++++++++++++++++++++++++----------------------------- src/menu.h | 3 ++ 2 files changed, 55 insertions(+), 47 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index e4db5a363..010f35816 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -149,6 +149,57 @@ MenuItem::change_input(const char *text_) } } +/* Set ControlField a key */ +void MenuItem::set_controlfield_key(SDLKey key, char ch[]) +{ +*int_p = key; +if(ch[0] != '\0') + strcpy(input, ch); +else + switch(key) + { + case SDLK_UP: + strcpy(input, "Up cursor"); + break; + case SDLK_DOWN: + strcpy(input, "Down cursor"); + break; + case SDLK_LEFT: + strcpy(input, "Left cursor"); + break; + case SDLK_RIGHT: + strcpy(input, "Right cursor"); + break; + case SDLK_RETURN: + strcpy(input, "Return"); + break; + case SDLK_SPACE: + strcpy(input, "Space"); + break; + case SDLK_RSHIFT: + strcpy(input, "Right Shift"); + break; + case SDLK_LSHIFT: + strcpy(input, "Left Shift"); + break; + case SDLK_RCTRL: + strcpy(input, "Right Control"); + break; + case SDLK_LCTRL: + strcpy(input, "Left Control"); + break; + case SDLK_RALT: + strcpy(input, "Right Alt"); + break; + case SDLK_LALT: + strcpy(input, "Left Alt"); + break; + default: + strcpy(input, "?"); + break; + } +} + /* Free a menu and all its items */ Menu::~Menu() { @@ -619,53 +670,7 @@ Menu::event(SDL_Event& event) if(item[active_item].kind == MN_CONTROLFIELD) { - *item[active_item].int_p = event.key.keysym.sym; - if(ch[0] != '\0') - strcpy(item[active_item].input, ch); - else - switch(key) - { - case SDLK_UP: - strcpy(item[active_item].input, "Up cursor"); - break; - case SDLK_DOWN: - strcpy(item[active_item].input, "Down cursor"); - break; - case SDLK_LEFT: - strcpy(item[active_item].input, "Left cursor"); - break; - case SDLK_RIGHT: - strcpy(item[active_item].input, "Right cursor"); - break; - case SDLK_RETURN: - strcpy(item[active_item].input, "Return"); - break; - case SDLK_SPACE: - strcpy(item[active_item].input, "Space"); - break; - case SDLK_RSHIFT: - strcpy(item[active_item].input, "Right Shift"); - break; - case SDLK_LSHIFT: - strcpy(item[active_item].input, "Left Shift"); - break; - case SDLK_RCTRL: - strcpy(item[active_item].input, "Right Control"); - break; - case SDLK_LCTRL: - strcpy(item[active_item].input, "Left Control"); - break; - case SDLK_RALT: - strcpy(item[active_item].input, "Right Alt"); - break; - case SDLK_LALT: - strcpy(item[active_item].input, "Left Alt"); - break; - default: - strcpy(item[active_item].input, "?"); - break; - } - + item[active_item].set_controlfield_key(key, ch); menuaction = MENU_ACTION_DOWN; return; } diff --git a/src/menu.h b/src/menu.h index 8342a465a..33c8b2468 100644 --- a/src/menu.h +++ b/src/menu.h @@ -59,6 +59,8 @@ public: void change_input(const char *text); static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int* int_p); + + void set_controlfield_key(SDLKey key, char ch[]); }; class Menu @@ -69,6 +71,7 @@ private: static void push_current(Menu* pmenu); static void pop_current(); + public: /** Set the current menu, if pmenu is NULL, hide the current menu */ static void set_current(Menu* pmenu); -- 2.11.0