载入中...
搜索中...
未找到
ImGuiBackend.h
浏览该文件的文档.
1#pragma once
2
3#include "ui/UIBackend.h"
4
5#include <imgui.h>
6
7#include <cstdint>
8#include <map>
9
10namespace eve::ui {
11
13class ImGuiBackend final : public UIBackend {
14public:
15 ImGuiBackend() = default;
16 ~ImGuiBackend() override;
17
18 ImGuiBackend(const ImGuiBackend &) = delete;
20
21 bool init(SDL_Window *window, eve::graphics::Graphics *gfx) override;
22 void shutdown() override;
23 bool isInitialized() const override { return initialized_; }
24
25 void processEvent(const SDL_Event *event) override;
26 void newFrame() override;
27
28 bool wantCaptureMouse() const override;
29 bool wantCaptureKeyboard() const override;
30
31 void setScale(float scale) override;
32 float getScale() const override { return uiScale_; }
33
34private:
35 void renderDrawData(void *vkCommandBuffer);
36 static void presentOverlayThunk(void *userdata, void *commandBuffer);
37 static void windowDestroyedThunk(void *userdata);
38 void applyScale(float scale);
40 float computeInitialScale() const;
42 float computeDpiScale() const;
44 void loadFonts();
46 void rebuildFonts();
47
48 uint64_t registerTexture(graphics::Texture *tex) override;
49 void unregisterTexture(uint64_t id) override;
50 bool textureSize(uint64_t id, int *w, int *h) const override;
51 void *textureHandle(uint64_t id) const override;
52
53 struct RegisteredTexture {
54 ImTextureID imId = nullptr;
55 int width = 0;
56 int height = 0;
57 };
58 std::map<uint64_t, RegisteredTexture> textures_;
59 uint64_t nextTextureKey_ = 1;
60 ImVector<ImWchar> fontRanges_; // kept alive for cfg.GlyphRanges across font builds
61
62 bool initialized_ = false;
63 bool fontsUploaded_ = false;
64 bool frameOpen_ = false;
65 float uiScale_ = 1.f;
66 float dpiScale_ = 1.f;
67 eve::graphics::Graphics *gfx_ = nullptr;
68 SDL_Window *window_ = nullptr;
69 void *imguiDescriptorPool_ = nullptr; // VkDescriptorPool
70 void *imguiTexturePool_ = nullptr; // VkDescriptorPool (texture sets)
71 void *imguiTextureLayout_ = nullptr; // VkDescriptorSetLayout (texture sets)
72 ImGuiContext *ctx_ = nullptr; // ImGui context owned by this backend
73};
74
75} // namespace eve::ui
float height
Definition Grass.cpp:235
int h
int w
int width
float scale
Definition TreeMesh.cpp:122
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:17
Dear ImGui + SDL input + Vulkan present overlay.
bool isInitialized() const override
float getScale() const override
void shutdown() override
bool wantCaptureKeyboard() const override
void newFrame() override
bool init(SDL_Window *window, eve::graphics::Graphics *gfx) override
ImGuiBackend & operator=(const ImGuiBackend &)=delete
ImGuiBackend(const ImGuiBackend &)=delete
bool wantCaptureMouse() const override
void setScale(float scale) override
Scale fonts + ImGui style metrics (1 = default desktop).
void processEvent(const SDL_Event *event) override
Platform / renderer backend for declarative UI. Concrete implementations live under ui/<backend>/ (e....
Definition UIBackend.h:18