AGS: Use real font height for speech & dialog option bitmap sizes

From upstream 22af623cadce89ac27777cf2178649a71fc2a345
This commit is contained in:
Paul Gilbert 2022-03-23 20:50:27 -07:00
parent d378ce6d89
commit 86f3f8933b
7 changed files with 29 additions and 21 deletions

View File

@ -360,7 +360,7 @@ int write_dialog_options(Bitmap *ds, bool ds_has_alpha, int dlgxp, int curyp, in
needheight = 0;\
for (int i = 0; i < numdisp; ++i) {\
break_up_text_into_lines(get_translation(dtop->optionnames[(int)disporder[i]]), _GP(Lines), areawid-(2*padding+2+bullet_wid), usingfont);\
needheight += getheightoflines(usingfont, _GP(Lines).Count()) + data_to_game_coord(_GP(game).options[OPT_DIALOGGAP]);\
needheight += get_text_lines_surf_height(usingfont, _GP(Lines).Count()) + data_to_game_coord(_GP(game).options[OPT_DIALOGGAP]);\
}\
if (parserInput) needheight += parserInput->Height + data_to_game_coord(_GP(game).options[OPT_DIALOGGAP]);\
}

View File

@ -63,9 +63,8 @@ using namespace AGS::Shared;
using namespace AGS::Shared::BitmapHelper;
struct DisplayVars {
int lineheight; // font's height of single line
int linespacing; // font's line spacing
int fulltxtheight; // total height of all the text
int linespacing = 0; // font's line spacing
int fulltxtheight = 0; // total height of all the text
} disp;
// Pass yy = -1 to find Y co-ord automatically
@ -100,9 +99,8 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
ensure_text_valid_for_font(todis, usingfont);
break_up_text_into_lines(todis, _GP(Lines), wii - 2 * padding, usingfont);
disp.lineheight = get_font_height_outlined(usingfont);
disp.linespacing = get_font_linespacing(usingfont);
disp.fulltxtheight = getheightoflines(usingfont, _GP(Lines).Count());
disp.fulltxtheight = get_text_lines_surf_height(usingfont, _GP(Lines).Count());
// AGS 2.x: If the screen is faded out, fade in again when displaying a message box.
if (!asspch && (_G(loaded_game_file_version) <= kGameVersion_272))
@ -563,10 +561,6 @@ int get_font_outline_padding(int font) {
return 0;
}
int getheightoflines(int font, int numlines) {
return get_font_linespacing(font) * (numlines - 1) + get_font_height_outlined(font);
}
int get_text_width_outlined(const char *tex, int font) {
return get_text_width(tex, font) + 2 * get_font_outline_padding(font);
}

View File

@ -52,8 +52,6 @@ int GetTextDisplayTime(const char *text, int canberel = 0);
// Draw an outline if requested, then draw the text on top
void wouttext_outline(Shared::Bitmap *ds, int xxp, int yyp, int usingfont, color_t text_color, const char *texx);
void wouttext_aligned(Shared::Bitmap *ds, int usexp, int yy, int oriwid, int usingfont, color_t text_color, const char *text, HorAlignment align);
// Gets the total maximal height of the given number of lines printed with the given font
int getheightoflines(int font, int numlines);
// Get the maximal width of the given font, with corresponding outlining
int get_text_width_outlined(const char *tex, int font);
void do_corner(Shared::Bitmap *ds, int sprn, int xx1, int yy1, int typx, int typy);

View File

