First commit
This commit is contained in:
64
runtime/lib/fennec_core.cpp
Normal file
64
runtime/lib/fennec_core.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
21
runtime/lib/fennec_core.h
Normal file
21
runtime/lib/fennec_core.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef FENNEC_CORE_H
|
||||
#define FENNEC_CORE_H
|
||||
|
||||
#include <3ds.h>
|
||||
#include <citro2d.h>
|
||||
#include <string>
|
||||
|
||||
namespace Fennec {
|
||||
void init();
|
||||
void exit();
|
||||
void beginFrame();
|
||||
void endFrame();
|
||||
|
||||
void drawRect(float x, float y, float w, float h, u32 color);
|
||||
void drawText(float x, float y, std::string content, u32 color);
|
||||
|
||||
void selectScreen(gfxScreen_t screen);
|
||||
u32 color(u8 r, u8 g, u8 b, u8 a = 255);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user