Route editor actions by active target
This commit is contained in:
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