[Super-tux-commit] supertux/src menu.cpp,1.60,1.61 menu.h,1.52,1.53
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-04-29 11:32:21
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4086/src Modified Files: menu.cpp menu.h Log Message: Added a flickering cursor for input menu fields. The code is kinda of sucky, so feel free to clean it up. Unfortanely, there isn't any '_' charcter, so I have to use '-' :( I hope, we will soon add a new row of characters. Index: menu.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.cpp,v retrieving revision 1.60 retrieving revision 1.61 diff -u -d -r1.60 -r1.61 --- menu.cpp 29 Apr 2004 10:34:45 -0000 1.60 +++ menu.cpp 29 Apr 2004 11:32:13 -0000 1.61 @@ -39,6 +39,8 @@ #include "timer.h" #include "high_scores.h" +#define FLICK_CURSOR_TIME 500 + Surface* checkbox; Surface* checkbox_checked; Surface* back; @@ -165,6 +167,10 @@ pnew_item->id = id; pnew_item->int_p = int_p_; + pnew_item->input_flickering = false; + pnew_item->input_flickering_timer.init(true); + pnew_item->input_flickering_timer.start(FLICK_CURSOR_TIME); + return pnew_item; } @@ -190,6 +196,31 @@ } } +char* MenuItem::get_input_with_symbol(bool active_item) +{ +if(!active_item) + input_flickering = true; +else + { + if(input_flickering_timer.get_left() < 0) + { + if(input_flickering) + input_flickering = false; + else + input_flickering = true; + input_flickering_timer.start(FLICK_CURSOR_TIME); + } + } + +char str[1024]; +if(input_flickering) + sprintf(str,"%s-",input); +else + sprintf(str,"%s ",input); + +return (char*)str; +} + /* Set ControlField a key */ void Menu::get_controlfield_key_into_input(MenuItem *item) { @@ -461,7 +492,7 @@ int y_pos = pos_y + 24*index - menu_height/2 + 12 + effect_offset; int shadow_size = 2; int text_width = strlen(pitem.text) * font_width; - int input_width = strlen(pitem.input) * font_width; + int input_width = (strlen(pitem.input)+ 1) * font_width; int list_width = strlen(string_list_active(pitem.list)) * font_width; Text* text_font = white_text; @@ -521,7 +552,15 @@ if(pitem.kind == MN_CONTROLFIELD) get_controlfield_key_into_input(&pitem); - gold_text->draw_align(pitem.input, + if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD) + { + if(active_item == index) + gold_text->draw_align(pitem.get_input_with_symbol(true), x_pos + text_pos, y_pos, A_HMIDDLE, A_VMIDDLE, 2); + else + gold_text->draw_align(pitem.get_input_with_symbol(false), x_pos + text_pos, y_pos, A_HMIDDLE, A_VMIDDLE, 2); + } + else + gold_text->draw_align(pitem.input, x_pos + text_pos, y_pos, A_HMIDDLE, A_VMIDDLE, 2); Index: menu.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.h,v retrieving revision 1.52 retrieving revision 1.53 diff -u -d -r1.52 -r1.53 --- menu.h 29 Apr 2004 10:34:45 -0000 1.52 +++ menu.h 29 Apr 2004 11:32:13 -0000 1.53 @@ -102,6 +102,11 @@ void change_input(const char *text); static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p); + + char* get_input_with_symbol(bool active_item); // returns the text with an input symbol +private: + bool input_flickering; + Timer input_flickering_timer; }; class Menu |