mirror of https://github.com/AxioDL/metaforce.git
Use freetype for ImGui fonts if available
This commit is contained in:
parent
a9bcb7a9ce
commit
073af40c4d
|
@ -37,7 +37,7 @@ jobs:
|
|||
sudo apt-get -y install build-essential curl git cmake ninja-build clang lld python3 python-is-python3 \
|
||||
zlib1g-dev libglu1-mesa-dev libdbus-1-dev libvulkan-dev libxi-dev libxrandr-dev libasound2-dev \
|
||||
libpulse-dev libudev-dev libpng-dev libncurses5-dev libx11-xcb-dev libcurl4-openssl-dev qt5-default \
|
||||
llvm-11-dev libclang-11-dev clang-11
|
||||
llvm-11-dev libclang-11-dev clang-11 libfreetype-dev
|
||||
|
||||
# free up disk space
|
||||
# https://github.com/actions/virtual-environments/issues/2840#issuecomment-790492173
|
||||
|
@ -78,7 +78,7 @@ jobs:
|
|||
run: |
|
||||
brew update
|
||||
brew upgrade --formula
|
||||
brew install ninja qt@5 graphicsmagick imagemagick
|
||||
brew install ninja qt@5 graphicsmagick imagemagick freetype
|
||||
brew link qt@5
|
||||
yarn global add create-dmg
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ jobs:
|
|||
sudo apt-get -y install build-essential curl git cmake ninja-build clang lld python3 python-is-python3 \
|
||||
zlib1g-dev libglu1-mesa-dev libdbus-1-dev libvulkan-dev libxi-dev libxrandr-dev libasound2-dev \
|
||||
libpulse-dev libudev-dev libpng-dev libncurses5-dev libx11-xcb-dev libcurl4-openssl-dev qt5-default \
|
||||
llvm-11-dev libclang-11-dev clang-11 intel-oneapi-ipp-devel
|
||||
llvm-11-dev libclang-11-dev clang-11 intel-oneapi-ipp-devel libfreetype-dev
|
||||
|
||||
yarn global add @sentry/cli
|
||||
echo "$(yarn global bin)" >> $GITHUB_PATH
|
||||
|
@ -104,7 +104,7 @@ jobs:
|
|||
run: |
|
||||
brew update
|
||||
brew upgrade --formula
|
||||
brew install ninja qt@5 graphicsmagick imagemagick getsentry/tools/sentry-cli
|
||||
brew install ninja qt@5 graphicsmagick imagemagick getsentry/tools/sentry-cli freetype
|
||||
brew link qt@5
|
||||
yarn global add create-dmg
|
||||
|
||||
|
|
11
README.md
11
README.md
|
@ -64,13 +64,14 @@ NFS files dumped from Metroid Prime Trilogy on Wii U VC can be used directly wit
|
|||
* **[Linux]** recent development packages of `udev`, `x11`, `xcb`, `xinput`, `glx`, `asound`
|
||||
* Ubuntu 20.04+ packages
|
||||
```
|
||||
build-essential curl git ninja-build llvm-dev libclang-dev clang lld zlib1g-dev libcurl4-openssl-dev
|
||||
libglu1-mesa-dev libdbus-1-dev libvulkan-dev libxi-dev libxrandr-dev libasound2-dev libpulse-dev
|
||||
libudev-dev libpng-dev libncurses5-dev cmake libx11-xcb-dev python3 python-is-python3 qt5-default
|
||||
build-essential curl git ninja-build llvm-dev libclang-dev clang lld zlib1g-dev libcurl4-openssl-dev \
|
||||
libglu1-mesa-dev libdbus-1-dev libvulkan-dev libxi-dev libxrandr-dev libasound2-dev libpulse-dev \
|
||||
libudev-dev libpng-dev libncurses5-dev cmake libx11-xcb-dev python3 python-is-python3 qt5-default \
|
||||
libfreetype-dev
|
||||
```
|
||||
* Arch packages
|
||||
* Arch packages
|
||||
```
|
||||
base-devel cmake ninja llvm vulkan-headers python3 qt6 clang lld alsa-lib libpulse libxrandr
|
||||
base-devel cmake ninja llvm vulkan-headers python3 qt6 clang lld alsa-lib libpulse libxrandr freetype2
|
||||
```
|
||||
|
||||
### Prep Directions
|
||||
|
|
|
@ -29,7 +29,7 @@ void ImGuiStringViewText(std::string_view text) {
|
|||
|
||||
void ImGuiTextCenter(std::string_view text) {
|
||||
ImGui::NewLine();
|
||||
float fontSize = ImGui::GetFontSize() * float(text.size()) / 2;
|
||||
float fontSize = ImGui::CalcTextSize(text.data(), text.data() + text.size()).x;
|
||||
ImGui::SameLine(ImGui::GetWindowSize().x / 2 - fontSize + fontSize / 2);
|
||||
ImGuiStringViewText(text);
|
||||
}
|
||||
|
@ -1118,7 +1118,6 @@ void ImGuiConsole::ShowAppMainMenuBar(bool canInspect) {
|
|||
}
|
||||
}
|
||||
|
||||
s32 TranslateBooSpecialKey(boo::ESpecialKey key) { return 256 + static_cast<int>(key); }
|
||||
void ImGuiConsole::PreUpdate() {
|
||||
if (!m_isInitialized) {
|
||||
m_isInitialized = true;
|
||||
|
|
|
@ -1,23 +1,31 @@
|
|||
add_library(imgui
|
||||
../extern/imgui/imgui.cpp
|
||||
../extern/imgui/imgui_demo.cpp
|
||||
../extern/imgui/imgui_draw.cpp
|
||||
../extern/imgui/imgui_tables.cpp
|
||||
../extern/imgui/imgui_widgets.cpp
|
||||
../extern/imgui/misc/cpp/imgui_stdlib.cpp
|
||||
ImGuiEngine.cpp
|
||||
ImGuiEngine.hpp
|
||||
NotoMono.cpp
|
||||
MetaforceIcon.cpp
|
||||
)
|
||||
../extern/imgui/imgui.cpp
|
||||
../extern/imgui/imgui_demo.cpp
|
||||
../extern/imgui/imgui_draw.cpp
|
||||
../extern/imgui/imgui_tables.cpp
|
||||
../extern/imgui/imgui_widgets.cpp
|
||||
../extern/imgui/misc/cpp/imgui_stdlib.cpp
|
||||
ImGuiEngine.cpp
|
||||
ImGuiEngine.hpp
|
||||
NotoMono.cpp
|
||||
MetaforceIcon.cpp
|
||||
)
|
||||
target_include_directories(imgui PUBLIC ${CMAKE_SOURCE_DIR}/extern/imgui ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_compile_definitions(imgui PUBLIC IMGUI_USER_CONFIG="imconfig_user.h")
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
# currently explicitly ignored for clang in imgui code, but not gcc (yet)
|
||||
target_compile_options(imgui PRIVATE -Wno-deprecated-enum-enum-conversion)
|
||||
endif()
|
||||
# currently explicitly ignored for clang in imgui code, but not gcc (yet)
|
||||
target_compile_options(imgui PRIVATE -Wno-deprecated-enum-enum-conversion)
|
||||
endif ()
|
||||
target_link_libraries(imgui PRIVATE boo hecl-light RetroDataSpec)
|
||||
|
||||
# Optional, replaces stb_freetype if available
|
||||
find_package(Freetype)
|
||||
if (FREETYPE_FOUND)
|
||||
target_sources(imgui PRIVATE ../extern/imgui/misc/freetype/imgui_freetype.cpp)
|
||||
target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE)
|
||||
target_link_libraries(imgui PRIVATE Freetype::Freetype)
|
||||
endif ()
|
||||
|
||||
bintoc_compress(NotoMono.cpp NotoMono-Regular.ttf NOTO_MONO_FONT)
|
||||
bintoc(MetaforceIcon.cpp ../Runtime/platforms/freedesktop/256x256/apps/metaforce.png METAFORCE_ICON)
|
||||
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
#define STBI_ONLY_PNG
|
||||
#include "stb_image.h"
|
||||
|
||||
#ifdef IMGUI_ENABLE_FREETYPE
|
||||
#include "misc/freetype/imgui_freetype.h"
|
||||
#endif
|
||||
|
||||
#include "Runtime/GameGlobalObjects.hpp"
|
||||
#include "Runtime/Input/CInputGenerator.hpp"
|
||||
#include <zeus/CMatrix4f.hpp>
|
||||
|
@ -83,21 +87,21 @@ void ImGuiEngine::Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* w
|
|||
io.BackendPlatformName = "Boo";
|
||||
io.BackendRendererName = "Boo";
|
||||
|
||||
io.KeyMap[ImGuiKey_Tab] = 256 + static_cast<int>(boo::ESpecialKey::Tab);
|
||||
io.KeyMap[ImGuiKey_LeftArrow] = 256 + static_cast<int>(boo::ESpecialKey::Left);
|
||||
io.KeyMap[ImGuiKey_RightArrow] = 256 + static_cast<int>(boo::ESpecialKey::Right);
|
||||
io.KeyMap[ImGuiKey_UpArrow] = 256 + static_cast<int>(boo::ESpecialKey::Up);
|
||||
io.KeyMap[ImGuiKey_DownArrow] = 256 + static_cast<int>(boo::ESpecialKey::Down);
|
||||
io.KeyMap[ImGuiKey_PageUp] = 256 + static_cast<int>(boo::ESpecialKey::PgUp);
|
||||
io.KeyMap[ImGuiKey_PageDown] = 256 + static_cast<int>(boo::ESpecialKey::PgDown);
|
||||
io.KeyMap[ImGuiKey_Home] = 256 + static_cast<int>(boo::ESpecialKey::Home);
|
||||
io.KeyMap[ImGuiKey_End] = 256 + static_cast<int>(boo::ESpecialKey::End);
|
||||
io.KeyMap[ImGuiKey_Insert] = 256 + static_cast<int>(boo::ESpecialKey::Insert);
|
||||
io.KeyMap[ImGuiKey_Delete] = 256 + static_cast<int>(boo::ESpecialKey::Delete);
|
||||
io.KeyMap[ImGuiKey_Backspace] = 256 + static_cast<int>(boo::ESpecialKey::Backspace);
|
||||
io.KeyMap[ImGuiKey_Tab] = TranslateBooSpecialKey(boo::ESpecialKey::Tab);
|
||||
io.KeyMap[ImGuiKey_LeftArrow] = TranslateBooSpecialKey(boo::ESpecialKey::Left);
|
||||
io.KeyMap[ImGuiKey_RightArrow] = TranslateBooSpecialKey(boo::ESpecialKey::Right);
|
||||
io.KeyMap[ImGuiKey_UpArrow] = TranslateBooSpecialKey(boo::ESpecialKey::Up);
|
||||
io.KeyMap[ImGuiKey_DownArrow] = TranslateBooSpecialKey(boo::ESpecialKey::Down);
|
||||
io.KeyMap[ImGuiKey_PageUp] = TranslateBooSpecialKey(boo::ESpecialKey::PgUp);
|
||||
io.KeyMap[ImGuiKey_PageDown] = TranslateBooSpecialKey(boo::ESpecialKey::PgDown);
|
||||
io.KeyMap[ImGuiKey_Home] = TranslateBooSpecialKey(boo::ESpecialKey::Home);
|
||||
io.KeyMap[ImGuiKey_End] = TranslateBooSpecialKey(boo::ESpecialKey::End);
|
||||
io.KeyMap[ImGuiKey_Insert] = TranslateBooSpecialKey(boo::ESpecialKey::Insert);
|
||||
io.KeyMap[ImGuiKey_Delete] = TranslateBooSpecialKey(boo::ESpecialKey::Delete);
|
||||
io.KeyMap[ImGuiKey_Backspace] = TranslateBooSpecialKey(boo::ESpecialKey::Backspace);
|
||||
io.KeyMap[ImGuiKey_Space] = ' ';
|
||||
io.KeyMap[ImGuiKey_Enter] = 256 + static_cast<int>(boo::ESpecialKey::Enter);
|
||||
io.KeyMap[ImGuiKey_Escape] = 256 + static_cast<int>(boo::ESpecialKey::Esc);
|
||||
io.KeyMap[ImGuiKey_Enter] = TranslateBooSpecialKey(boo::ESpecialKey::Enter);
|
||||
io.KeyMap[ImGuiKey_Escape] = TranslateBooSpecialKey(boo::ESpecialKey::Esc);
|
||||
io.KeyMap[ImGuiKey_A] = 'a'; // for text edit CTRL+A: select all
|
||||
io.KeyMap[ImGuiKey_C] = 'c'; // for text edit CTRL+C: copy
|
||||
io.KeyMap[ImGuiKey_V] = 'v'; // for text edit CTRL+V: paste
|
||||
|
@ -114,22 +118,32 @@ void ImGuiEngine::Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* w
|
|||
auto* metaforceIcon = stbi_load_from_memory(static_cast<const stbi_uc*>(METAFORCE_ICON), int(METAFORCE_ICON_SZ),
|
||||
&iconWidth, &iconHeight, nullptr, 4);
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
unsigned char* pixels = nullptr;
|
||||
ImFontConfig fontConfig{};
|
||||
fontConfig.FontData = fontData;
|
||||
fontConfig.FontDataSize = int(NOTO_MONO_FONT_DECOMPRESSED_SZ);
|
||||
fontConfig.SizePixels = std::floor(14.f * scale);
|
||||
#ifdef IMGUI_ENABLE_FREETYPE
|
||||
fontConfig.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting;
|
||||
#endif
|
||||
snprintf(static_cast<char*>(fontConfig.Name), sizeof(fontConfig.Name), "Noto Mono Regular, %dpx",
|
||||
static_cast<int>(fontConfig.SizePixels));
|
||||
fontNormal = io.Fonts->AddFont(&fontConfig);
|
||||
|
||||
fontConfig.FontDataOwnedByAtlas = false; // first one took ownership
|
||||
fontConfig.SizePixels = std::floor(24.f * scale);
|
||||
#ifdef IMGUI_ENABLE_FREETYPE
|
||||
fontConfig.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_Bold;
|
||||
snprintf(static_cast<char*>(fontConfig.Name), sizeof(fontConfig.Name), "Noto Mono Bold, %dpx",
|
||||
static_cast<int>(fontConfig.SizePixels));
|
||||
#else
|
||||
snprintf(static_cast<char*>(fontConfig.Name), sizeof(fontConfig.Name), "Noto Mono Regular, %dpx",
|
||||
static_cast<int>(fontConfig.SizePixels));
|
||||
#endif
|
||||
fontLarge = io.Fonts->AddFont(&fontConfig);
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
unsigned char* pixels = nullptr;
|
||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
||||
factory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) {
|
||||
ShaderPipeline = hecl::conv->convert(Shader_ImGuiShader{});
|
||||
|
@ -419,12 +433,12 @@ void ImGuiWindowCallback::charKeyUp(unsigned long charCode, boo::EModifierKey mo
|
|||
}
|
||||
|
||||
void ImGuiWindowCallback::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat) {
|
||||
ImGuiEngine::Input.m_keys[256 + static_cast<int>(key)] = true;
|
||||
ImGuiEngine::Input.m_keys[TranslateBooSpecialKey(key)] = true;
|
||||
ImGuiEngine::Input.m_modifiers = mods;
|
||||
}
|
||||
|
||||
void ImGuiWindowCallback::specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods) {
|
||||
ImGuiEngine::Input.m_keys[256 + static_cast<int>(key)] = false;
|
||||
ImGuiEngine::Input.m_keys[TranslateBooSpecialKey(key)] = false;
|
||||
ImGuiEngine::Input.m_modifiers = mods;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
|
||||
|
||||
namespace metaforce {
|
||||
constexpr inline int TranslateBooSpecialKey(boo::ESpecialKey key) { return 256 + static_cast<int>(key); }
|
||||
|
||||
class ImGuiEngine {
|
||||
public:
|
||||
static struct Input {
|
||||
|
|
Loading…
Reference in New Issue