Simplify launcher title drawing

This commit is contained in:
UnknownShadow200 2024-02-03 13:49:42 +11:00
parent d65fad3836
commit 2955330e49
5 changed files with 56 additions and 45 deletions

View File

@ -30,3 +30,4 @@
end end
.end .end

View File

@ -35,3 +35,4 @@
end end
.end .end

View File

@ -34,3 +34,4 @@
end end
.end .end

View File

@ -22,6 +22,7 @@
#include "PackedCol.h" #include "PackedCol.h"
#include "SystemFonts.h" #include "SystemFonts.h"
#include "TexturePack.h" #include "TexturePack.h"
#include "Gui.h"
struct LScreen* Launcher_Active; struct LScreen* Launcher_Active;
cc_bool Launcher_ShouldExit, Launcher_ShouldUpdate; cc_bool Launcher_ShouldExit, Launcher_ShouldUpdate;
@ -528,48 +529,52 @@ cc_bool Launcher_BitmappedText(void) {
return (useBitmappedFont || Launcher_Theme.ClassicBackground) && hasBitmappedFont; return (useBitmappedFont || Launcher_Theme.ClassicBackground) && hasBitmappedFont;
} }
void Launcher_DrawTitle(struct FontDesc* font, const char* text, struct Context2D* ctx) { static void DrawTitleText(struct FontDesc* font, const char* text, struct Context2D* ctx,
cc_uint8 horAnchor, cc_uint8 verAnchor) {
cc_string title = String_FromReadonly(text); cc_string title = String_FromReadonly(text);
struct DrawTextArgs args; struct DrawTextArgs args;
int x; int x, y;
int y;
/* Skip dragging logo when very small window to save space */ DrawTextArgs_Make(&args, &title, font, false);
if (Window_Main.Height < 240) return; x = Gui_CalcPos(horAnchor, 0, Drawer2D_TextWidth(&args), ctx->width);
y = Gui_CalcPos(verAnchor, 0, Drawer2D_TextHeight(&args), ctx->height);
Drawer2D.Colors['f'] = BITMAPCOLOR_BLACK;
Context2D_DrawText(ctx, &args, x + Display_ScaleX(4), y + Display_ScaleY(4));
Drawer2D.Colors['f'] = BITMAPCOLOR_WHITE;
Context2D_DrawText(ctx, &args, x, y);
}
#ifdef CC_BUILD_DUALSCREEN #ifdef CC_BUILD_DUALSCREEN
void Launcher_DrawTitle(struct FontDesc* font, const char* text, struct Context2D* ctx) {
/* Put title on top screen */ /* Put title on top screen */
enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN); enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN);
struct Bitmap bmp;
struct Context2D topCtx; struct Context2D topCtx;
struct Bitmap bmp;
ctx = &topCtx; ctx = &topCtx;
bmp.width = max(Window_Main.Width, 1); bmp.width = max(Window_Main.Width, 1);
bmp.height = max(Window_Main.Height, 1); bmp.height = max(Window_Main.Height, 1);
Window_AllocFramebuffer(&bmp); Window_AllocFramebuffer(&bmp);
Context2D_Wrap(ctx, &bmp); Context2D_Wrap(ctx, &bmp);
Launcher_DrawBackgroundAll(ctx); Launcher_DrawBackgroundAll(ctx);
#endif DrawTitleText(font, text, ctx, ANCHOR_CENTRE, ANCHOR_CENTRE);
DrawTextArgs_Make(&args, &title, font, false); Rect2D rect = { 0, 0, bmp.width, bmp.height };
x = ctx->width / 2 - Drawer2D_TextWidth(&args) / 2; Window_DrawFramebuffer(rect);
y = 0;
#ifdef CC_BUILD_DUALSCREEN
// vertically center the title
y = ctx->height / 2 - Drawer2D_TextHeight(&args) / 2;
#endif
Drawer2D.Colors['f'] = BITMAPCOLOR_BLACK;
Context2D_DrawText(ctx, &args, x + Display_ScaleX(4), y + Display_ScaleY(4));
Drawer2D.Colors['f'] = BITMAPCOLOR_WHITE;
Context2D_DrawText(ctx, &args, x, y);
#ifdef CC_BUILD_DUALSCREEN
Window_DrawFramebuffer((Rect2D){ 0, 0, bmp.width, bmp.height });
Window_3DS_SetRenderScreen(scr); Window_3DS_SetRenderScreen(scr);
#endif Window_FreeFramebuffer(&bmp);
} }
#else
void Launcher_DrawTitle(struct FontDesc* font, const char* text, struct Context2D* ctx) {
int x;
/* Skip dragging logo when very small window to save space */
if (Window_Main.Height < 240) return;
DrawTitleText(font, text, ctx, ANCHOR_CENTRE, ANCHOR_MIN);
}
#endif
void Launcher_MakeTitleFont(struct FontDesc* font) { void Launcher_MakeTitleFont(struct FontDesc* font) {
Drawer2D.BitmappedText = Launcher_BitmappedText(); Drawer2D.BitmappedText = Launcher_BitmappedText();

View File

@ -15,12 +15,13 @@
static cc_bool launcherMode; static cc_bool launcherMode;
static Result irrst_result; static Result irrst_result;
static enum Screen3DS renderScreen = TOP_SCREEN; static enum Screen3DS renderScreen = TOP_SCREEN;
static u16 top_width, top_height;
static u16 btm_width, btm_height;
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo; struct _WindowData WindowInfo;
struct _WindowData Window_Alt; struct _WindowData Window_Alt;
// Note from https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/gfx.h // Note from https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/gfx.h
// * Please note that the 3DS uses *portrait* screens rotated 90 degrees counterclockwise. // * Please note that the 3DS uses *portrait* screens rotated 90 degrees counterclockwise.
// * Width/height refer to the physical dimensions of the screen; that is, the top screen // * Width/height refer to the physical dimensions of the screen; that is, the top screen
@ -28,17 +29,18 @@ struct _WindowData Window_Alt;
void Window_Init(void) { void Window_Init(void) {
gfxInit(GSP_BGR8_OES, GSP_BGR8_OES, false); gfxInit(GSP_BGR8_OES, GSP_BGR8_OES, false);
u16 width, height; // deliberately swapped
gfxGetFramebuffer(GFX_TOP, GFX_LEFT, &width, &height); gfxGetFramebuffer(GFX_TOP, GFX_LEFT, &top_height, &top_width);
gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, &btm_height, &btm_width);
DisplayInfo.Width = height; // deliberately swapped DisplayInfo.Width = top_width;
DisplayInfo.Height = width; // deliberately swapped DisplayInfo.Height = top_height;
DisplayInfo.Depth = 4; // 32 bit DisplayInfo.Depth = 4; // 32 bit
DisplayInfo.ScaleX = 0.5f; DisplayInfo.ScaleX = 0.5f;
DisplayInfo.ScaleY = 0.5f; DisplayInfo.ScaleY = 0.5f;
Window_Main.Width = height; // deliberately swapped Window_Main.Width = top_width;
Window_Main.Height = width; // deliberately swapped Window_Main.Height = top_height;
Window_Main.Focused = true; Window_Main.Focused = true;
Window_Main.Exists = true; Window_Main.Exists = true;
@ -46,9 +48,8 @@ void Window_Init(void) {
Input.Sources = INPUT_SOURCE_GAMEPAD; Input.Sources = INPUT_SOURCE_GAMEPAD;
irrst_result = irrstInit(); irrst_result = irrstInit();
gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, &width, &height); Window_Alt.Width = btm_width;
Window_Alt.Width = height; // deliberately swapped Window_Alt.Height = btm_height;
Window_Alt.Height = width; // deliberately swapped
} }
void Window_Free(void) { irrstExit(); } void Window_Free(void) { irrstExit(); }
@ -177,24 +178,24 @@ void Window_UpdateRawMouse(void) { }
/*########################################################################################################################* /*########################################################################################################################*
*------------------------------------------------------Framebuffer--------------------------------------------------------* *------------------------------------------------------Framebuffer--------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static struct Bitmap top_fb_bmp; static struct Bitmap top_fb_bmp, btm_fb_bmp;
static struct Bitmap bottom_fb_bmp;
void Window_AllocFramebuffer(struct Bitmap* bmp) { void Window_AllocFramebuffer(struct Bitmap* bmp) {
bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels"); bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
if (renderScreen == TOP_SCREEN) { if (renderScreen == TOP_SCREEN) {
top_fb_bmp = *bmp; top_fb_bmp = *bmp;
} } else {
else { btm_fb_bmp = *bmp;
bottom_fb_bmp = *bmp;
} }
} }
void Window_DrawFramebuffer(Rect2D r) { void Window_DrawFramebuffer(Rect2D r) {
u16 width, height; u16 width, height;
gfxScreen_t screen = (renderScreen == TOP_SCREEN) ? GFX_TOP : GFX_BOTTOM; gfxScreen_t screen = (renderScreen == TOP_SCREEN) ? GFX_TOP : GFX_BOTTOM;
gfxSetDoubleBuffering(screen, false); gfxSetDoubleBuffering(screen, false);
u8* fb = gfxGetFramebuffer(screen, GFX_LEFT, &width, &height); u8* fb = gfxGetFramebuffer(screen, GFX_LEFT, &width, &height);
struct Bitmap *bmp = (renderScreen == TOP_SCREEN) ? &top_fb_bmp : &bottom_fb_bmp; struct Bitmap *bmp = (renderScreen == TOP_SCREEN) ? &top_fb_bmp : &btm_fb_bmp;
// SRC y = 0 to 240 // SRC y = 0 to 240
// SRC x = 0 to 400 // SRC x = 0 to 400
// DST X = 0 to 240 // DST X = 0 to 240
@ -209,7 +210,6 @@ void Window_DrawFramebuffer(Rect2D r) {
fb[addr+1] = BitmapCol_G(color); fb[addr+1] = BitmapCol_G(color);
fb[addr+2] = BitmapCol_R(color); fb[addr+2] = BitmapCol_R(color);
} }
// TODO implement
// TODO gspWaitForVBlank(); // TODO gspWaitForVBlank();
gfxFlushBuffers(); gfxFlushBuffers();
//gfxSwapBuffers(); //gfxSwapBuffers();
@ -223,7 +223,10 @@ void Window_DrawFramebuffer(Rect2D r) {
} }
void Window_FreeFramebuffer(struct Bitmap* bmp) { void Window_FreeFramebuffer(struct Bitmap* bmp) {
/* TODO implement */ if (top_fb_bmp.scan0 == bmp->scan0) top_fb_bmp.scan0 = NULL;
if (btm_fb_bmp.scan0 == bmp->scan0) btm_fb_bmp.scan0 = NULL;
Mem_Free(bmp->scan0);
} }