From 67faf6decd67dcd3e7c9aebe42b5ef7513c8f528 Mon Sep 17 00:00:00 2001 From: "p.kosyh" Date: Mon, 7 Jun 2010 12:15:40 +0000 Subject: [PATCH] aligned themes/games dialog width --- debian/changelog | 2 ++ src/sdl-instead/game.c | 42 ++++++++++++++++++++++++++++++++++++------ src/sdl-instead/game.h | 2 ++ src/sdl-instead/menu.c | 36 +++++++++++++++++++++++++++++++++++- src/sdl-instead/menu.h | 2 ++ 5 files changed, 77 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index 20b0f54..7d29841 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,8 @@ instead (1.2.0) unstable; urgency=low * hook and inherit; * entered human friendly action; * stead.cmd, stead.args added; + * require added (module goto); + * aligned width for themes/games dialog; -- Peter Kosyh Tue, 01 Jun 2010 17:40:00 +0300 diff --git a/src/sdl-instead/game.c b/src/sdl-instead/game.c index 2b00632..1d8ad32 100644 --- a/src/sdl-instead/game.c +++ b/src/sdl-instead/game.c @@ -951,9 +951,20 @@ img_t game_pict_scale(img_t img, int ww, int hh) return img2; } +int game_menu_box_wh(const char *txt, int *w, int *h) +{ + layout_t lay; + int b = game_theme.border_w; + int pad = game_theme.pad; + lay = txt_layout(game_theme.menu_font, ALIGN_CENTER, game_theme.win_w - 2 * (b + pad), 0); + txt_layout_set(lay, (char*)txt); + txt_layout_real_size(lay, w, h); + txt_layout_free(lay); + return 0; +} -void game_menu_box(int show, const char *txt) +void game_menu_box_width(int show, const char *txt, int width) { // img_t menu; int w, h, mw, mh; @@ -987,21 +998,27 @@ void game_menu_box(int show, const char *txt) gfx_flip(); return; } - lay = txt_layout(game_theme.menu_font, ALIGN_CENTER, game_theme.win_w - 2 * (b + pad), 0); - txt_layout_set(lay, (char*)txt); - txt_layout_real_size(lay, &w, &h); - txt_layout_free(lay); + + + game_menu_box_wh(txt, &w, &h); + + if (width) + w = width; lay = txt_layout(game_theme.menu_font, ALIGN_CENTER, w, 0); txt_layout_set(lay, (char*)txt); - txt_layout_real_size(lay, &w, &h); + txt_layout_real_size(lay, &w, &h); + if (width) + w = width; txt_layout_color(lay, game_theme.menu_fg); txt_layout_link_color(lay, game_theme.menu_link); txt_layout_active_color(lay, game_theme.menu_alink); txt_layout_set(lay, (char*)txt); txt_layout_real_size(lay, &w, &h); + if (width) + w = width; if (menu) { gfx_free_image(menu); menu = NULL; @@ -1025,6 +1042,19 @@ void game_menu_box(int show, const char *txt) gfx_flip(); } +void game_menu_box(int show, const char *txt) +{ + int w = 0; + if (cur_menu == menu_games) { /* hack a bit :( */ + w = games_menu_maxw(); + game_menu_gen(); + } else if (cur_menu == menu_themes) { + w = themes_menu_maxw(); + game_menu_gen(); + } + return game_menu_box_width(show, txt, w); +} + int check_new_place(char *title) { int rc = 0; diff --git a/src/sdl-instead/game.h b/src/sdl-instead/game.h index c1498d5..38cdeec 100644 --- a/src/sdl-instead/game.h +++ b/src/sdl-instead/game.h @@ -52,6 +52,8 @@ extern int game_cmd(char *cmd); extern void game_menu(int nr); /* select and show menu */ extern void game_menu_box(int show, const char *txt); /* show menu */ +extern int game_menu_box_wh(const char *txt, int *w, int *h); +extern void game_menu_box_width(int show, const char *txt, int width); extern int game_load(int nr); extern int game_save(int nr); diff --git a/src/sdl-instead/menu.c b/src/sdl-instead/menu.c index f17ca16..0b74210 100644 --- a/src/sdl-instead/menu.c +++ b/src/sdl-instead/menu.c @@ -44,7 +44,7 @@ char *FROM_THEME = NULL; char *DISABLED_SAVE_MENU = NULL; -static char menu_buff[4096]; +static char menu_buff[8192]; static char *slot_name(const char *path) { @@ -227,6 +227,23 @@ static void games_menu(void) strcat(menu_buff, BACK_MENU); } +int games_menu_maxw(void) +{ + int i = 0; + int oldm = games_menu_from; + int maxw = 0; + for (i = 0; i < games_nr; i += MENU_GAMES_MAX) { + int w; + games_menu_from = i; + games_menu(); + game_menu_box_wh(menu_buff, &w, NULL); + if (w > maxw) + maxw = w; + } + games_menu_from = oldm; + return maxw; +} + static void themes_menu(void) { int i, n; @@ -254,6 +271,23 @@ static void themes_menu(void) strcat(menu_buff, BACK_MENU); } +int themes_menu_maxw(void) +{ + int i = 0; + int oldm = themes_menu_from; + int maxw = 0; + for (i = 0; i < themes_nr; i += MENU_THEMES_MAX) { + int w; + themes_menu_from = i; + themes_menu(); + game_menu_box_wh(menu_buff, &w, NULL); + if (w > maxw) + maxw = w; + } + themes_menu_from = oldm; + return maxw; +} + static char *opt_get_mode(void) { static char buff[128]; diff --git a/src/sdl-instead/menu.h b/src/sdl-instead/menu.h index 362c51c..e6eba1b 100644 --- a/src/sdl-instead/menu.h +++ b/src/sdl-instead/menu.h @@ -18,6 +18,8 @@ extern int game_menu_act(const char *a); extern void custom_theme_warn(void); extern int menu_langs_lookup(const char *path); extern int menu_lang_select(const char *name); +extern int games_menu_maxw(void); +extern int themes_menu_maxw(void); struct lang { char *path;