@ -1924,14 +1924,13 @@ PBitmap draw_room_background(Viewport *view, const SpriteTransform &room_trans)
return _GP(CameraDrawData)[view_index].Frame;
}
void draw_fps(const Rect &viewport) {
// TODO: make allocated "fps struct" instead of using static vars!!
static IDriverDependantBitmap *ddb = nullptr;
static Bitmap *fpsDisplay = nullptr;
const int font = FONT_NORMAL;
if (fpsDisplay == nullptr) {
fpsDisplay = CreateCompatBitmap(viewport.GetWidth(), (get_font_height_outlined(font) + get_fixed_pixel_size(5)));
fpsDisplay = CreateCompatBitmap(viewport.GetWidth(), (get_font_surface_height(font) + get_fixed_pixel_size(5)));
}
fpsDisplay->ClearTransparent();
@ -2268,7 +2267,7 @@ void construct_engine_overlay() {
const int font = FONT_NORMAL;
int ypp = 1;
int txtspacing = get_font_linespacing(font);
int barheight = getheightoflines(font, DEBUG_CONSOLE_NUMLINES - 1) + 4;
int barheight = get_text_lines_surf_height(font, DEBUG_CONSOLE_NUMLINES - 1) + 4;
if (_G(debugConsoleBuffer) == nullptr) {
_G(debugConsoleBuffer) = CreateCompatBitmap(viewport.GetWidth(), barheight);

View File

@ -40,9 +40,6 @@ namespace AGS3 {
using namespace AGS::Shared;
int IsGUIOn(int guinum) {
if ((guinum < 0) || (guinum >= _GP(game).numgui))
quit("!IsGUIOn: invalid GUI number specified");
@ -187,7 +184,7 @@ int GetTextHeight(const char *text, int fontnum, int width) {
if (break_up_text_into_lines(text, _GP(Lines), data_to_game_coord(width), fontnum) == 0)
return 0;
return game_to_data_coord(getheightoflines(fontnum, _GP(Lines).Count()));
return game_to_data_coord(get_text_lines_height(fontnum, _GP(Lines).Count()));
}
int GetFontHeight(int fontnum) {

View File

@ -224,6 +224,22 @@ void set_font_linespacing(size_t fontNumber, int spacing) {
}
}
int get_text_lines_height(size_t fontNumber, size_t numlines) {
if (fontNumber >= _GP(fonts).size() || numlines == 0)
return 0;
return _GP(fonts)[fontNumber].LineSpacingCalc * (numlines - 1) +
(_GP(fonts)[fontNumber].Metrics.CompatHeight +
2 * _GP(fonts)[fontNumber].Info.AutoOutlineThickness);
}
int get_text_lines_surf_height(size_t fontNumber, size_t numlines) {
if (fontNumber >= _GP(fonts).size() || numlines == 0)
return 0;
return _GP(fonts)[fontNumber].LineSpacingCalc * (numlines - 1) +
(_GP(fonts)[fontNumber].Metrics.RealHeight +
2 * _GP(fonts)[fontNumber].Info.AutoOutlineThickness);
}
// Project-dependent implementation
extern int get_text_width_outlined(const char *tex, int font);

View File

@ -97,8 +97,6 @@ int get_text_width(const char *texx, size_t fontNumber);
// note that this is a "formal" font height, that may have different value
// depending on compatibility mode (used when running old games);
int get_font_height(size_t fontNumber);
// TODO: GUI classes located in Common library do not make use of outlining,
// need to find a way to make all code use same functions.
// Get the maximal height of the given font, with corresponding outlining
int get_font_height_outlined(size_t fontNumber);
// Get font's surface height: this always returns the height enough to accomodate
@ -112,6 +110,12 @@ void set_font_linespacing(size_t fontNumber, int spacing);
int get_font_outline(size_t font_number);
// Get font's automatic outline thickness (if set)
int get_font_outline_thickness(size_t font_number);
// Gets the total maximal height of the given number of lines printed with the given font;
// note that this uses formal font height, for compatibility purposes
int get_text_lines_height(size_t fontNumber, size_t numlines);
// Gets the height of a graphic surface enough to accomodate this number of text lines;
// note this accounts for the real pixel font height
int get_text_lines_surf_height(size_t fontNumber, size_t numlines);
// get the source font associated with an outline font
int get_font_outline_font(size_t font_number);
// Set font's outline type