Skip to content

Commit a4ffc5b

Browse files
committed
fix fullscreen toggling
1 parent 671c5de commit a4ffc5b

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/DevTools.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include <imgui_internal.h>
32
#include "DevTools.hpp"
43
#include "fonts/FeatherIcons.hpp"
@@ -189,11 +188,15 @@ void DevTools::setupFonts() {
189188
void* font, size_t realSize, float size, const ImWchar* range
190189
) {
191190
auto& io = ImGui::GetIO();
191+
// AddFontFromMemoryTTF assumes ownership of the passed data unless you configure it not to.
192+
// Our font data has static lifetime, so we're handling the ownership.
193+
192194
ImFontConfig config;
193-
config.MergeMode = true;
195+
config.FontDataOwnedByAtlas = false;
194196
auto* result = io.Fonts->AddFontFromMemoryTTF(
195-
font, realSize, size, nullptr, range
197+
font, realSize, size, &config, range
196198
);
199+
config.MergeMode = true;
197200
io.Fonts->AddFontFromMemoryTTF(
198201
Font_FeatherIcons, sizeof(Font_FeatherIcons), size - 4.f, &config, icon_ranges
199202
);
@@ -213,7 +216,7 @@ void DevTools::setup() {
213216

214217
IMGUI_CHECKVERSION();
215218

216-
auto ctx = ImGui::CreateContext();
219+
ImGui::CreateContext();
217220

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

235238
void DevTools::destroy() {
236239
if (!m_setup) return;
237-
m_setup = false;
238-
m_visible = false;
240+
this->show(false);
241+
auto& io = ImGui::GetIO();
242+
io.BackendPlatformUserData = nullptr;
243+
m_fontTexture->release();
244+
m_fontTexture = nullptr;
239245

240-
// crashes :(
241-
// ImGui::DestroyContext();
246+
ImGui::DestroyContext();
247+
m_setup = false;
248+
m_reloadTheme = true;
242249
}
243250

244251
void DevTools::show(bool visible) {
245252
m_visible = visible;
253+
254+
auto& io = ImGui::GetIO();
255+
io.WantCaptureMouse = visible;
256+
io.WantCaptureKeyboard = visible;
246257
}
247258

248259
void DevTools::toggle() {
249260
this->show(!m_visible);
250-
if (!m_visible) {
251-
ImGui::GetIO().WantCaptureMouse = false;
252-
ImGui::GetIO().WantCaptureKeyboard = false;
253-
}
254261
}
255262

256263
void DevTools::sceneChanged() {

src/DevTools.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <Geode/utils/addresser.hpp>
99
#include <Geode/loader/Loader.hpp>
1010
#include <Geode/loader/ModMetadata.hpp>
11-
#include <unordered_map>
1211

1312
using namespace geode::prelude;
1413

@@ -44,6 +43,7 @@ class DevTools {
4443
ImFont* m_smallFont = nullptr;
4544
ImFont* m_monoFont = nullptr;
4645
ImFont* m_boxFont = nullptr;
46+
CCTexture2D* m_fontTexture = nullptr;
4747
Ref<CCNode> m_selectedNode;
4848
std::vector<std::pair<CCNode*, HighlightMode>> m_toHighlight;
4949

src/backend.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ using namespace cocos2d;
1212
// based off https://github.com/matcool/gd-imgui-cocos
1313

1414
void DevTools::setupPlatform() {
15-
ImGui::CreateContext();
16-
1715
auto& io = ImGui::GetIO();
1816

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

32-
auto* tex2d = new CCTexture2D;
33-
tex2d->initWithData(pixels, kCCTexture2DPixelFormat_RGBA8888, width, height, CCSize(width, height));
34-
35-
// TODO: not leak this :-)
36-
tex2d->retain();
30+
m_fontTexture = new CCTexture2D;
31+
m_fontTexture->initWithData(pixels, kCCTexture2DPixelFormat_RGBA8888, width, height, CCSize(width, height));
32+
m_fontTexture->retain();
3733

38-
io.Fonts->SetTexID(reinterpret_cast<ImTextureID>(static_cast<intptr_t>(tex2d->getName())));
34+
io.Fonts->SetTexID(reinterpret_cast<ImTextureID>(static_cast<intptr_t>(m_fontTexture->getName())));
3935
}
4036

4137
void DevTools::newFrame() {

0 commit comments

Comments
 (0)