Route editor actions by active target
This commit is contained in:
65
editor/src/UI/ImGuiBackendBridge.h
Normal file
65
editor/src/UI/ImGuiBackendBridge.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d12.h>
|
||||
#include <dxgi1_6.h>
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_dx12.h>
|
||||
#include <imgui_impl_win32.h>
|
||||
#include <windows.h>
|
||||
|
||||
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace UI {
|
||||
|
||||
class ImGuiBackendBridge {
|
||||
public:
|
||||
void Initialize(
|
||||
HWND hwnd,
|
||||
ID3D12Device* device,
|
||||
ID3D12DescriptorHeap* srvHeap,
|
||||
int frameCount = 3,
|
||||
DXGI_FORMAT backBufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM) {
|
||||
ImGui_ImplWin32_Init(hwnd);
|
||||
ImGui_ImplDX12_Init(
|
||||
device,
|
||||
frameCount,
|
||||
backBufferFormat,
|
||||
srvHeap,
|
||||
srvHeap->GetCPUDescriptorHandleForHeapStart(),
|
||||
srvHeap->GetGPUDescriptorHandleForHeapStart());
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
if (!m_initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui_ImplDX12_Shutdown();
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
void BeginFrame() const {
|
||||
ImGui_ImplDX12_NewFrame();
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
void RenderDrawData(ID3D12GraphicsCommandList* commandList) const {
|
||||
ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), commandList);
|
||||
}
|
||||
|
||||
static bool HandleWindowMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
return ImGui_ImplWin32_WndProcHandler(hwnd, msg, wParam, lParam) != 0;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_initialized = false;
|
||||
};
|
||||
|
||||
} // namespace UI
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
77
editor/src/UI/ImGuiSession.h
Normal file
77
editor/src/UI/ImGuiSession.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseTheme.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace UI {
|
||||
|
||||
class ImGuiSession {
|
||||
public:
|
||||
void Initialize(const std::string& projectPath) {
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
|
||||
ConfigureIniFile(projectPath, io);
|
||||
ConfigureFonts(io);
|
||||
ApplyBaseTheme(ImGui::GetStyle());
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
SaveSettings();
|
||||
if (ImGui::GetCurrentContext() != nullptr) {
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
m_iniPath.clear();
|
||||
}
|
||||
|
||||
void SaveSettings() const {
|
||||
if (m_iniPath.empty() || ImGui::GetCurrentContext() == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::SaveIniSettingsToDisk(m_iniPath.c_str());
|
||||
}
|
||||
|
||||
const std::string& GetIniPath() const {
|
||||
return m_iniPath;
|
||||
}
|
||||
|
||||
private:
|
||||
void ConfigureIniFile(const std::string& projectPath, ImGuiIO& io) {
|
||||
const std::filesystem::path configDir = std::filesystem::path(projectPath) / ".xceditor";
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(configDir, ec);
|
||||
|
||||
m_iniPath = (configDir / "imgui_layout.ini").string();
|
||||
io.IniFilename = m_iniPath.c_str();
|
||||
}
|
||||
|
||||
void ConfigureFonts(ImGuiIO& io) const {
|
||||
if (ImFont* uiFont = io.Fonts->AddFontFromFileTTF("C:/Windows/Fonts/msyh.ttc", 15.0f)) {
|
||||
io.FontDefault = uiFont;
|
||||
} else {
|
||||
io.FontDefault = io.Fonts->AddFontDefault();
|
||||
}
|
||||
|
||||
unsigned char* pixels = nullptr;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
||||
}
|
||||
|
||||
std::string m_iniPath;
|
||||
};
|
||||
|
||||
} // namespace UI
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user