Add Font_ReducePadding method

Instead of drawing bitmapped font with large padding and then adjusting v1/v2 in the final texture, this method simply reduces the padding the bitmapped font gets drawn with
This commit is contained in:
UnknownShadow200 2019-09-05 08:21:52 +10:00
parent c2e5e17109
commit eba6ddd138
8 changed files with 14 additions and 11 deletions

View file

@ -139,13 +139,20 @@ void Drawer2D_SetFontBitmap(Bitmap* bmp) {
Drawer2D_CalculateTextWidths();
}
void Font_ReducePadding(struct FontDesc* desc, int scale) {
int padding;
if (!Drawer2D_BitmappedText) return;
padding = (desc->height - desc->size) / scale;
desc->height -= padding * 2;
}
/* Measures width of the given text when drawn with the given system font. */
static int Font_SysTextWidth(struct DrawTextArgs* args);
/* Draws the given text with the given system font onto the given bitmap. */
static int Font_SysTextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, BitmapCol col, bool shadow);
/*########################################################################################################################*
*---------------------------------------------------Drawing functions-----------------------------------------------------*
*#########################################################################################################################*/

View file

@ -101,6 +101,8 @@ void Drawer2D_SetFontBitmap(Bitmap* bmp);
/* Gets the list of all supported system font names on this platform. */
void Font_GetNames(StringsBuffer* buffer);
/* Reduces padding for a bitmapped font. */
void Font_ReducePadding(struct FontDesc* desc, int scale);
/* Finds the path and face number of the given system font, with closest matching style */
String Font_Lookup(const String* fontName, int style);
/* Allocates a new system font from the given arguments. */

View file

@ -341,7 +341,6 @@ void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, struct FontDes
}
Mem_Free(bmp.Scan0);
Drawer2D_ReducePadding_Tex(&atlas->tex, font->size, 4);
atlas->uScale = 1.0f / (float)bmp.Width;
atlas->tex.uv.U2 = atlas->offset * atlas->uScale;
atlas->tex.Width = atlas->offset;

View file

@ -2807,6 +2807,7 @@ static void TexIdsOverlay_ContextRecreated(void* screen) {
s->dynamicVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, TEXID_OVERLAY_VERTICES_COUNT);
Drawer2D_MakeFont(&textFont, 8, FONT_STYLE_NORMAL);
Font_ReducePadding(&textFont, 4);
TextAtlas_Make(&s->idAtlas, &chars, &textFont, &prefix);
Font_Free(&textFont);

View file

@ -107,8 +107,8 @@ static int Program_Run(int argc, char** argv) {
#ifdef _MSC_VER
/* NOTE: Make sure to comment this out before pushing a commit */
//String rawArgs = String_FromConst("UnknownShadow200 fffff 127.0.0.1 25565");
//String rawArgs = String_FromConst("UnknownShadow200");
//argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4);
String rawArgs = String_FromConst("UnknownShadow200");
argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4);
#endif
if (argsCount == 0) {

View file

@ -355,10 +355,10 @@ static void StatusScreen_ContextRecreated(void* screen) {
struct TextWidget* line2 = &s->line2;
int y;
Drawer2D_MakeFont(&s->font, 16, FONT_STYLE_NORMAL);
Font_ReducePadding(&s->font, 4);
y = 2;
TextWidget_Make(line1, ANCHOR_MIN, ANCHOR_MIN, 2, y);
line1->reducePadding = true;
StatusScreen_Update(s, 1.0);
y += line1->height;
@ -367,7 +367,6 @@ static void StatusScreen_ContextRecreated(void* screen) {
y += s->posAtlas.tex.Height;
TextWidget_Make(line2, ANCHOR_MIN, ANCHOR_MIN, 2, y);
line2->reducePadding = true;
if (Game_ClassicMode) {
/* Swap around so 0.30 version is at top */

View file

@ -70,10 +70,6 @@ void TextWidget_Set(struct TextWidget* w, const String* text, struct FontDesc* f
Drawer2D_MakeTextTexture(&w->tex, &args);
}
if (w->reducePadding) {
Drawer2D_ReducePadding_Tex(&w->tex, font->size, 4);
}
w->width = w->tex.Width; w->height = w->tex.Height;
Widget_Reposition(w);
}

View file

@ -13,7 +13,6 @@ struct FontDesc;
struct TextWidget {
Widget_Layout
struct Texture tex;
bool reducePadding;
PackedCol col;
};
/* Initialises a text widget. */