aligned themes/games dialog width

This commit is contained in:
p.kosyh 2010-06-07 12:15:40 +00:00
parent f86dca706b
commit 67faf6decd
5 changed files with 77 additions and 7 deletions

2
debian/changelog vendored
View file

@ -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 <p.kosyh@gmail.com> Tue, 01 Jun 2010 17:40:00 +0300

View file

@ -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;

View file

@ -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);

View file

@ -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];

View file

@ -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;