From: Ingo Ruhnke Date: Sun, 21 Mar 2004 22:13:04 +0000 (+0000) Subject: - more menu cleanup X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=70357b238b8f56bf1ff709df3e1743a7386e156d;p=supertux.git - more menu cleanup SVN-Revision: 306 --- diff --git a/src/Makefile.am b/src/Makefile.am index e2b2947b2..7e5fea56a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,3 @@ -AM_CXXFLAGS = -Wall -O2 -g - bin_PROGRAMS = supertux supertux_SOURCES = \ diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index c7dd55758..ac8c4114e 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -489,14 +489,14 @@ int le_init() } menu_init(&leveleditor_menu); - menu_additem(&leveleditor_menu,menu_item_create(MN_LABEL,"Level Editor Menu",0,0)); - menu_additem(&leveleditor_menu,menu_item_create(MN_HL,"",0,0)); - menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Return To Level Editor",0,0)); - menu_additem(&leveleditor_menu,menu_item_create(MN_DEACTIVE,"Level Subset Settings",0,&subset_settings_menu)); - menu_additem(&leveleditor_menu,menu_item_create(MN_GOTO,"Load Level Subset",0,&subset_load_menu)); - menu_additem(&leveleditor_menu,menu_item_create(MN_GOTO,"New Level Subset",0,&subset_new_menu)); - menu_additem(&leveleditor_menu,menu_item_create(MN_HL,"",0,0)); - menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Quit Level Editor",0,0)); + menu_additem(&leveleditor_menu, menu_item_create(MN_LABEL,"Level Editor Menu",0,0)); + menu_additem(&leveleditor_menu, menu_item_create(MN_HL,"",0,0)); + menu_additem(&leveleditor_menu, menu_item_create(MN_ACTION,"Return To Level Editor",0,0)); + menu_additem(&leveleditor_menu, menu_item_create(MN_DEACTIVE,"Level Subset Settings",0,&subset_settings_menu)); + menu_additem(&leveleditor_menu, menu_item_create(MN_GOTO,"Load Level Subset",0,&subset_load_menu)); + menu_additem(&leveleditor_menu, menu_item_create(MN_GOTO,"New Level Subset",0,&subset_new_menu)); + menu_additem(&leveleditor_menu, menu_item_create(MN_HL,"",0,0)); + menu_additem(&leveleditor_menu, menu_item_create(MN_ACTION,"Quit Level Editor",0,0)); menu_reset(); menu_set_current(&leveleditor_menu); diff --git a/src/menu.cpp b/src/menu.cpp index ce2b3b8d0..d7c939e04 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -56,7 +56,7 @@ void menu_set_current(menu_type* pmenu) } /* Return a pointer to a new menu item */ -menu_item_type* menu_item_create(int kind, char *text, int init_toggle, void* target_menu) +menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, void* target_menu) { menu_item_type *pnew_item = (menu_item_type*) malloc(sizeof(menu_item_type)); pnew_item->kind = kind; @@ -259,147 +259,159 @@ int menu_check(menu_type* pmenu) return -1; } -void menu_draw_item(menu_type* pmenu, const menu_item_type& pitem, - int offset, // Position of the current item in the menu +void menu_draw_item(menu_type* pmenu, + int index, // Position of the current item in the menu int menu_width, int menu_height) { - int a; - int b; - int e; - int f; + const menu_item_type& pitem = pmenu->item[index]; + int arrange = 0; if(pmenu->arrange_left == YES) - a = menu_width * 16; - else - a = 0; + arrange = ((menu_width - 48) + (16 * (strlen(pitem.text) + + strlen(pitem.input) + + strlen(string_list_active(pitem.list)))))/2; - if(pmenu->arrange_left == YES) - b = (a - ((strlen(pitem.text)+strlen(pitem.input)+ strlen(string_list_active(pitem.list))) * 16)) / 2; - else - b = 0; + int f = 0; + { + int effect_time = 0; + if(timer_check(&pmenu->effect)) + effect_time = timer_get_left(&pmenu->effect) / 4; - if(timer_check(&pmenu->effect)) - e = timer_get_left(&pmenu->effect) / 4; - else - e = 0; - - if(e != 0) - f = (offset % 2) ? e : -e; - else - f = 0; + f = (index % 2) ? effect_time : -effect_time; + } int x_pos = screen->w/2 - menu_width/2; - int y_pos = offset*24 - menu_height/2; + int y_pos = index * 24 - menu_height/2; - int center_x = screen->w/2; - int center_y = screen->h /2; - int start_x = center_x - b; + int start_x = screen->w/2 + arrange; + int center_y = screen->h /2; - if(pitem.kind == MN_DEACTIVE) - { - text_drawf(&black_text, pitem.text, - -b, y_pos + 10 + f, - A_HMIDDLE, A_VMIDDLE, 2, NO_UPDATE); - } - else if(pitem.kind == MN_HL) - { - /* Draw a horizontal line with a little 3d effect */ - fillrect(x_pos, y_pos + 6 + center_y, - menu_width, 4, - 210,50,50,225); - fillrect(x_pos, y_pos + 10 + center_y, - menu_width, 2, - 0,0,0,255); - } - else if(pitem.kind == MN_LABEL) - { - text_drawf(&white_big_text, pitem.text, - -b, y_pos + 10, - A_HMIDDLE, A_VMIDDLE, 2); - } - else if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD) - { - int input_pos = ((strlen(pitem.input)*16)/2); - int text_pos = ((strlen(pitem.text) + 1)*16)/2; - fillrect(-b +center_x - input_pos + text_pos - 1,y_pos + 10 + center_y - 10 + f, - (strlen(pitem.input)+1)*16 + 2, 20, - 255,255,255,255); - fillrect(-b +center_x - input_pos + text_pos, y_pos + 10 + center_y - 9 + f, - (strlen(pitem.input)+1)*16, 18, - 0,0,0,128); - text_drawf(&gold_text, pitem.input, - -b + text_pos, y_pos + 10 + f, - A_HMIDDLE, A_VMIDDLE, 2); - - if(offset == pmenu->active_item) - { - text_drawf(&blue_text,pitem.text, -b -(((strlen(pitem.input)+1) * 16)/2),y_pos + 10 + f,A_HMIDDLE, A_VMIDDLE,3); - } - else - { - text_drawf(&white_text,pitem.text, -b -(((strlen(pitem.input)+1) * 16)/2),y_pos +10 + f,A_HMIDDLE, A_VMIDDLE,2); - } - } - else if(pitem.kind == MN_STRINGSELECT) - { - int list_pos = ((strlen(string_list_active(pitem.list))*16)/2); - int list_pos_2 = (strlen(string_list_active(pitem.list))+1)*16; - int text_pos = ((strlen(pitem.text) + 1)*16)/2; - - /* Draw arrows */ - texture_draw(&arrow_left, start_x - list_pos + text_pos - 17, y_pos + 10 + center_y -8 + f); - texture_draw(&arrow_right, start_x - list_pos + text_pos - 1 + list_pos_2, y_pos + 10 + center_y -8 + f); - - /* Draw input background */ - fillrect(start_x - list_pos + text_pos - 1, y_pos + 10 + center_y - 10 + f, - list_pos_2 + 2, 20, - 255,255,255,255); - fillrect(start_x - list_pos + text_pos, y_pos + 10 + center_y - 9 + f, - list_pos_2, 18, - 0,0,0,128); - - text_drawf(&gold_text, string_list_active(pitem.list), - -b + text_pos, y_pos + 10 + f, - A_HMIDDLE, A_VMIDDLE,2); - - if(offset == pmenu->active_item) - { - text_drawf(&blue_text,pitem.text, - -b - list_pos_2/2, y_pos + 10 + f, - A_HMIDDLE, A_VMIDDLE,3); - } - else - { - text_drawf(&white_text,pitem.text, - -b - list_pos_2/2, y_pos +10 + f, - A_HMIDDLE, A_VMIDDLE,2); - } - } - else if(offset == pmenu->active_item) + int cen_y = center_y + y_pos; + int cen_y_10_f = 10 + f + cen_y; + + int shadow_size = 2; + text_type* text_font = &white_text; + if(index == pmenu->active_item) { - text_drawf(&blue_text, pitem.text, - -b,y_pos + 10 + f, - A_HMIDDLE, A_VMIDDLE, 3); + shadow_size = 3; + text_font = &blue_text; } - else + + switch (pitem.kind) { - text_drawf(&white_text, pitem.text, - -b, y_pos + 10 + f, - A_HMIDDLE, A_VMIDDLE, 2); + case MN_DEACTIVE: + { + text_drawf(&black_text, pitem.text, + arrange, y_pos + 10 + f, + A_HMIDDLE, A_VMIDDLE, 2); + break; + } + + case MN_HL: + { + /* Draw a horizontal line with a little 3d effect */ + fillrect(x_pos, cen_y + 6, + menu_width, 4, + 210,50,50,225); + fillrect(x_pos, 10 + cen_y + 6, + menu_width, 2, + 0,0,0,255); + break; + } + case MN_LABEL: + { + text_drawf(&white_big_text, pitem.text, + arrange, y_pos + 10, + A_HMIDDLE, A_VMIDDLE, 2); + break; + } + case MN_TEXTFIELD: + case MN_NUMFIELD: + { + int input_pos = ((strlen(pitem.input)*16)/2); + int text_pos = ((strlen(pitem.text) + 1)*16)/2; + + fillrect(start_x - input_pos + text_pos - 1, cen_y_10_f - 10, + (strlen(pitem.input)+1)*16 + 2, 20, + 255,255,255,255); + fillrect(start_x - input_pos + text_pos, cen_y_10_f - 9, + (strlen(pitem.input)+1)*16, 18, + 0,0,0,128); + + text_drawf(&gold_text, pitem.input, + arrange + text_pos, 10 + f + y_pos, + A_HMIDDLE, A_VMIDDLE, 2); + + text_drawf(text_font, pitem.text, + arrange - (((strlen(pitem.input)+1) * 16)/2), y_pos + 10 + f, + A_HMIDDLE, A_VMIDDLE, shadow_size); + break; + } + case MN_STRINGSELECT: + { + int list_pos_2 = (strlen(string_list_active(pitem.list))+1)*16; + int list_pos = (strlen(string_list_active(pitem.list))*16)/2; + int text_pos = ((strlen(pitem.text) + 1)*16)/2; + + /* Draw arrows */ + texture_draw(&arrow_left, start_x - list_pos + text_pos - 17, cen_y_10_f - 8); + texture_draw(&arrow_right, start_x - list_pos + text_pos - 1 + list_pos_2, cen_y_10_f - 8); + + /* Draw input background */ + fillrect(start_x - list_pos + text_pos - 1, cen_y_10_f - 10, + list_pos_2 + 2, 20, + 255,255,255,255); + fillrect(start_x - list_pos + text_pos, cen_y_10_f - 9, + list_pos_2, 18, + 0,0,0,128); + + text_drawf(&gold_text, string_list_active(pitem.list), + arrange + text_pos, 10 + f + y_pos, + A_HMIDDLE, A_VMIDDLE,2); + + text_drawf(text_font, pitem.text, + arrange - list_pos_2/2, 10 + f + y_pos, + A_HMIDDLE, A_VMIDDLE, shadow_size); + break; + } + case MN_BACK: + { + texture_draw(&back, start_x + (strlen(pitem.text) * 16)/2 + 16, cen_y_10_f - 8); + break; + } + + case MN_TOGGLE: + { + if(pitem.toggled == YES) + texture_draw(&checkbox_checked, start_x + (strlen(pitem.text) * 16)/2 + 16, cen_y_10_f - 8); + else + texture_draw(&checkbox, start_x + (strlen(pitem.text) * 16)/2 + 16, cen_y_10_f - 8); + break; + } + case MN_ACTION: + break; + + case MN_GOTO: + break; } - if(pitem.kind == MN_TOGGLE) + switch (pitem.kind) { - if(pitem.toggled == YES) - texture_draw(&checkbox_checked, -b + screen->w / 2 + (strlen(pitem.text) * 16)/2 + 16,y_pos + 10 + center_y -8 + f); - else - texture_draw(&checkbox, -b + screen->w / 2 + (strlen(pitem.text) * 16)/2 + 16,y_pos + 10 + center_y - 8 + f); + case MN_ACTION: + case MN_GOTO: + case MN_TOGGLE: + case MN_BACK: + text_drawf(text_font, pitem.text, arrange, 10 + f + y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size); + break; + case MN_DEACTIVE: + case MN_TEXTFIELD: + case MN_NUMFIELD: + case MN_STRINGSELECT: + case MN_LABEL: + case MN_HL: + break; } - else if(pitem.kind == MN_BACK) - { - texture_draw(&back, -b + screen->w / 2 + (strlen(pitem.text) * 16)/2 + 16,y_pos + 10 + center_y -8 + f); - } } /* Draw the current menu. */ @@ -431,7 +443,7 @@ void menu_draw(menu_type* pmenu) for(int i = 0; i < pmenu->num_items; ++i) { - menu_draw_item(pmenu, pmenu->item[i], i, menu_width, menu_height); + menu_draw_item(pmenu, i, menu_width, menu_height); } } diff --git a/src/menu.h b/src/menu.h index e5bbdba82..fc3aa1aca 100644 --- a/src/menu.h +++ b/src/menu.h @@ -18,9 +18,23 @@ #include "timer.h" #include "type.h" +/* Kinds of menu items */ +enum MenuItemKind { + MN_ACTION, + MN_GOTO, + MN_TOGGLE, + MN_BACK, + MN_DEACTIVE, + MN_TEXTFIELD, + MN_NUMFIELD, + MN_STRINGSELECT, + MN_LABEL, + MN_HL /* horizontal line */ +}; + typedef struct menu_item_type { - int kind; + MenuItemKind kind; int toggled; char *text; char *input; @@ -29,7 +43,7 @@ typedef struct menu_item_type } menu_item_type; -menu_item_type* menu_item_create(int kind, char *text, int init_toggle, void* target_menu); +menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, void* target_menu); void menu_item_change_text(menu_item_type* pmenu_item, const char *text); void menu_item_change_input(menu_item_type* pmenu_item, const char *text); @@ -51,20 +65,6 @@ int menu_check(menu_type* pmenu); void menu_draw(menu_type* pmenu); void menu_set_current(menu_type* pmenu); -/* Kinds of menu items */ -enum { - MN_ACTION, - MN_GOTO, - MN_TOGGLE, - MN_BACK, - MN_DEACTIVE, - MN_TEXTFIELD, - MN_NUMFIELD, - MN_STRINGSELECT, - MN_LABEL, - MN_HL /* horizontal line */ -}; - /* Action done on the menu */ enum { MN_UP, diff --git a/src/type.h b/src/type.h index 6b5877b66..45d92b800 100644 --- a/src/type.h +++ b/src/type.h @@ -37,13 +37,13 @@ typedef struct string_list_type } string_list_type; -void string_list_init(string_list_type* pstring_list); +void string_list_init(string_list_type* pstring_list); char* string_list_active(string_list_type* pstring_list); -void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig); -int string_list_find(string_list_type* pstring_list, const char* str); -void string_list_sort(string_list_type* pstring_list); -void string_list_add_item(string_list_type* pstring_list, const char* str); -void string_list_free(string_list_type* pstring_list); +void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig); +int string_list_find(string_list_type* pstring_list, const char* str); +void string_list_sort(string_list_type* pstring_list); +void string_list_add_item(string_list_type* pstring_list, const char* str); +void string_list_free(string_list_type* pstring_list); #endif /*SUPERTUX_TYPE_H*/