diff --git a/resources/fonts/fontawesome5/LICENSE.txt b/resources/fonts/fontawesome5/LICENSE.txt new file mode 100644 index 000000000..f31bef92b --- /dev/null +++ b/resources/fonts/fontawesome5/LICENSE.txt @@ -0,0 +1,34 @@ +Font Awesome Free License +------------------------- + +Font Awesome Free is free, open source, and GPL friendly. You can use it for +commercial projects, open source projects, or really almost whatever you want. +Full Font Awesome Free license: https://fontawesome.com/license/free. + +# Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/) +In the Font Awesome Free download, the CC BY 4.0 license applies to all icons +packaged as SVG and JS file types. + +# Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL) +In the Font Awesome Free download, the SIL OFL license applies to all icons +packaged as web and desktop font files. + +# Code: MIT License (https://opensource.org/licenses/MIT) +In the Font Awesome Free download, the MIT license applies to all non-font and +non-icon files. + +# Attribution +Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font +Awesome Free files already contain embedded comments with sufficient +attribution, so you shouldn't need to do anything additional when using these +files normally. + +We've kept attribution comments terse, so we ask that you do not actively work +to remove them from files, especially code. They're a great way for folks to +learn about Font Awesome. + +# Brand Icons +All brand icons are trademarks of their respective owners. The use of these +trademarks does not indicate endorsement of the trademark holder by Font +Awesome, nor vice versa. **Please do not use brand logos for any purpose except +to represent the company, product, or service to which they refer.** diff --git a/resources/fonts/fontawesome5/fa-regular-400.ttf b/resources/fonts/fontawesome5/fa-regular-400.ttf new file mode 100644 index 000000000..d71787bd2 Binary files /dev/null and b/resources/fonts/fontawesome5/fa-regular-400.ttf differ diff --git a/resources/fonts/fontawesome5/fa-solid-900.ttf b/resources/fonts/fontawesome5/fa-solid-900.ttf new file mode 100644 index 000000000..d4e300d6b Binary files /dev/null and b/resources/fonts/fontawesome5/fa-solid-900.ttf differ diff --git a/source/app/recon/private/converter_app.cpp b/source/app/recon/private/converter_app.cpp index a87050df4..af2a5a5e1 100644 --- a/source/app/recon/private/converter_app.cpp +++ b/source/app/recon/private/converter_app.cpp @@ -134,12 +134,16 @@ void up::recon::ConverterApp::registerConverters() { #endif _converters.push_back({[](string_view path) { return path::extension(path) == ".hlsli"; }, new_box()}); + _converters.push_back({[](string_view path) { return path::extension(path) == ".txt"; }, + new_box()}); _converters.push_back({[](string_view path) { return path::extension(path) == ".json"; }, new_box()}); _converters.push_back({[](string_view path) { return path::extension(path) == ".png"; }, new_box()}); _converters.push_back({[](string_view path) { return path::extension(path) == ".jpg"; }, new_box()}); + _converters.push_back({[](string_view path) { return path::extension(path) == ".ttf"; }, + new_box()}); _converters.push_back({[](string_view path) { return path::extension(path) == ".obj"; }, new_box()}); } diff --git a/source/app/shell/private/shell_app.cpp b/source/app/shell/private/shell_app.cpp index 637307bc7..66e238540 100644 --- a/source/app/shell/private/shell_app.cpp +++ b/source/app/shell/private/shell_app.cpp @@ -137,6 +137,15 @@ int up::ShellApp::initialize() { } _drawImgui.bindShaders(std::move(imguiVertShader), std::move(imguiPixelShader)); + auto fontStream = _fileSystem.openRead("resources/fonts/fontawesome5/fa-solid-900.ttf"); + if (!fontStream) { + _errorDialog("Failed to open FontAwesome font"); + return 1; + } + if (!_drawImgui.loadFontAwesome5(std::move(fontStream))) { + _errorDialog("Failed to load FontAwesome font"); + return 1; + } _drawImgui.createResources(*_device); _camera.lookAt({0, 10, 15}, {0, 0, 0}, {0, 1, 0}); @@ -286,14 +295,14 @@ void up::ShellApp::_drawUI() { if (ImGui::BeginMainMenuBar()) { menuSize = ImGui::GetWindowSize(); - if (ImGui::BeginMenu("Potato")) { - if (ImGui::MenuItem("Quit", "ESC")) { + if (ImGui::BeginMenu(u8"\uf094 Potato")) { + if (ImGui::MenuItem(u8"\uf52b Quit", "ESC")) { _running = false; } ImGui::EndMenu(); } - if (ImGui::BeginMenu("View")) { + if (ImGui::BeginMenu(u8"\uf06e View")) { if (ImGui::BeginMenu("Camera")) { if (ImGui::MenuItem("Fly", "ctrl-f")) { _cameraController = new_box(_camera); @@ -316,7 +325,7 @@ void up::ShellApp::_drawUI() { ImGui::Spacing(); ImGui::Spacing(); - if (ImGui::MenuItem(!_paused ? "Pause" : "Play", "F5")) { + if (ImGui::MenuItem(!_paused ? u8"\uf04c Pause" : u8"\uf04b Play", "F5")) { _paused = !_paused; } diff --git a/source/library/render/private/draw_imgui.cpp b/source/library/render/private/draw_imgui.cpp index f6b8a908d..39f876d7e 100644 --- a/source/library/render/private/draw_imgui.cpp +++ b/source/library/render/private/draw_imgui.cpp @@ -66,6 +66,31 @@ bool up::DrawImgui::createResources(GpuDevice& device) { return true; } +auto up::DrawImgui::loadFontAwesome5(Stream fontFile) -> bool { + static constexpr auto s_minGlyph = 0xf000; + static constexpr auto s_maxGlyph = 0xf897; + static constexpr ImWchar s_ranges[] = {s_minGlyph, s_maxGlyph, 0}; + + _ensureContext(); + + ImGui::SetCurrentContext(_context.get()); + auto& io = ImGui::GetIO(); + + vector fontData; + if (readBinary(fontFile, fontData) != IOResult::Success) { + return false; + } + + + ImFontConfig config; // = {.MergeMode = true, .PixelSnapH = true}; + config.MergeMode = true; + config.PixelSnapH = true; + config.FontDataOwnedByAtlas = false; + + auto font = io.Fonts->AddFontFromMemoryTTF(fontData.data(), static_cast(fontData.size()), 13.0f, &config, s_ranges); + return font != nullptr; +} + void up::DrawImgui::releaseResources() { _indexBuffer.reset(); _vertexBuffer.reset(); @@ -264,6 +289,8 @@ void up::DrawImgui::_ensureContext() { ImGui::SetCurrentContext(_context.get()); auto& io = ImGui::GetIO(); + io.Fonts->AddFontDefault(); + io.BackendPlatformName = "potato::grui"; io.IniFilename = nullptr; diff --git a/source/library/render/public/potato/render/draw_imgui.h b/source/library/render/public/potato/render/draw_imgui.h index 5d962cc5c..0eaff0d50 100644 --- a/source/library/render/public/potato/render/draw_imgui.h +++ b/source/library/render/public/potato/render/draw_imgui.h @@ -7,6 +7,7 @@ #include "potato/foundation/rc.h" #include "potato/foundation/unique_resource.h" #include "potato/foundation/string.h" +#include "potato/filesystem/stream.h" namespace up { class GpuBuffer; @@ -37,6 +38,8 @@ namespace up { UP_RENDER_API bool createResources(GpuDevice& device); UP_RENDER_API void releaseResources(); + UP_RENDER_API bool loadFontAwesome5(Stream fontFile); + UP_RENDER_API bool handleEvent(SDL_Event const& ev); UP_RENDER_API void beginFrame();