Skip to content

Commit

Permalink
Properly adjust text when scaling to higher resolutions
Browse files Browse the repository at this point in the history
Use scale_ui_value to adjust text height and offsets to keep it aligned properly at higher resolutions. Also make a few adjustments to the existing offsets to better align the text.
  • Loading branch information
wtlangford committed Dec 17, 2023
1 parent f50b909 commit 314ff7a
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/frontmenu_ingame_tabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,13 +545,13 @@ void gui_area_big_room_button(struct GuiButton *gbtn)
draw_gui_panel_sprite_left(gbtn->scr_pos_x - 4*units_per_px/16, gbtn->scr_pos_y - 32*units_per_px/16, ps_units_per_px, gbtn->sprite_idx + 1);
}
LbTextUseByteCoding(false);
int tx_units_per_px = (22 * units_per_pixel) / LbTextLineHeight();
draw_string64k(gbtn->scr_pos_x + 44*units_per_px/16, gbtn->scr_pos_y + (8 - 6)*units_per_px/16, tx_units_per_px, gui_textbuf);
int tx_units_per_px = scale_ui_value(22);
draw_string64k(gbtn->scr_pos_x + scale_ui_value(44), gbtn->scr_pos_y + -scale_ui_value(4), tx_units_per_px, gui_textbuf);

long amount = count_player_rooms_of_type(player->id_number, rkind);
// Note that "@" is "x" in that font
sprintf(gui_textbuf, "@%ld", amount);
draw_string64k(gbtn->scr_pos_x + 40*units_per_px/16, gbtn->scr_pos_y - (14 + 6)*units_per_px/16, tx_units_per_px, gui_textbuf);
draw_string64k(gbtn->scr_pos_x + scale_ui_value(44), gbtn->scr_pos_y - scale_ui_value(32), tx_units_per_px, gui_textbuf);
LbTextUseByteCoding(true);
lbDisplay.DrawFlags = flg_mem;
}
Expand Down Expand Up @@ -694,8 +694,7 @@ void gui_area_big_spell_button(struct GuiButton *gbtn)
draw_gui_panel_sprite_left(gbtn->scr_pos_x - 4*units_per_px/16, gbtn->scr_pos_y - 32*units_per_px/16, ps_units_per_px, gbtn->sprite_idx + 1);
}
LbTextUseByteCoding(false);
int tx_units_per_px = (22 * units_per_pixel) / LbTextLineHeight();
draw_string64k(gbtn->scr_pos_x + 44*units_per_px/16, gbtn->scr_pos_y + (8 - 6)*units_per_px/16, tx_units_per_px, text);
draw_string64k(gbtn->scr_pos_x + scale_ui_value(44), gbtn->scr_pos_y - scale_ui_value(4), scale_ui_value(22), text);
LbTextUseByteCoding(true);
lbDisplay.DrawFlags = flg_mem;
}
Expand Down Expand Up @@ -1017,8 +1016,8 @@ void gui_area_big_trap_button(struct GuiButton *gbtn)
} else {
draw_gui_panel_sprite_left(gbtn->scr_pos_x - 4*units_per_px/16, gbtn->scr_pos_y - 32*units_per_px/16, ps_units_per_px, gbtn->sprite_idx);
}
int tx_units_per_px = (22 * units_per_pixel) / LbTextLineHeight();
draw_string64k(gbtn->scr_pos_x + 44*units_per_px/16, gbtn->scr_pos_y + (8 - 6)*units_per_px/16, tx_units_per_px, gui_textbuf);
int tx_units_per_px = scale_ui_value(22);
draw_string64k(gbtn->scr_pos_x + scale_ui_value(44), gbtn->scr_pos_y - scale_ui_value(4), tx_units_per_px, gui_textbuf);
lbDisplay.DrawFlags = flg_mem;
}

Expand Down Expand Up @@ -1177,29 +1176,27 @@ void draw_centred_string64k(const char *text, short x, short y, short base_w, sh
unsigned long flg_mem = lbDisplay.DrawFlags;
lbDisplay.DrawFlags &= ~Lb_TEXT_ONE_COLOR;
LbTextSetJustifyWindow((x - (dst_w / 2)), y, dst_w);
LbTextSetClipWindow( (x - (dst_w / 2)), y, dst_w, 16*dst_w/base_w);
LbTextSetClipWindow( (x - (dst_w / 2)), y, dst_w, scale_ui_value(LbTextLineHeight()));
lbDisplay.DrawFlags |= Lb_TEXT_HALIGN_CENTER;
int tx_units_per_px;
int text_x;
int text_y = -6*dst_w/base_w;
int text_x = 0;
int text_y = -scale_ui_value(6);
if ( (MyScreenHeight < 400) && (dbc_language > 0) )
{
tx_units_per_px = scale_ui_value(32);
text_x = 12;
}
else
{
tx_units_per_px = (22 * units_per_pixel) / LbTextLineHeight();
if ( (dbc_language > 0) && (MyScreenWidth > 640) )
{
tx_units_per_px = scale_value_by_horizontal_resolution(12 + (MyScreenWidth / 640));
text_y += 12;
}
else
{
tx_units_per_px = (22 * units_per_pixel) / LbTextLineHeight();
tx_units_per_px = scale_ui_value(16);
}
text_x = 0;
}
LbTextDrawResized(text_x, text_y, tx_units_per_px, text);
LbTextSetJustifyWindow(0, 0, LbGraphicsScreenWidth());
Expand Down Expand Up @@ -1244,7 +1241,7 @@ void draw_name_box(long x, long y, int width, struct Thing *thing)
}
// Draw creature name
const char* text = creature_own_name(thing);
draw_centred_string64k(text, x + 63*width/140, y + 2*width/140, 120, 120*width/140);
draw_centred_string64k(text, x + width/2, y + scale_ui_value(6), 120, 120*width/140);
}
}

Expand Down Expand Up @@ -2128,7 +2125,7 @@ void gui_area_payday_button(struct GuiButton *gbtn)
gui_area_progress_bar_wide(gbtn, units_per_px, game.pay_day_progress, game.pay_day_gap);
struct Dungeon* dungeon = get_players_num_dungeon(my_player_number);
char* text = buf_sprintf("%d", (int)dungeon->creatures_total_pay);
draw_centred_string64k(text, gbtn->scr_pos_x + (gbtn->width >> 1), gbtn->scr_pos_y + 8*units_per_px/16, 130, gbtn->width);
draw_centred_string64k(text, gbtn->scr_pos_x + (gbtn->width >> 1), gbtn->scr_pos_y + scale_ui_value(8), 130, gbtn->width);
}

void gui_area_research_bar(struct GuiButton *gbtn)
Expand Down

0 comments on commit 314ff7a

Please sign in to comment.