Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/DevTools.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <imgui_internal.h>
#include "DevTools.hpp"
#include "fonts/FeatherIcons.hpp"
Expand Down Expand Up @@ -189,11 +188,15 @@ void DevTools::setupFonts() {
void* font, size_t realSize, float size, const ImWchar* range
) {
auto& io = ImGui::GetIO();
// AddFontFromMemoryTTF assumes ownership of the passed data unless you configure it not to.
// Our font data has static lifetime, so we're handling the ownership.

ImFontConfig config;
config.MergeMode = true;
config.FontDataOwnedByAtlas = false;
auto* result = io.Fonts->AddFontFromMemoryTTF(
font, realSize, size, nullptr, range
font, realSize, size, &config, range
);
config.MergeMode = true;
io.Fonts->AddFontFromMemoryTTF(
Font_FeatherIcons, sizeof(Font_FeatherIcons), size - 4.f, &config, icon_ranges
);
Expand All @@ -213,7 +216,7 @@ void DevTools::setup() {

IMGUI_CHECKVERSION();

auto ctx = ImGui::CreateContext();
ImGui::CreateContext();

auto& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
Expand All @@ -234,23 +237,27 @@ void DevTools::setup() {

void DevTools::destroy() {
if (!m_setup) return;
m_setup = false;
m_visible = false;
this->show(false);
auto& io = ImGui::GetIO();
io.BackendPlatformUserData = nullptr;
m_fontTexture->release();
m_fontTexture = nullptr;

// crashes :(
// ImGui::DestroyContext();
ImGui::DestroyContext();
m_setup = false;
m_reloadTheme = true;
}

void DevTools::show(bool visible) {
m_visible = visible;

auto& io = ImGui::GetIO();
io.WantCaptureMouse = visible;
io.WantCaptureKeyboard = visible;
}

void DevTools::toggle() {
this->show(!m_visible);
if (!m_visible) {
ImGui::GetIO().WantCaptureMouse = false;
ImGui::GetIO().WantCaptureKeyboard = false;
}
}

void DevTools::sceneChanged() {
Expand Down
2 changes: 1 addition & 1 deletion src/DevTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <Geode/utils/addresser.hpp>
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/ModMetadata.hpp>
#include <unordered_map>

using namespace geode::prelude;

Expand Down Expand Up @@ -44,6 +43,7 @@ class DevTools {
ImFont* m_smallFont = nullptr;
ImFont* m_monoFont = nullptr;
ImFont* m_boxFont = nullptr;
CCTexture2D* m_fontTexture = nullptr;
Ref<CCNode> m_selectedNode;
std::vector<std::pair<CCNode*, HighlightMode>> m_toHighlight;

Expand Down
12 changes: 4 additions & 8 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ using namespace cocos2d;
// based off https://github.com/matcool/gd-imgui-cocos

void DevTools::setupPlatform() {
ImGui::CreateContext();

auto& io = ImGui::GetIO();

io.BackendPlatformUserData = this;
Expand All @@ -29,13 +27,11 @@ void DevTools::setupPlatform() {
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);

auto* tex2d = new CCTexture2D;
tex2d->initWithData(pixels, kCCTexture2DPixelFormat_RGBA8888, width, height, CCSize(width, height));

// TODO: not leak this :-)
tex2d->retain();
m_fontTexture = new CCTexture2D;
m_fontTexture->initWithData(pixels, kCCTexture2DPixelFormat_RGBA8888, width, height, CCSize(width, height));
m_fontTexture->retain();

io.Fonts->SetTexID(reinterpret_cast<ImTextureID>(static_cast<intptr_t>(tex2d->getName())));
io.Fonts->SetTexID(reinterpret_cast<ImTextureID>(static_cast<intptr_t>(m_fontTexture->getName())));
}

void DevTools::newFrame() {
Expand Down