Update Font System

This commit is contained in:
tobid7 2024-05-19 11:35:59 +02:00
parent a1de7e9d13
commit a9600f8d02
4 changed files with 17 additions and 9 deletions

View File

@ -48,7 +48,7 @@ std::string TextShort(const std::string& in, int max_len);
// Overrite TextBox Size (by default Screenwidth x Text.h)
void TextMaxBox(R7Vec2 size);
void TextDefaultBox();
void TextFont(Font fnt);
void TextFont(Font::Ref fnt);
void TextDefaultFont();
namespace Draw2 {
void Rect(R7Vec2 pos, R7Vec2 size, unsigned int color, int t = 1);

View File

@ -21,15 +21,21 @@
#include <citro2d.h>
#include <fstream>
#include <memory>
#include <renderd7/Error.hpp>
namespace RenderD7 {
class Font {
public:
Font() = default;
Font(const std::string& path) { load(path); };
~Font() { unload(); }
void load(const std::string& path) {
Font(const std::string& path) { Load(path); };
~Font() { Unload(); }
using Ref = std::shared_ptr<Font>;
template<typename ...args>
inline static Ref New(args &&...a) {
return std::make_shared<Font>(std::forward<args>(a)...);
}
void Load(const std::string& path) {
std::ifstream ft(path, std::ios::in | std::ios::binary);
bool io = ft.is_open();
ft.close();
@ -37,8 +43,8 @@ class Font {
fnt = C2D_FontLoad(path.c_str());
RenderD7::InlineAssert(fnt, "Font could not be loaded!");
}
C2D_Font ptr() { return fnt; }
void unload() {
C2D_Font Ptr() { return fnt; }
void Unload() {
if (!fnt) return;
C2D_FontFree(fnt);
fnt = nullptr;

View File

@ -26,8 +26,10 @@ int main() {
RD7::Ftrace::Beg("app", "app_init");
RD7::Init::Main("rd7tf");
RD7::FadeIn();
auto fnt = RD7::Font::New("romfs:/roboto_bold.bcfnt");
RD7::TextFont(fnt);
// IdbServer();
RD7::Init::NdspFirm();
//RD7::Init::NdspFirm();
RD7::Scene::Load(std::make_unique<Sample>());
RD7::Ftrace::End("app", "app_init");
while (RD7::MainLoop()) {
@ -41,6 +43,5 @@ int main() {
RD7::FrameEnd();
RD7::Ftrace::End("app", "app_mainloop");
}
return 0;
}

View File

@ -104,6 +104,7 @@ bool RD7I_FNT_VALID() {
}
namespace RenderD7 {
// TODO: Fix wrong Width/Height on other fonts
R7Vec2 GetTextDimensions(const std::string &text) {
C2D_TextBufClear(rd7i_d2_dimbuf);
float w = 0, h = 0;
@ -122,7 +123,7 @@ void TextMaxBox(R7Vec2 size) { rd7i_d7_mwh = size; }
void TextDefaultBox() { rd7i_d7_mwh = R7Vec2(0, 0); }
void TextFont(Font fnt) { rd7i_d2_fnt = fnt.ptr(); }
void TextFont(Font::Ref fnt) { rd7i_d2_fnt = fnt->Ptr(); }
void TextDefaultFont() { rd7i_d2_fnt = rd7i_base_font; }