Take FontDesc out of Core.h and remove its Typedef

This commit is contained in:
UnknownShadow200 2019-08-29 13:28:28 +10:00
parent aac15edbab
commit 12833fdaa5
16 changed files with 109 additions and 107 deletions

View File

@ -119,7 +119,6 @@ typedef cc_uint64 TimeMS;
typedef struct Rect2D_ { int X, Y, Width, Height; } Rect2D;
typedef struct Size2D_ { int Width, Height; } Size2D;
typedef struct FontDesc_ { void* Handle; cc_uint16 Size, Style; } FontDesc;
typedef struct TextureRec_ { float U1, V1, U2, V2; } TextureRec;
/*#define CC_BUILD_GL11*/

View File

@ -19,13 +19,13 @@ BitmapCol Drawer2D_Cols[DRAWER2D_MAX_COLS];
static char fontNameBuffer[STRING_SIZE];
String Drawer2D_FontName = String_FromArray(fontNameBuffer);
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const String* text, FontDesc* font, bool useShadow) {
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const String* text, struct FontDesc* font, bool useShadow) {
args->text = *text;
args->font = font;
args->useShadow = useShadow;
}
void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, FontDesc* font, bool useShadow) {
void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, struct FontDesc* font, bool useShadow) {
args->text = String_Empty;
args->font = font;
args->useShadow = useShadow;
@ -47,14 +47,14 @@ static String font_candidates[9] = {
String_FromConst("Roboto") /* android */
};
void Drawer2D_MakeFont(FontDesc* desc, int size, int style) {
void Drawer2D_MakeFont(struct FontDesc* desc, int size, int style) {
int i;
ReturnCode res;
if (Drawer2D_BitmappedText) {
desc->Handle = NULL;
desc->Size = size;
desc->Style = style;
desc->handle = NULL;
desc->size = size;
desc->style = style;
} else {
font_candidates[0] = Drawer2D_FontName;
@ -138,7 +138,7 @@ void Drawer2D_SetFontBitmap(Bitmap* bmp) {
/* Measures width of the given text when drawn with the given system font. */
static int Font_SysTextWidth(struct DrawTextArgs* args);
/* Measures height of any text when drawn with the given system font. */
static int Font_SysFontHeight(const FontDesc* desc);
static int Font_SysFontHeight(const struct FontDesc* desc);
/* 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);
@ -427,7 +427,7 @@ static void Drawer2D_DrawCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int
BitmapCol black = BITMAPCOL_CONST(0, 0, 0, 255);
BitmapCol col;
String text = args->text;
int i, point = args->font->Size, count = 0;
int i, point = args->font->size, count = 0;
int xPadding, yPadding;
int srcX, srcY, dstX, dstY;
@ -504,7 +504,7 @@ static void Drawer2D_DrawCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int
x = begX;
}
if (!(args->font->Style & FONT_FLAG_UNDERLINE)) return;
if (!(args->font->style & FONT_FLAG_UNDERLINE)) return;
/* scale up bottom row of a cell to drawn text font */
cellY = (8 - 1) * dstHeight / 8;
underlineY = y + (cellY + yPadding);
@ -523,7 +523,7 @@ static void Drawer2D_DrawCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int
}
static void Drawer2D_DrawBitmapText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y) {
int offset = Drawer2D_ShadowOffset(args->font->Size);
int offset = Drawer2D_ShadowOffset(args->font->size);
if (args->useShadow) {
Drawer2D_DrawCore(bmp, args, x + offset, y + offset, true);
@ -532,7 +532,7 @@ static void Drawer2D_DrawBitmapText(Bitmap* bmp, struct DrawTextArgs* args, int
}
static int Drawer2D_MeasureBitmapWidth(const struct DrawTextArgs* args) {
int i, point = args->font->Size;
int i, point = args->font->size;
int xPadding, width;
String text;
@ -608,10 +608,10 @@ int Drawer2D_TextHeight(struct DrawTextArgs* args) {
return Drawer2D_FontHeight(args->font, args->useShadow);
}
int Drawer2D_FontHeight(const FontDesc* font, bool useShadow) {
int Drawer2D_FontHeight(const struct FontDesc* font, bool useShadow) {
int height, point;
if (Drawer2D_BitmappedText) {
point = font->Size;
point = font->size;
/* adjust coords to make drawn text match GDI fonts */
height = Drawer2D_AdjHeight(point);
@ -991,16 +991,16 @@ String Font_Lookup(const String* fontName, int style) {
return path.length ? path : Font_LookupOf(fontName, 'R');
}
ReturnCode Font_Make(FontDesc* desc, const String* fontName, int size, int style) {
ReturnCode Font_Make(struct FontDesc* desc, const String* fontName, int size, int style) {
struct SysFont* font;
String value, path, index;
int faceIndex;
FT_Open_Args args;
FT_Error err;
desc->Size = size;
desc->Style = style;
desc->Handle = NULL;
desc->size = size;
desc->style = style;
desc->handle = NULL;
value = Font_Lookup(fontName, style);
if (!value.length) return ERR_INVALID_ARGUMENT;
@ -1009,28 +1009,28 @@ ReturnCode Font_Make(FontDesc* desc, const String* fontName, int size, int style
font = (struct SysFont*)Mem_Alloc(1, sizeof(struct SysFont), "SysFont");
if ((err = SysFont_Init(&path, font, &args))) { Mem_Free(font); return err; }
desc->Handle = font;
desc->handle = font;
if ((err = FT_New_Face(ft_lib, &args, faceIndex, &font->face))) return err;
return FT_Set_Char_Size(font->face, size * 64, 0, Display_DpiX, Display_DpiY);
}
void Font_Free(FontDesc* desc) {
void Font_Free(struct FontDesc* desc) {
struct SysFont* font;
desc->Size = 0;
desc->Style = 0;
desc->size = 0;
desc->style = 0;
/* NULL for fonts created by Drawer2D_MakeFont and bitmapped text mode is on */
if (!desc->Handle) return;
if (!desc->handle) return;
font = (struct SysFont*)desc->Handle;
font = (struct SysFont*)desc->handle;
FT_Done_Face(font->face);
Mem_Free(font);
desc->Handle = NULL;
desc->handle = NULL;
}
#define TEXT_CEIL(x) (((x) + 63) >> 6)
static int Font_SysTextWidth(struct DrawTextArgs* args) {
struct SysFont* font = (struct SysFont*)args->font->Handle;
struct SysFont* font = (struct SysFont*)args->font->handle;
FT_Face face = font->face;
String text = args->text;
int i, width = 0, charWidth;
@ -1058,8 +1058,8 @@ static int Font_SysTextWidth(struct DrawTextArgs* args) {
return TEXT_CEIL(width);
}
static int Font_SysFontHeight(const FontDesc* desc) {
struct SysFont* font = (struct SysFont*)desc->Handle;
static int Font_SysFontHeight(const struct FontDesc* desc) {
struct SysFont* font = (struct SysFont*)desc->handle;
FT_Face face = font->face;
return TEXT_CEIL(face->size->metrics.height);
}
@ -1113,7 +1113,7 @@ static void DrawBlackWhiteGlyph(FT_Bitmap* img, Bitmap* bmp, int x, int y, Bitma
}
static int Font_SysTextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, BitmapCol col, bool shadow) {
struct SysFont* font = (struct SysFont*)args->font->Handle;
struct SysFont* font = (struct SysFont*)args->font->handle;
FT_BitmapGlyph* glyphs = font->glyphs;
FT_Face face = font->face;
@ -1166,7 +1166,7 @@ static int Font_SysTextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y
x -= glyph->left; y -= offset;
}
if (args->font->Style & FONT_FLAG_UNDERLINE) {
if (args->font->style & FONT_FLAG_UNDERLINE) {
int ul_pos = FT_MulFix(face->underline_position, face->size->metrics.y_scale);
int ul_thick = FT_MulFix(face->underline_thickness, face->size->metrics.y_scale);

View File

@ -7,15 +7,16 @@
Copyright 2014-2019 ClassiCube | Licensed under BSD-3
*/
struct DrawTextArgs { String text; FontDesc* font; bool useShadow; };
struct FontDesc { void* handle; cc_uint16 size, style; };
struct DrawTextArgs { String text; struct FontDesc* font; bool useShadow; };
struct Texture;
struct IGameComponent;
extern struct IGameComponent Drawer2D_Component;
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const String* text, FontDesc* font, bool useShadow);
void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, FontDesc* font, bool useShadow);
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const String* text, struct FontDesc* font, bool useShadow);
void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, struct FontDesc* font, bool useShadow);
/* Initialises the given font. When Drawer2D_BitmappedText is false, creates native font handle using Font_Make. */
CC_NOINLINE void Drawer2D_MakeFont(FontDesc* desc, int size, int style);
CC_NOINLINE void Drawer2D_MakeFont(struct FontDesc* desc, int size, int style);
/* Whether text should be drawn and measured using the currently set font bitmap. */
/* If false, then text is instead draw using platform/system fonts. */
@ -72,7 +73,7 @@ CC_API Size2D Drawer2D_MeasureText(struct DrawTextArgs* args);
/* Similar to Drawer2D_DrawText, but trims the text with trailing ".." if wider than maxWidth. */
void Drawer2D_DrawClippedText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y, int maxWidth);
/* Returns the line height for drawing any character in the font. */
int Drawer2D_FontHeight(const FontDesc* font, bool useShadow);
int Drawer2D_FontHeight(const struct FontDesc* font, bool useShadow);
/* Creates a texture consisting only of the given text drawn onto it. */
/* NOTE: The returned texture is always padded up to nearest power of two dimensions. */
@ -103,9 +104,9 @@ void Font_GetNames(StringsBuffer* buffer);
/* 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. */
ReturnCode Font_Make(FontDesc* desc, const String* fontName, int size, int style);
ReturnCode Font_Make(struct FontDesc* desc, const String* fontName, int size, int style);
/* Frees an allocated font. */
CC_API void Font_Free(FontDesc* desc);
CC_API void Font_Free(struct FontDesc* desc);
/* Attempts to decode one or fonts from the given file. */
/* NOTE: If this file has been decoded before (fontscache.txt), does nothing. */
void SysFonts_Register(const String* path);

View File

@ -233,7 +233,7 @@ static void Entity_MakeNameTexture(struct Entity* e) {
BitmapCol origWhiteCol;
struct DrawTextArgs args;
FontDesc font;
struct FontDesc font;
bool bitmapped;
String name;
Size2D size;

View File

@ -290,7 +290,7 @@ void Gui_OnResize(void) {
/*########################################################################################################################*
*-------------------------------------------------------TextAtlas---------------------------------------------------------*
*#########################################################################################################################*/
void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, const FontDesc* font, const String* prefix) {
void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, const struct FontDesc* font, const String* prefix) {
struct DrawTextArgs args;
Size2D size;
Bitmap bmp;
@ -324,7 +324,7 @@ void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, const FontDesc
}
Mem_Free(bmp.Scan0);
Drawer2D_ReducePadding_Tex(&atlas->tex, font->Size, 4);
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

@ -16,6 +16,7 @@ enum GuiAnchor {
};
struct IGameComponent;
struct FontDesc;
struct Widget;
extern struct IGameComponent Gui_Component;
@ -151,7 +152,7 @@ struct TextAtlas {
short widths[TEXTATLAS_MAX_WIDTHS];
short offsets[TEXTATLAS_MAX_WIDTHS];
};
void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, const FontDesc* font, const String* prefix);
void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, const struct FontDesc* font, const String* prefix);
void TextAtlas_Free(struct TextAtlas* atlas);
void TextAtlas_Add(struct TextAtlas* atlas, int charI, VertexP3fT2fC4b** vertices);
void TextAtlas_AddInt(struct TextAtlas* atlas, int value, VertexP3fT2fC4b** vertices);

View File

@ -316,10 +316,8 @@ static bool InputHandler_CheckIsFree(BlockID block) {
void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right) {
TimeMS now = DateTime_CurrentUTC_MS();
int delta = (int)(now - input_lastClick);
IVec3 pos;
BlockID old, cur, block;
int i;
if (cooldown && delta < 250) return; /* 4 times per second */
input_lastClick = now;

View File

@ -1099,7 +1099,7 @@ static struct ServersScreen {
struct LButton btnBack, btnConnect, btnRefresh;
struct LTable table;
struct LWidget* _widgets[6];
FontDesc rowFont;
struct FontDesc rowFont;
float tableAcc;
} ServersScreen_Instance;

View File

@ -1089,7 +1089,7 @@ static struct LWidgetVTABLE ltable_VTABLE = {
LTable_MouseDown, LTable_StopDragging, /* Select */
LTable_MouseWheel, /* Wheel */
};
void LTable_Init(struct LTable* w, FontDesc* rowFont) {
void LTable_Init(struct LTable* w, struct FontDesc* rowFont) {
int i;
w->VTABLE = &ltable_VTABLE;
w->Columns = tableColumns;

View File

@ -7,6 +7,7 @@
Copyright 2014-2019 ClassiCube | Licensed under BSD-3
*/
struct LScreen;
struct FontDesc;
struct LWidgetVTABLE {
/* Called to draw contents of this widget */
@ -94,7 +95,7 @@ CC_NOINLINE void LInput_Clear(struct LInput* w);
/* Represents non-interactable text. */
struct LLabel {
LWidget_Layout
FontDesc* Font;
struct FontDesc* Font;
String Text;
Size2D _TextSize;
char _TextBuffer[STRING_SIZE];
@ -149,7 +150,7 @@ struct LTable {
/* Number of columns in the table. */
int NumColumns;
/* Fonts for text in rows. */
FontDesc* RowFont;
struct FontDesc* RowFont;
/* Y start and end of rows and height of each row. */
int RowsBegY, RowsEndY, RowHeight;
/* Y height of headers. */
@ -185,7 +186,7 @@ struct LTable {
/* Initialises a table. */
/* NOTE: Must also call LTable_Reset to make a table actually useful. */
void LTable_Init(struct LTable* table, FontDesc* rowFont);
void LTable_Init(struct LTable* table, struct FontDesc* rowFont);
/* Resets state of a table (reset sorter, filter, etc) */
void LTable_Reset(struct LTable* table);
/* Adjusts Y position of rows and number of visible rows. */

View File

@ -21,10 +21,10 @@ struct LScreen* Launcher_Screen;
Rect2D Launcher_Dirty;
Bitmap Launcher_Framebuffer;
bool Launcher_ClassicBackground;
FontDesc Launcher_TitleFont, Launcher_TextFont, Launcher_HintFont;
struct FontDesc Launcher_TitleFont, Launcher_TextFont, Launcher_HintFont;
static bool pendingRedraw;
static FontDesc logoFont;
static struct FontDesc logoFont;
bool Launcher_ShouldExit, Launcher_ShouldUpdate;
static void Launcher_ApplyUpdate(void);

View File

@ -6,6 +6,7 @@
Copyright 2014-2019 ClassiCube | Licensed under BSD-3
*/
struct LScreen;
struct FontDesc;
/* Currently active screen/menu. */
extern struct LScreen* Launcher_Screen;
@ -17,9 +18,9 @@ extern Bitmap Launcher_Framebuffer;
/* Whether to use stone tile background like minecraft.net. */
extern bool Launcher_ClassicBackground;
/* Default font for buttons and labels. */
extern FontDesc Launcher_TitleFont, Launcher_TextFont;
extern struct FontDesc Launcher_TitleFont, Launcher_TextFont;
/* Default font for input widget hints. */
extern FontDesc Launcher_HintFont;
extern struct FontDesc Launcher_HintFont;
/* Whether at the next tick, the launcher window should proceed to stop displaying frames and subsequently exit. */
extern bool Launcher_ShouldExit;

View File

@ -64,8 +64,8 @@ static void Menu_Back(void* s, int i, struct ButtonWidget* btn, Widget_LeftClick
Menu_Button(s, i, btn, width, onClick, ANCHOR_CENTRE, ANCHOR_MAX, 0, 25);
}
CC_NOINLINE static void Menu_MakeTitleFont(FontDesc* font) { Drawer2D_MakeFont(font, 16, FONT_STYLE_BOLD); }
CC_NOINLINE static void Menu_MakeBodyFont(FontDesc* font) { Drawer2D_MakeFont(font, 16, FONT_STYLE_NORMAL); }
CC_NOINLINE static void Menu_MakeTitleFont(struct FontDesc* font) { Drawer2D_MakeFont(font, 16, FONT_STYLE_BOLD); }
CC_NOINLINE static void Menu_MakeBodyFont(struct FontDesc* font) { Drawer2D_MakeFont(font, 16, FONT_STYLE_NORMAL); }
static void Menu_NullFunc(void* screen) { }
@ -231,7 +231,7 @@ static struct ListScreen {
Screen_Layout
struct ButtonWidget buttons[LIST_SCREEN_ITEMS];
struct ButtonWidget left, right, done;
FontDesc font;
struct FontDesc font;
float wheelAcc;
int currentIndex;
Widget_LeftClick EntryClick;
@ -476,7 +476,7 @@ static void PauseScreen_CheckHacksAllowed(void* screen) {
static void PauseScreen_ContextRecreated(void* screen) {
struct PauseScreen* s = (struct PauseScreen*)screen;
FontDesc titleFont;
struct FontDesc titleFont;
int i;
Menu_MakeTitleFont(&titleFont);
@ -567,7 +567,7 @@ void PauseScreen_Show(void) {
static struct OptionsGroupScreen {
Screen_Layout
int selectedI;
FontDesc textFont;
struct FontDesc textFont;
struct ButtonWidget buttons[7];
struct TextWidget desc;
struct ButtonWidget done;
@ -609,7 +609,7 @@ static void OptionsGroupScreen_ContextLost(void* screen) {
static void OptionsGroupScreen_ContextRecreated(void* screen) {
struct OptionsGroupScreen* s = (struct OptionsGroupScreen*)screen;
FontDesc titleFont;
struct FontDesc titleFont;
int i;
Menu_MakeTitleFont(&titleFont);
Menu_MakeBodyFont(&s->textFont);
@ -683,7 +683,7 @@ static struct EditHotkeyScreen {
struct HotkeyData curHotkey, origHotkey;
int selectedI;
bool supressNextPress;
FontDesc titleFont, textFont;
struct FontDesc titleFont, textFont;
struct MenuInputWidget input;
struct ButtonWidget buttons[5], cancel;
} EditHotkeyScreen_Instance;
@ -903,7 +903,7 @@ void EditHotkeyScreen_Show(struct HotkeyData original) {
*#########################################################################################################################*/
static struct GenLevelScreen {
Screen_Layout
FontDesc textFont;
struct FontDesc textFont;
struct ButtonWidget flatgrass, vanilla, cancel;
struct MenuInputWidget* selected;
struct MenuInputWidget inputs[4];
@ -1007,7 +1007,7 @@ static void GenLevelScreen_ContextLost(void* screen) {
static void GenLevelScreen_ContextRecreated(void* screen) {
struct GenLevelScreen* s = (struct GenLevelScreen*)screen;
FontDesc titleFont;
struct FontDesc titleFont;
Menu_MakeTitleFont(&titleFont);
Menu_MakeBodyFont(&s->textFont);
@ -1090,7 +1090,7 @@ static void ClassicGenScreen_Make(struct ClassicGenScreen* s, int i, int y, Widg
static void ClassicGenScreen_ContextRecreated(void* screen) {
struct ClassicGenScreen* s = (struct ClassicGenScreen*)screen;
FontDesc titleFont;
struct FontDesc titleFont;
Menu_MakeTitleFont(&titleFont);
ButtonWidget_SetConst(&s->buttons[0], "Small", &titleFont);
@ -1133,7 +1133,7 @@ void ClassicGenScreen_Show(void) {
*#########################################################################################################################*/
static struct SaveLevelScreen {
Screen_Layout
FontDesc titleFont, textFont;
struct FontDesc titleFont, textFont;
struct ButtonWidget save, schem, cancel;
struct MenuInputWidget input;
struct TextWidget mcEdit, desc;
@ -1355,7 +1355,7 @@ static void FontListScreen_EntryClick(void* screen, void* widget) {
}
static void FontListScreen_UpdateEntry(struct ListScreen* s, struct ButtonWidget* button, const String* text) {
FontDesc font;
struct FontDesc font;
ReturnCode res;
if (String_CaselessEqualsConst(text, LIST_SCREEN_EMPTY)) {
@ -1519,7 +1519,7 @@ static struct KeyBindingsScreen {
InitKeyBindings DoInit;
const char* titleText;
const char* msgText;
FontDesc titleFont;
struct FontDesc titleFont;
struct TextWidget title, msg;
struct ButtonWidget back, left, right;
struct ButtonWidget buttons[12];
@ -1586,7 +1586,7 @@ static void KeyBindingsScreen_ContextLost(void* screen) {
static void KeyBindingsScreen_ContextRecreated(void* screen) {
struct KeyBindingsScreen* s = (struct KeyBindingsScreen*)screen;
FontDesc textFont;
struct FontDesc textFont;
int i;
Menu_MakeTitleFont(&s->titleFont);
@ -1778,7 +1778,7 @@ static struct MenuOptionsScreen {
int activeI, selectedI, descriptionsCount;
InitMenuOptions DoInit, DoRecreateExtra, OnHacksChanged;
int numButtons;
FontDesc titleFont, textFont;
struct FontDesc titleFont, textFont;
struct ButtonWidget ok, Default;
struct MenuInputWidget input;
struct TextGroupWidget extHelp;
@ -2804,7 +2804,7 @@ static void TexIdsOverlay_ContextRecreated(void* screen) {
static const String chars = String_FromConst("0123456789");
static const String prefix = String_FromConst("f");
struct TexIdsOverlay* s = (struct TexIdsOverlay*)screen;
FontDesc textFont, titleFont;
struct FontDesc textFont, titleFont;
int size;
size = Window_Height / ATLAS2D_TILES_PER_ROW;
@ -2965,7 +2965,7 @@ static void UrlWarningOverlay_AppendUrl(void* screen, void* b) {
static void UrlWarningOverlay_ContextRecreated(void* screen) {
struct UrlWarningOverlay* s = (struct UrlWarningOverlay*)screen;
FontDesc titleFont, textFont;
struct FontDesc titleFont, textFont;
Menu_MakeTitleFont(&titleFont);
Menu_MakeBodyFont(&textFont);
@ -3018,7 +3018,7 @@ static struct TexPackOverlay {
bool deny, alwaysDeny;
cc_uint32 contentLength;
String url, identifier;
FontDesc textFont;
struct FontDesc textFont;
struct ButtonWidget buttons[4];
struct TextWidget labels[4];
char _identifierBuffer[STRING_SIZE + 4];
@ -3101,7 +3101,7 @@ static void TexPackOverlay_ContextLost(void* screen) {
static void TexPackOverlay_ContextRecreated(void* screen) {
struct TexPackOverlay* s = (struct TexPackOverlay*)screen;
FontDesc titleFont;
struct FontDesc titleFont;
Menu_MakeTitleFont(&titleFont);
Menu_MakeBodyFont(&s->textFont);

View File

@ -29,7 +29,7 @@ struct HUDScreen {
struct HotbarWidget hotbar;
/* player list state */
struct PlayerListWidget playerList;
FontDesc playerFont;
struct FontDesc playerFont;
bool showingList, wasShowingList;
/* chat state */
int inputOldHeight;
@ -37,7 +37,7 @@ struct HUDScreen {
bool suppressNextPress;
int chatIndex;
int lastDownloadStatus;
FontDesc chatFont, announcementFont;
struct FontDesc chatFont, announcementFont;
struct TextWidget announcement;
struct ChatInputWidget input;
struct TextGroupWidget status, bottomRight, chat, clientStatus;
@ -79,7 +79,7 @@ CC_NOINLINE static bool IsOnlyHudActive(void) {
*#########################################################################################################################*/
static struct InventoryScreen {
Screen_Layout
FontDesc font;
struct FontDesc font;
struct TableWidget table;
bool releasedInv, deferredSelect;
} InventoryScreen_Instance;
@ -234,7 +234,7 @@ void InventoryScreen_Show(void) {
*#########################################################################################################################*/
static struct StatusScreen {
Screen_Layout
FontDesc font;
struct FontDesc font;
struct TextWidget line1, line2;
struct TextAtlas posAtlas;
double accumulator;
@ -423,7 +423,7 @@ void StatusScreen_Show(void) {
*#########################################################################################################################*/
static struct LoadingScreen {
Screen_Layout
FontDesc font;
struct FontDesc font;
float progress;
struct TextWidget title, message;
@ -696,7 +696,7 @@ static bool HUDScreen_ChatUpdateFont(struct HUDScreen* s) {
Math_Clamp(size, 8, 60);
/* don't recreate font if possible */
if (size == s->chatFont.Size) return false;
if (size == s->chatFont.size) return false;
HUDScreen_FreeChatFonts(s);
Drawer2D_MakeFont(&s->chatFont, size, FONT_STYLE_NORMAL);
@ -1243,7 +1243,7 @@ static struct DisconnectScreen {
int lastSecsLeft;
struct ButtonWidget reconnect;
FontDesc titleFont, messageFont;
struct FontDesc titleFont, messageFont;
struct TextWidget title, message;
char _titleBuffer[STRING_SIZE];
char _messageBuffer[STRING_SIZE];

View File

@ -58,7 +58,7 @@ void TextWidget_Make(struct TextWidget* w, cc_uint8 horAnchor, cc_uint8 verAncho
Widget_SetLocation(w, horAnchor, verAnchor, xOffset, yOffset);
}
void TextWidget_Set(struct TextWidget* w, const String* text, const FontDesc* font) {
void TextWidget_Set(struct TextWidget* w, const String* text, const struct FontDesc* font) {
struct DrawTextArgs args;
Gfx_DeleteTexture(&w->tex.ID);
@ -71,14 +71,14 @@ void TextWidget_Set(struct TextWidget* w, const String* text, const FontDesc* fo
}
if (w->reducePadding) {
Drawer2D_ReducePadding_Tex(&w->tex, font->Size, 4);
Drawer2D_ReducePadding_Tex(&w->tex, font->size, 4);
}
w->width = w->tex.Width; w->height = w->tex.Height;
Widget_Reposition(w);
}
void TextWidget_SetConst(struct TextWidget* w, const char* text, const FontDesc* font) {
void TextWidget_SetConst(struct TextWidget* w, const char* text, const struct FontDesc* font) {
String str = String_FromReadonly(text);
TextWidget_Set(w, &str, font);
}
@ -161,7 +161,7 @@ void ButtonWidget_Make(struct ButtonWidget* w, int minWidth, Widget_LeftClick on
Widget_SetLocation(w, horAnchor, verAnchor, xOffset, yOffset);
}
void ButtonWidget_Set(struct ButtonWidget* w, const String* text, const FontDesc* font) {
void ButtonWidget_Set(struct ButtonWidget* w, const String* text, const struct FontDesc* font) {
struct DrawTextArgs args;
Gfx_DeleteTexture(&w->tex.ID);
@ -178,7 +178,7 @@ void ButtonWidget_Set(struct ButtonWidget* w, const String* text, const FontDesc
Widget_Reposition(w);
}
void ButtonWidget_SetConst(struct ButtonWidget* w, const char* text, const FontDesc* font) {
void ButtonWidget_SetConst(struct ButtonWidget* w, const char* text, const struct FontDesc* font) {
String str = String_FromReadonly(text);
ButtonWidget_Set(w, &str, font);
}
@ -1457,7 +1457,7 @@ void MenuInputWidget_Create(struct MenuInputWidget* w, int width, int height, co
String_Copy(&w->base.text, text);
}
void MenuInputWidget_SetFont(struct MenuInputWidget* w, FontDesc* font) {
void MenuInputWidget_SetFont(struct MenuInputWidget* w, struct FontDesc* font) {
w->base.font = font;
w->base.lineHeight = Drawer2D_FontHeight(font, false);
InputWidget_UpdateText(&w->base);
@ -1717,7 +1717,7 @@ void ChatInputWidget_Create(struct ChatInputWidget* w) {
String_InitArray(w->origStr, w->_origBuffer);
}
void ChatInputWidget_SetFont(struct ChatInputWidget* w, FontDesc* font) {
void ChatInputWidget_SetFont(struct ChatInputWidget* w, struct FontDesc* font) {
struct DrawTextArgs args;
DrawTextArgs_Make(&args, &chatInputPrefix, font, true);
@ -1749,7 +1749,7 @@ static void PlayerListWidget_DrawName(struct Texture* tex, struct PlayerListWidg
DrawTextArgs_Make(&args, &tmp, w->font, !w->classic);
Drawer2D_MakeTextTexture(tex, &args);
Drawer2D_ReducePadding_Tex(tex, w->font->Size, 3);
Drawer2D_ReducePadding_Tex(tex, w->font->size, 3);
}
static int PlayerListWidget_HighlightedName(struct PlayerListWidget* w, int x, int y) {
@ -2106,7 +2106,7 @@ static const struct WidgetVTABLE PlayerListWidget_VTABLE = {
Widget_Mouse, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
PlayerListWidget_Reposition
};
void PlayerListWidget_Create(struct PlayerListWidget* w, FontDesc* font, bool classic) {
void PlayerListWidget_Create(struct PlayerListWidget* w, struct FontDesc* font, bool classic) {
Widget_Reset(w);
w->VTABLE = &PlayerListWidget_VTABLE;
w->horAnchor = ANCHOR_CENTRE;
@ -2407,9 +2407,9 @@ static void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Textu
ul = (bit.Len & TEXTGROUPWIDGET_URL);
args->text = String_UNSAFE_Substring(text, bit.LineBeg, bit.LineLen);
if (ul) args->font->Style |= FONT_FLAG_UNDERLINE;
if (ul) args->font->style |= FONT_FLAG_UNDERLINE;
Drawer2D_DrawText(&bmp, args, x, 0);
if (ul) args->font->Style &= ~FONT_FLAG_UNDERLINE;
if (ul) args->font->style &= ~FONT_FLAG_UNDERLINE;
x += partWidths[i];
}
@ -2438,7 +2438,7 @@ void TextGroupWidget_Redraw(struct TextGroupWidget* w, int index) {
} else {
Drawer2D_MakeTextTexture(&tex, &args);
}
Drawer2D_ReducePadding_Tex(&tex, w->font->Size, 3);
Drawer2D_ReducePadding_Tex(&tex, w->font->size, 3);
} else {
tex.Height = w->collapsible[index] ? 0 : w->defaultHeight;
}
@ -2466,11 +2466,11 @@ void TextGroupWidget_RedrawAllWithCol(struct TextGroupWidget* group, char col) {
}
void TextGroupWidget_SetFont(struct TextGroupWidget* w, FontDesc* font) {
void TextGroupWidget_SetFont(struct TextGroupWidget* w, struct FontDesc* font) {
int i, height;
height = Drawer2D_FontHeight(font, true);
Drawer2D_ReducePadding_Height(&height, font->Size, 3);
Drawer2D_ReducePadding_Height(&height, font->size, 3);
w->defaultHeight = height;
for (i = 0; i < w->lines; i++) {
@ -2752,7 +2752,7 @@ static const struct WidgetVTABLE SpecialInputWidget_VTABLE = {
SpecialInputWidget_MouseDown, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
SpecialInputWidget_Reposition
};
void SpecialInputWidget_Create(struct SpecialInputWidget* w, FontDesc* font, struct InputWidget* target) {
void SpecialInputWidget_Create(struct SpecialInputWidget* w, struct FontDesc* font, struct InputWidget* target) {
Widget_Reset(w);
w->VTABLE = &SpecialInputWidget_VTABLE;
w->verAnchor = ANCHOR_MAX;

View File

@ -7,6 +7,7 @@
/* Contains all 2D widget implementations.
Copyright 2014-2019 ClassiCube | Licensed under BSD-3
*/
struct FontDesc;
/* A text label. */
struct TextWidget {
@ -19,9 +20,9 @@ struct TextWidget {
CC_NOINLINE void TextWidget_Make(struct TextWidget* w,
cc_uint8 horAnchor, cc_uint8 verAnchor, int xOffset, int yOffset);
/* Draws the given text into a texture, then updates the position and size of this widget. */
CC_NOINLINE void TextWidget_Set(struct TextWidget* w, const String* text, const FontDesc* font);
CC_NOINLINE void TextWidget_Set(struct TextWidget* w, const String* text, const struct FontDesc* font);
/* Shorthand for TextWidget_Set using String_FromReadonly */
CC_NOINLINE void TextWidget_SetConst(struct TextWidget* w, const char* text, const FontDesc* font);
CC_NOINLINE void TextWidget_SetConst(struct TextWidget* w, const char* text, const struct FontDesc* font);
typedef void (*Button_Get)(String* raw);
@ -39,9 +40,9 @@ struct ButtonWidget {
CC_NOINLINE void ButtonWidget_Make(struct ButtonWidget* w, int minWidth, Widget_LeftClick onClick,
cc_uint8 horAnchor, cc_uint8 verAnchor, int xOffset, int yOffset);
/* Draws the given text into a texture, then updates the position and size of this widget. */
CC_NOINLINE void ButtonWidget_Set(struct ButtonWidget* w, const String* text, const FontDesc* font);
CC_NOINLINE void ButtonWidget_Set(struct ButtonWidget* w, const String* text, const struct FontDesc* font);
/* Shorthand for ButtonWidget_Set using String_FromReadonly */
CC_NOINLINE void ButtonWidget_SetConst(struct ButtonWidget* w, const char* text, const FontDesc* font);
CC_NOINLINE void ButtonWidget_SetConst(struct ButtonWidget* w, const char* text, const struct FontDesc* font);
/* Clickable and draggable scrollbar. */
struct ScrollbarWidget {
@ -72,7 +73,7 @@ struct TableWidget {
Widget_Layout
int blocksCount, blocksPerRow, rowsCount;
int lastCreatedIndex;
FontDesc* font;
struct FontDesc* font;
int selectedIndex, cellSize;
float selBlockExpand;
GfxResourceID vb;
@ -98,7 +99,7 @@ CC_NOINLINE void TableWidget_Recreate(struct TableWidget* w);
#define INPUTWIDGET_LEN STRING_SIZE
struct InputWidget {
Widget_Layout
FontDesc* font;
struct FontDesc* font;
int (*GetMaxLines)(void);
void (*RemakeTexture)(void* elem); /* Remakes the raw texture containing all the chat lines. Also updates dimensions. */
void (*OnPressedEnter)(void* elem); /* Invoked when the user presses enter. */
@ -180,7 +181,7 @@ struct MenuInputWidget {
};
CC_NOINLINE void MenuInputWidget_Create(struct MenuInputWidget* w, int width, int height, const String* text, struct MenuInputDesc* d);
/* Sets the font used, then redraws the input widget. */
CC_NOINLINE void MenuInputWidget_SetFont(struct MenuInputWidget* w, FontDesc* font);
CC_NOINLINE void MenuInputWidget_SetFont(struct MenuInputWidget* w, struct FontDesc* font);
struct ChatInputWidget {
@ -192,7 +193,7 @@ struct ChatInputWidget {
};
CC_NOINLINE void ChatInputWidget_Create(struct ChatInputWidget* w);
CC_NOINLINE void ChatInputWidget_SetFont(struct ChatInputWidget* w, FontDesc* font);
CC_NOINLINE void ChatInputWidget_SetFont(struct ChatInputWidget* w, struct FontDesc* font);
/* Retrieves the text for the i'th line in the group */
@ -204,7 +205,7 @@ typedef String (*TextGroupWidget_Get)(void* obj, int i);
struct TextGroupWidget {
Widget_Layout
int lines, defaultHeight;
FontDesc* font;
struct FontDesc* font;
/* Whether a line has zero height when that line has no text in it. */
bool collapsible[TEXTGROUPWIDGET_MAX_LINES];
bool underlineUrls;
@ -214,7 +215,7 @@ struct TextGroupWidget {
};
CC_NOINLINE void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, struct Texture* textures, TextGroupWidget_Get getLine);
CC_NOINLINE void TextGroupWidget_SetFont(struct TextGroupWidget* w, FontDesc* font);
CC_NOINLINE void TextGroupWidget_SetFont(struct TextGroupWidget* w, struct FontDesc* font);
/* Deletes first line, then moves all other lines upwards, then redraws last line. */
/* NOTE: GetLine must also adjust the lines it returns for this to behave properly. */
CC_NOINLINE void TextGroupWidget_ShiftUp(struct TextGroupWidget* w);
@ -238,7 +239,7 @@ static String TextGroupWidget_UNSAFE_Get(struct TextGroupWidget* w, int i) { ret
struct PlayerListWidget {
Widget_Layout
FontDesc* font;
struct FontDesc* font;
int namesCount, elementOffset;
int xMin, xMax, yHeight;
bool classic;
@ -246,7 +247,7 @@ struct PlayerListWidget {
cc_uint16 ids[TABLIST_MAX_NAMES * 2];
struct Texture textures[TABLIST_MAX_NAMES * 2];
};
CC_NOINLINE void PlayerListWidget_Create(struct PlayerListWidget* w, FontDesc* font, bool classic);
CC_NOINLINE void PlayerListWidget_Create(struct PlayerListWidget* w, struct FontDesc* font, bool classic);
CC_NOINLINE void PlayerListWidget_GetNameUnder(struct PlayerListWidget* w, int mouseX, int mouseY, String* name);
@ -263,14 +264,14 @@ struct SpecialInputWidget {
bool pendingRedraw;
struct InputWidget* target;
struct Texture tex;
FontDesc* font;
struct FontDesc* font;
int titleHeight;
struct SpecialInputTab tabs[5];
String colString;
char _colBuffer[DRAWER2D_MAX_COLS * 4];
};
CC_NOINLINE void SpecialInputWidget_Create(struct SpecialInputWidget* w, FontDesc* font, struct InputWidget* target);
CC_NOINLINE void SpecialInputWidget_Create(struct SpecialInputWidget* w, struct FontDesc* font, struct InputWidget* target);
CC_NOINLINE void SpecialInputWidget_Redraw(struct SpecialInputWidget* w);
CC_NOINLINE void SpecialInputWidget_UpdateCols(struct SpecialInputWidget* w);
CC_NOINLINE void SpecialInputWidget_SetActive(struct SpecialInputWidget* w, bool active);