Export Drawer2D per request

This commit is contained in:
UnknownShadow200 2021-05-20 17:36:26 +10:00
parent 763a7e23eb
commit d15ef3ed69
9 changed files with 41 additions and 41 deletions

View File

@ -14,9 +14,7 @@
#include "Window.h" #include "Window.h"
#include "Options.h" #include "Options.h"
cc_bool Drawer2D_BitmappedText; struct _Drawer2DData Drawer2D;
cc_bool Drawer2D_BlackTextShadows;
BitmapCol Drawer2D_Cols[DRAWER2D_MAX_COLS];
#define Font_IsBitmap(font) (!(font)->handle) #define Font_IsBitmap(font) (!(font)->handle)
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const cc_string* text, struct FontDesc* font, cc_bool useShadow) { void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const cc_string* text, struct FontDesc* font, cc_bool useShadow) {
@ -68,7 +66,7 @@ void Drawer2D_MakeBitmappedFont(struct FontDesc* desc, int size, int flags) {
} }
void Drawer2D_MakeFont(struct FontDesc* desc, int size, int flags) { void Drawer2D_MakeFont(struct FontDesc* desc, int size, int flags) {
if (Drawer2D_BitmappedText) { if (Drawer2D.BitmappedText) {
Drawer2D_MakeBitmappedFont(desc, size, flags); Drawer2D_MakeBitmappedFont(desc, size, flags);
} else { } else {
Font_MakeDefault(desc, size, flags); Font_MakeDefault(desc, size, flags);
@ -368,7 +366,7 @@ cc_bool Drawer2D_IsWhiteCol(char c) { return c == '\0' || c == 'f' || c == 'F';
/* Divides R/G/B by 4 */ /* Divides R/G/B by 4 */
#define SHADOW_MASK ((0x3F << BITMAPCOL_R_SHIFT) | (0x3F << BITMAPCOL_G_SHIFT) | (0x3F << BITMAPCOL_B_SHIFT)) #define SHADOW_MASK ((0x3F << BITMAPCOL_R_SHIFT) | (0x3F << BITMAPCOL_G_SHIFT) | (0x3F << BITMAPCOL_B_SHIFT))
CC_NOINLINE static BitmapCol GetShadowCol(BitmapCol c) { CC_NOINLINE static BitmapCol GetShadowCol(BitmapCol c) {
if (Drawer2D_BlackTextShadows) return BITMAPCOL_BLACK; if (Drawer2D.BlackTextShadows) return BITMAPCOL_BLACK;
/* Initial layout: aaaa_aaaa|rrrr_rrrr|gggg_gggg|bbbb_bbbb */ /* Initial layout: aaaa_aaaa|rrrr_rrrr|gggg_gggg|bbbb_bbbb */
/* Shift right 2: 00aa_aaaa|aarr_rrrr|rrgg_gggg|ggbb_bbbb */ /* Shift right 2: 00aa_aaaa|aarr_rrrr|rrgg_gggg|ggbb_bbbb */
@ -387,7 +385,7 @@ static int Drawer2D_Width(int point, char c) {
void Drawer2D_ReducePadding_Tex(struct Texture* tex, int point, int scale) { void Drawer2D_ReducePadding_Tex(struct Texture* tex, int point, int scale) {
int padding; int padding;
float vAdj; float vAdj;
if (!Drawer2D_BitmappedText) return; if (!Drawer2D.BitmappedText) return;
padding = (tex->Height - point) / scale; padding = (tex->Height - point) / scale;
vAdj = (float)padding / Math_NextPowOf2(tex->Height); vAdj = (float)padding / Math_NextPowOf2(tex->Height);
@ -397,7 +395,7 @@ void Drawer2D_ReducePadding_Tex(struct Texture* tex, int point, int scale) {
void Drawer2D_ReducePadding_Height(int* height, int point, int scale) { void Drawer2D_ReducePadding_Height(int* height, int point, int scale) {
int padding; int padding;
if (!Drawer2D_BitmappedText) return; if (!Drawer2D.BitmappedText) return;
padding = (*height - point) / scale; padding = (*height - point) / scale;
*height -= padding * 2; *height -= padding * 2;
@ -438,7 +436,7 @@ static void DrawBitmappedTextCore(struct Bitmap* bmp, struct DrawTextArgs* args,
BitmapCol cols[256]; BitmapCol cols[256];
cc_uint16 dstWidths[256]; cc_uint16 dstWidths[256];
col = Drawer2D_Cols['f']; col = Drawer2D.Colors['f'];
if (shadow) col = GetShadowCol(col); if (shadow) col = GetShadowCol(col);
for (i = 0; i < text.length; i++) { for (i = 0; i < text.length; i++) {
@ -616,7 +614,7 @@ void Drawer2D_DrawClippedText(struct Bitmap* bmp, struct DrawTextArgs* args,
*---------------------------------------------------Drawer2D component----------------------------------------------------* *---------------------------------------------------Drawer2D component----------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void InitHexEncodedCol(int i, int hex, cc_uint8 lo, cc_uint8 hi) { static void InitHexEncodedCol(int i, int hex, cc_uint8 lo, cc_uint8 hi) {
Drawer2D_Cols[i] = BitmapCol_Make( Drawer2D.Colors[i] = BitmapCol_Make(
lo * ((hex >> 2) & 1) + hi * (hex >> 3), lo * ((hex >> 2) & 1) + hi * (hex >> 3),
lo * ((hex >> 1) & 1) + hi * (hex >> 3), lo * ((hex >> 1) & 1) + hi * (hex >> 3),
lo * ((hex >> 0) & 1) + hi * (hex >> 3), lo * ((hex >> 0) & 1) + hi * (hex >> 3),
@ -626,7 +624,7 @@ static void InitHexEncodedCol(int i, int hex, cc_uint8 lo, cc_uint8 hi) {
static void OnReset(void) { static void OnReset(void) {
int i; int i;
for (i = 0; i < DRAWER2D_MAX_COLS; i++) { for (i = 0; i < DRAWER2D_MAX_COLS; i++) {
Drawer2D_Cols[i] = 0; Drawer2D.Colors[i] = 0;
} }
for (i = 0; i <= 9; i++) { for (i = 0; i <= 9; i++) {
@ -655,8 +653,8 @@ static void OnFileChanged(void* obj, struct Stream* src, const cc_string* name)
static void OnInit(void) { static void OnInit(void) {
OnReset(); OnReset();
Drawer2D_BitmappedText = Game_ClassicMode || !Options_GetBool(OPT_USE_CHAT_FONT, false); Drawer2D.BitmappedText = Game_ClassicMode || !Options_GetBool(OPT_USE_CHAT_FONT, false);
Drawer2D_BlackTextShadows = Options_GetBool(OPT_BLACK_TEXT, false); Drawer2D.BlackTextShadows = Options_GetBool(OPT_BLACK_TEXT, false);
Options_Get(OPT_FONT_NAME, &font_candidates[0], ""); Options_Get(OPT_FONT_NAME, &font_candidates[0], "");
if (Game_ClassicMode) font_candidates[0].length = 0; if (Game_ClassicMode) font_candidates[0].length = 0;
@ -1164,7 +1162,7 @@ static void Font_SysTextDraw(struct DrawTextArgs* args, struct Bitmap* bmp, int
height = args->font->height; height = args->font->height;
descender = TEXT_CEIL(face->size->metrics.descender); descender = TEXT_CEIL(face->size->metrics.descender);
col = Drawer2D_Cols['f']; col = Drawer2D.Colors['f'];
if (shadow) col = GetShadowCol(col); if (shadow) col = GetShadowCol(col);
for (i = 0; i < text.length; i++) { for (i = 0; i < text.length; i++) {

View File

@ -15,6 +15,17 @@ struct IGameComponent;
struct StringsBuffer; struct StringsBuffer;
extern struct IGameComponent Drawer2D_Component; extern struct IGameComponent Drawer2D_Component;
CC_VAR extern struct _Drawer2DData {
/* Whether text should be drawn and measured using the currently set font bitmap. */
/* If false, then text is instead draw using platform/system fonts. */
cc_bool BitmappedText;
/* Whether the shadows behind text (that uses shadows) is fully black. */
cc_bool BlackTextShadows;
/* List of all colours. (An A of 0 means the colour is not used) */
BitmapCol Colors[DRAWER2D_MAX_COLS];
} Drawer2D;
#define Drawer2D_GetCol(c) Drawer2D.Colors[(cc_uint8)c]
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const cc_string* text, struct FontDesc* font, cc_bool useShadow); void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const cc_string* text, struct FontDesc* font, cc_bool useShadow);
void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, struct FontDesc* font, cc_bool useShadow); void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, struct FontDesc* font, cc_bool useShadow);
@ -25,15 +36,6 @@ void Drawer2D_MakeBitmappedFont(struct FontDesc* desc, int size, int flags);
/* Initialises the given font. Uses Drawer2D_MakeBitmappedFont or Font_MakeDefault depending on Drawer2D_BitmappedText. */ /* Initialises the given font. Uses Drawer2D_MakeBitmappedFont or Font_MakeDefault depending on Drawer2D_BitmappedText. */
CC_API void Drawer2D_MakeFont(struct FontDesc* desc, int size, int flags); CC_API void Drawer2D_MakeFont(struct FontDesc* desc, int size, int flags);
/* Whether text should be drawn and measured using the currently set font bitmap. */
/* If false, then text is instead draw using platform/system fonts. */
extern cc_bool Drawer2D_BitmappedText;
/* Whether the shadows behind text (that uses shadows) is fully black. */
extern cc_bool Drawer2D_BlackTextShadows;
/* List of all colours. (An A of 0 means the colour is not used) */
extern BitmapCol Drawer2D_Cols[DRAWER2D_MAX_COLS];
#define Drawer2D_GetCol(c) Drawer2D_Cols[(cc_uint8)c]
/* Clamps the given rectangle to lie inside the bitmap. */ /* Clamps the given rectangle to lie inside the bitmap. */
/* Returns false if rectangle is completely outside bitmap's rectangle. */ /* Returns false if rectangle is completely outside bitmap's rectangle. */
cc_bool Drawer2D_Clamp(struct Bitmap* bmp, int* x, int* y, int* width, int* height); cc_bool Drawer2D_Clamp(struct Bitmap* bmp, int* x, int* y, int* width, int* height);

View File

@ -254,14 +254,14 @@ static void MakeNameTexture(struct Entity* e) {
Bitmap_AllocateClearedPow2(&bmp, width, height); Bitmap_AllocateClearedPow2(&bmp, width, height);
{ {
origWhiteCol = Drawer2D_Cols['f']; origWhiteCol = Drawer2D.Colors['f'];
Drawer2D_Cols['f'] = shadowCol; Drawer2D.Colors['f'] = shadowCol;
Drawer2D_WithoutCols(&colorlessName, &name); Drawer2D_WithoutCols(&colorlessName, &name);
args.text = colorlessName; args.text = colorlessName;
Drawer2D_DrawText(&bmp, &args, NAME_OFFSET, NAME_OFFSET); Drawer2D_DrawText(&bmp, &args, NAME_OFFSET, NAME_OFFSET);
Drawer2D_Cols['f'] = origWhiteCol; Drawer2D.Colors['f'] = origWhiteCol;
args.text = name; args.text = name;
Drawer2D_DrawText(&bmp, &args, 0, 0); Drawer2D_DrawText(&bmp, &args, 0, 0);
} }

View File

@ -162,11 +162,11 @@ static void LButton_Draw(void* widget) {
LButton_DrawBorder(w); LButton_DrawBorder(w);
LButton_DrawHighlight(w); LButton_DrawHighlight(w);
if (!w->hovered) Drawer2D_Cols['f'] = Drawer2D_Cols['7']; if (!w->hovered) Drawer2D.Colors['f'] = Drawer2D.Colors['7'];
Drawer2D_DrawText(&Launcher_Framebuffer, &args, Drawer2D_DrawText(&Launcher_Framebuffer, &args,
w->x + xOffset / 2, w->y + yOffset / 2); w->x + xOffset / 2, w->y + yOffset / 2);
if (!w->hovered) Drawer2D_Cols['f'] = Drawer2D_Cols['F']; if (!w->hovered) Drawer2D.Colors['f'] = Drawer2D.Colors['F'];
Launcher_MarkDirty(w->x, w->y, w->width, w->height); Launcher_MarkDirty(w->x, w->y, w->width, w->height);
} }
@ -310,9 +310,9 @@ static void LInput_Draw(void* widget) {
w->width - xBorder4, w->height - yBorder4); w->width - xBorder4, w->height - yBorder4);
LInput_BlendBoxTop(w); LInput_BlendBoxTop(w);
Drawer2D_Cols['f'] = Drawer2D_Cols['0']; Drawer2D.Colors['f'] = Drawer2D.Colors['0'];
LInput_DrawText(w, &args); LInput_DrawText(w, &args);
Drawer2D_Cols['f'] = Drawer2D_Cols['F']; Drawer2D.Colors['f'] = Drawer2D.Colors['F'];
} }
static Rect2D LInput_MeasureCaret(struct LInput* w) { static Rect2D LInput_MeasureCaret(struct LInput* w) {

View File

@ -254,7 +254,7 @@ static void Launcher_Init(void) {
Drawer2D_MakeFont(&Launcher_HintFont, 12, FONT_FLAGS_NONE); Drawer2D_MakeFont(&Launcher_HintFont, 12, FONT_FLAGS_NONE);
titleX = Display_ScaleX(4); titleY = Display_ScaleY(4); titleX = Display_ScaleX(4); titleY = Display_ScaleY(4);
Drawer2D_Cols['g'] = BitmapCol_Make(125, 125, 125, 255); Drawer2D.Colors['g'] = BitmapCol_Make(125, 125, 125, 255);
Utils_EnsureDirectory("texpacks"); Utils_EnsureDirectory("texpacks");
Utils_EnsureDirectory("audio"); Utils_EnsureDirectory("audio");
} }
@ -291,8 +291,8 @@ void Launcher_Run(void) {
#endif #endif
Drawer2D_Component.Init(); Drawer2D_Component.Init();
Drawer2D_BitmappedText = false; Drawer2D.BitmappedText = false;
Drawer2D_BlackTextShadows = true; Drawer2D.BlackTextShadows = true;
InitFramebuffer(); InitFramebuffer();
Options_Get(LOPT_USERNAME, &Game_Username, ""); Options_Get(LOPT_USERNAME, &Game_Username, "");
@ -501,9 +501,9 @@ void Launcher_TryLoadTexturePack(void) {
void Launcher_UpdateLogoFont(void) { void Launcher_UpdateLogoFont(void) {
Font_Free(&logoFont); Font_Free(&logoFont);
Drawer2D_BitmappedText = (useBitmappedFont || Launcher_ClassicBackground) && hasBitmappedFont; Drawer2D.BitmappedText = (useBitmappedFont || Launcher_ClassicBackground) && hasBitmappedFont;
Drawer2D_MakeFont(&logoFont, 32, FONT_FLAGS_NONE); Drawer2D_MakeFont(&logoFont, 32, FONT_FLAGS_NONE);
Drawer2D_BitmappedText = false; Drawer2D.BitmappedText = false;
} }
/* Fills the given area using pixels from the source bitmap, by repeatedly tiling the bitmap. */ /* Fills the given area using pixels from the source bitmap, by repeatedly tiling the bitmap. */

View File

@ -2864,9 +2864,9 @@ void ChatOptionsScreen_Show(void) {
/*########################################################################################################################* /*########################################################################################################################*
*----------------------------------------------------GuiOptionsScreen-----------------------------------------------------* *----------------------------------------------------GuiOptionsScreen-----------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void GuiOptionsScreen_GetShadows(cc_string* v) { Menu_GetBool(v, Drawer2D_BlackTextShadows); } static void GuiOptionsScreen_GetShadows(cc_string* v) { Menu_GetBool(v, Drawer2D.BlackTextShadows); }
static void GuiOptionsScreen_SetShadows(const cc_string* v) { static void GuiOptionsScreen_SetShadows(const cc_string* v) {
Drawer2D_BlackTextShadows = Menu_SetBool(v, OPT_BLACK_TEXT); Drawer2D.BlackTextShadows = Menu_SetBool(v, OPT_BLACK_TEXT);
Event_RaiseVoid(&ChatEvents.FontChanged); Event_RaiseVoid(&ChatEvents.FontChanged);
} }
@ -2882,9 +2882,9 @@ static void GuiOptionsScreen_SetInventory(const cc_string* v) { ChatOptionsScree
static void GuiOptionsScreen_GetTabAuto(cc_string* v) { Menu_GetBool(v, Gui.TabAutocomplete); } static void GuiOptionsScreen_GetTabAuto(cc_string* v) { Menu_GetBool(v, Gui.TabAutocomplete); }
static void GuiOptionsScreen_SetTabAuto(const cc_string* v) { Gui.TabAutocomplete = Menu_SetBool(v, OPT_TAB_AUTOCOMPLETE); } static void GuiOptionsScreen_SetTabAuto(const cc_string* v) { Gui.TabAutocomplete = Menu_SetBool(v, OPT_TAB_AUTOCOMPLETE); }
static void GuiOptionsScreen_GetUseFont(cc_string* v) { Menu_GetBool(v, !Drawer2D_BitmappedText); } static void GuiOptionsScreen_GetUseFont(cc_string* v) { Menu_GetBool(v, !Drawer2D.BitmappedText); }
static void GuiOptionsScreen_SetUseFont(const cc_string* v) { static void GuiOptionsScreen_SetUseFont(const cc_string* v) {
Drawer2D_BitmappedText = !Menu_SetBool(v, OPT_USE_CHAT_FONT); Drawer2D.BitmappedText = !Menu_SetBool(v, OPT_USE_CHAT_FONT);
Event_RaiseVoid(&ChatEvents.FontChanged); Event_RaiseVoid(&ChatEvents.FontChanged);
} }

View File

@ -1202,7 +1202,7 @@ static void CPE_SetTextColor(cc_uint8* data) {
if (code == '\0' || code == ' ' || code == 0xFF) return; if (code == '\0' || code == ' ' || code == 0xFF) return;
if (code == '%' || code == '&') return; if (code == '%' || code == '&') return;
Drawer2D_Cols[code] = c; Drawer2D.Colors[code] = c;
Event_RaiseInt(&ChatEvents.ColCodeChanged, code); Event_RaiseInt(&ChatEvents.ColCodeChanged, code);
} }

View File

@ -652,7 +652,7 @@ static void TabListOverlay_ContextRecreated(void* screen) {
struct TabListOverlay* s = (struct TabListOverlay*)screen; struct TabListOverlay* s = (struct TabListOverlay*)screen;
int size, id; int size, id;
size = Drawer2D_BitmappedText ? 16 : 11; size = Drawer2D.BitmappedText ? 16 : 11;
Drawer2D_MakeFont(&s->font, size, FONT_FLAGS_PADDING); Drawer2D_MakeFont(&s->font, size, FONT_FLAGS_PADDING);
s->namesCount = 0; s->namesCount = 0;

View File

@ -2255,7 +2255,7 @@ static void SpecialInputWidget_UpdateColString(struct SpecialInputWidget* w) {
for (i = 0; i < DRAWER2D_MAX_COLS; i++) { for (i = 0; i < DRAWER2D_MAX_COLS; i++) {
if (i >= 'A' && i <= 'F') continue; if (i >= 'A' && i <= 'F') continue;
if (!BitmapCol_A(Drawer2D_Cols[i])) continue; if (!BitmapCol_A(Drawer2D.Colors[i])) continue;
String_Append(&w->colString, '&'); String_Append(&w->colString, (char)i); String_Append(&w->colString, '&'); String_Append(&w->colString, (char)i);
String_Append(&w->colString, '%'); String_Append(&w->colString, (char)i); String_Append(&w->colString, '%'); String_Append(&w->colString, (char)i);