rexglue-skate3/include/rex/ui/imgui_dialog.h
2026-06-14 05:22:30 +01:00

75 lines
2.3 KiB
C++

/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2022 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*
* @modified Tom Clay, 2026 - Adapted for ReXGlue runtime
*/
#ifndef REX_UI_IMGUI_DIALOG_H_
#define REX_UI_IMGUI_DIALOG_H_
#include <memory>
#include <vector>
#include <rex/thread.h>
#include <rex/ui/imgui_drawer.h>
#include <rex/ui/window_listener.h>
struct ImGuiIO;
namespace rex {
namespace ui {
class ImGuiDialog {
public:
~ImGuiDialog();
// Shows a simple message box containing a text message.
// Callers can want for the dialog to close with Wait().
// Dialogs retain themselves and will delete themselves when closed.
static ImGuiDialog* ShowMessageBox(ImGuiDrawer* imgui_drawer, std::string title,
std::string body);
// A fence to signal when the dialog is closed.
void Then(rex::thread::Fence* fence);
void Draw();
// Whether the dialog needs the UI to repaint continuously while it's open
// (interactive dialogs - input handling, animations). Passive readouts
// should return false so they only repaint when something else (such as a
// new guest output frame) triggers a paint - a continuous repaint loop
// presents without new guest frames, inflating externally measured FPS and
// burning CPU/GPU.
virtual bool WantsContinuousRepaint() const { return true; }
protected:
ImGuiDialog(ImGuiDrawer* imgui_drawer);
ImGuiDrawer* imgui_drawer() const { return imgui_drawer_; }
ImGuiIO& GetIO();
void SetDrawActive(bool active);
bool IsDrawActive() const { return is_draw_active_; }
// Closes the dialog and returns to any waiters.
void Close();
virtual void OnShow() {}
virtual void OnClose() {}
virtual void OnDraw(ImGuiIO& io) { (void)io; }
private:
ImGuiDrawer* imgui_drawer_ = nullptr;
bool is_draw_active_ = true;
bool has_close_pending_ = false;
std::vector<rex::thread::Fence*> waiting_fences_;
};
} // namespace ui
} // namespace rex
#endif // REX_UI_IMGUI_DIALOG_H_