diff --git a/include/renderd7/DrawV2.hpp b/include/renderd7/DrawV2.hpp index d64f8fa..c77c886 100644 --- a/include/renderd7/DrawV2.hpp +++ b/include/renderd7/DrawV2.hpp @@ -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); diff --git a/include/renderd7/font.hpp b/include/renderd7/font.hpp index 43408f6..f17dcef 100644 --- a/include/renderd7/font.hpp +++ b/include/renderd7/font.hpp @@ -21,15 +21,21 @@ #include #include +#include #include 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; + template + inline static Ref New(args &&...a) { + return std::make_shared(std::forward(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; diff --git a/rd7tf/source/main.cpp b/rd7tf/source/main.cpp index 79674fd..aa5f437 100644 --- a/rd7tf/source/main.cpp +++ b/rd7tf/source/main.cpp @@ -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()); 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; } \ No newline at end of file diff --git a/source/DrawV2.cpp b/source/DrawV2.cpp index e5be75e..012c8f7 100644 --- a/source/DrawV2.cpp +++ b/source/DrawV2.cpp @@ -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; }