diff options
| -rw-r--r-- | assets/glyphs/box.svg | 21 | ||||
| -rw-r--r-- | assets/glyphs/circle.svg | 21 | ||||
| -rw-r--r-- | config.mk | 1 | ||||
| -rw-r--r-- | editor/editor.cpp | 76 | ||||
| -rw-r--r-- | src/static-ui.hpp | 12 |
5 files changed, 131 insertions, 0 deletions
diff --git a/assets/glyphs/box.svg b/assets/glyphs/box.svg new file mode 100644 index 0000000..66e0078 --- /dev/null +++ b/assets/glyphs/box.svg @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + width="16" + height="16" + viewBox="0 0 16 16" + version="1.1" + id="svg1" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"> + <defs + id="defs1" /> + <g + id="layer1"> + <path + id="rect4" + style="fill:#000000;stroke:none" + d="M 0 0 L 0 16 L 16 16 L 16 0 L 0 0 z M 1 1 L 15 1 L 15 15 L 1 15 L 1 1 z " /> + </g> +</svg> diff --git a/assets/glyphs/circle.svg b/assets/glyphs/circle.svg new file mode 100644 index 0000000..a0fd061 --- /dev/null +++ b/assets/glyphs/circle.svg @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + width="16" + height="16" + viewBox="0 0 16 16" + version="1.1" + id="svg1" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"> + <defs + id="defs1" /> + <g + id="layer1"> + <path + id="path5" + style="display:inline;fill:#000000;stroke:none" + d="M 8 0 A 8 8 0 0 0 0 8 A 8 8 0 0 0 8 16 A 8 8 0 0 0 16 8 A 8 8 0 0 0 8 0 z M 8 1 A 7 7 0 0 1 15 8 A 7 7 0 0 1 8 15 A 7 7 0 0 1 1 8 A 7 7 0 0 1 8 1 z " /> + </g> +</svg> @@ -17,6 +17,7 @@ USED_LIBS = \ glm \ freetype2 \ libpng \ + tinyxml2 \ INCS = `$(PKG_CONFIG) --cflags $(USED_LIBS)` diff --git a/editor/editor.cpp b/editor/editor.cpp index 28798d5..ee35d27 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -14,9 +14,11 @@ #include "level.hpp" #include "math-helpers.hpp" #include "msdf-atlas-gen/msdf-atlas-gen.h" +#include "msdfgen.h" #include "player-input.hpp" #include "plugins.hpp" #include "project.hpp" +#include "static-ui.hpp" #include "thread-pool.hpp" #include "vendor-glm-include.hpp" #include "vendor-tinyfiledialogs.h" @@ -884,6 +886,28 @@ void GenerateMTSDF(FontTypeMSDFSettings *msdf_settings, const Asset *a) { FontType_RegisterFont(font_title, ah_image, ah_glyphs, msdf_settings, &ft_spacing); } +void GenerateMTSDFGlyph(MSDFGlyphSettings *settings, const char *name) { + assert(settings != nullptr); + NULL_CHAR_ARR(src_path, 128); + NULL_CHAR_ARR(dst_path, 128); + std::error_code e; + std::filesystem::create_directory("./glyphs", e); + sprintf(src_path, "./assets/glyphs/%s.svg", name); + sprintf(dst_path, "./glyphs/%s.png", name); + msdfgen::Shape shape; + if (!msdfgen::loadSvgShape(shape, src_path)) { + return; + } + shape.normalize(); + msdfgen::edgeColoringSimple(shape, 3.0); + msdfgen::Bitmap<float, 4> mtsdf(settings->width, settings->height); + msdfgen::Vector2 scale(settings->scale); + msdfgen::Vector2 em_translation(settings->translate_em, settings->translate_em); + msdfgen::SDFTransformation t(msdfgen::Projection(scale, em_translation), msdfgen::Range(settings->range_em)); + msdfgen::generateMTSDF(mtsdf, shape, t); + msdfgen::savePng(mtsdf, dst_path); +} + bool RecordImGui_GenerateMTSDFModal() { bool ret_value = false; static struct FontTypeMSDFSettings msdf_settings{}; @@ -921,6 +945,54 @@ bool RecordImGui_GenerateMTSDFModal() { return ret_value; } +bool RecordImGui_GenerateMTSDFGlyphModal() { + bool ret_value = false; + static std::regex reg_svg_file(".+\\.svg$", std::regex_constants::icase); + static MSDFGlyphSettings msdf_glyph_settings = { + .width = 80, + .height = 80, + .scale = 4, + .translate_em = 2, + .range_em = 4, + }; + if (ImGui::BeginPopupModal("MTSDFGlyphModal", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { + + ImGui::InputFloat("width", &msdf_glyph_settings.width); + ImGui::InputFloat("height", &msdf_glyph_settings.height); + ImGui::InputFloat("scale", &msdf_glyph_settings.scale); + ImGui::InputFloat("translate_em", &msdf_glyph_settings.translate_em); + ImGui::InputFloat("range_em", &msdf_glyph_settings.range_em); + + ImGui::Separator(); + + ImGui::Text("%s", "Glyphs in asset dir:"); + std::filesystem::directory_iterator di{"assets/glyphs"}; + for (const std::filesystem::directory_entry &sde : di) { + if (sde.is_regular_file() && std::regex_search(sde.path().c_str(), reg_svg_file)) { + ImGui::Text("%s", sde.path().filename().c_str()); + } + } + + ImGui::Separator(); + + if (ImGui::Button("Generate")) { + di = std::filesystem::directory_iterator {"assets/glyphs"}; + for (const std::filesystem::directory_entry &sde : di) { + if (sde.is_regular_file() && std::regex_search(sde.path().c_str(), reg_svg_file)) { + GenerateMTSDFGlyph(&msdf_glyph_settings, sde.path().stem().c_str()); + } + } + ImGui::CloseCurrentPopup(); + } + ImGui::SameLine(); + if (ImGui::Button("Cancel")) { + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + return ret_value; +} + void RecordImGuiAssets() { if (!ImGui::Begin("AssetList")) { ImGui::End(); @@ -1570,6 +1642,9 @@ void RecordImGuiSceneEditor() { if (ImGui::Button("Generate MTSDF")) { ImGui::OpenPopup("MTSDFModal"); } + if (ImGui::Button("Generate UI MTSDFs")) { + ImGui::OpenPopup("MTSDFGlyphModal"); + } if (ImGui::Button("Clear Selection")) { selectedEntity = nullptr; } @@ -1624,6 +1699,7 @@ void RecordImGuiSceneEditor() { RecordImGuiModalCreateAsset(); RecordImGuiModalCreateEntityType(); RecordImGui_GenerateMTSDFModal(); + RecordImGui_GenerateMTSDFGlyphModal(); ImGui::End(); } diff --git a/src/static-ui.hpp b/src/static-ui.hpp new file mode 100644 index 0000000..b0bf98c --- /dev/null +++ b/src/static-ui.hpp @@ -0,0 +1,12 @@ +#ifndef PKE_STATIC_UI_HPP +#define PKE_STATIC_UI_HPP + +struct MSDFGlyphSettings { + float width; + float height; + float scale; + float translate_em; + float range_em; +}; + +#endif /* PKE_STATIC_UI_HPP */ |
