64 lines
1.6 KiB
C++
64 lines
1.6 KiB
C++
#include "fennec_core.h"
|
|
|
|
namespace Fennec {
|
|
static C3D_RenderTarget* topTarget;
|
|
static C3D_RenderTarget* bottomTarget;
|
|
static C3D_RenderTarget* currentTarget;
|
|
|
|
static C2D_TextBuf staticTextBuf;
|
|
|
|
void init() {
|
|
gfxInitDefault();
|
|
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
|
|
C2D_Init(C2D_DEFAULT_MAX_OBJECTS);
|
|
C2D_Prepare();
|
|
|
|
staticTextBuf = C2D_TextBufNew(4096);
|
|
|
|
topTarget = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
|
|
bottomTarget = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
|
|
|
|
currentTarget = topTarget;
|
|
}
|
|
|
|
void drawRect(float x, float y, float z, float w, float h, u32 color) {
|
|
C2D_DrawRectSolid(x, y, 0.5f, w, h, color);
|
|
}
|
|
|
|
void drawText(float x, float y, std::string content, u32 color) {
|
|
if (!staticTextBuf) return;
|
|
C2D_Text textObj;
|
|
C2D_TextParse(&textObj, staticTextBuf, content.c_str());
|
|
C2D_TextOptimize(&textObj);
|
|
C2D_DrawText(&textObj, C2D_WithColor, x, y, 0.5f, 0.1f, 0.1f, color);
|
|
}
|
|
|
|
void clearTextBuffer() {
|
|
C2D_TextBufClear(staticTextBuf)
|
|
}
|
|
|
|
void exit() {
|
|
C2D_TextBufDelete(staticTextBuf);
|
|
C2D_Fini();
|
|
C3D_Fini();
|
|
gfxExit();
|
|
}
|
|
|
|
void beginFrame() {
|
|
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
|
C2D_TextBufClear(staticTextBuf);
|
|
}
|
|
|
|
void endFrame() {
|
|
C3D_FrameEnd(0);
|
|
}
|
|
|
|
void selectScreen(gfxScreen_t screen) {
|
|
currentTarget = (screen == GFX_TOP) ? topTarget : bottomTarget;
|
|
C2D_SceneBegin(currentTarget);
|
|
}
|
|
|
|
u32 color(u8 r, u8 g, u8 b, u8 a) {
|
|
return C2D_Color32(r, g, b, a);
|
|
}
|
|
} |