Skip to content

Commit

Permalink
ImGui: Add TTF font support
Browse files Browse the repository at this point in the history
We use the Roboto font that we're already shipping for now, although, we could
also support other fonts or have a setting.
  • Loading branch information
hrydgard committed Nov 22, 2024
1 parent 21ffc37 commit c529743
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
10 changes: 8 additions & 2 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace std::placeholders;
#include "Common/Render/Text/draw_text.h"
#include "Common/File/FileUtil.h"
#include "Common/Battery/Battery.h"

#include "Common/File/VFS/VFS.h"
#include "Common/UI/Root.h"
#include "Common/UI/UI.h"
#include "Common/UI/Context.h"
Expand Down Expand Up @@ -1646,7 +1646,13 @@ void EmuScreen::renderImDebugger() {
if (!imguiInited_) {
imguiInited_ = true;
imDebugger_ = std::make_unique<ImDebugger>();
ImGui_ImplThin3d_Init(draw);

// Read the TTF font
size_t size = 0;
uint8_t *fontData = g_VFS.ReadFile("Roboto-Condensed.ttf", &size);
// This call works even if fontData is nullptr, in which case the font just won't get loaded.
// This takes ownership of the font array.
ImGui_ImplThin3d_Init(draw, fontData, size);
}

if (PSP_IsInited()) {
Expand Down
7 changes: 6 additions & 1 deletion UI/ImDebugger/ImDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) {
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Window")) {
ImGui::Checkbox("Dear ImGUI Demo", &cfg_.demoOpen);
ImGui::Checkbox("CPU debugger", &cfg_.disasmOpen);
ImGui::Checkbox("Registers", &cfg_.regsOpen);
ImGui::Checkbox("Callstacks", &cfg_.callstackOpen);
Expand All @@ -382,6 +381,8 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) {
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Misc")) {
ImGui::Checkbox("Dear ImGui Demo", &cfg_.demoOpen);
ImGui::Checkbox("ImGui Style editor", &cfg_.styleEditorOpen);
if (ImGui::MenuItem("Close Debugger")) {
g_Config.bShowImDebugger = false;
}
Expand All @@ -394,6 +395,10 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) {
ImGui::ShowDemoWindow(&cfg_.demoOpen);
}

if (cfg_.styleEditorOpen) {
ImGui::ShowStyleEditor();
}

if (cfg_.disasmOpen) {
disasm_.Draw(mipsDebug, &cfg_.disasmOpen, coreState);
}
Expand Down
1 change: 1 addition & 0 deletions UI/ImDebugger/ImDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct ImConfig {
bool hleModulesOpen = false;
bool atracOpen = true;
bool structViewerOpen = false;
bool styleEditorOpen = false;

// HLE explorer settings
// bool filterByUsed = true;
Expand Down
10 changes: 9 additions & 1 deletion ext/imgui/imgui_impl_thin3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,16 @@ void ImGui_ImplThin3d_DestroyDeviceObjects() {
}
}

bool ImGui_ImplThin3d_Init(Draw::DrawContext *draw) {
bool ImGui_ImplThin3d_Init(Draw::DrawContext *draw, const uint8_t *ttf_font, size_t size) {
ImGuiIO& io = ImGui::GetIO();
if (ttf_font) {
io.Fonts->AddFontFromMemoryTTF((void *)ttf_font, size, 18.0f * g_display.dpi_scale_x, nullptr, io.Fonts->GetGlyphRangesDefault());
} else {
// necessary?
io.Fonts->AddFontDefault();
}
ImGui::GetStyle().ScaleAllSizes(g_display.dpi_scale_x);

IMGUI_CHECKVERSION();
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");

Expand Down
4 changes: 2 additions & 2 deletions ext/imgui/imgui_impl_thin3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include "Common/GPU/thin3d.h"
#include "Common/Math/lin/matrix4x4.h"

// Called by user code
IMGUI_IMPL_API bool ImGui_ImplThin3d_Init(Draw::DrawContext *draw);
// Called by user code. Takes ownership of the font buffer and later deletes it.
IMGUI_IMPL_API bool ImGui_ImplThin3d_Init(Draw::DrawContext *draw, const uint8_t *ttf_font, size_t size);
IMGUI_IMPL_API void ImGui_ImplThin3d_Shutdown();
IMGUI_IMPL_API void ImGui_ImplThin3d_NewFrame(Draw::DrawContext *draw, Lin::Matrix4x4 drawMatrix);
IMGUI_IMPL_API void ImGui_ImplThin3d_RenderDrawData(ImDrawData* draw_data, Draw::DrawContext *draw);
Expand Down
2 changes: 1 addition & 1 deletion ext/lua
Submodule lua updated 1 files
+2 −9 luaconf.h

0 comments on commit c529743

Please sign in to comment.