Update Font System
This commit is contained in:
parent
a1de7e9d13
commit
a9600f8d02
@ -48,7 +48,7 @@ std::string TextShort(const std::string& in, int max_len);
|
|||||||
// Overrite TextBox Size (by default Screenwidth x Text.h)
|
// Overrite TextBox Size (by default Screenwidth x Text.h)
|
||||||
void TextMaxBox(R7Vec2 size);
|
void TextMaxBox(R7Vec2 size);
|
||||||
void TextDefaultBox();
|
void TextDefaultBox();
|
||||||
void TextFont(Font fnt);
|
void TextFont(Font::Ref fnt);
|
||||||
void TextDefaultFont();
|
void TextDefaultFont();
|
||||||
namespace Draw2 {
|
namespace Draw2 {
|
||||||
void Rect(R7Vec2 pos, R7Vec2 size, unsigned int color, int t = 1);
|
void Rect(R7Vec2 pos, R7Vec2 size, unsigned int color, int t = 1);
|
||||||
|
@ -21,15 +21,21 @@
|
|||||||
#include <citro2d.h>
|
#include <citro2d.h>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
#include <renderd7/Error.hpp>
|
#include <renderd7/Error.hpp>
|
||||||
|
|
||||||
namespace RenderD7 {
|
namespace RenderD7 {
|
||||||
class Font {
|
class Font {
|
||||||
public:
|
public:
|
||||||
Font() = default;
|
Font() = default;
|
||||||
Font(const std::string& path) { load(path); };
|
Font(const std::string& path) { Load(path); };
|
||||||
~Font() { unload(); }
|
~Font() { Unload(); }
|
||||||
void load(const std::string& path) {
|
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);
|
std::ifstream ft(path, std::ios::in | std::ios::binary);
|
||||||
bool io = ft.is_open();
|
bool io = ft.is_open();
|
||||||
ft.close();
|
ft.close();
|
||||||
@ -37,8 +43,8 @@ class Font {
|
|||||||
fnt = C2D_FontLoad(path.c_str());
|
fnt = C2D_FontLoad(path.c_str());
|
||||||
RenderD7::InlineAssert(fnt, "Font could not be loaded!");
|
RenderD7::InlineAssert(fnt, "Font could not be loaded!");
|
||||||
}
|
}
|
||||||
C2D_Font ptr() { return fnt; }
|
C2D_Font Ptr() { return fnt; }
|
||||||
void unload() {
|
void Unload() {
|
||||||
if (!fnt) return;
|
if (!fnt) return;
|
||||||
C2D_FontFree(fnt);
|
C2D_FontFree(fnt);
|
||||||
fnt = nullptr;
|
fnt = nullptr;
|
||||||
|
@ -26,8 +26,10 @@ int main() {
|
|||||||
RD7::Ftrace::Beg("app", "app_init");
|
RD7::Ftrace::Beg("app", "app_init");
|
||||||
RD7::Init::Main("rd7tf");
|
RD7::Init::Main("rd7tf");
|
||||||
RD7::FadeIn();
|
RD7::FadeIn();
|
||||||
|
auto fnt = RD7::Font::New("romfs:/roboto_bold.bcfnt");
|
||||||
|
RD7::TextFont(fnt);
|
||||||
// IdbServer();
|
// IdbServer();
|
||||||
RD7::Init::NdspFirm();
|
//RD7::Init::NdspFirm();
|
||||||
RD7::Scene::Load(std::make_unique<Sample>());
|
RD7::Scene::Load(std::make_unique<Sample>());
|
||||||
RD7::Ftrace::End("app", "app_init");
|
RD7::Ftrace::End("app", "app_init");
|
||||||
while (RD7::MainLoop()) {
|
while (RD7::MainLoop()) {
|
||||||
@ -41,6 +43,5 @@ int main() {
|
|||||||
RD7::FrameEnd();
|
RD7::FrameEnd();
|
||||||
RD7::Ftrace::End("app", "app_mainloop");
|
RD7::Ftrace::End("app", "app_mainloop");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -104,6 +104,7 @@ bool RD7I_FNT_VALID() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace RenderD7 {
|
namespace RenderD7 {
|
||||||
|
// TODO: Fix wrong Width/Height on other fonts
|
||||||
R7Vec2 GetTextDimensions(const std::string &text) {
|
R7Vec2 GetTextDimensions(const std::string &text) {
|
||||||
C2D_TextBufClear(rd7i_d2_dimbuf);
|
C2D_TextBufClear(rd7i_d2_dimbuf);
|
||||||
float w = 0, h = 0;
|
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 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; }
|
void TextDefaultFont() { rd7i_d2_fnt = rd7i_base_font; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user