[Super-tux-commit] supertux/src menu.cpp,1.46,1.47 menu.h,1.41,1.42
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-04-22 14:12:06
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29740/src Modified Files: menu.cpp menu.h Log Message: 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). Index: menu.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.cpp,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- menu.cpp 22 Apr 2004 11:20:58 -0000 1.46 +++ menu.cpp 22 Apr 2004 14:11:57 -0000 1.47 @@ -149,6 +149,57 @@ } } +/* 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 @@ 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; } Index: menu.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.h,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- menu.h 21 Apr 2004 15:15:27 -0000 1.41 +++ menu.h 22 Apr 2004 14:11:57 -0000 1.42 @@ -59,6 +59,8 @@ 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 @@ 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); |