mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 09:01:57 -05:00
Simplify launcher title drawing
This commit is contained in:
parent
d65fad3836
commit
2955330e49
5 changed files with 56 additions and 45 deletions
|
@ -30,3 +30,4 @@
|
|||
|
||||
end
|
||||
.end
|
||||
|
||||
|
|
|
@ -35,3 +35,4 @@
|
|||
|
||||
end
|
||||
.end
|
||||
|
||||
|
|
|
@ -34,3 +34,4 @@
|
|||
|
||||
end
|
||||
.end
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "PackedCol.h"
|
||||
#include "SystemFonts.h"
|
||||
#include "TexturePack.h"
|
||||
#include "Gui.h"
|
||||
|
||||
struct LScreen* Launcher_Active;
|
||||
cc_bool Launcher_ShouldExit, Launcher_ShouldUpdate;
|
||||
|
@ -528,52 +529,56 @@ cc_bool Launcher_BitmappedText(void) {
|
|||
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);
|
||||
struct DrawTextArgs args;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
/* Skip dragging logo when very small window to save space */
|
||||
if (Window_Main.Height < 240) return;
|
||||
int x, y;
|
||||
|
||||
DrawTextArgs_Make(&args, &title, font, false);
|
||||
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
|
||||
void Launcher_DrawTitle(struct FontDesc* font, const char* text, struct Context2D* ctx) {
|
||||
/* Put title on top screen */
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
struct Bitmap bmp;
|
||||
struct Context2D topCtx;
|
||||
struct Bitmap bmp;
|
||||
|
||||
ctx = &topCtx;
|
||||
bmp.width = max(Window_Main.Width, 1);
|
||||
bmp.height = max(Window_Main.Height, 1);
|
||||
Window_AllocFramebuffer(&bmp);
|
||||
Context2D_Wrap(ctx, &bmp);
|
||||
|
||||
Launcher_DrawBackgroundAll(ctx);
|
||||
#endif
|
||||
DrawTitleText(font, text, ctx, ANCHOR_CENTRE, ANCHOR_CENTRE);
|
||||
|
||||
DrawTextArgs_Make(&args, &title, font, false);
|
||||
x = ctx->width / 2 - Drawer2D_TextWidth(&args) / 2;
|
||||
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 });
|
||||
Rect2D rect = { 0, 0, bmp.width, bmp.height };
|
||||
Window_DrawFramebuffer(rect);
|
||||
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) {
|
||||
Drawer2D.BitmappedText = Launcher_BitmappedText();
|
||||
Font_Make(font, 32, FONT_FLAGS_NONE);
|
||||
Drawer2D.BitmappedText = false;
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -15,12 +15,13 @@
|
|||
static cc_bool launcherMode;
|
||||
static Result irrst_result;
|
||||
static enum Screen3DS renderScreen = TOP_SCREEN;
|
||||
static u16 top_width, top_height;
|
||||
static u16 btm_width, btm_height;
|
||||
|
||||
struct _DisplayData DisplayInfo;
|
||||
struct _WindowData WindowInfo;
|
||||
struct _WindowData Window_Alt;
|
||||
|
||||
|
||||
// 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.
|
||||
// * 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) {
|
||||
gfxInit(GSP_BGR8_OES, GSP_BGR8_OES, false);
|
||||
|
||||
u16 width, height;
|
||||
gfxGetFramebuffer(GFX_TOP, GFX_LEFT, &width, &height);
|
||||
// deliberately swapped
|
||||
gfxGetFramebuffer(GFX_TOP, GFX_LEFT, &top_height, &top_width);
|
||||
gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, &btm_height, &btm_width);
|
||||
|
||||
DisplayInfo.Width = height; // deliberately swapped
|
||||
DisplayInfo.Height = width; // deliberately swapped
|
||||
DisplayInfo.Width = top_width;
|
||||
DisplayInfo.Height = top_height;
|
||||
DisplayInfo.Depth = 4; // 32 bit
|
||||
DisplayInfo.ScaleX = 0.5f;
|
||||
DisplayInfo.ScaleY = 0.5f;
|
||||
|
||||
Window_Main.Width = height; // deliberately swapped
|
||||
Window_Main.Height = width; // deliberately swapped
|
||||
Window_Main.Width = top_width;
|
||||
Window_Main.Height = top_height;
|
||||
Window_Main.Focused = true;
|
||||
Window_Main.Exists = true;
|
||||
|
||||
|
@ -46,9 +48,8 @@ void Window_Init(void) {
|
|||
Input.Sources = INPUT_SOURCE_GAMEPAD;
|
||||
irrst_result = irrstInit();
|
||||
|
||||
gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, &width, &height);
|
||||
Window_Alt.Width = height; // deliberately swapped
|
||||
Window_Alt.Height = width; // deliberately swapped
|
||||
Window_Alt.Width = btm_width;
|
||||
Window_Alt.Height = btm_height;
|
||||
}
|
||||
|
||||
void Window_Free(void) { irrstExit(); }
|
||||
|
@ -177,24 +178,24 @@ void Window_UpdateRawMouse(void) { }
|
|||
/*########################################################################################################################*
|
||||
*------------------------------------------------------Framebuffer--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static struct Bitmap top_fb_bmp;
|
||||
static struct Bitmap bottom_fb_bmp;
|
||||
static struct Bitmap top_fb_bmp, btm_fb_bmp;
|
||||
|
||||
void Window_AllocFramebuffer(struct Bitmap* bmp) {
|
||||
bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
|
||||
if (renderScreen == TOP_SCREEN) {
|
||||
top_fb_bmp = *bmp;
|
||||
}
|
||||
else {
|
||||
bottom_fb_bmp = *bmp;
|
||||
} else {
|
||||
btm_fb_bmp = *bmp;
|
||||
}
|
||||
}
|
||||
|
||||
void Window_DrawFramebuffer(Rect2D r) {
|
||||
u16 width, height;
|
||||
gfxScreen_t screen = (renderScreen == TOP_SCREEN) ? GFX_TOP : GFX_BOTTOM;
|
||||
|
||||
gfxSetDoubleBuffering(screen, false);
|
||||
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 x = 0 to 400
|
||||
// DST X = 0 to 240
|
||||
|
@ -209,7 +210,6 @@ void Window_DrawFramebuffer(Rect2D r) {
|
|||
fb[addr+1] = BitmapCol_G(color);
|
||||
fb[addr+2] = BitmapCol_R(color);
|
||||
}
|
||||
// TODO implement
|
||||
// TODO gspWaitForVBlank();
|
||||
gfxFlushBuffers();
|
||||
//gfxSwapBuffers();
|
||||
|
@ -223,7 +223,10 @@ void Window_DrawFramebuffer(Rect2D r) {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -285,4 +288,4 @@ cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) {
|
|||
cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) {
|
||||
return ERR_NOT_SUPPORTED;
|
||||
}
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in a new issue