BACKENDS: Update ImGui callbacks in OSystem and fix engines

This commit is contained in:
scemino 2024-05-03 20:25:01 +02:00
parent 6cd43c2ddf
commit 936109fe4f
7 changed files with 19 additions and 23 deletions

View File

@ -49,7 +49,7 @@ public:
virtual bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) { return (mode == 0); }
virtual int getGraphicsMode() const { return 0; }
#if defined(USE_IMGUI)
virtual void setImGuiRenderCallback(ImGuiCallbacks callbacks) { }
virtual void setImGuiCallbacks(const ImGuiCallbacks &callbacks) { }
#endif
virtual bool setShader(const Common::Path &fileName) { return false; }
virtual const OSystem::GraphicsMode *getSupportedStretchModes() const {

View File

@ -208,7 +208,7 @@ private:
#if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
public:
void setImGuiRenderCallback(ImGuiCallbacks callbacks) override { _callbacks = callbacks; }
void setImGuiCallbacks(const ImGuiCallbacks &callbacks) override { _callbacks = callbacks; }
protected:
ImGuiCallbacks _callbacks;

View File

@ -74,8 +74,8 @@ int ModularGraphicsBackend::getGraphicsMode() const {
}
#if defined(USE_IMGUI)
void ModularGraphicsBackend::setImGuiRenderCallback(ImGuiCallbacks callbacks) {
_graphicsManager->setImGuiRenderCallback(callbacks);
void ModularGraphicsBackend::setImGuiCallbacks(const ImGuiCallbacks &callbacks) {
_graphicsManager->setImGuiCallbacks(callbacks);
}
#endif

View File

@ -68,7 +68,7 @@ public:
bool setGraphicsMode(int mode, uint flags = kGfxModeNoFlags) override;
int getGraphicsMode() const override;
#if defined(USE_IMGUI)
void setImGuiRenderCallback(ImGuiCallbacks callbacks) override final;
void setImGuiCallbacks(const ImGuiCallbacks &callbacks) override final;
#endif
bool setShader(const Common::Path &name) override final;
const GraphicsMode *getSupportedStretchModes() const override final;

View File

@ -917,13 +917,13 @@ public:
#if defined(USE_IMGUI)
/**
* Set the address for ImGui rendering callback
* Set the init/render/cleanup callbacks for ImGui.
*
* This is only supported on select backends desktop oriented
* This is only supported on select backends desktop oriented.
*
* @param render The function pointer called while rendering on screen
* @param callbacks Structure containing init/render/cleanup callbacks called on screen initialization, rendering and when deinitialized.
*/
virtual void setImGuiRenderCallback(ImGuiCallbacks callbacks) { }
virtual void setImGuiCallbacks(const ImGuiCallbacks &callbacks) {}
#endif
/**

View File

@ -290,8 +290,11 @@ Common::Error DirectorEngine::run() {
}
#ifdef USE_IMGUI
onImGuiInit();
_system->setImGuiRenderCallback(onImGuiRender);
ImGuiCallbacks callbacks;
callbacks.init = onImGuiInit;
callbacks.render = onImGuiRender;
callbacks.cleanup = onImGuiCleanup;
_system->setImGuiCallbacks(callbacks);
#endif
bool loop = true;
@ -320,11 +323,6 @@ Common::Error DirectorEngine::run() {
g_director->delayMillis(10);
}
#ifdef USE_IMGUI
_system->setImGuiRenderCallback(nullptr);
onImGuiCleanup();
#endif
return Common::kNoError;
}

View File

@ -873,8 +873,11 @@ Common::Error TwpEngine::run() {
updateSettingVars();
#ifdef USE_IMGUI
onImGuiInit();
_system->setImGuiRenderCallback(onImGuiRender);
ImGuiCallbacks callbacks;
callbacks.init = onImGuiInit;
callbacks.render = onImGuiRender;
callbacks.cleanup = onImGuiCleanup;
_system->setImGuiCallbacks(callbacks);
#endif
// Simple event handling loop
@ -1101,11 +1104,6 @@ Common::Error TwpEngine::run() {
}
}
#ifdef USE_IMGUI
_system->setImGuiRenderCallback(nullptr);
onImGuiCleanup();
#endif
return Common::kNoError;
}