Launcher: Add dedicated DrawBackground method to Screens for drawing background launcher of screen/menu

This means that e.g. time isn't wasted with drawing default background, then completely drawing over the top of it with checkresourcescreen's custom background
This commit is contained in:
UnknownShadow200 2022-01-18 11:42:04 +11:00
parent c83f53ae93
commit f1b2de34d4
4 changed files with 43 additions and 49 deletions

View File

@ -16,6 +16,7 @@
#include "Input.h" #include "Input.h"
#include "Options.h" #include "Options.h"
#include "Utils.h" #include "Utils.h"
#include "LBackend.h"
/*########################################################################################################################* /*########################################################################################################################*
*---------------------------------------------------------Screen base-----------------------------------------------------* *---------------------------------------------------------Screen base-----------------------------------------------------*
@ -170,6 +171,31 @@ static void LScreen_MouseMove(struct LScreen* s, int idx) {
} }
static void LScreen_MouseWheel(struct LScreen* s, float delta) { } static void LScreen_MouseWheel(struct LScreen* s, float delta) { }
static void LScreen_DrawBackground(struct LScreen* s) {
cc_string title_fore, title_back;
struct DrawTextArgs args;
int x;
if (!s->title_fore) {
Launcher_ResetArea(0, 0, WindowInfo.Width, WindowInfo.Height);
return;
}
title_fore = String_FromReadonly(s->title_fore);
title_back = String_FromReadonly(s->title_back);
LBackend_ResetPixels();
DrawTextArgs_Make(&args, &title_fore, &Launcher_LogoFont, false);
x = WindowInfo.Width / 2 - Drawer2D_TextWidth(&args) / 2;
args.text = title_back;
Drawer2D_DrawText(&Launcher_Framebuffer, &args,
x + Display_ScaleX(4), Display_ScaleY(4));
args.text = title_fore;
Drawer2D_DrawText(&Launcher_Framebuffer, &args,
x, 0);
}
CC_NOINLINE static void LScreen_Reset(struct LScreen* s) { CC_NOINLINE static void LScreen_Reset(struct LScreen* s) {
int i; int i;
@ -184,9 +210,10 @@ CC_NOINLINE static void LScreen_Reset(struct LScreen* s) {
s->MouseUp = LScreen_MouseUp; s->MouseUp = LScreen_MouseUp;
s->MouseMove = LScreen_MouseMove; s->MouseMove = LScreen_MouseMove;
s->MouseWheel = LScreen_MouseWheel; s->MouseWheel = LScreen_MouseWheel;
s->HoverWidget = LScreen_HoverWidget; s->HoverWidget = LScreen_HoverWidget;
s->UnhoverWidget = LScreen_UnhoverWidget; s->UnhoverWidget = LScreen_UnhoverWidget;
s->TextChanged = LScreen_TextChanged; s->TextChanged = LScreen_TextChanged;
s->DrawBackground = LScreen_DrawBackground;
/* reset all widgets mouse state */ /* reset all widgets mouse state */
for (i = 0; i < s->numWidgets; i++) { for (i = 0; i < s->numWidgets; i++) {
@ -1067,7 +1094,7 @@ CC_NOINLINE static void CheckResourcesScreen_ResetArea(int x, int y, int width,
Launcher_MarkDirty(x, y, width, height); Launcher_MarkDirty(x, y, width, height);
} }
CC_NOINLINE static void CheckResourcesScreen_DrawBase(void) { CC_NOINLINE static void CheckResourcesScreen_DrawBackground(struct LScreen* s) {
int x, y, width, height; int x, y, width, height;
Drawer2D_Clear(&Launcher_Framebuffer, BitmapCol_Make(12, 12, 12, 255), Drawer2D_Clear(&Launcher_Framebuffer, BitmapCol_Make(12, 12, 12, 255),
0, 0, WindowInfo.Width, WindowInfo.Height); 0, 0, WindowInfo.Width, WindowInfo.Height);
@ -1079,19 +1106,14 @@ CC_NOINLINE static void CheckResourcesScreen_DrawBase(void) {
CheckResourcesScreen_ResetArea(x, y, width, height); CheckResourcesScreen_ResetArea(x, y, width, height);
} }
static void CheckResourcesScreen_Draw(struct LScreen* s) {
CheckResourcesScreen_DrawBase();
LScreen_Draw(s);
}
void CheckResourcesScreen_SetActive(void) { void CheckResourcesScreen_SetActive(void) {
struct CheckResourcesScreen* s = &CheckResourcesScreen_Instance; struct CheckResourcesScreen* s = &CheckResourcesScreen_Instance;
LScreen_Reset((struct LScreen*)s); LScreen_Reset((struct LScreen*)s);
s->Init = CheckResourcesScreen_Init; s->Init = CheckResourcesScreen_Init;
s->Show = CheckResourcesScreen_Show; s->Show = CheckResourcesScreen_Show;
s->Draw = CheckResourcesScreen_Draw;
s->Layout = CheckResourcesScreen_Layout; s->Layout = CheckResourcesScreen_Layout;
s->onEnterWidget = (struct LWidget*)&s->btnYes; s->DrawBackground = CheckResourcesScreen_DrawBackground;
s->onEnterWidget = (struct LWidget*)&s->btnYes;
Launcher_SetScreen((struct LScreen*)s); Launcher_SetScreen((struct LScreen*)s);
} }
@ -1127,11 +1149,6 @@ static void FetchResourcesScreen_Layout(struct LScreen* s_) {
LWidget_SetLocation(&s->sdrProgress, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 15); LWidget_SetLocation(&s->sdrProgress, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 15);
} }
static void FetchResourcesScreen_Draw(struct LScreen* s) {
CheckResourcesScreen_DrawBase();
LScreen_Draw(s);
}
static void FetchResourcesScreen_SetStatus(const cc_string* str) { static void FetchResourcesScreen_SetStatus(const cc_string* str) {
struct LLabel* w = &FetchResourcesScreen_Instance.lblStatus; struct LLabel* w = &FetchResourcesScreen_Instance.lblStatus;
CheckResourcesScreen_ResetArea(w->last.X, w->last.Y, CheckResourcesScreen_ResetArea(w->last.X, w->last.Y,
@ -1197,9 +1214,9 @@ void FetchResourcesScreen_SetActive(void) {
LScreen_Reset((struct LScreen*)s); LScreen_Reset((struct LScreen*)s);
s->Init = FetchResourcesScreen_Init; s->Init = FetchResourcesScreen_Init;
s->Show = FetchResourcesScreen_Show; s->Show = FetchResourcesScreen_Show;
s->Draw = FetchResourcesScreen_Draw;
s->Tick = FetchResourcesScreen_Tick; s->Tick = FetchResourcesScreen_Tick;
s->Layout = FetchResourcesScreen_Layout; s->Layout = FetchResourcesScreen_Layout;
s->DrawBackground = CheckResourcesScreen_DrawBackground;
Launcher_SetScreen((struct LScreen*)s); Launcher_SetScreen((struct LScreen*)s);
} }

View File

@ -17,6 +17,7 @@ typedef void(*LWidget_Func)(struct LScreen* s, struct LWidget* w);
LScreen_Func Layout; /* Positions the widgets on the screen. */ \ LScreen_Func Layout; /* Positions the widgets on the screen. */ \
LScreen_Func Draw; /* Draws all widgets and any other features such as lines/rectangles. */ \ LScreen_Func Draw; /* Draws all widgets and any other features such as lines/rectangles. */ \
LScreen_Func Tick; /* Repeatedly called multiple times every second. */ \ LScreen_Func Tick; /* Repeatedly called multiple times every second. */ \
void (*DrawBackground)(struct LScreen* s); \
void (*KeyDown)(struct LScreen* s, int key, cc_bool wasDown); \ void (*KeyDown)(struct LScreen* s, int key, cc_bool wasDown); \
void (*KeyPress)(struct LScreen* s, char c); \ void (*KeyPress)(struct LScreen* s, char c); \
void (*MouseDown)(struct LScreen* s, int idx); \ void (*MouseDown)(struct LScreen* s, int idx); \

View File

@ -27,11 +27,9 @@ static Rect2D dirty_rect;
static struct LScreen* activeScreen; static struct LScreen* activeScreen;
struct Bitmap Launcher_Framebuffer; struct Bitmap Launcher_Framebuffer;
struct FontDesc Launcher_TitleFont, Launcher_TextFont, Launcher_HintFont; struct FontDesc Launcher_TitleFont, Launcher_TextFont;
struct FontDesc Launcher_HintFont, Launcher_LogoFont;
static cc_bool pendingRedraw; static cc_bool pendingRedraw;
static struct FontDesc logoFont;
static int titleX, titleY;
cc_bool Launcher_ShouldExit, Launcher_ShouldUpdate; cc_bool Launcher_ShouldExit, Launcher_ShouldUpdate;
static char hashBuffer[STRING_SIZE], userBuffer[STRING_SIZE]; static char hashBuffer[STRING_SIZE], userBuffer[STRING_SIZE];
@ -255,7 +253,6 @@ static void Launcher_Init(void) {
Drawer2D_MakeFont(&Launcher_TitleFont, 16, FONT_FLAGS_BOLD); Drawer2D_MakeFont(&Launcher_TitleFont, 16, FONT_FLAGS_BOLD);
Drawer2D_MakeFont(&Launcher_TextFont, 14, FONT_FLAGS_NONE); Drawer2D_MakeFont(&Launcher_TextFont, 14, FONT_FLAGS_NONE);
Drawer2D_MakeFont(&Launcher_HintFont, 12, FONT_FLAGS_NONE); Drawer2D_MakeFont(&Launcher_HintFont, 12, FONT_FLAGS_NONE);
titleX = Display_ScaleX(4); titleY = Display_ScaleY(4);
Drawer2D.Colors['g'] = BitmapCol_Make(125, 125, 125, 255); Drawer2D.Colors['g'] = BitmapCol_Make(125, 125, 125, 255);
Utils_EnsureDirectory("texpacks"); Utils_EnsureDirectory("texpacks");
@ -265,10 +262,10 @@ static void Launcher_Init(void) {
static void Launcher_Free(void) { static void Launcher_Free(void) {
Event_UnregisterAll(); Event_UnregisterAll();
Flags_Free(); Flags_Free();
Font_Free(&logoFont);
Font_Free(&Launcher_TitleFont); Font_Free(&Launcher_TitleFont);
Font_Free(&Launcher_TextFont); Font_Free(&Launcher_TextFont);
Font_Free(&Launcher_HintFont); Font_Free(&Launcher_HintFont);
Font_Free(&Launcher_LogoFont);
hasBitmappedFont = false; hasBitmappedFont = false;
CloseActiveScreen(); CloseActiveScreen();
@ -487,9 +484,9 @@ void Launcher_TryLoadTexturePack(void) {
} }
void Launcher_UpdateLogoFont(void) { void Launcher_UpdateLogoFont(void) {
Font_Free(&logoFont); Font_Free(&Launcher_LogoFont);
Drawer2D.BitmappedText = (useBitmappedFont || Launcher_Theme.ClassicBackground) && hasBitmappedFont; Drawer2D.BitmappedText = (useBitmappedFont || Launcher_Theme.ClassicBackground) && hasBitmappedFont;
Drawer2D_MakeFont(&logoFont, 32, FONT_FLAGS_NONE); Drawer2D_MakeFont(&Launcher_LogoFont, 32, FONT_FLAGS_NONE);
Drawer2D.BitmappedText = false; Drawer2D.BitmappedText = false;
} }
@ -498,31 +495,8 @@ void Launcher_ResetArea(int x, int y, int width, int height) {
Launcher_MarkDirty(x, y, width, height); Launcher_MarkDirty(x, y, width, height);
} }
void Launcher_ResetPixels(void) {
cc_string title_fore, title_back;
struct DrawTextArgs args;
int x;
if (activeScreen && !activeScreen->title_fore) {
Launcher_ResetArea(0, 0, WindowInfo.Width, WindowInfo.Height);
return;
}
title_fore = String_FromReadonly(activeScreen->title_fore);
title_back = String_FromReadonly(activeScreen->title_back);
LBackend_ResetPixels();
DrawTextArgs_Make(&args, &title_fore, &logoFont, false);
x = WindowInfo.Width / 2 - Drawer2D_TextWidth(&args) / 2;
args.text = title_back;
Drawer2D_DrawText(&Launcher_Framebuffer, &args, x + titleX, titleY);
args.text = title_fore;
Drawer2D_DrawText(&Launcher_Framebuffer, &args, x, 0);
Launcher_MarkAllDirty();
}
void Launcher_Redraw(void) { void Launcher_Redraw(void) {
Launcher_ResetPixels(); activeScreen->DrawBackground(activeScreen);
activeScreen->Draw(activeScreen); activeScreen->Draw(activeScreen);
Launcher_MarkAllDirty(); Launcher_MarkAllDirty();
} }

View File

@ -13,6 +13,8 @@ extern struct Bitmap Launcher_Framebuffer;
extern struct FontDesc Launcher_TitleFont, Launcher_TextFont; extern struct FontDesc Launcher_TitleFont, Launcher_TextFont;
/* Default font for input widget hints. */ /* Default font for input widget hints. */
extern struct FontDesc Launcher_HintFont; extern struct FontDesc Launcher_HintFont;
/* Default font for screen/menu titles. */
extern struct FontDesc Launcher_LogoFont;
/* Whether at the next tick, the launcher window should proceed to stop displaying frames and subsequently exit. */ /* Whether at the next tick, the launcher window should proceed to stop displaying frames and subsequently exit. */
extern cc_bool Launcher_ShouldExit; extern cc_bool Launcher_ShouldExit;