diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 5af7f22..a528b8d 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -17,6 +17,8 @@ add_subdirectory(./solanaceae_toxcore) add_subdirectory(./solanaceae_tox) add_subdirectory(./sdl) +add_subdirectory(./freetype) +add_subdirectory(./plutosvg) add_subdirectory(./imgui) add_subdirectory(./implot) diff --git a/external/freetype/CMakeLists.txt b/external/freetype/CMakeLists.txt new file mode 100644 index 0000000..101da7b --- /dev/null +++ b/external/freetype/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.24 FATAL_ERROR) + +include(FetchContent) + +if (NOT TARGET Freetype::Freetype) + find_package(Freetype 2.12 CONFIG GLOBAL QUIET) + + if (NOT TARGET Freetype::Freetype) + find_package(Freetype 2.12 GLOBAL QUIET) + endif() + + #if (NOT TARGET Freetype::Freetype) + # find_package(PkgConfig) + # if (PKG_CONFIG_FOUND) + # pkg_check_modules(freetype_PKG IMPORTED_TARGET freetype) + + # if (TARGET PkgConfig::freetype_PKG) + # add_library(Freetype::Freetype ALIAS PkgConfig::freetype_PKG) + # endif() + # endif() + #endif() + + if (TARGET Freetype::Freetype) + message(STATUS "found freetype") + else() + message(STATUS "freetype not found") + endif() +endif() + diff --git a/external/imgui/CMakeLists.txt b/external/imgui/CMakeLists.txt index e6a6b41..e77f07d 100644 --- a/external/imgui/CMakeLists.txt +++ b/external/imgui/CMakeLists.txt @@ -21,6 +21,22 @@ add_library(imgui target_compile_definitions(imgui PUBLIC IMGUI_USE_WCHAR32) target_compile_features(imgui PUBLIC cxx_std_11) +if (TARGET Freetype::Freetype) + message(STATUS "Freetype detected, enabling support in imgui") + target_sources(imgui PUBLIC + imgui/misc/freetype/imgui_freetype.h + imgui/misc/freetype/imgui_freetype.cpp + ) + target_link_libraries(imgui PUBLIC Freetype::Freetype) # public in case of static + target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE) + + if (TARGET plutosvg::plutosvg) + message(STATUS "plutosvg detected, enabling support in imgui") + target_link_libraries(imgui PUBLIC plutosvg::plutosvg) # public in case of static + target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE_PLUTOSVG) + endif() +endif() + target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui") # im sad diff --git a/external/plutosvg/CMakeLists.txt b/external/plutosvg/CMakeLists.txt new file mode 100644 index 0000000..35f4c57 --- /dev/null +++ b/external/plutosvg/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.24 FATAL_ERROR) + +include(FetchContent) + +#makes no sense without freetype +if (NOT TARGET plutosvg::plutosvg AND TARGET Freetype::Freetype) + set(PLUTOSVG_ENABLE_FREETYPE ON CACHE INTERNAL "") + set(PLUTOSVG_BUILD_EXAMPLES OFF CACHE INTERNAL "") + FetchContent_Declare(plutosvg + GIT_REPOSITORY https://github.com/sammycage/plutosvg.git + GIT_TAG v0.0.6 + FIND_PACKAGE_ARGS # for the future + ) + FetchContent_MakeAvailable(plutosvg) +endif() + diff --git a/flake.lock b/flake.lock index b32e75d..51ec220 100644 --- a/flake.lock +++ b/flake.lock @@ -68,12 +68,32 @@ "type": "github" } }, + "plutosvg": { + "flake": false, + "locked": { + "lastModified": 1740306654, + "narHash": "sha256-radjL0bP+JPDk7FQ/qSOIxlokhwQ78fO52/S5V6rAmk=", + "ref": "refs/tags/v0.0.6", + "rev": "c5388fa96feca1f1376a3d0485d5e35159452707", + "revCount": 111, + "submodules": true, + "type": "git", + "url": "https://github.com/sammycage/plutosvg" + }, + "original": { + "ref": "refs/tags/v0.0.6", + "submodules": true, + "type": "git", + "url": "https://github.com/sammycage/plutosvg" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", "implot": "implot", "nixpkgs": "nixpkgs", "nlohmann-json": "nlohmann-json", + "plutosvg": "plutosvg", "sdl3": "sdl3", "sdl3_image": "sdl3_image" } diff --git a/flake.nix b/flake.nix index e93b3d6..f687b79 100644 --- a/flake.nix +++ b/flake.nix @@ -20,13 +20,17 @@ url = "github:libsdl-org/SDL_image/4ff27afa450eabd2a827e49ed86fab9e3bf826c5"; flake = false; }; + plutosvg = { + url = "git+https://github.com/sammycage/plutosvg?submodules=1&ref=refs/tags/v0.0.6"; + flake = false; + }; implot = { url = "github:epezent/implot/193b9d8f92c4a437e84182b171f1ae266e72321f"; flake = false; }; }; - outputs = { self, nixpkgs, flake-utils, nlohmann-json, sdl3, sdl3_image, implot }: + outputs = { self, nixpkgs, flake-utils, nlohmann-json, sdl3, sdl3_image, plutosvg, implot }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; @@ -85,6 +89,8 @@ libsodium libopus libvpx + + freetype ] ++ self.packages.${system}.default.dlopenBuildInputs; cmakeFlags = [ @@ -102,6 +108,7 @@ "-DFETCHCONTENT_SOURCE_DIR_SDL3=${sdl3}" "-DFETCHCONTENT_SOURCE_DIR_SDL3_IMAGE=${sdl3_image}" "-DSDLIMAGE_JXL=ON" + "-DFETCHCONTENT_SOURCE_DIR_PLUTOSVG=${plutosvg}" # not in pkgs "-DFETCHCONTENT_SOURCE_DIR_IMPLOT=${implot}" # could use pkgs.implot.src for outdated version ]; diff --git a/src/start_screen.cpp b/src/start_screen.cpp index b06829f..849d736 100644 --- a/src/start_screen.cpp +++ b/src/start_screen.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -105,6 +106,10 @@ StartScreen::StartScreen(const std::vector& args, SDL_Renderer fontcfg.OversampleH = 2; fontcfg.OversampleV = 1; fontcfg.MergeMode = false; +#if defined(IMGUI_ENABLE_FREETYPE) && defined(IMGUI_ENABLE_FREETYPE_PLUTOSVG) + std::cout << "Font: enabling freetype color loading\n"; + fontcfg.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_LoadColor; +#endif for (const auto [font_path, should_load] : _conf.entries_bool("ImGuiFonts", "fonts")) { if (!should_load) {