Skip to content

Commit

Permalink
Text is now mainly drawn in a region-centric way, instead of drawing …
Browse files Browse the repository at this point in the history
…at whatever the font's size is.

- This allows changing the font size while still making the text occupy the same space.
- Also adjusted some strings as I went along.
  • Loading branch information
Espyo committed Sep 14, 2024
1 parent 5f1c943 commit 77f77c3
Show file tree
Hide file tree
Showing 23 changed files with 508 additions and 758 deletions.
280 changes: 111 additions & 169 deletions Source/source/drawing.cpp

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Source/source/drawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ namespace DRAWING {
extern const float DEF_HEALTH_WHEEL_RADIUS;
extern const float LIQUID_WOBBLE_DELTA_X;
extern const float LIQUID_WOBBLE_TIME_SCALE;
extern const float LOADING_SCREEN_SUBTITLE_SCALE;
extern const int LOADING_SCREEN_PADDING;
extern const float LOADING_SCREEN_SUBTEXT_SCALE;
extern const float LOADING_SCREEN_TEXT_HEIGHT;
extern const float LOADING_SCREEN_TEXT_WIDTH;
extern const unsigned char NOTIFICATION_ALPHA;
extern const float NOTIFICATION_CONTROL_SIZE;
extern const float NOTIFICATION_PADDING;
Expand Down Expand Up @@ -176,7 +178,7 @@ void draw_button(
void draw_fraction(
const point &bottom, const size_t value_nr,
const size_t requirement_nr, const ALLEGRO_COLOR &color,
const float scale = 1.0f
const float height
);
void draw_health(
const point &center, const float ratio,
Expand Down
36 changes: 0 additions & 36 deletions Source/source/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,42 +480,6 @@ float get_liquid_limit_length(edge* e_ptr) {
}


/**
* @brief Returns the width and height of a block of multi-line text.
*
* Lines are split by a single "\n" character.
* These are the dimensions of a bitmap
* that would hold a drawing by draw_text_lines().
*
* @param font The text's font.
* @param text The text.
* @param out_ret_w If not nullptr, the width is returned here.
* @param out_ret_h If not nullptr, the height is returned here.
*/
void get_multiline_text_dimensions(
const ALLEGRO_FONT* const font, const string &text,
int* out_ret_w, int* out_ret_h
) {
vector<string> lines = split(text, "\n", true);
int fh = al_get_font_line_height(font);
size_t n_lines = lines.size();

if(out_ret_h) *out_ret_h = std::max(0, (int) ((fh + 1) * n_lines) - 1);

if(out_ret_w) {
int largest_w = 0;
for(size_t l = 0; l < lines.size(); ++l) {
largest_w =
std::max(
largest_w, al_get_text_width(font, lines[l].c_str())
);
}

*out_ret_w = largest_w;
}
}


/**
* @brief Returns an area's subtitle or, if none is specified,
* the mission's goal.
Expand Down
4 changes: 0 additions & 4 deletions Source/source/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ ALLEGRO_COLOR get_ledge_smoothing_color(edge* e_ptr);
ALLEGRO_COLOR get_liquid_limit_color(edge* e_ptr);
float get_ledge_smoothing_length(edge* e_ptr);
float get_liquid_limit_length(edge* e_ptr);
void get_multiline_text_dimensions(
const ALLEGRO_FONT* const font, const string &text,
int* out_ret_w, int* out_ret_h
);
void get_next_edge(
vertex* v_ptr, const float pivot_angle, const bool clockwise,
const edge* ignore, edge** out_edge, float* out_angle, float* out_diff
Expand Down
14 changes: 8 additions & 6 deletions Source/source/game_states/animation_editor/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,14 @@ void animation_editor::draw_timeline() {
if(text.size() >= 4) {
text = text.substr(1, 3);
}
al_draw_text(
game.sys_assets.fnt_builtin, al_map_rgb(32, 32, 32),
floor(x_to_use) + 2,
canvas_br.y - ANIM_EDITOR::TIMELINE_HEIGHT + 2,
ALLEGRO_ALIGN_LEFT,
text.c_str()
draw_text(
text, game.sys_assets.fnt_builtin,
point(
floor(x_to_use) + 2,
canvas_br.y - ANIM_EDITOR::TIMELINE_HEIGHT + 2
),
point(LARGE_FLOAT, 8.0f), al_map_rgb(32, 32, 32),
ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_TOP
);
al_draw_line(
x_to_use + 0.5, canvas_br.y - ANIM_EDITOR::TIMELINE_HEIGHT,
Expand Down
2 changes: 1 addition & 1 deletion Source/source/game_states/animation_editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ void animation_editor::unload() {

if(bg) {
al_destroy_bitmap(bg);
bg = NULL;
bg = nullptr;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Source/source/game_states/animation_editor/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void animation_editor::process_gui_options_dialog() {
if(!use_bg) {
if(bg) {
al_destroy_bitmap(bg);
bg = NULL;
bg = nullptr;
}
game.options.anim_editor_bg_texture.clear();
}
Expand All @@ -629,7 +629,7 @@ void animation_editor::process_gui_options_dialog() {
game.options.anim_editor_bg_texture = f[0];
if(bg) {
al_destroy_bitmap(bg);
bg = NULL;
bg = nullptr;
}
bg =
load_bmp(
Expand Down
54 changes: 25 additions & 29 deletions Source/source/game_states/area_editor/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,15 +1099,16 @@ void area_editor::draw_canvas() {
path_preview_checkpoints[c].y + factor,
al_map_rgb(240, 224, 160)
);
draw_scaled_text(
game.sys_assets.fnt_builtin, al_map_rgb(0, 64, 64),
draw_text(
letter, game.sys_assets.fnt_builtin,
path_preview_checkpoints[c],
point(
AREA_EDITOR::POINT_LETTER_TEXT_SCALE / game.cam.zoom,
AREA_EDITOR::POINT_LETTER_TEXT_SCALE / game.cam.zoom
AREA_EDITOR::PATH_PREVIEW_CHECKPOINT_RADIUS * 1.8f /
game.cam.zoom,
AREA_EDITOR::PATH_PREVIEW_CHECKPOINT_RADIUS * 1.8f /
game.cam.zoom
),
ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER,
letter
al_map_rgb(0, 64, 64)
);
}
}
Expand Down Expand Up @@ -1203,15 +1204,16 @@ void area_editor::draw_canvas() {
(AREA_EDITOR::CROSS_SECTION_POINT_RADIUS / game.cam.zoom),
al_map_rgb(255, 255, 32)
);
draw_scaled_text(
game.sys_assets.fnt_builtin, al_map_rgb(0, 64, 64),
draw_text(
letter, game.sys_assets.fnt_builtin,
cross_section_checkpoints[p],
point(
AREA_EDITOR::POINT_LETTER_TEXT_SCALE / game.cam.zoom,
AREA_EDITOR::POINT_LETTER_TEXT_SCALE / game.cam.zoom
AREA_EDITOR::CROSS_SECTION_POINT_RADIUS * 1.8f /
game.cam.zoom,
AREA_EDITOR::CROSS_SECTION_POINT_RADIUS * 1.8f /
game.cam.zoom
),
ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER,
letter
al_map_rgb(0, 64, 64)
);
}
al_draw_line(
Expand Down Expand Up @@ -1662,22 +1664,23 @@ void area_editor::draw_canvas() {
COLOR_WHITE, 1
);

draw_scaled_text(
game.sys_assets.fnt_builtin, COLOR_WHITE,
draw_text(
i2s(z), game.sys_assets.fnt_builtin,
point(
(cross_section_z_window_start.x + 8),
line_y
),
point(1, 1),
ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_CENTER, i2s(z)
point(LARGE_FLOAT, 8.0f), COLOR_WHITE,
ALLEGRO_ALIGN_LEFT
);
}
}

} else {

draw_scaled_text(
game.sys_assets.fnt_builtin, COLOR_WHITE,
draw_text(
"Please cross some edges.",
game.sys_assets.fnt_builtin,
point(
(
cross_section_window_start.x +
Expand All @@ -1688,8 +1691,7 @@ void area_editor::draw_canvas() {
cross_section_window_end.y
) * 0.5
),
point(1, 1), ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER,
"Please cross\nsome edges."
point(LARGE_FLOAT, 8.0f), COLOR_WHITE
);

}
Expand Down Expand Up @@ -1819,15 +1821,9 @@ void area_editor::draw_debug_text(
al_map_rgba(0, 0, 0, 128)
);

draw_scaled_text(
game.sys_assets.fnt_builtin, color,
where,
point(
AREA_EDITOR::DEBUG_TEXT_SCALE / game.cam.zoom,
AREA_EDITOR::DEBUG_TEXT_SCALE / game.cam.zoom
),
ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER,
text
draw_text(
text, game.sys_assets.fnt_builtin, where,
point(bbox_w, bbox_h) * 0.80f, color
);

if(dots > 0) {
Expand Down
12 changes: 6 additions & 6 deletions Source/source/game_states/control_binds_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ void control_binds_menu_state::do_drawing() {
);

draw_text_lines(
game.sys_assets.fnt_standard,
COLOR_WHITE,
point(game.win_w / 2.0f, game.win_h / 2.0f),
ALLEGRO_ALIGN_CENTER,
V_ALIGN_MODE_CENTER,
"Please perform the new input for \n" +
game.controls.get_player_action_type(cur_action_type).name + "\n"
"\n"
"(Or wait " + i2s(capturing_input_timeout + 1) + "s to cancel...)"
"(Or wait " + i2s(capturing_input_timeout + 1) + "s to cancel...)",
game.sys_assets.fnt_standard,
point(game.win_w / 2.0f, game.win_h / 2.0f),
point(LARGE_FLOAT, LARGE_FLOAT),
COLOR_WHITE, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER,
TEXT_SETTING_FLAG_CANT_GROW
);
}

Expand Down
Loading

0 comments on commit 77f77c3

Please sign in to comment.