载入中...
搜索中...
未找到
ImGuiBackend.h
浏览该文件的文档.
1#pragma once
2
3#include "ui/UIBackend.h"
4
5#include <imgui.h>
6
7#include <cstdint>
8#include <deque>
9#include <map>
10#include <vector>
11
12namespace eve::ui {
13
15class ImGuiBackend final : public UIBackend {
16public:
18 ImGuiBackend() = default;
20 ~ImGuiBackend() override;
21
22 ImGuiBackend(const ImGuiBackend &) = delete;
24
26 bool init(SDL_Window *window, eve::graphics::Graphics *gfx) override;
28 void shutdown() override;
30 bool isInitialized() const override { return initialized_; }
31
33 void processEvent(const SDL_Event *event) override;
35 void newFrame() override;
36
38 bool wantCaptureMouse() const override;
40 bool wantCaptureKeyboard() const override;
41
43 void setScale(float scale) override;
45 float getScale() const override { return uiScale_; }
46
47private:
48 void renderDrawData(void *vkCommandBuffer);
49 static bool presentOverlayThunk(void *userdata, void *commandBuffer);
50 static void textureDrawThunk(const ImDrawList* list, const ImDrawCmd* command);
51 static void windowDestroyedThunk(void *userdata);
52 void applyScale(float scale);
54 float computeInitialScale() const;
56 float computeDpiScale() const;
58 void loadFonts();
60 void rebuildFonts();
62 void checkFontCoverage() const;
63
64 [[nodiscard("retain the UI texture registration id or explicitly handle failure")]]
65 uint64_t registerTexture(graphics::Texture *tex) override;
66 void unregisterTexture(uint64_t id) override;
67 bool textureSize(uint64_t id, int *w, int *h) const override;
76 void *textureHandle(uint64_t id) const override;
77 bool usesQueuedTextureDraws() const override;
78 void queueTextureDraw(uint64_t id, float x, float y, float w, float h, float u0, float v0,
79 float u1, float v1, float r, float g, float b, float a,
80 bool opaque) override;
81
82 struct RegisteredTexture {
83 ImTextureID imId = nullptr;
84 graphics::Texture *texture = nullptr;
85 int width = 0;
86 int height = 0;
87 };
88 struct QueuedTextureDraw {
89 uint64_t id = 0;
90 float x = 0.f;
91 float y = 0.f;
92 float w = 0.f;
93 float h = 0.f;
94 float u0 = 0.f;
95 float v0 = 0.f;
96 float u1 = 1.f;
97 float v1 = 1.f;
98 float r = 1.f;
99 float g = 1.f;
100 float b = 1.f;
101 float a = 1.f;
102 float clipX = 0.f;
103 float clipY = 0.f;
104 float clipW = 0.f;
105 float clipH = 0.f;
106 bool opaque = false;
107 ImGuiBackend* owner = nullptr; // ImGui callback ABI; owned by this backend until frame end.
108 std::size_t bufferIndex = 0;
109 };
110 std::map<uint64_t, RegisteredTexture> textures_;
111 std::deque<QueuedTextureDraw> queuedTextureDraws_; // Stable callback addresses while appending.
112 void* activeCommandBuffer_ = nullptr; // Borrowed only during renderDrawData's synchronous callbacks.
113 uint64_t nextTextureKey_ = 1;
114 ImVector<ImWchar> fontRanges_; // kept alive for cfg.GlyphRanges across font builds
115 ImVector<ImWchar> cjkRanges_; // kept alive for the merged CJK font config
116
117 bool initialized_ = false;
118 bool fontsUploaded_ = false;
119 bool frameOpen_ = false;
120 float uiScale_ = 1.f;
121 float dpiScale_ = 1.f;
122 eve::graphics::Graphics *gfx_ = nullptr;
123 SDL_Window *window_ = nullptr;
124 void *imguiDescriptorPool_ = nullptr; // VkDescriptorPool
132 void *imguiTexturePool_ = nullptr; // VkDescriptorPool (texture sets)
140 void *imguiTextureLayout_ = nullptr; // VkDescriptorSetLayout (texture sets)
141 ImGuiContext *ctx_ = nullptr; // ImGui context owned by this backend
142};
143
144} // namespace eve::ui
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
tensor::Graph g
Definition GpuGraph.cpp:7
double r
int h
std::uint32_t height
std::uint32_t width
std::array< float, 3 > scale
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
Dear ImGui + SDL input + Vulkan present overlay.
bool isInitialized() const override
True when initialized.
float getScale() const override
Returns the scale.
void shutdown() override
Shutdown.
bool wantCaptureKeyboard() const override
Want capture keyboard.
void newFrame() override
Creates a frame. @ownership Caller deletes unless documented otherwise.
bool init(SDL_Window *window, eve::graphics::Graphics *gfx) override
Initializes .
ImGuiBackend & operator=(const ImGuiBackend &)=delete
~ImGuiBackend() override
Releases ImGuiBackend resources.
ImGuiBackend()=default
Constructs a ImGuiBackend.
ImGuiBackend(const ImGuiBackend &)=delete
bool wantCaptureMouse() const override
Want capture mouse.
void setScale(float scale) override
Sets the scale.
void processEvent(const SDL_Event *event) override
Process event.
Platform / renderer backend for declarative UI. Concrete implementations live under ui/<backend>/ (e....
Definition UIBackend.h:20
WidgetDesc list(std::string listId, const std::vector< std::string > &items, const std::function< WidgetDesc(const std::string &, int)> &itemFn)
Expand a string list into a Group of item widgets. itemFn(label, index) builds each row; keys default...
Definition Widget.cpp:715