Add BMF loading support
- Add ability to make textures not unloadable
This commit is contained in:
BIN
example/romfs/ComicNeue.png
Normal file
BIN
example/romfs/ComicNeue.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
@@ -11,8 +11,11 @@ class Example : public Amy::App {
|
||||
Top = C3D::CreateScreen(GFX_TOP);
|
||||
Mgr = new Amy::AssetMgr();
|
||||
Iron::Init();
|
||||
auto fnt = Iron::Font::New();
|
||||
fnt->LoadBMF("romfs:/ComicNeue.png");
|
||||
Mgr->AutoLoad("icon", "romfs:/icon.png");
|
||||
Mgr->AutoLoad("font", "romfs:/ComicNeue.ttf");
|
||||
Mgr->Add("font", fnt);
|
||||
// Mgr->AutoLoad("font", "romfs:/ComicNeue.ttf");
|
||||
dl = new Iron::Drawlist();
|
||||
dl->SetFont(Mgr->Get<Iron::Font>("font"));
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ class Iron {
|
||||
public:
|
||||
Drawlist() { DrawSolid(); }
|
||||
~Drawlist() { pData.clear(); }
|
||||
AMY_SHARED(Drawlist)
|
||||
|
||||
// required due to memory management
|
||||
Drawlist(const Drawlist&) = delete;
|
||||
@@ -122,7 +123,9 @@ class Iron {
|
||||
void DrawSolid();
|
||||
void DrawTex(Texture::Ref tex) { pTex = tex; }
|
||||
void SetFont(Font::Ref fnt) { pCurrentFont = fnt; }
|
||||
|
||||
void SetFontScale(float v) { pFontScale = v; }
|
||||
float GetFontScale() { return pFontScale; }
|
||||
void DefaultFontScale() { pFontScale = 0.7; }
|
||||
/** Draw Api */
|
||||
void DrawRect(const fvec2& pos, const fvec2& size, ui color,
|
||||
int thickness = 1);
|
||||
|
||||
@@ -29,6 +29,8 @@ class Texture : public Asset {
|
||||
// Dont set as loaded as only the root tex can be loaded
|
||||
}
|
||||
void Unload();
|
||||
void Unloadable(bool v) { pLoaded = v; }
|
||||
bool Unloadable() { return pLoaded; }
|
||||
|
||||
int W() const { return pSize.x; }
|
||||
int& W() { return pSize.x; }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <amethyst/iron.hpp>
|
||||
#include <amethyst/utils.hpp>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#if AMY_STB_TT == 1
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
@@ -8,7 +9,45 @@
|
||||
#include <stb_truetype.h>
|
||||
|
||||
namespace Amy {
|
||||
void Iron::Font::LoadBMF(ksr path) {}
|
||||
// Dont read this code please ... tnaks
|
||||
void Iron::Font::LoadBMF(ksr path) {
|
||||
Image img(path);
|
||||
if (img.Width() != img.Height() || img.Bpp() != 4) {
|
||||
throw std::runtime_error(
|
||||
"[Amy] Font: BMF is not in rgba or not 1x1 dimensioned!");
|
||||
}
|
||||
auto base = Amy::Texture::New();
|
||||
base->Load(img.GetBuffer(), img.Width(), img.Height(), img.Bpp());
|
||||
base->Unloadable(false);
|
||||
PxHeight = img.Height() / 16;
|
||||
for (int i = 0; i < img.Height(); i += PxHeight) {
|
||||
for (int j = 0; j < img.Width(); j += PxHeight) {
|
||||
int maxw = 0;
|
||||
Amy::Texture::Ref tex = Amy::Texture::New();
|
||||
for (int y = i; y < i + PxHeight; y++) {
|
||||
for (int x = j; x < j + PxHeight; x++) {
|
||||
if (img.GetBuffer()[((y * img.Width() + x) * 4) + 3] != 0) {
|
||||
maxw = std::max(maxw, x - j);
|
||||
}
|
||||
}
|
||||
}
|
||||
maxw++;
|
||||
tex->Load(base->Ptr(), base->Size(), base->Uv());
|
||||
Codepoint cp;
|
||||
cp.Cp = (i / PxHeight) * 16 + (j / PxHeight);
|
||||
cp.Offset = 0.f;
|
||||
cp.Size = fvec2(maxw, PxHeight);
|
||||
cp.Tex = tex;
|
||||
cp.Uv = fvec4(float(j) / float(img.Width()),
|
||||
1.f - float(i) / float(img.Height()),
|
||||
float(j + maxw) / float(img.Width()),
|
||||
1.f - float(i + PxHeight) / float(img.Height()));
|
||||
cp.Valid = maxw != 0;
|
||||
pCodeMap[(i / PxHeight) * 16 + (j / PxHeight)] = cp;
|
||||
Textures.push_back(tex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Iron::Font::LoadTTF(ksr path, int size) {
|
||||
auto data = Amy::Utils::LoadFile2Mem(path);
|
||||
|
||||
Reference in New Issue
Block a user