From: Ricardo Cruz Date: Thu, 22 Apr 2004 18:39:52 +0000 (+0000) Subject: Controls menu wasn't showing the keys until they were changed (fixed). X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=da1e6aa00fb3a7c4c003288d5b081c051e8ba978;p=supertux.git Controls menu wasn't showing the keys until they were changed (fixed). Also made a few internal changes regarding this. SVN-Revision: 647 --- diff --git a/src/menu.cpp b/src/menu.cpp index 3fe722624..6978fadc5 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -150,54 +150,50 @@ MenuItem::change_input(const char *text_) } /* Set ControlField a key */ -void MenuItem::set_controlfield_key(SDLKey key, char ch[]) +void Menu::get_controlfield_key_into_input(MenuItem *item) { -*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; - } +switch(*item->int_p) + { + case SDLK_UP: + strcpy(item->input, "Up cursor"); + break; + case SDLK_DOWN: + strcpy(item->input, "Down cursor"); + break; + case SDLK_LEFT: + strcpy(item->input, "Left cursor"); + break; + case SDLK_RIGHT: + strcpy(item->input, "Right cursor"); + break; + case SDLK_RETURN: + strcpy(item->input, "Return"); + break; + case SDLK_SPACE: + strcpy(item->input, "Space"); + break; + case SDLK_RSHIFT: + strcpy(item->input, "Right Shift"); + break; + case SDLK_LSHIFT: + strcpy(item->input, "Left Shift"); + break; + case SDLK_RCTRL: + strcpy(item->input, "Right Control"); + break; + case SDLK_LCTRL: + strcpy(item->input, "Left Control"); + break; + case SDLK_RALT: + strcpy(item->input, "Right Alt"); + break; + case SDLK_LALT: + strcpy(item->input, "Left Alt"); + break; + default: + strcpy(item->input, (char*)item->int_p); + break; + } } /* Free a menu and all its items */ @@ -430,7 +426,7 @@ Menu::draw_item(int index, // Position of the current item in the menu int menu_width, int menu_height) { - const MenuItem& pitem = item[index]; + MenuItem& pitem = item[index]; int font_width = 16; int effect_offset = 0; @@ -504,6 +500,9 @@ Menu::draw_item(int index, // Position of the current item in the menu input_width + font_width, 18, 0,0,0,128); + if(pitem.kind == MN_CONTROLFIELD) + get_controlfield_key_into_input(&pitem); + gold_text->draw_align(pitem.input, x_pos + text_pos, y_pos, A_HMIDDLE, A_VMIDDLE, 2); @@ -642,7 +641,7 @@ Menu::event(SDL_Event& event) if(item[active_item].kind == MN_CONTROLFIELD) { - item[active_item].set_controlfield_key(key, ch); + *item[active_item].int_p = key; menuaction = MENU_ACTION_DOWN; return; } diff --git a/src/menu.h b/src/menu.h index 33c8b2468..47643507b 100644 --- a/src/menu.h +++ b/src/menu.h @@ -59,8 +59,6 @@ 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 @@ -132,6 +130,8 @@ public: MenuItem& get_item(int index) { return item[index]; } + void Menu::get_controlfield_key_into_input(MenuItem *item); + void draw (); void draw_item(int index, int menu_width, int menu_height); void set_pos(int x, int y, float rw = 0, float rh = 0);