From 77f77c3130c100b17a0037774c769a895c7f7cc9 Mon Sep 17 00:00:00 2001 From: Espyo Date: Sat, 14 Sep 2024 22:43:57 +0100 Subject: [PATCH] Text is now mainly drawn in a region-centric way, instead of drawing 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. --- Source/source/drawing.cpp | 280 +++++++----------- Source/source/drawing.h | 6 +- Source/source/functions.cpp | 36 --- Source/source/functions.h | 4 - .../game_states/animation_editor/drawing.cpp | 14 +- .../game_states/animation_editor/editor.cpp | 2 +- .../game_states/animation_editor/gui.cpp | 4 +- .../game_states/area_editor/drawing.cpp | 54 ++-- .../source/game_states/control_binds_menu.cpp | 12 +- .../source/game_states/gameplay/drawing.cpp | 87 +++--- .../source/game_states/gameplay/gameplay.cpp | 2 +- Source/source/game_states/gameplay/hud.cpp | 233 ++++++--------- .../game_states/gameplay/in_world_hud.cpp | 14 +- .../game_states/gameplay/in_world_hud.h | 3 +- .../game_states/gameplay/onion_menu.cpp | 40 ++- .../game_states/gameplay/pause_menu.cpp | 17 +- .../source/game_states/gui_editor/drawing.cpp | 14 +- Source/source/game_states/main_menu.cpp | 19 +- Source/source/gui.cpp | 104 ++++--- Source/source/gui.h | 1 + Source/source/misc_structs.cpp | 10 +- Source/source/utils/drawing_utils.cpp | 278 +++++++---------- Source/source/utils/drawing_utils.h | 32 +- 23 files changed, 508 insertions(+), 758 deletions(-) diff --git a/Source/source/drawing.cpp b/Source/source/drawing.cpp index 3a6dd895..9adb81a7 100644 --- a/Source/source/drawing.cpp +++ b/Source/source/drawing.cpp @@ -23,6 +23,7 @@ #include "mobs/scale.h" #include "utils/allegro_utils.h" #include "utils/drawing_utils.h" +#include "utils/drawing_utils.h" #include "utils/general_utils.h" #include "utils/geometry_utils.h" #include "utils/string_utils.h" @@ -59,11 +60,17 @@ const float LIQUID_WOBBLE_DELTA_X = 3.0f; //Liquid surfaces wobble using this time scale. const float LIQUID_WOBBLE_TIME_SCALE = 2.0f; -//Loading screen subtitle text padding. +//Loading screen subtext padding. const int LOADING_SCREEN_PADDING = 64; -//Loading screen subtitle text scale. -const float LOADING_SCREEN_SUBTITLE_SCALE = 0.6f; +//Loading screen subtext scale. +const float LOADING_SCREEN_SUBTEXT_SCALE = 0.6f; + +//Loading screen text height, in screen ratio. +const float LOADING_SCREEN_TEXT_HEIGHT = 0.10f; + +//Loading screen text width, in screen ratio. +const float LOADING_SCREEN_TEXT_WIDTH = 0.70f; //Notification opacity. const unsigned char NOTIFICATION_ALPHA = 160; @@ -195,12 +202,11 @@ void draw_button( const ALLEGRO_FONT* font, const ALLEGRO_COLOR &color, const bool selected, const float juicy_grow_amount ) { - draw_compressed_scaled_text( - font, color, - center, - point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, size, true, - text + draw_text( + text, font, center, size * GUI::STANDARD_CONTENT_SIZE, color, + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, + TEXT_SETTING_FLAG_CANT_GROW, + point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount) ); ALLEGRO_COLOR box_tint = @@ -229,37 +235,34 @@ void draw_button( * @param value_nr Number that represents the current value. * @param requirement_nr Number that represents the requirement. * @param color Color of the fraction's text. - * @param scale Scale the fraction by this much. + * @param height Height of the whole fraction. */ void draw_fraction( const point &bottom, const size_t value_nr, - const size_t requirement_nr, const ALLEGRO_COLOR &color, const float scale + const size_t requirement_nr, const ALLEGRO_COLOR &color, const float height ) { - float font_h = al_get_font_line_height(game.sys_assets.fnt_value) * scale; - - float value_nr_y = bottom.y - font_h * 3; - float value_nr_scale = - value_nr >= requirement_nr ? scale * 1.2f : scale * 1.0f; - draw_scaled_text( - game.sys_assets.fnt_value, color, point(bottom.x, value_nr_y), - point(value_nr_scale, value_nr_scale), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_TOP, (i2s(value_nr).c_str()) + const float value_nr_y = bottom.y - IN_WORLD_FRACTION::ROW_HEIGHT * 3; + const float value_nr_scale = value_nr >= requirement_nr ? 1.2f : 1.0f; + draw_text( + i2s(value_nr), game.sys_assets.fnt_value, point(bottom.x, value_nr_y), + point(LARGE_FLOAT, IN_WORLD_FRACTION::ROW_HEIGHT * value_nr_scale), + color, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_TOP, 0 ); - float bar_y = bottom.y - font_h * 2; - draw_scaled_text( - game.sys_assets.fnt_value, color, point(bottom.x, bar_y), - point(scale, scale), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_TOP, "-" + const float bar_y = bottom.y - IN_WORLD_FRACTION::ROW_HEIGHT * 2; + draw_text( + "-", game.sys_assets.fnt_value, point(bottom.x, bar_y), + point(LARGE_FLOAT, IN_WORLD_FRACTION::ROW_HEIGHT), + color, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_TOP, 0 ); - float req_nr_y = bottom.y - font_h; - float req_nr_scale = - requirement_nr > value_nr ? scale * 1.2f : scale * 1.0f; - draw_scaled_text( - game.sys_assets.fnt_value, color, point(bottom.x, req_nr_y), - point(req_nr_scale, req_nr_scale), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_TOP, (i2s(requirement_nr).c_str()) + float req_nr_y = bottom.y - IN_WORLD_FRACTION::ROW_HEIGHT; + float req_nr_scale = requirement_nr > value_nr ? 1.2f : 1.0f; + draw_text( + i2s(requirement_nr), game.sys_assets.fnt_value, + point(bottom.x, req_nr_y), + point(LARGE_FLOAT, IN_WORLD_FRACTION::ROW_HEIGHT * req_nr_scale), + color, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_TOP, 0 ); } @@ -476,6 +479,11 @@ void draw_liquid( void draw_loading_screen( const string &text, const string &subtext, const float opacity ) { + const float text_w = game.win_w * DRAWING::LOADING_SCREEN_TEXT_WIDTH; + const float text_h = game.win_h * DRAWING::LOADING_SCREEN_TEXT_HEIGHT; + const float subtext_w = text_w * DRAWING::LOADING_SCREEN_SUBTEXT_SCALE; + const float subtext_h = text_h * DRAWING::LOADING_SCREEN_SUBTEXT_SCALE; + unsigned char blackness_alpha = 255.0f * std::max(0.0f, opacity * 4 - 3); al_draw_filled_rectangle( 0, 0, game.win_w, game.win_h, al_map_rgba(0, 0, 0, blackness_alpha) @@ -487,67 +495,37 @@ void draw_loading_screen( ); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE); - //Set up the bitmap that will hold the text. - int text_w = 0, text_h = 0; - if(!text.empty()) { - if(!game.loading_text_bmp) { - //No main text buffer? Create it! - - get_multiline_text_dimensions( - game.sys_assets.fnt_area_name, text, &text_w, &text_h + //Set up the bitmap that will hold the text if it doesn't exist. + if(!text.empty() && !game.loading_text_bmp) { + game.loading_text_bmp = al_create_bitmap(text_w, text_h); + + al_set_target_bitmap(game.loading_text_bmp); { + al_clear_to_color(COLOR_EMPTY); + draw_text( + text, game.sys_assets.fnt_area_name, + point(text_w * 0.5f, text_h * 0.5f), + point(text_w, text_h), + COLOR_GOLD, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0 ); - game.loading_text_bmp = - al_create_bitmap(text_w, text_h); - - //Draw the main text on its bitmap. - al_set_target_bitmap(game.loading_text_bmp); { - al_clear_to_color(COLOR_EMPTY); - draw_text_lines( - game.sys_assets.fnt_area_name, COLOR_GOLD, - point(), ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_TOP, - text - ); - } al_set_target_backbuffer(game.display); - - } else { - text_w = - al_get_bitmap_width(game.loading_text_bmp); - text_h = - al_get_bitmap_height(game.loading_text_bmp); - } + } al_set_target_backbuffer(game.display); } - int subtext_w = 0, subtext_h = 0; - if(!subtext.empty()) { - - if(!game.loading_subtext_bmp) { - //No subtext buffer? Create it! - get_multiline_text_dimensions( - game.sys_assets.fnt_area_name, subtext, &subtext_w, &subtext_h + //Set up the bitmap that will hold the text if it doesn't exist. + if(!subtext.empty() && !game.loading_subtext_bmp) { + game.loading_subtext_bmp = al_create_bitmap(subtext_w, subtext_h); + + al_set_target_bitmap(game.loading_subtext_bmp); { + al_clear_to_color(COLOR_EMPTY); + draw_text( + subtext, game.sys_assets.fnt_area_name, + point(subtext_w * 0.5f, subtext_h * 0.5f), + point(subtext_w, subtext_h), + al_map_rgb(224, 224, 224), + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0 ); - game.loading_subtext_bmp = - al_create_bitmap(subtext_w, subtext_h); - - al_set_target_bitmap(game.loading_subtext_bmp); { - al_clear_to_color(COLOR_EMPTY); - draw_text_lines( - game.sys_assets.fnt_area_name, al_map_rgb(224, 224, 224), - point(), - ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_TOP, - subtext - ); - - } al_set_target_backbuffer(game.display); - //We'll be scaling this, so let's update the mipmap. - game.loading_subtext_bmp = - recreate_bitmap(game.loading_subtext_bmp); - - } else { - subtext_w = al_get_bitmap_width(game.loading_subtext_bmp); - subtext_h = al_get_bitmap_height(game.loading_subtext_bmp); - } + } al_set_target_backbuffer(game.display); } @@ -556,69 +534,63 @@ void draw_loading_screen( ); //Draw the text bitmap in its place. - float text_y = 0; + const float text_x = game.win_w * 0.5 - text_w * 0.5; + float text_y = game.win_h * 0.5 - text_h * 0.5; if(!text.empty()) { - - text_y = - subtext.empty() ? - (game.win_h * 0.5 - text_h * 0.5) : - (game.win_h * 0.5 - DRAWING::LOADING_SCREEN_PADDING * 0.5 - text_h); + if(!subtext.empty()) { + text_y -= DRAWING::LOADING_SCREEN_PADDING * 0.5; + } al_draw_tinted_bitmap( - game.loading_text_bmp, al_map_rgba(255, 255, 255, 255.0 * opacity), + game.loading_text_bmp, + al_map_rgba(255, 255, 255, 255.0 * opacity), game.win_w * 0.5 - text_w * 0.5, text_y, 0 ); } //Draw the subtext bitmap in its place. + const float subtext_x = game.win_w * 0.5 - subtext_w * 0.5; float subtext_y = game.win_h * 0.5 + DRAWING::LOADING_SCREEN_PADDING * 0.5; if(!subtext.empty()) { - al_draw_tinted_scaled_bitmap( + al_draw_tinted_bitmap( game.loading_subtext_bmp, al_map_rgba(255, 255, 255, 255.0 * opacity), - 0, 0, subtext_w, subtext_h, - game.win_w * 0.5 - - (subtext_w * DRAWING::LOADING_SCREEN_SUBTITLE_SCALE * 0.5), - subtext_y, - subtext_w * DRAWING::LOADING_SCREEN_SUBTITLE_SCALE, - subtext_h * DRAWING::LOADING_SCREEN_SUBTITLE_SCALE, - 0 + game.win_w * 0.5 - subtext_w * 0.5, subtext_y, 0 ); } - unsigned char reflection_alpha = 128.0 * opacity; + const unsigned char reflection_alpha = 128.0 * opacity; //Now, draw the polygon that will hold the reflection for the text. if(!text.empty()) { ALLEGRO_VERTEX text_vertexes[4]; - float text_reflection_h = - std::min((int) (DRAWING::LOADING_SCREEN_PADDING * 0.5), text_h); + const float text_reflection_h = text_h * 0.80f; //Top-left vertex. - text_vertexes[0].x = game.win_w * 0.5 - text_w * 0.5; + text_vertexes[0].x = text_x; text_vertexes[0].y = text_y + text_h; text_vertexes[0].z = 0; text_vertexes[0].u = 0; text_vertexes[0].v = text_h; text_vertexes[0].color = al_map_rgba(255, 255, 255, reflection_alpha); //Top-right vertex. - text_vertexes[1].x = game.win_w * 0.5 + text_w * 0.5; + text_vertexes[1].x = text_x + text_w; text_vertexes[1].y = text_y + text_h; text_vertexes[1].z = 0; text_vertexes[1].u = text_w; text_vertexes[1].v = text_h; text_vertexes[1].color = al_map_rgba(255, 255, 255, reflection_alpha); //Bottom-right vertex. - text_vertexes[2].x = game.win_w * 0.5 + text_w * 0.5; + text_vertexes[2].x = text_x + text_w; text_vertexes[2].y = text_y + text_h + text_reflection_h; text_vertexes[2].z = 0; text_vertexes[2].u = text_w; text_vertexes[2].v = text_h - text_reflection_h; text_vertexes[2].color = al_map_rgba(255, 255, 255, 0); //Bottom-left vertex. - text_vertexes[3].x = game.win_w * 0.5 - text_w * 0.5; + text_vertexes[3].x = text_x; text_vertexes[3].y = text_y + text_h + text_reflection_h; text_vertexes[3].z = 0; text_vertexes[3].u = 0; @@ -636,55 +608,33 @@ void draw_loading_screen( if(!subtext.empty()) { ALLEGRO_VERTEX subtext_vertexes[4]; - float subtext_reflection_h = - std::min( - (int) (DRAWING::LOADING_SCREEN_PADDING * 0.5), - (int) (text_h * DRAWING::LOADING_SCREEN_SUBTITLE_SCALE) - ); + const float subtext_reflection_h = subtext_h * 0.80f; //Top-left vertex. - subtext_vertexes[0].x = - game.win_w * 0.5 - subtext_w * - DRAWING::LOADING_SCREEN_SUBTITLE_SCALE * 0.5; - subtext_vertexes[0].y = - subtext_y + subtext_h * - DRAWING::LOADING_SCREEN_SUBTITLE_SCALE; + subtext_vertexes[0].x = subtext_x; + subtext_vertexes[0].y = subtext_y + subtext_h; subtext_vertexes[0].z = 0; subtext_vertexes[0].u = 0; subtext_vertexes[0].v = subtext_h; subtext_vertexes[0].color = al_map_rgba(255, 255, 255, reflection_alpha); //Top-right vertex. - subtext_vertexes[1].x = - game.win_w * 0.5 + subtext_w * - DRAWING::LOADING_SCREEN_SUBTITLE_SCALE * 0.5; - subtext_vertexes[1].y = - subtext_y + subtext_h * - DRAWING::LOADING_SCREEN_SUBTITLE_SCALE; + subtext_vertexes[1].x = subtext_x + subtext_w; + subtext_vertexes[1].y = subtext_y + subtext_h; subtext_vertexes[1].z = 0; subtext_vertexes[1].u = subtext_w; subtext_vertexes[1].v = subtext_h; subtext_vertexes[1].color = al_map_rgba(255, 255, 255, reflection_alpha); //Bottom-right vertex. - subtext_vertexes[2].x = - game.win_w * 0.5 + subtext_w * - DRAWING::LOADING_SCREEN_SUBTITLE_SCALE * 0.5; - subtext_vertexes[2].y = - subtext_y + subtext_h * - DRAWING::LOADING_SCREEN_SUBTITLE_SCALE + - subtext_reflection_h; + subtext_vertexes[2].x = subtext_x + subtext_w; + subtext_vertexes[2].y = subtext_y + subtext_h + subtext_reflection_h; subtext_vertexes[2].z = 0; subtext_vertexes[2].u = subtext_w; subtext_vertexes[2].v = subtext_h - subtext_reflection_h; subtext_vertexes[2].color = al_map_rgba(255, 255, 255, 0); //Bottom-left vertex. - subtext_vertexes[3].x = - game.win_w * 0.5 - subtext_w * - DRAWING::LOADING_SCREEN_SUBTITLE_SCALE * 0.5; - subtext_vertexes[3].y = - subtext_y + subtext_h * - DRAWING::LOADING_SCREEN_SUBTITLE_SCALE + - subtext_reflection_h; + subtext_vertexes[3].x = subtext_x; + subtext_vertexes[3].y = subtext_y + subtext_h + subtext_reflection_h; subtext_vertexes[3].z = 0; subtext_vertexes[3].u = 0; subtext_vertexes[3].v = subtext_h - subtext_reflection_h; @@ -697,32 +647,30 @@ void draw_loading_screen( } - //Draw the game's logo to the left of the "Loading..." text. + //Draw the game's logo to the left of the "Loading..." text, + //if we're not fading. if(opacity == 1.0f) { - point icon_pos( - game.win_w - 8 - - al_get_text_width(game.sys_assets.fnt_standard, "Loading...") - - 8 - al_get_font_line_height(game.sys_assets.fnt_standard) * 0.5, - game.win_h - 8 - al_get_font_line_height(game.sys_assets.fnt_standard) * 0.5 - ); + const point text_box(game.win_w * 0.11f, game.win_h * 0.03f); if( game.sys_assets.bmp_icon && game.sys_assets.bmp_icon != game.bmp_error ) { + point icon_pos( + game.win_w - 8 - text_box.x - 8 - text_box.y / 2.0f, + game.win_h - 8 - text_box.y / 2.0f + ); draw_bitmap( game.sys_assets.bmp_icon, icon_pos, - point(-1, al_get_font_line_height(game.sys_assets.fnt_standard)), + point(-1, text_box.y), 0, al_map_rgba(255, 255, 255, opacity * 255.0) ); } - //Draw the "Loading..." text, if we're not fading. - al_draw_text( - game.sys_assets.fnt_standard, al_map_rgb(192, 192, 192), - game.win_w - 8, - game.win_h - 8 - al_get_font_line_height(game.sys_assets.fnt_standard), - ALLEGRO_ALIGN_RIGHT, "Loading..." + draw_text( + "Loading...", game.sys_assets.fnt_standard, + point(game.win_w - 8, game.win_h - 8), text_box, + al_map_rgb(192, 192, 192), ALLEGRO_ALIGN_RIGHT, V_ALIGN_MODE_BOTTOM ); } @@ -1043,20 +991,14 @@ void draw_player_input_icon( } //And finally, the text inside. - draw_compressed_text( - font, - final_text_color, - point( - where.x, - where.y - ), - ALLEGRO_ALIGN_CENTER, - V_ALIGN_MODE_CENTER, + draw_text( + text, font, where, point( (max_size.x == 0 ? 0 : max_size.x - CONTROL_BIND_ICON::PADDING), (max_size.y == 0 ? 0 : max_size.y - CONTROL_BIND_ICON::PADDING) ), - text + final_text_color, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, + TEXT_SETTING_FLAG_CANT_GROW | TEXT_SETTING_COMPENSATE_Y_OFFSET ); } @@ -1266,12 +1208,12 @@ void draw_string_tokens( float token_final_width = tokens[t].width * x_scale; switch(tokens[t].type) { case STRING_TOKEN_CHAR: { - draw_scaled_text( - text_font, COLOR_WHITE, - point(caret, where.y), - point(x_scale * scale.x, y_scale * scale.y), + draw_text( + tokens[t].content, text_font, point(caret, where.y), + point(LARGE_FLOAT, LARGE_FLOAT), COLOR_WHITE, ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_TOP, - tokens[t].content + TEXT_SETTING_FLAG_CANT_GROW, + point(x_scale * scale.x, y_scale * scale.y) ); break; } diff --git a/Source/source/drawing.h b/Source/source/drawing.h index 7f1d69e2..2c131d0e 100644 --- a/Source/source/drawing.h +++ b/Source/source/drawing.h @@ -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; @@ -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 ¢er, const float ratio, diff --git a/Source/source/functions.cpp b/Source/source/functions.cpp index e1820295..54f51533 100644 --- a/Source/source/functions.cpp +++ b/Source/source/functions.cpp @@ -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 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. diff --git a/Source/source/functions.h b/Source/source/functions.h index 5c7c1eb5..a53dc4eb 100644 --- a/Source/source/functions.h +++ b/Source/source/functions.h @@ -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 diff --git a/Source/source/game_states/animation_editor/drawing.cpp b/Source/source/game_states/animation_editor/drawing.cpp index e7386577..a21ac93f 100644 --- a/Source/source/game_states/animation_editor/drawing.cpp +++ b/Source/source/game_states/animation_editor/drawing.cpp @@ -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, diff --git a/Source/source/game_states/animation_editor/editor.cpp b/Source/source/game_states/animation_editor/editor.cpp index f560a769..5b802d78 100644 --- a/Source/source/game_states/animation_editor/editor.cpp +++ b/Source/source/game_states/animation_editor/editor.cpp @@ -1445,7 +1445,7 @@ void animation_editor::unload() { if(bg) { al_destroy_bitmap(bg); - bg = NULL; + bg = nullptr; } } diff --git a/Source/source/game_states/animation_editor/gui.cpp b/Source/source/game_states/animation_editor/gui.cpp index 69e04ba3..66af6102 100644 --- a/Source/source/game_states/animation_editor/gui.cpp +++ b/Source/source/game_states/animation_editor/gui.cpp @@ -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(); } @@ -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( diff --git a/Source/source/game_states/area_editor/drawing.cpp b/Source/source/game_states/area_editor/drawing.cpp index 91b6fbf7..a814153e 100644 --- a/Source/source/game_states/area_editor/drawing.cpp +++ b/Source/source/game_states/area_editor/drawing.cpp @@ -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) ); } } @@ -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( @@ -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 + @@ -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 ); } @@ -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) { diff --git a/Source/source/game_states/control_binds_menu.cpp b/Source/source/game_states/control_binds_menu.cpp index 2a6284b7..b1cd37e2 100644 --- a/Source/source/game_states/control_binds_menu.cpp +++ b/Source/source/game_states/control_binds_menu.cpp @@ -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 ); } diff --git a/Source/source/game_states/gameplay/drawing.cpp b/Source/source/game_states/gameplay/drawing.cpp index f7e7b384..b1d077cd 100644 --- a/Source/source/game_states/gameplay/drawing.cpp +++ b/Source/source/game_states/gameplay/drawing.cpp @@ -275,7 +275,7 @@ void gameplay_state::draw_big_msg() { } case BIG_MESSAGE_READY: { const float TEXT_W = game.win_w * 0.60f; - const float TEXT_INITIAL_SCALE = 2.0f; + const float TEXT_INITIAL_HEIGHT = 0.10; const float TEXT_VARIATION_DUR = 0.08f; const float TEXT_START_T = 0.15f; const float TEXT_MOVE_MID_T = 0.30f; @@ -288,11 +288,9 @@ void gameplay_state::draw_big_msg() { ki_y.add(TEXT_MOVE_MID_T, game.win_h * 0.40f, EASE_METHOD_IN); ki_y.add(TEXT_PAUSE_T, game.win_h / 2.0f, EASE_METHOD_OUT_ELASTIC); ki_y.add(TEXT_SHRINK_T, game.win_h / 2.0f); - keyframe_interpolator ki_s(TEXT_INITIAL_SCALE); - ki_s.add(TEXT_SHRINK_T, TEXT_INITIAL_SCALE * 1.4f); - ki_s.add(1.0f, 0.0f, EASE_METHOD_IN); - - float scale = ki_s.get(t); + keyframe_interpolator ki_h(TEXT_INITIAL_HEIGHT); + ki_h.add(TEXT_SHRINK_T, TEXT_INITIAL_HEIGHT * 1.4f); + ki_h.add(1.0f, 0.0f, EASE_METHOD_IN); for(size_t c = 0; c < GAMEPLAY::BIG_MSG_READY_TEXT.size(); ++c) { float char_ratio = @@ -300,14 +298,11 @@ void gameplay_state::draw_big_msg() { char_ratio = 1.0f - char_ratio; float x_offset = (TEXT_W / 2.0f) - (TEXT_W * char_ratio); float y = ki_y.get(t + char_ratio * TEXT_VARIATION_DUR); - draw_scaled_text( + draw_text( + string(1, GAMEPLAY::BIG_MSG_READY_TEXT[c]), game.sys_assets.fnt_area_name, - COLOR_GOLD, point((game.win_w / 2.0f) + x_offset, y), - point(scale, scale), - ALLEGRO_ALIGN_CENTER, - V_ALIGN_MODE_CENTER, - string(1, GAMEPLAY::BIG_MSG_READY_TEXT[c]) + point(LARGE_FLOAT, game.win_h * ki_h.get(t)), COLOR_GOLD ); } break; @@ -317,24 +312,19 @@ void gameplay_state::draw_big_msg() { const float TEXT_GROW_STOP_T = 0.10f; const float t = big_msg_time / GAMEPLAY::BIG_MSG_GO_DUR; - keyframe_interpolator ki_s(0.0f); - ki_s.add(TEXT_GROW_STOP_T, 4.0f, EASE_METHOD_OUT_ELASTIC); - ki_s.add(1.0f, 4.4f); + keyframe_interpolator ki_h(0.0f); + ki_h.add(TEXT_GROW_STOP_T, 0.20f, EASE_METHOD_OUT_ELASTIC); + ki_h.add(1.0f, 0.22f); keyframe_interpolator ki_a(1.0f); ki_a.add(TEXT_GROW_STOP_T, 1.0f); ki_a.add(1.0f, 0.0f); - float scale = ki_s.get(t); - float alpha = ki_a.get(t); - - draw_scaled_text( + draw_text( + GAMEPLAY::BIG_MSG_GO_TEXT, game.sys_assets.fnt_area_name, - change_alpha(COLOR_GOLD, 255 * alpha), point(game.win_w / 2.0f, game.win_h / 2.0f), - point(scale, scale), - ALLEGRO_ALIGN_CENTER, - V_ALIGN_MODE_CENTER, - GAMEPLAY::BIG_MSG_GO_TEXT + point(LARGE_FLOAT, game.win_h * ki_h.get(t)), + change_alpha(COLOR_GOLD, 255 * ki_a.get(t)) ); break; @@ -345,7 +335,7 @@ void gameplay_state::draw_big_msg() { GAMEPLAY::BIG_MSG_MISSION_CLEAR_TEXT : GAMEPLAY::BIG_MSG_MISSION_FAILED_TEXT; const float TEXT_W = game.win_w * 0.80f; - const float TEXT_INITIAL_SCALE = 1.1f; + const float TEXT_INITIAL_HEIGHT = 0.05f; const float TEXT_VARIATION_DUR = 0.08f; const float TEXT_MOVE_MID_T = 0.30f; const float TEXT_PAUSE_T = 0.50f; @@ -358,13 +348,12 @@ void gameplay_state::draw_big_msg() { keyframe_interpolator ki_y(game.win_h * (-0.2f)); ki_y.add(TEXT_MOVE_MID_T, game.win_h * 0.40f, EASE_METHOD_IN); ki_y.add(TEXT_PAUSE_T, game.win_h / 2.0f, EASE_METHOD_OUT_ELASTIC); - keyframe_interpolator ki_s(TEXT_INITIAL_SCALE); - ki_s.add(1.0f, TEXT_INITIAL_SCALE * 1.4f, EASE_METHOD_IN); + keyframe_interpolator ki_h(TEXT_INITIAL_HEIGHT); + ki_h.add(1.0f, TEXT_INITIAL_HEIGHT * 1.4f, EASE_METHOD_IN); keyframe_interpolator ki_a(1.0f); ki_a.add(TEXT_FADE_T, 1.0f); ki_a.add(1.0f, 0.0f); - float scale = ki_s.get(t); float alpha = ki_a.get(t); for(size_t c = 0; c < TEXT.size(); ++c) { @@ -372,14 +361,12 @@ void gameplay_state::draw_big_msg() { char_ratio = 1.0f - char_ratio; float x_offset = (TEXT_W / 2.0f) - (TEXT_W * char_ratio); float y = ki_y.get(t + char_ratio * TEXT_VARIATION_DUR); - draw_scaled_text( - game.sys_assets.fnt_area_name, - change_alpha(COLOR_GOLD, 255 * alpha), + + draw_text( + string(1, TEXT[c]), game.sys_assets.fnt_area_name, point((game.win_w / 2.0f) + x_offset, y), - point(scale, scale), - ALLEGRO_ALIGN_CENTER, - V_ALIGN_MODE_CENTER, - string(1, TEXT[c]) + point(LARGE_FLOAT, game.win_h * ki_h.get(t)), + change_alpha(COLOR_GOLD, 255 * alpha) ); } break; @@ -1026,15 +1013,12 @@ void gameplay_state::draw_leader_cursor(const ALLEGRO_COLOR &color) { std::max(bmp_cursor_w, bmp_cursor_h) * 0.18f * game.cam.zoom; if(n_standby_pikmin > 0) { - draw_scaled_text( - game.sys_assets.fnt_cursor_counter, - color, + draw_text( + i2s(n_standby_pikmin), game.sys_assets.fnt_cursor_counter, leader_cursor_s + point(count_offset, count_offset), - point(1.0f, 1.0f), - ALLEGRO_ALIGN_LEFT, - V_ALIGN_MODE_TOP, - i2s(n_standby_pikmin) + point(LARGE_FLOAT, game.win_h * 0.02f), color, + ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_TOP ); } @@ -1330,12 +1314,13 @@ void gameplay_state::draw_message_box() { float token_final_width = cur_token.width * x_scale; switch(cur_token.type) { case STRING_TOKEN_CHAR: { - draw_scaled_text( - game.sys_assets.fnt_standard, map_alpha(alpha), + draw_text( + cur_token.content, game.sys_assets.fnt_standard, point(x, y), - point(x_scale, 1.0f), - ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_TOP, - cur_token.content + point(token_final_width, LARGE_FLOAT), + map_alpha(alpha), + ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_TOP, 0, + point(x_scale, 1.0f) ); break; } @@ -1437,8 +1422,12 @@ void gameplay_state::draw_system_stuff() { al_map_rgba(0, 0, 0, 96 * alpha_mult) ); draw_text_lines( - game.sys_assets.fnt_builtin, al_map_rgba(255, 255, 255, 128 * alpha_mult), - point(8, 8), 0, V_ALIGN_MODE_TOP, game.maker_tools.info_print_text + game.maker_tools.info_print_text, + game.sys_assets.fnt_builtin, + point(8, 8), + point(LARGE_FLOAT, LARGE_FLOAT), + al_map_rgba(255, 255, 255, 128 * alpha_mult), + ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_TOP, TEXT_SETTING_FLAG_CANT_GROW ); } diff --git a/Source/source/game_states/gameplay/gameplay.cpp b/Source/source/game_states/gameplay/gameplay.cpp index d325345b..dc650ca3 100644 --- a/Source/source/game_states/gameplay/gameplay.cpp +++ b/Source/source/game_states/gameplay/gameplay.cpp @@ -34,7 +34,7 @@ namespace GAMEPLAY { const float AREA_INTRO_HUD_MOVE_TIME = 3.0f; //How long it takes for the area name to fade away, in-game. -const float AREA_TITLE_FADE_DURATION = 3.0f; +const float AREA_TITLE_FADE_DURATION = 1.0f; //How long the "Go!" big message lasts for. const float BIG_MSG_GO_DUR = 1.5f; diff --git a/Source/source/game_states/gameplay/hud.cpp b/Source/source/game_states/gameplay/hud.cpp index a6a9e46e..9087cb62 100644 --- a/Source/source/game_states/gameplay/hud.cpp +++ b/Source/source/game_states/gameplay/hud.cpp @@ -379,10 +379,10 @@ hud_t::hud_t() : gui_item* day_nr = new gui_item(); day_nr->on_draw = [this] (const point & center, const point & size) { - draw_compressed_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, i2s(game.states.gameplay->day) + draw_text( + i2s(game.states.gameplay->day), + game.sys_assets.fnt_counter, center, + point(size.x * 0.70f, size.y * 0.50f) ); }; gui.add_item(day_nr, "day_number"); @@ -577,13 +577,12 @@ hud_t::hud_t() : standby_count_nr = n_standby_pikmin; } - draw_compressed_scaled_text( - game.sys_assets.fnt_counter, + draw_text( + i2s(n_standby_pikmin), game.sys_assets.fnt_counter, + center, size, map_alpha(game.states.gameplay->hud->standby_items_opacity * 255), - center, - point(1.0f, 1.0f) + standby_amount->get_juice_value(), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size * 0.7, true, i2s(n_standby_pikmin) + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0, + point(1.0f, 1.0f) + standby_amount->get_juice_value() ); }; gui.add_item(standby_amount, "standby_amount"); @@ -616,13 +615,11 @@ hud_t::hud_t() : group_count_nr = cur_amount; } - draw_compressed_scaled_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, - point(1.0f, 1.0f) + group_amount->get_juice_value(), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size * 0.7, true, - i2s(cur_amount) + draw_text( + i2s(cur_amount), game.sys_assets.fnt_counter, + center, point(size.x * 0.70f, size.y * 0.50f), COLOR_WHITE, + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0, + point(1.0f, 1.0f) + group_amount->get_juice_value() ); }; gui.add_item(group_amount, "group_amount"); @@ -654,13 +651,11 @@ hud_t::hud_t() : field_count_nr = cur_amount; } - draw_compressed_scaled_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, - point(1.0f, 1.0f) + field_amount->get_juice_value(), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size * 0.7, true, - i2s(cur_amount) + draw_text( + i2s(cur_amount), game.sys_assets.fnt_counter, + center, point(size.x * 0.70f, size.y * 0.50f), COLOR_WHITE, + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0, + point(1.0f, 1.0f) + field_amount->get_juice_value() ); }; gui.add_item(field_amount, "field_amount"); @@ -692,13 +687,11 @@ hud_t::hud_t() : total_count_nr = cur_amount; } - draw_compressed_scaled_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, - point(1.0f, 1.0f) + total_amount->get_juice_value(), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size * 0.7, true, - i2s(cur_amount) + draw_text( + i2s(total_count_nr), game.sys_assets.fnt_counter, + center, point(size.x * 0.70f, size.y * 0.50f), COLOR_WHITE, + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0, + point(1.0f, 1.0f) + total_amount->get_juice_value() ); }; gui.add_item(total_amount, "total_amount"); @@ -708,10 +701,9 @@ hud_t::hud_t() : gui_item* counters_x = new gui_item(); counters_x->on_draw = [this] (const point & center, const point & size) { - draw_compressed_text( - game.sys_assets.fnt_counter, - map_alpha(game.states.gameplay->hud->standby_items_opacity * 255), - center, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, size, "x" + draw_text( + "x", game.sys_assets.fnt_counter, center, size, + map_alpha(game.states.gameplay->hud->standby_items_opacity * 255) ); }; gui.add_item(counters_x, "counters_x"); @@ -723,9 +715,8 @@ hud_t::hud_t() : counter_slash->on_draw = [this] (const point & center, const point & size) { if(!game.states.gameplay->cur_leader_ptr) return; - draw_compressed_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, size, "/" + draw_text( + "/", game.sys_assets.fnt_counter, center, size ); }; gui.add_item(counter_slash, "counters_slash_" + i2s(s + 1)); @@ -756,14 +747,14 @@ hud_t::hud_t() : } if(top_spray_idx == INVALID) return; - draw_compressed_scaled_text( + draw_text( + "x" + + i2s(game.states.gameplay->spray_stats[top_spray_idx].nr_sprays), game.sys_assets.fnt_counter, + point(center.x - size.x / 2.0, center.y), size, map_alpha(game.states.gameplay->hud->spray_items_opacity * 255), - point(center.x - size.x / 2.0, center.y), - point(1.0f, 1.0f) + spray_1_amount->get_juice_value(), - ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_CENTER, size, true, - "x" + - i2s(game.states.gameplay->spray_stats[top_spray_idx].nr_sprays) + ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_CENTER, 0, + point(1.0f, 1.0f) + spray_1_amount->get_juice_value() ); }; gui.add_item(spray_1_amount, "spray_1_amount"); @@ -836,14 +827,14 @@ hud_t::hud_t() : } if(bottom_spray_idx == INVALID) return; - draw_compressed_scaled_text( + draw_text( + "x" + + i2s(game.states.gameplay->spray_stats[bottom_spray_idx].nr_sprays), game.sys_assets.fnt_counter, + point(center.x - size.x / 2.0, center.y), size, map_alpha(game.states.gameplay->hud->spray_items_opacity * 255), - point(center.x - size.x / 2.0, center.y), - point(1.0f, 1.0f) + spray_2_amount->get_juice_value(), - ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_CENTER, size, true, - "x" + - i2s(game.states.gameplay->spray_stats[bottom_spray_idx].nr_sprays) + ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_CENTER, 0, + point(1.0f, 1.0f) + spray_2_amount->get_juice_value() ); }; gui.add_item(spray_2_amount, "spray_2_amount"); @@ -1014,12 +1005,9 @@ hud_t::hud_t() : mission_goal_cur_label->on_draw = [this, goal_cur_label_text] (const point & center, const point & size) { - draw_compressed_scaled_text( - game.sys_assets.fnt_standard, al_map_rgba(255, 255, 255, 128), - center, point(1.0f, 1.0f), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, - goal_cur_label_text + draw_text( + goal_cur_label_text, game.sys_assets.fnt_standard, + center, size, al_map_rgba(255, 255, 255, 128) ); }; gui.add_item(mission_goal_cur_label, "mission_goal_cur_label"); @@ -1044,13 +1032,10 @@ hud_t::hud_t() : } float juicy_grow_amount = mission_goal_cur->get_juice_value(); - draw_compressed_scaled_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, - point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, - text + draw_text( + text, game.sys_assets.fnt_counter, center, size, + COLOR_WHITE, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0, + point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount) ); }; gui.add_item(mission_goal_cur, "mission_goal_cur"); @@ -1061,12 +1046,9 @@ hud_t::hud_t() : gui_item* mission_goal_req_label = new gui_item(); mission_goal_req_label->on_draw = [this] (const point & center, const point & size) { - draw_compressed_scaled_text( - game.sys_assets.fnt_standard, al_map_rgba(255, 255, 255, 128), - center, point(1.0f, 1.0f), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, - "Goal" + draw_text( + "Goal", game.sys_assets.fnt_standard, center, size, + al_map_rgba(255, 255, 255, 128) ); }; gui.add_item(mission_goal_req_label, "mission_goal_req_label"); @@ -1088,12 +1070,8 @@ hud_t::hud_t() : } else { text = i2s(value); } - draw_compressed_scaled_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, point(1.0f, 1.0f), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, - text + draw_text( + text, game.sys_assets.fnt_counter, center, size ); }; gui.add_item(mission_goal_req, "mission_goal_req"); @@ -1103,12 +1081,8 @@ hud_t::hud_t() : gui_item* mission_goal_slash = new gui_item(); mission_goal_slash->on_draw = [this] (const point & center, const point & size) { - draw_compressed_scaled_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, point(1.0f, 1.0f), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, - "/" + draw_text( + "/", game.sys_assets.fnt_counter, center, size ); }; gui.add_item(mission_goal_slash, "mission_goal_slash"); @@ -1119,13 +1093,10 @@ hud_t::hud_t() : gui_item* mission_goal_name = new gui_item(); mission_goal_name->on_draw = [this] (const point & center, const point & size) { - draw_compressed_scaled_text( - game.sys_assets.fnt_standard, al_map_rgba(255, 255, 255, 128), - center, point(1.0f, 1.0f), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, + draw_text( game.mission_goals[game.cur_area_data.mission.goal]-> - get_name() + get_name(), game.sys_assets.fnt_standard, + center, size, al_map_rgba(255, 255, 255, 128) ); }; gui.add_item(mission_goal_name, "mission_goal_name"); @@ -1159,12 +1130,10 @@ hud_t::hud_t() : gui_item* mission_score_score_label = new gui_item(); mission_score_score_label->on_draw = [this] (const point & center, const point & size) { - draw_compressed_scaled_text( - game.sys_assets.fnt_standard, al_map_rgba(255, 255, 255, 128), - point(center.x + size.x / 2.0f, center.y), point(1.0f, 1.0f), - ALLEGRO_ALIGN_RIGHT, V_ALIGN_MODE_CENTER, - size, true, - "Score:" + draw_text( + "Score:", game.sys_assets.fnt_standard, + point(center.x + size.x / 2.0f, center.y), size, + al_map_rgba(255, 255, 255, 128), ALLEGRO_ALIGN_RIGHT ); }; gui.add_item(mission_score_score_label, "mission_score_score_label"); @@ -1176,13 +1145,11 @@ hud_t::hud_t() : [this, mission_score_points] (const point & center, const point & size) { float juicy_grow_amount = mission_score_points->get_juice_value(); - draw_compressed_scaled_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, - point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, - i2s(game.states.gameplay->mission_score) + draw_text( + i2s(game.states.gameplay->mission_score), + game.sys_assets.fnt_counter, center, size, COLOR_WHITE, + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0, + point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount) ); }; gui.add_item(mission_score_points, "mission_score_points"); @@ -1193,12 +1160,10 @@ hud_t::hud_t() : gui_item* mission_score_points_label = new gui_item(); mission_score_points_label->on_draw = [this] (const point & center, const point & size) { - draw_compressed_scaled_text( - game.sys_assets.fnt_standard, al_map_rgba(255, 255, 255, 128), - point(center.x - size.x / 2.0f, center.y), point(1.0f, 1.0f), - ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_CENTER, - size, true, - "pts" + draw_text( + "pts", game.sys_assets.fnt_standard, + point(center.x + size.x / 2.0f, center.y), size, + al_map_rgba(255, 255, 255, 128), ALLEGRO_ALIGN_RIGHT ); }; gui.add_item(mission_score_points_label, "mission_score_points_label"); @@ -1534,13 +1499,11 @@ void hud_t::create_mission_fail_cond_items(const bool primary) { gui_item* mission_fail_cur_label = new gui_item(); mission_fail_cur_label->on_draw = [this, cond] (const point & center, const point & size) { - draw_compressed_scaled_text( - game.sys_assets.fnt_standard, al_map_rgba(255, 255, 255, 128), - center, point(1.0f, 1.0f), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, + draw_text( game.mission_fail_conds[cond]-> - get_hud_label(game.states.gameplay) + get_hud_label(game.states.gameplay), + game.sys_assets.fnt_standard, center, size, + al_map_rgba(255, 255, 255, 128) ); }; gui.add_item( @@ -1566,13 +1529,10 @@ void hud_t::create_mission_fail_cond_items(const bool primary) { text = i2s(value); } float juicy_grow_amount = mission_fail_cur->get_juice_value(); - draw_compressed_scaled_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, - point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, - text + draw_text( + text, game.sys_assets.fnt_counter, center, size, + COLOR_WHITE, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0, + point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount) ); }; gui.add_item( @@ -1593,12 +1553,9 @@ void hud_t::create_mission_fail_cond_items(const bool primary) { mission_fail_req_label->on_draw = [this] (const point & center, const point & size) { - draw_compressed_scaled_text( - game.sys_assets.fnt_standard, al_map_rgba(255, 255, 255, 128), - center, point(1.0f, 1.0f), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, - "Fail" + draw_text( + "Fail", game.sys_assets.fnt_standard, center, size, + al_map_rgba(255, 255, 255, 128) ); }; gui.add_item( @@ -1622,12 +1579,8 @@ void hud_t::create_mission_fail_cond_items(const bool primary) { } else { text = i2s(value); } - draw_compressed_scaled_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, point(1.0f, 1.0f), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, - text + draw_text( + text, game.sys_assets.fnt_counter, center, size ); }; gui.add_item( @@ -1642,12 +1595,8 @@ void hud_t::create_mission_fail_cond_items(const bool primary) { gui_item* mission_fail_slash = new gui_item(); mission_fail_slash->on_draw = [this] (const point & center, const point & size) { - draw_compressed_scaled_text( - game.sys_assets.fnt_counter, COLOR_WHITE, - center, point(1.0f, 1.0f), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, - "/" + draw_text( + "/", game.sys_assets.fnt_counter, center, size ); }; gui.add_item( @@ -1663,13 +1612,11 @@ void hud_t::create_mission_fail_cond_items(const bool primary) { gui_item* mission_fail_name = new gui_item(); mission_fail_name->on_draw = [this, cond] (const point & center, const point & size) { - draw_compressed_scaled_text( - game.sys_assets.fnt_standard, al_map_rgba(255, 255, 255, 128), - center, point(1.0f, 1.0f), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, + draw_text( "Fail: " + - game.mission_fail_conds[cond]->get_name() + game.mission_fail_conds[cond]->get_name(), + game.sys_assets.fnt_standard, center, size, + al_map_rgba(255, 255, 255, 128) ); }; gui.add_item( diff --git a/Source/source/game_states/gameplay/in_world_hud.cpp b/Source/source/game_states/gameplay/in_world_hud.cpp index 8eb239b2..83deeb54 100644 --- a/Source/source/game_states/gameplay/in_world_hud.cpp +++ b/Source/source/game_states/gameplay/in_world_hud.cpp @@ -35,6 +35,9 @@ const float REQ_MET_GROW_JUICE_AMOUNT = 0.12f; //How long it takes to animate the numbers flashing. const float REQ_MET_JUICE_DURATION = 0.5f; +//Height of one of the fraction's rows. +const float ROW_HEIGHT = 18.0f; + //How long it takes to fade in. const float TRANSITION_IN_DURATION = 0.4f; @@ -132,7 +135,7 @@ void in_world_fraction::draw() { draw_fraction( pos, value_number, requirement_number, - final_color, size_mult + final_color, IN_WORLD_FRACTION::ROW_HEIGHT * 3 * size_mult ); } else { point pos( @@ -141,11 +144,10 @@ void in_world_fraction::draw() { al_get_font_line_height(game.sys_assets.fnt_standard) - IN_WORLD_FRACTION::PADDING ); - draw_scaled_text( - game.sys_assets.fnt_standard, - final_color, pos, - point(size_mult, size_mult), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, i2s(value_number) + draw_text( + i2s(value_number), game.sys_assets.fnt_standard, pos, + point(LARGE_FLOAT, IN_WORLD_FRACTION::ROW_HEIGHT * size_mult), + final_color ); } } diff --git a/Source/source/game_states/gameplay/in_world_hud.h b/Source/source/game_states/gameplay/in_world_hud.h index f3e8e7f0..ac7fa360 100644 --- a/Source/source/game_states/gameplay/in_world_hud.h +++ b/Source/source/game_states/gameplay/in_world_hud.h @@ -21,8 +21,9 @@ namespace IN_WORLD_FRACTION { extern const float GROW_JUICE_DURATION; extern const float GROW_JUICE_AMOUNT; extern const float PADDING; -extern const float REQ_MET_JUICE_DURATION; extern const float REQ_MET_GROW_JUICE_AMOUNT; +extern const float REQ_MET_JUICE_DURATION; +extern const float ROW_HEIGHT; extern const float TRANSITION_IN_DURATION; extern const float TRANSITION_OUT_DURATION; } diff --git a/Source/source/game_states/gameplay/onion_menu.cpp b/Source/source/game_states/gameplay/onion_menu.cpp index 80109075..a7a9d8f6 100644 --- a/Source/source/game_states/gameplay/onion_menu.cpp +++ b/Source/source/game_states/gameplay/onion_menu.cpp @@ -151,15 +151,13 @@ onion_menu_t::onion_menu_t( } float juicy_grow_amount = field_amount_text->get_juice_value(); - draw_compressed_scaled_text( - game.sys_assets.fnt_standard, - color, - center, - point(1.0f + juicy_grow_amount, 1.0f + juicy_grow_amount), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, + draw_text( "Field: " + - i2s(game.states.gameplay->mobs.pikmin_list.size() + total_delta) + i2s(game.states.gameplay->mobs.pikmin_list.size() + total_delta), + game.sys_assets.fnt_standard, center, + size * GUI::STANDARD_CONTENT_SIZE, color, + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0, + point(1.0f + juicy_grow_amount, 1.0f + juicy_grow_amount) ); }; gui.add_item(field_amount_text, "field"); @@ -279,13 +277,12 @@ onion_menu_t::onion_menu_t( } float juicy_grow_amount = onion_amount_text->get_juice_value(); - draw_compressed_scaled_text( - game.sys_assets.fnt_area_name, - color, - center, - point(1.0f + juicy_grow_amount, 1.0f + juicy_grow_amount), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, i2s(real_onion_amount - t_ptr->delta) + draw_text( + i2s(real_onion_amount - t_ptr->delta), + game.sys_assets.fnt_area_name, center, + size * GUI::STANDARD_CONTENT_SIZE, color, + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0, + point(1.0f + juicy_grow_amount, 1.0f + juicy_grow_amount) ); }; gui.add_item(onion_amount_text, "onion_" + i2s(t + 1) + "_amount"); @@ -387,13 +384,12 @@ onion_menu_t::onion_menu_t( } float juicy_grow_amount = group_amount_text->get_juice_value(); - draw_compressed_scaled_text( - game.sys_assets.fnt_area_name, - color, - center, - point(1.0f + juicy_grow_amount, 1.0f + juicy_grow_amount), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, true, i2s(real_group_amount + t_ptr->delta) + draw_text( + i2s(real_group_amount + t_ptr->delta), + game.sys_assets.fnt_area_name, center, + size * GUI::STANDARD_CONTENT_SIZE, color, + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, 0, + point(1.0f + juicy_grow_amount, 1.0f + juicy_grow_amount) ); }; gui.add_item(group_amount_text, "group_" + i2s(t + 1) + "_amount"); diff --git a/Source/source/game_states/gameplay/pause_menu.cpp b/Source/source/game_states/gameplay/pause_menu.cpp index 80a745c4..7a82286a 100644 --- a/Source/source/game_states/gameplay/pause_menu.cpp +++ b/Source/source/game_states/gameplay/pause_menu.cpp @@ -1236,17 +1236,14 @@ void pause_menu_t::draw_radar( north_ind_center.x, north_ind_center.y, 12.0f, PAUSE_MENU::RADAR_BG_COLOR ); - draw_compressed_text( - game.sys_assets.fnt_slim, - PAUSE_MENU::RADAR_HIGHEST_COLOR, + draw_text( + "N", game.sys_assets.fnt_slim, point( north_ind_center.x, north_ind_center.y + 4.0f ), - ALLEGRO_ALIGN_CENTER, - V_ALIGN_MODE_CENTER, point(12.0f, 12.0f), - "N" + PAUSE_MENU::RADAR_HIGHEST_COLOR ); al_draw_filled_triangle( north_ind_center.x, @@ -1271,11 +1268,9 @@ void pause_menu_t::draw_radar( area_name_center, area_name_size, 12.0f, PAUSE_MENU::RADAR_BG_COLOR ); - draw_compressed_text( - game.sys_assets.fnt_standard, PAUSE_MENU::RADAR_HIGHEST_COLOR, - area_name_center, ALLEGRO_ALIGN_CENTER, - V_ALIGN_MODE_CENTER, area_name_size, - game.cur_area_data.name + draw_text( + game.cur_area_data.name, game.sys_assets.fnt_standard, + area_name_center, area_name_size, PAUSE_MENU::RADAR_HIGHEST_COLOR ); //Draw some scan lines. diff --git a/Source/source/game_states/gui_editor/drawing.cpp b/Source/source/game_states/gui_editor/drawing.cpp index b9d27d6c..14fae76d 100644 --- a/Source/source/game_states/gui_editor/drawing.cpp +++ b/Source/source/game_states/gui_editor/drawing.cpp @@ -92,22 +92,16 @@ void gui_editor::draw_canvas() { orig_clip_x, orig_clip_y, orig_clip_w, orig_clip_h, clip_x, clip_y, clip_w, clip_h ); - draw_scaled_text( - game.sys_assets.fnt_builtin, - al_map_rgb(40, 40, 96), + draw_text( + items[i].name, game.sys_assets.fnt_builtin, point( (items[i].center.x - items[i].size.x / 2.0f) + (4.0f / game.cam.zoom), (items[i].center.y - items[i].size.y / 2.0f) + (4.0f / game.cam.zoom) ), - point( - 1.0f / game.cam.zoom, - 1.0f / game.cam.zoom - ), - ALLEGRO_ALIGN_LEFT, - V_ALIGN_MODE_TOP, - items[i].name + point(LARGE_FLOAT, 8.0 / game.cam.zoom), + al_map_rgb(40, 40, 96), ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_TOP ); al_set_clipping_rectangle( orig_clip_x, orig_clip_y, orig_clip_w, orig_clip_h diff --git a/Source/source/game_states/main_menu.cpp b/Source/source/game_states/main_menu.cpp index db718e86..e60a1f5f 100644 --- a/Source/source/game_states/main_menu.cpp +++ b/Source/source/game_states/main_menu.cpp @@ -69,12 +69,12 @@ void main_menu_state::do_drawing() { ); } - draw_scaled_text( - game.sys_assets.fnt_standard, COLOR_WHITE, + draw_text( + "Pikifen and contents are fan works. Pikmin is (c) Nintendo.", + game.sys_assets.fnt_standard, point(8, game.win_h - 8), - point(0.6, 0.6), - ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_BOTTOM, - "Pikmin (c) Nintendo" + point(game.win_w * 0.45f, game.win_h * 0.02f), COLOR_WHITE, + ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_BOTTOM ); string version_text; if(!game.config.name.empty()) { @@ -86,12 +86,11 @@ void main_menu_state::do_drawing() { } version_text += "Pikifen " + get_engine_version_string(); - draw_scaled_text( - game.sys_assets.fnt_standard, COLOR_WHITE, + draw_text( + version_text, game.sys_assets.fnt_standard, point(game.win_w - 8, game.win_h - 8), - point(0.6, 0.6), - ALLEGRO_ALIGN_RIGHT, V_ALIGN_MODE_BOTTOM, - version_text + point(game.win_w * 0.45f, game.win_h * 0.02f), COLOR_WHITE, + ALLEGRO_ALIGN_RIGHT, V_ALIGN_MODE_BOTTOM ); main_gui.draw(); diff --git a/Source/source/gui.cpp b/Source/source/gui.cpp index fb929f06..6b2332c2 100644 --- a/Source/source/gui.cpp +++ b/Source/source/gui.cpp @@ -55,6 +55,9 @@ const float JUICY_GROW_TEXT_LOW_MULT = 0.02f; //Grow scale multiplier for a juicy text medium grow animation. const float JUICY_GROW_TEXT_MEDIUM_MULT = 0.05f; +//Standard size of the content inside of a GUI item, in ratio. +const float STANDARD_CONTENT_SIZE = 0.80f; + } @@ -93,12 +96,13 @@ bullet_point_gui_item::bullet_point_gui_item( this->color ); float juicy_grow_amount = get_juice_value(); - draw_compressed_scaled_text( - this->font, this->color, + draw_text( + this->text, this->font, point(item_x_start + text_x_offset, center.y), - point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount), - ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_CENTER, text_space, true, - this->text + text_space * GUI::STANDARD_CONTENT_SIZE, + this->color, ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_CENTER, + TEXT_SETTING_FLAG_CANT_GROW, + point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount) ); if(selected) { draw_textured_box( @@ -157,12 +161,13 @@ check_gui_item::check_gui_item( on_draw = [this] (const point & center, const point & size) { float juicy_grow_amount = get_juice_value(); - draw_compressed_scaled_text( - this->font, this->color, + draw_text( + this->text, this->font, point(center.x - size.x * 0.45, center.y), - point(1.0f + juicy_grow_amount, 1.0f + juicy_grow_amount), - ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_CENTER, - point(size.x * 0.90, size.y), true, this->text + point(size.x * 0.95, size.y) * GUI::STANDARD_CONTENT_SIZE, + this->color, ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_CENTER, + TEXT_SETTING_FLAG_CANT_GROW, + point(1.0f + juicy_grow_amount, 1.0f + juicy_grow_amount) ); draw_bitmap( @@ -1372,48 +1377,54 @@ picker_gui_item::picker_gui_item( } ALLEGRO_COLOR arrow_highlight_color = al_map_rgb(87, 200, 208); ALLEGRO_COLOR arrow_regular_color = COLOR_WHITE; - point arrow_highlight_size = point(1.4f, 1.4f); - point arrow_regular_size = point(1.0f, 1.0f); + point arrow_highlight_scale = point(1.4f, 1.4f); + point arrow_regular_scale = point(1.0f, 1.0f); - draw_compressed_scaled_text( + point arrow_box( + size.x * 0.10 * GUI::STANDARD_CONTENT_SIZE, + size.y * GUI::STANDARD_CONTENT_SIZE + ); + draw_text( + "<", game.sys_assets.fnt_standard, + point(center.x - size.x * 0.45, center.y), + arrow_box, real_arrow_highlight == 0 ? arrow_highlight_color : arrow_regular_color, - point(center.x - size.x * 0.45, center.y), - real_arrow_highlight == 0 ? - arrow_highlight_size : - arrow_regular_size, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, - false, - "<" + TEXT_SETTING_FLAG_CANT_GROW, + real_arrow_highlight == 0 ? + arrow_highlight_scale : + arrow_regular_scale ); - draw_compressed_scaled_text( + draw_text( + ">", game.sys_assets.fnt_standard, + point(center.x + size.x * 0.45, center.y), + arrow_box, real_arrow_highlight == 1 ? arrow_highlight_color : arrow_regular_color, - point(center.x + size.x * 0.45, center.y), - real_arrow_highlight == 1 ? - arrow_highlight_size : - arrow_regular_size, ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, - size, - false, - ">" + TEXT_SETTING_FLAG_CANT_GROW, + real_arrow_highlight == 1 ? + arrow_highlight_scale : + arrow_regular_scale ); float juicy_grow_amount = this->get_juice_value(); - draw_compressed_scaled_text( - game.sys_assets.fnt_standard, COLOR_WHITE, + point text_box(size.x * 0.80, size.y * GUI::STANDARD_CONTENT_SIZE); + draw_text( + this->base_text + this->option, + game.sys_assets.fnt_standard, point(center.x - size.x * 0.40, center.y), - point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount), + text_box, + COLOR_WHITE, ALLEGRO_ALIGN_LEFT, V_ALIGN_MODE_CENTER, - point(size.x * 0.80, size.y), - true, - this->base_text + this->option + TEXT_SETTING_FLAG_CANT_GROW, + point(1.0f + juicy_grow_amount, 1.0f + juicy_grow_amount) ); ALLEGRO_COLOR box_tint = @@ -1586,12 +1597,11 @@ text_gui_item::text_gui_item( } else { - draw_compressed_scaled_text( - this->font, this->color, - point(text_x, text_y), - point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount), - this->flags, V_ALIGN_MODE_CENTER, size, true, - this->text + draw_text( + this->text, this->font, point(text_x, text_y), size, + this->color, this->flags, V_ALIGN_MODE_CENTER, + TEXT_SETTING_FLAG_CANT_GROW, + point(1.0 + juicy_grow_amount, 1.0 + juicy_grow_amount) ); } @@ -1624,13 +1634,15 @@ tooltip_gui_item::tooltip_gui_item(gui_manager* gui) : this->prev_text = cur_text; } float juicy_grow_amount = get_juice_value(); - draw_compressed_scaled_text( - game.sys_assets.fnt_standard, COLOR_WHITE, + draw_text( + cur_text, + game.sys_assets.fnt_standard, center, - point(0.7f + juicy_grow_amount, 0.7f + juicy_grow_amount), - ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, size, - false, - cur_text + size, + COLOR_WHITE, + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, + TEXT_SETTING_FLAG_CANT_GROW, + point(0.7f + juicy_grow_amount, 0.7f + juicy_grow_amount) ); }; } diff --git a/Source/source/gui.h b/Source/source/gui.h index 055cd8cb..0b23d69f 100644 --- a/Source/source/gui.h +++ b/Source/source/gui.h @@ -43,6 +43,7 @@ extern const float JUICY_GROW_ICON_MULT; extern const float JUICY_GROW_TEXT_HIGH_MULT; extern const float JUICY_GROW_TEXT_LOW_MULT; extern const float JUICY_GROW_TEXT_MEDIUM_MULT; +extern const float STANDARD_CONTENT_SIZE; } diff --git a/Source/source/misc_structs.cpp b/Source/source/misc_structs.cpp index cc091917..cd379918 100644 --- a/Source/source/misc_structs.cpp +++ b/Source/source/misc_structs.cpp @@ -726,20 +726,18 @@ void notification_t::draw() const { ); } - draw_compressed_text( - game.sys_assets.fnt_standard, - map_alpha(DRAWING::NOTIFICATION_ALPHA * visibility), + draw_text( + text, game.sys_assets.fnt_standard, point( (text_box_x1 + text_box_x2) * 0.5, (text_box_y1 + text_box_y2) * 0.5 ), - ALLEGRO_ALIGN_CENTER, - V_ALIGN_MODE_CENTER, point( text_box_x2 - text_box_x1, text_box_y2 - text_box_y1 ), - text + map_alpha(DRAWING::NOTIFICATION_ALPHA * visibility), + ALLEGRO_ALIGN_CENTER, V_ALIGN_MODE_CENTER, TEXT_SETTING_FLAG_CANT_GROW ); al_use_transform(&old_tra); diff --git a/Source/source/utils/drawing_utils.cpp b/Source/source/utils/drawing_utils.cpp index f761fcc6..63962707 100644 --- a/Source/source/utils/drawing_utils.cpp +++ b/Source/source/utils/drawing_utils.cpp @@ -82,129 +82,6 @@ void draw_bitmap_in_box( } -/** - * @brief Draws text, scaled, but also compresses (scales) it - * to fit within the specified range. - * - * @param font Font to use. - * @param color Tint the text by this color. - * @param where Coordinates to draw it at. - * @param scale Scale to use. - * @param flags Allegro text render function flags. - * @param v_align Vertical alignment. - * @param max_size The maximum width and height. Use <= 0 to have no limit. - * @param scale_past_max If true, the max size will only be taken into - * account when the scale is 1. If it is any bigger, it will overflow - * past the max size. - * @param text Text to draw. - */ -void draw_compressed_scaled_text( - const ALLEGRO_FONT* const font, const ALLEGRO_COLOR &color, - const point &where, const point &scale, - const int flags, const V_ALIGN_MODE v_align, - const point &max_size, const bool scale_past_max, const string &text -) { - - if(max_size.x == 0.0f && max_size.y == 0.0f) return; - - int text_ox; - int text_oy; - int text_w; - int text_h; - al_get_text_dimensions( - font, text.c_str(), - &text_ox, &text_oy, &text_w, &text_h - ); - - point normal_text_size(text_w, text_h); - point text_size_to_check = normal_text_size; - point final_scale(1.0f, 1.0f); - - if(!scale_past_max) { - final_scale = scale; - text_size_to_check = normal_text_size * scale; - } - - if(max_size.x > 0 && text_size_to_check.x > max_size.x) { - final_scale.x = max_size.x / normal_text_size.x; - } - if(max_size.y > 0 && text_size_to_check.y > max_size.y) { - final_scale.y = max_size.y / normal_text_size.y; - } - - if(scale_past_max) { - final_scale = final_scale * scale; - } - - float final_text_height = normal_text_size.y * final_scale.y; - float v_align_offset = - get_vertical_align_offset(v_align, final_text_height); - - ALLEGRO_TRANSFORM text_transform, old_transform; - get_text_drawing_transforms( - where, final_scale, 0.0f, v_align_offset, - &text_transform, &old_transform - ); - - al_use_transform(&text_transform); { - al_draw_text(font, color, 0, 0, flags, text.c_str()); - }; al_use_transform(&old_transform); -} - - -/** - * @brief Draws text on the screen, but compresses (scales) it - * to fit within the specified range. - * - * @param font Font to use. - * @param color Tint the text by this color. - * @param where Coordinates to draw it at. - * @param flags Allegro text render function flags. - * @param v_align Vertical alignment. - * @param max_size The maximum width and height. Use <= 0 to have no limit. - * @param text Text to draw. - */ -void draw_compressed_text( - const ALLEGRO_FONT* const font, const ALLEGRO_COLOR &color, - const point &where, const int flags, const V_ALIGN_MODE v_align, - const point &max_size, const string &text -) { - if(max_size.x == 0 && max_size.y == 0) return; - - int text_ox; - int text_oy; - int text_w; - int text_h; - al_get_text_dimensions( - font, text.c_str(), - &text_ox, &text_oy, &text_w, &text_h - ); - point scale(1.0, 1.0); - float final_text_height = text_h; - - if(text_w > max_size.x && max_size.x > 0) { - scale.x = max_size.x / text_w; - } - if(text_h > max_size.y && max_size.y > 0) { - scale.y = max_size.y / text_h; - final_text_height = max_size.y; - } - - float v_align_offset = - get_vertical_align_offset(v_align, final_text_height); - - ALLEGRO_TRANSFORM text_transform, old_transform; - get_text_drawing_transforms( - where, scale, text_oy, v_align_offset, - &text_transform, &old_transform - ); - - al_use_transform(&text_transform); { - al_draw_text(font, color, 0, 0, flags, text.c_str()); - }; al_use_transform(&old_transform); -} - - /** * @brief Draws an equilateral triangle made of three lines. * @@ -356,35 +233,6 @@ void draw_rounded_rectangle( } -/** - * @brief Draws text, scaled. - * - * @param font Font to use. - * @param color Tint the text with this color. - * @param where Coordinates to draw in. - * @param scale Horizontal or vertical scale. - * @param flags Same flags you'd use for al_draw_text. - * @param v_align Vertical alignment. - * @param text Text to draw. - */ -void draw_scaled_text( - const ALLEGRO_FONT* const font, const ALLEGRO_COLOR &color, - const point &where, const point &scale, - const int flags, const V_ALIGN_MODE v_align, const string &text -) { - - ALLEGRO_TRANSFORM text_transform, old_transform; - get_text_drawing_transforms( - where, scale, 0.0f, 0.0f, - &text_transform, &old_transform - ); - - al_use_transform(&text_transform); { - draw_text_lines(font, color, point(), flags, v_align, text); - }; al_use_transform(&old_transform); -} - - /** * @brief Draws plain text, scaled as necessary. * @@ -443,7 +291,10 @@ void draw_text( get_text_drawing_transforms( where, text_final_scale * further_scale, - text_orig_oy, v_align_offset * further_scale.y, + has_flag(settings, TEXT_SETTING_COMPENSATE_Y_OFFSET) ? + text_orig_oy : + 0.0f, + v_align_offset * further_scale.y, &text_transform, &old_transform ); @@ -457,41 +308,72 @@ void draw_text( /** * @brief Draws text, but if there are line breaks, * it'll draw every line one under the other. - * It basically calls Allegro's text drawing functions, but for each line. * + * @param text Text to draw. * @param font Font to use. - * @param color Color. - * @param where Coordinates of the text. - * @param flags Flags, just like the ones you'd pass to al_draw_text. + * @param where Coordinates to draw it at. + * @param box_size Size of the box it must be scaled to. + * @param color Tint the text with this color. + * @param text_flags Allegro text drawing function flags. * @param v_align Vertical alignment. - * @param text Text to write, line breaks included ('\n'). + * @param settings Settings to control how the text can be scaled. + * Use TEXT_SETTING_FLAG. + * @param further_scale After calculating everything, further scale the + * text by this much before drawing. */ void draw_text_lines( - const ALLEGRO_FONT* const font, const ALLEGRO_COLOR &color, - const point &where, const int flags, - const V_ALIGN_MODE v_align, const string &text + const string &text, const ALLEGRO_FONT* const font, + const point &where, const point &box_size, const ALLEGRO_COLOR &color, + int text_flags, V_ALIGN_MODE v_align, bitmask_8_t settings, + const point &further_scale ) { + //Initial checks. + if(text.empty()) return; + if(box_size.x == 0 || box_size.y == 0) return; + vector lines = split(text, "\n", true); - int fh = al_get_font_line_height(font); - size_t n_lines = lines.size(); - float top; - if(v_align == V_ALIGN_MODE_TOP) { - top = where.y; - } else { - //We add n_lines - 1 because there is a 1px gap between each line. - int total_height = (int) n_lines * fh + (int) (n_lines - 1); - if(v_align == V_ALIGN_MODE_CENTER) { - top = where.y - total_height / 2; - } else { - top = where.y - total_height; - } - } + //Get the basic text information. + int total_orig_width = 0; + int total_orig_height = 0; + int line_orig_height = 0; + get_multiline_text_dimensions( + lines, font, &total_orig_width, &total_orig_height, &line_orig_height + ); + point total_orig_size(total_orig_width, total_orig_height); - for(size_t l = 0; l < n_lines; ++l) { - float line_y = (fh + 1) * l + top; - al_draw_text(font, color, where.x, line_y, flags, lines[l].c_str()); - } + //Figure out the scales. + point total_final_scale = + scale_rectangle_to_box( + total_orig_size, box_size, + !has_flag(settings, TEXT_SETTING_FLAG_CANT_GROW_X), + !has_flag(settings, TEXT_SETTING_FLAG_CANT_GROW_Y), + !has_flag(settings, TEXT_SETTING_FLAG_CANT_SHRINK_X), + !has_flag(settings, TEXT_SETTING_FLAG_CANT_SHRINK_Y), + has_flag(settings, TEXT_SETTING_FLAG_CAN_CHANGE_RATIO) + ); + point total_final_size = total_orig_size * total_final_scale; + + //Figure out offsets. + float v_align_offset = + get_vertical_align_offset(v_align, total_final_size.y); + + //Create the transformation. + ALLEGRO_TRANSFORM text_transform, old_transform; + get_text_drawing_transforms( + where, + total_final_scale * further_scale, + 0.0f, v_align_offset * further_scale.y, + &text_transform, &old_transform + ); + + //Draw! + al_use_transform(&text_transform); { + for(size_t l = 0; l < lines.size(); ++l) { + float line_y = (line_orig_height + 1) * l; + al_draw_text(font, color, 0, line_y, text_flags, lines[l].c_str()); + } + }; al_use_transform(&old_transform); } @@ -644,6 +526,44 @@ void draw_textured_box( } +/** + * @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 lines The text lines. + * @param font The text's font. + * @param out_width If not nullptr, the width is returned here. + * @param out_height If not nullptr, the height is returned here. + * @param out_line_height If not nullptr, the line height is returned here. + */ +void get_multiline_text_dimensions( + const vector &lines, const ALLEGRO_FONT* const font, + int* out_width, int* out_height, int* out_line_height +) { + int lh = al_get_font_line_height(font); + size_t n_lines = lines.size(); + + if(out_height) *out_height = std::max(0, (int) ((lh + 1) * n_lines) - 1); + + if(out_width) { + 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_width = largest_w; + } + + if(out_line_height) *out_line_height = lh; +} + + /** * @brief Returns the Allegro transform to use to draw text in the * specified way. diff --git a/Source/source/utils/drawing_utils.h b/Source/source/utils/drawing_utils.h index 0f3b9d1a..5ab57ebc 100644 --- a/Source/source/utils/drawing_utils.h +++ b/Source/source/utils/drawing_utils.h @@ -52,6 +52,9 @@ enum TEXT_SETTING_FLAG { //If necessary, the text's aspect ratio can be changed. TEXT_SETTING_FLAG_CAN_CHANGE_RATIO = 1 << 4, + //Compensate for the Y offset given by the font, by removing it. + TEXT_SETTING_COMPENSATE_Y_OFFSET = 1 << 5, + //Utility flag -- The text can never be grown in any way. TEXT_SETTING_FLAG_CANT_GROW = TEXT_SETTING_FLAG_CANT_GROW_X | @@ -90,17 +93,6 @@ void draw_bitmap_in_box( const float angle = 0, const ALLEGRO_COLOR &tint = COLOR_WHITE ); -void draw_compressed_scaled_text( - const ALLEGRO_FONT* const font, const ALLEGRO_COLOR &color, - const point &where, const point &scale, - const int flags, const V_ALIGN_MODE v_align, - const point &max_size, const bool scale_past_max, const string &text -); -void draw_compressed_text( - const ALLEGRO_FONT* const font, const ALLEGRO_COLOR &color, - const point &where, const int flags, const V_ALIGN_MODE v_align, - const point &max_size, const string &text -); void draw_equilateral_triangle( const point ¢er, float radius, float angle, const ALLEGRO_COLOR &color, float thickness @@ -124,11 +116,6 @@ void draw_rounded_rectangle( const point ¢er, const point &size, const float radii, const ALLEGRO_COLOR &color, const float thickness ); -void draw_scaled_text( - const ALLEGRO_FONT* const font, const ALLEGRO_COLOR &color, - const point &where, const point &scale, - const int flags, const V_ALIGN_MODE v_align, const string &text -); void draw_text( const string &text, const ALLEGRO_FONT* const font, const point &where, const point &box_size, @@ -138,14 +125,21 @@ void draw_text( const point &further_scale = point(1.0f, 1.0f) ); void draw_text_lines( - const ALLEGRO_FONT* const font, const ALLEGRO_COLOR &color, - const point &where, const int flags, const V_ALIGN_MODE v_align, - const string &text + const string &text, const ALLEGRO_FONT* const font, + const point &where, const point &box_size, + const ALLEGRO_COLOR &color = COLOR_WHITE, + int text_flags = ALLEGRO_ALIGN_CENTER, + V_ALIGN_MODE v_align = V_ALIGN_MODE_CENTER, bitmask_8_t settings = 0, + const point &further_scale = point(1.0f, 1.0f) ); void draw_textured_box( const point ¢er, const point &size, ALLEGRO_BITMAP* texture, const ALLEGRO_COLOR &tint = COLOR_WHITE ); +void get_multiline_text_dimensions( + const vector &lines, const ALLEGRO_FONT* const font, + int* out_width, int* out_height, int* out_line_height +); void get_text_drawing_transforms( const point &where, const point &scale, float text_orig_oy, float v_align_offset,