More text changes

This commit is contained in:
Dynamitos
2025-01-19 16:07:38 +01:00
parent 2915db8898
commit 4e6eb02e74
23 changed files with 390 additions and 110 deletions
+3 -1
View File
@@ -8,5 +8,7 @@ target_sources(Editor
MaterialLoader.cpp
MeshLoader.h
MeshLoader.cpp
SVGLoader.h
SVGLoader.cpp
TextureLoader.h
TextureLoader.cpp "../../../tests/Engine/UI/Element.cpp")
TextureLoader.cpp)
+7 -39
View File
@@ -31,45 +31,13 @@ void FontLoader::importAsset(FontImportArgs args) {
// in case of the space character there is no bitmap
// so we create a single pixel empty texture
void FontLoader::import(FontImportArgs args, PFontAsset asset) {
FT_Library ft;
FT_Error error = FT_Init_FreeType(&ft);
assert(!error);
FT_Face face;
error = FT_New_Face(ft, args.filePath.string().c_str(), 0, &face);
assert(!error);
FT_Set_Pixel_Sizes(face, 0, 48);
for (uint32 c = 0; c < 256; ++c) {
if (FT_Load_Char(face, c, FT_LOAD_RENDER | FT_LOAD_COLOR)) {
std::cout << "error loading " << (char)c << std::endl;
continue;
}
FontAsset::Glyph& glyph = asset->glyphs[c];
glyph.size = IVector2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
glyph.bearing = IVector2(face->glyph->bitmap_left, face->glyph->bitmap_top);
glyph.advance = face->glyph->advance.x;
glyph.textureData.resize(glyph.size.x * glyph.size.y);
if (glyph.textureData.size() == 0) {
glyph.size.x = 1;
glyph.size.y = 1;
glyph.textureData.add(0);
// load a single transparent pixel, so that we dont have to handle empty textures later
} else {
std::memcpy(glyph.textureData.data(), face->glyph->bitmap.buffer, glyph.textureData.size());
}
glyph.texture = graphics->createTexture2D(TextureCreateInfo{
.sourceData =
{
.size = glyph.textureData.size(),
.data = glyph.textureData.data(),
},
.format = Gfx::SE_FORMAT_R8_UNORM,
.width = glyph.size.x,
.height = glyph.size.y,
.name = "FontGlyph",
});
}
FT_Done_Face(face);
FT_Done_FreeType(ft);
std::ifstream stream(args.filePath.c_str(), std::ios::binary | std::ios::ate);
Array<uint8> ttfFile(stream.tellg());
stream.seekg(0);
stream.read((char*)ttfFile.data(), ttfFile.size());
asset->ttfFile = std::move(ttfFile);
asset->graphics = graphics;
asset->loadFace();
AssetRegistry::saveAsset(asset, FontAsset::IDENTIFIER, asset->getFolderPath(), asset->getName());
+35
View File
@@ -0,0 +1,35 @@
#include "SVGLoader.h"
#include "Asset/SVGAsset.h"
#include "Asset/AssetRegistry.h"
#include <fstream>
using namespace Seele;
SVGLoader::SVGLoader(Gfx::PGraphics graphic) {}
SVGLoader::~SVGLoader() {}
void SVGLoader::importAsset(SVGImportArgs args) {
std::filesystem::path assetPath = args.filePath.filename();
assetPath.replace_extension("asset");
OSVGAsset asset = new SVGAsset(args.importPath, assetPath.stem().string());
asset->setStatus(Asset::Status::Loading);
// the registry takes ownership, but we need to edit the reference
PSVGAsset ref = asset;
AssetRegistry::get().registerSVG(std::move(asset));
import(args, ref);
}
void SVGLoader::import(SVGImportArgs args, PSVGAsset asset) {
std::ifstream stream(args.filePath.c_str(), std::ios::binary | std::ios::ate);
Array<char> svgFile(stream.tellg());
stream.seekg(0);
stream.read((char*)svgFile.data(), svgFile.size());
asset->document = lunasvg::Document::loadFromData(svgFile.data());
asset->data = std::move(svgFile);
asset->graphics = graphics;
AssetRegistry::saveAsset(asset, SVGAsset::IDENTIFIER, asset->getFolderPath(), asset->getName());
asset->setStatus(Asset::Status::Ready);
}
+24
View File
@@ -0,0 +1,24 @@
#pragma once
#include "Containers/List.h"
#include "MinimalEngine.h"
#include <filesystem>
namespace Seele {
DECLARE_REF(SVGAsset)
DECLARE_NAME_REF(Gfx, Graphics)
struct SVGImportArgs {
std::filesystem::path filePath;
std::string importPath;
};
class SVGLoader {
public:
SVGLoader(Gfx::PGraphics graphic);
~SVGLoader();
void importAsset(SVGImportArgs args);
private:
void import(SVGImportArgs args, PSVGAsset asset);
Gfx::PGraphics graphics;
};
DECLARE_REF(SVGLoader)
} // namespace Seele
+8 -2
View File
@@ -11,8 +11,14 @@ using namespace Seele::Editor;
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo)
: View(graphics, window, createInfo, "InspectorView"),
uiSystem(new UI::System(new UI::Div(
UI::Attributes{}, {new UI::Div<W_Full, BG_Red>({}, {new UI::Text<Font_Arial>("OtherTest")}), new UI::Text<Font_Arial>("Test")}))) {
uiSystem(new UI::System(
new UI::Div<M_8>(UI::Attributes{}, {
new UI::Div<BG_Red, Inline>({},
{
new UI::Text<Font_Arial, Text_9XL>("OtherTestT"),
}),
new UI::Text<Font_Arial>("Test"),
}))) {
renderGraph.addPass(new UIPass(graphics, uiSystem));
renderGraph.setViewport(viewport);
renderGraph.createRenderPass();
+3
View File
@@ -87,6 +87,9 @@ int main() {
AssetImporter::importFont(FontImportArgs{
.filePath = "./fonts/arial.ttf",
});
AssetImporter::importFont(FontImportArgs{
.filePath = "C:\\Windows\\Fonts\\Calibri.ttf",
});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/cube.fbx",
});