From: Ingo Ruhnke Date: Mon, 22 Mar 2004 13:32:37 +0000 (+0000) Subject: - added ability to position menu freely on the screen X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ffcc9f26b5828f4157358d73d9f97e23fb0be427;p=supertux.git - added ability to position menu freely on the screen SVN-Revision: 316 --- diff --git a/src/menu.cpp b/src/menu.cpp index c5c83592f..5432925cf 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -117,6 +117,8 @@ void menu_free(menu_type* pmenu) /* Initialize a menu */ void menu_init(menu_type* pmenu) { + pmenu->x = screen->w/2; + pmenu->y = screen->h/2; pmenu->arrange_left = 0; pmenu->num_items = 0; pmenu->active_item = 0; @@ -296,8 +298,8 @@ void menu_draw_item(menu_type* pmenu, effect_offset = (index % 2) ? effect_time : -effect_time; } - int x_pos = screen->w/2; - int y_pos = screen->h/2 + 24*index - menu_height/2 + 12 + effect_offset; + int x_pos = pmenu->x; + int y_pos = pmenu->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; @@ -325,7 +327,7 @@ void menu_draw_item(menu_type* pmenu, case MN_HL: { - int x = screen->w/2 - menu_width/2; + int x = pmenu->x - menu_width/2; int y = y_pos - 12 - effect_offset; /* Draw a horizontal line with a little 3d effect */ fillrect(x, y + 6, @@ -446,9 +448,10 @@ void menu_draw(menu_type* pmenu) menu_width = menu_width * 16 + 48; menu_height = (pmenu->num_items) * 24; - int center_x = screen->w/2; /* Draw a transparent background */ - fillrect(center_x - menu_width/2,screen->h/2-(((pmenu->num_items)*24)/2),menu_width,menu_height,150,150,150,100); + fillrect(pmenu->x - menu_width/2, + pmenu->y - 24*pmenu->num_items/2, + menu_width,menu_height,150,150,150,100); for(int i = 0; i < pmenu->num_items; ++i) { diff --git a/src/menu.h b/src/menu.h index 74455c93b..f459b5c0d 100644 --- a/src/menu.h +++ b/src/menu.h @@ -48,13 +48,17 @@ 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); typedef struct menu_type - { - int num_items; - int active_item; - int arrange_left; - menu_item_type *item; - timer_type effect; - } +{ + // center of the menu on the screen + int x; + int y; + + int num_items; + int active_item; + int arrange_left; + menu_item_type *item; + timer_type effect; +} menu_type; void menu_init (menu_type* pmenu);