mirror of https://github.com/AxioDL/metaforce.git
ImGuiEngine updates & use ImGui stdlib functions
This commit is contained in:
parent
89f58beeb1
commit
281da0bfd4
|
@ -220,7 +220,6 @@ private:
|
|||
hecl::CVarCommons& m_cvarCommons;
|
||||
ImGuiConsole m_imGuiConsole;
|
||||
std::string m_errorString;
|
||||
std::string m_configPath;
|
||||
|
||||
boo::ObjToken<boo::ITextureR> m_renderTex;
|
||||
hecl::SystemString m_deferredProject;
|
||||
|
@ -392,10 +391,8 @@ public:
|
|||
}
|
||||
}
|
||||
if (!m_imGuiInitialized) {
|
||||
ImGuiEngine::Initialize(gfxF, m_window.get(), scale);
|
||||
m_configPath = hecl::SystemUTF8Conv(m_fileMgr.getStoreRoot()).str();
|
||||
m_configPath += "/imgui.ini";
|
||||
ImGui::GetIO().IniFilename = m_configPath.c_str();
|
||||
hecl::SystemUTF8Conv configDir{m_fileMgr.getStoreRoot()};
|
||||
ImGuiEngine::Initialize(gfxF, m_window.get(), scale, configDir.str());
|
||||
m_imGuiInitialized = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -254,10 +254,10 @@ void ImGuiConsole::ShowInspectWindow(bool* isOpen) {
|
|||
}
|
||||
}
|
||||
if (ImGui::Button("Clear")) {
|
||||
m_inspectFilterText[0] = '\0';
|
||||
m_inspectFilterText.clear();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::InputText("Filter", m_inspectFilterText.data(), m_inspectFilterText.size());
|
||||
ImGui::InputText("Filter", &m_inspectFilterText);
|
||||
ImGui::Checkbox("Active", &m_inspectActiveOnly);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Current area", &m_inspectCurrentAreaOnly);
|
||||
|
@ -284,8 +284,7 @@ void ImGuiConsole::ShowInspectWindow(bool* isOpen) {
|
|||
// since that's how we iterate over CObjectList
|
||||
(sortSpecs->Specs[0].ColumnUserID != 'id' ||
|
||||
sortSpecs->Specs[0].SortDirection != ImGuiSortDirection_Ascending);
|
||||
std::string_view search{m_inspectFilterText.data(), strlen(m_inspectFilterText.data())};
|
||||
if (!search.empty() || m_inspectActiveOnly || m_inspectCurrentAreaOnly || hasSortSpec) {
|
||||
if (!m_inspectFilterText.empty() || m_inspectActiveOnly || m_inspectCurrentAreaOnly || hasSortSpec) {
|
||||
std::vector<s16> sortedList;
|
||||
sortedList.reserve(list.size());
|
||||
s16 uid = list.GetFirstObjectIndex();
|
||||
|
@ -300,8 +299,8 @@ void ImGuiConsole::ShowInspectWindow(bool* isOpen) {
|
|||
ImGuiEntityEntry& entry = ImGuiConsole::entities[uid];
|
||||
if ((!m_inspectActiveOnly || entry.active) &&
|
||||
(!m_inspectCurrentAreaOnly || entry.ent->x4_areaId == currAreaId) &&
|
||||
(search.empty() || ContainsCaseInsensitive(entry.type, search) ||
|
||||
ContainsCaseInsensitive(entry.name, search))) {
|
||||
(m_inspectFilterText.empty() || ContainsCaseInsensitive(entry.type, m_inspectFilterText) ||
|
||||
ContainsCaseInsensitive(entry.name, m_inspectFilterText))) {
|
||||
sortedList.push_back(uid);
|
||||
}
|
||||
uid = list.GetNextObjectIndex(uid);
|
||||
|
@ -366,10 +365,10 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
|
|||
ImGui::SetNextWindowSize(ImVec2{initialWindowSize, initialWindowSize}, ImGuiCond_FirstUseEver);
|
||||
if (ImGui::Begin("Console Variables", &m_showConsoleVariablesWindow)) {
|
||||
if (ImGui::Button("Clear")) {
|
||||
m_cvarFiltersText[0] = '\0';
|
||||
m_cvarFiltersText.clear();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::InputText("Filter", m_cvarFiltersText.data(), m_cvarFiltersText.size());
|
||||
ImGui::InputText("Filter", &m_cvarFiltersText);
|
||||
auto cvars = m_cvarMgr.cvars(hecl::CVar::EFlags::Any & ~hecl::CVar::EFlags::Hidden);
|
||||
|
||||
if (ImGui::BeginTable("ConsoleVariables", 2,
|
||||
|
@ -387,14 +386,13 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
|
|||
bool hasSortSpec = sortSpecs != nullptr &&
|
||||
// no multi-sort
|
||||
sortSpecs->SpecsCount == 1;
|
||||
std::string_view search{m_cvarFiltersText.data(), strlen(m_cvarFiltersText.data())};
|
||||
std::vector<hecl::CVar*> sortedList;
|
||||
sortedList.reserve(cvars.size());
|
||||
|
||||
for (auto* cvar : cvars) {
|
||||
if (!search.empty()) {
|
||||
if (ContainsCaseInsensitive(magic_enum::enum_name(cvar->type()), search) ||
|
||||
ContainsCaseInsensitive(cvar->name(), search)) {
|
||||
if (!m_cvarFiltersText.empty()) {
|
||||
if (ContainsCaseInsensitive(magic_enum::enum_name(cvar->type()), m_cvarFiltersText) ||
|
||||
ContainsCaseInsensitive(cvar->name(), m_cvarFiltersText)) {
|
||||
sortedList.push_back(cvar);
|
||||
}
|
||||
} else {
|
||||
|
@ -1126,7 +1124,6 @@ void ImGuiConsole::PreUpdate() {
|
|||
}
|
||||
if (ImGui::IsKeyReleased(TranslateBooSpecialKey(boo::ESpecialKey::F5))) {
|
||||
m_paused ^= 1;
|
||||
fmt::print(FMT_STRING("PAUSE {}\n"), m_paused);
|
||||
g_Main->SetPaused(m_paused);
|
||||
}
|
||||
bool canInspect = g_StateManager != nullptr && g_StateManager->GetObjectList();
|
||||
|
@ -1419,14 +1416,14 @@ void ImGuiConsole::ShowLayersWindow() {
|
|||
|
||||
if (ImGui::Begin("Layers", &m_showLayersWindow)) {
|
||||
if (ImGui::Button("Clear")) {
|
||||
m_layersFilterText[0] = '\0';
|
||||
m_layersFilterText.clear();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::InputText("Filter", m_layersFilterText.data(), m_layersFilterText.size());
|
||||
std::string_view search{m_layersFilterText.data(), strlen(m_layersFilterText.data())};
|
||||
if (!search.empty()) {
|
||||
ImGui::InputText("Filter", &m_layersFilterText);
|
||||
bool hasSearch = !m_layersFilterText.empty();
|
||||
if (hasSearch) {
|
||||
// kinda hacky way reset the tree state when search changes
|
||||
ImGui::PushID(m_layersFilterText.data());
|
||||
ImGui::PushID(m_layersFilterText.c_str());
|
||||
}
|
||||
for (const auto& world : ListWorlds()) {
|
||||
const auto& layers = dummyWorlds[world.second]->GetWorldLayers();
|
||||
|
@ -1438,7 +1435,7 @@ void ImGuiConsole::ShowLayersWindow() {
|
|||
auto areas = ListAreas(world.second);
|
||||
auto iter = areas.begin();
|
||||
while (iter != areas.end()) {
|
||||
if (!search.empty() && !ContainsCaseInsensitive(iter->first, search)) {
|
||||
if (hasSearch && !ContainsCaseInsensitive(iter->first, m_layersFilterText)) {
|
||||
iter = areas.erase(iter);
|
||||
} else {
|
||||
iter++;
|
||||
|
@ -1448,7 +1445,7 @@ void ImGuiConsole::ShowLayersWindow() {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (ImGui::TreeNodeEx(world.first.c_str(), search.empty() ? 0 : ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
if (ImGui::TreeNodeEx(world.first.c_str(), hasSearch ? ImGuiTreeNodeFlags_DefaultOpen : 0)) {
|
||||
for (const auto& area : areas) {
|
||||
u32 layerCount = worldLayerState->GetAreaLayerCount(area.second);
|
||||
if (layerCount == 0) {
|
||||
|
@ -1475,7 +1472,7 @@ void ImGuiConsole::ShowLayersWindow() {
|
|||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
if (!search.empty()) {
|
||||
if (hasSearch) {
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,9 +65,9 @@ private:
|
|||
bool m_inspectActiveOnly = false;
|
||||
bool m_inspectCurrentAreaOnly = false;
|
||||
|
||||
std::array<char, 40> m_inspectFilterText{};
|
||||
std::array<char, 40> m_layersFilterText{};
|
||||
std::array<char, 40> m_cvarFiltersText{};
|
||||
std::string m_inspectFilterText;
|
||||
std::string m_layersFilterText;
|
||||
std::string m_cvarFiltersText;
|
||||
|
||||
// Debug overlays
|
||||
bool m_frameCounter = m_cvarCommons.m_debugOverlayShowFrameCounter->toBoolean();
|
||||
|
|
|
@ -4,6 +4,7 @@ add_library(imgui
|
|||
../extern/imgui/imgui_draw.cpp
|
||||
../extern/imgui/imgui_tables.cpp
|
||||
../extern/imgui/imgui_widgets.cpp
|
||||
../extern/imgui/misc/cpp/imgui_stdlib.cpp
|
||||
ImGuiEngine.cpp
|
||||
ImGuiEngine.hpp
|
||||
NotoMono.cpp
|
||||
|
|
|
@ -34,6 +34,8 @@ static boo::ObjToken<boo::IGraphicsBufferD> UniformBuffer;
|
|||
static std::array<boo::ObjToken<boo::IShaderDataBinding>, ImGuiUserTextureID_MAX> ShaderDataBindings;
|
||||
static std::array<boo::ObjToken<boo::ITextureS>, ImGuiUserTextureID_MAX> Textures;
|
||||
static boo::SWindowRect WindowRect;
|
||||
static std::string IniFilePath;
|
||||
static std::string LogFilePath;
|
||||
|
||||
struct Uniform {
|
||||
zeus::CMatrix4f xf;
|
||||
|
@ -59,11 +61,16 @@ void setClipboardText(void* userData, const char* text) {
|
|||
ImFont* ImGuiEngine::fontNormal;
|
||||
ImFont* ImGuiEngine::fontLarge;
|
||||
|
||||
void ImGuiEngine::Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* window, float scale) {
|
||||
void ImGuiEngine::Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* window, float scale,
|
||||
std::string_view configDir) {
|
||||
m_factory = factory;
|
||||
m_window = window;
|
||||
WindowRect = window->getWindowFrame();
|
||||
|
||||
std::string dir{configDir};
|
||||
IniFilePath = dir + "/imgui.ini";
|
||||
LogFilePath = dir + "/imgui.log";
|
||||
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset;
|
||||
|
@ -71,6 +78,10 @@ void ImGuiEngine::Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* w
|
|||
io.GetClipboardTextFn = getClipboardText;
|
||||
io.SetClipboardTextFn = setClipboardText;
|
||||
io.ClipboardUserData = window;
|
||||
io.IniFilename = IniFilePath.c_str();
|
||||
io.LogFilename = LogFilePath.c_str();
|
||||
io.BackendPlatformName = "Boo";
|
||||
io.BackendRendererName = "Boo";
|
||||
|
||||
io.KeyMap[ImGuiKey_Tab] = 256 + static_cast<int>(boo::ESpecialKey::Tab);
|
||||
io.KeyMap[ImGuiKey_LeftArrow] = 256 + static_cast<int>(boo::ESpecialKey::Left);
|
||||
|
@ -150,6 +161,8 @@ void ImGuiEngine::Shutdown() {
|
|||
IndexBuffer.reset();
|
||||
UniformBuffer.reset();
|
||||
ShaderPipeline.reset();
|
||||
IniFilePath.clear();
|
||||
LogFilePath.clear();
|
||||
}
|
||||
|
||||
void ImGuiEngine::Begin(float dt, float scale) {
|
||||
|
@ -256,17 +269,21 @@ void ImGuiEngine::End() {
|
|||
m_factory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) {
|
||||
bool rebind = false;
|
||||
if (drawData->TotalIdxCount > IndexBufferSize) {
|
||||
Log.report(logvisor::Info, FMT_STRING(_SYS_STR("Resizing index buffer from {} to {}")), IndexBufferSize,
|
||||
#if 0
|
||||
Log.report(logvisor::Info, FMT_STRING(_SYS_STR("Resizing index buffer ({} < {})")), IndexBufferSize,
|
||||
drawData->TotalIdxCount);
|
||||
IndexBuffer = ctx.newDynamicBuffer(boo::BufferUse::Index, sizeof(ImDrawIdx), drawData->TotalIdxCount);
|
||||
IndexBufferSize = drawData->TotalIdxCount;
|
||||
#endif
|
||||
IndexBufferSize = drawData->TotalIdxCount + 1000;
|
||||
IndexBuffer = ctx.newDynamicBuffer(boo::BufferUse::Index, sizeof(ImDrawIdx), IndexBufferSize);
|
||||
rebind = true;
|
||||
}
|
||||
if (drawData->TotalVtxCount > VertexBufferSize) {
|
||||
Log.report(logvisor::Info, FMT_STRING(_SYS_STR("Resizing vertex buffer from {} to {}")), VertexBufferSize,
|
||||
#if 0
|
||||
Log.report(logvisor::Info, FMT_STRING(_SYS_STR("Resizing vertex buffer ({} < {})")), VertexBufferSize,
|
||||
drawData->TotalVtxCount);
|
||||
VertexBuffer = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(ImDrawVert), drawData->TotalVtxCount);
|
||||
VertexBufferSize = drawData->TotalVtxCount;
|
||||
#endif
|
||||
VertexBufferSize = drawData->TotalVtxCount + 1000;
|
||||
VertexBuffer = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(ImDrawVert), VertexBufferSize);
|
||||
rebind = true;
|
||||
}
|
||||
if (rebind) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "imgui.h"
|
||||
#include "misc/cpp/imgui_stdlib.h"
|
||||
|
||||
#include <boo/IWindow.hpp>
|
||||
#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
|
||||
|
@ -20,7 +21,8 @@ public:
|
|||
static ImFont* fontNormal;
|
||||
static ImFont* fontLarge;
|
||||
|
||||
static void Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* window, float scale);
|
||||
static void Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* window, float scale,
|
||||
std::string_view configDir);
|
||||
static void Shutdown();
|
||||
|
||||
static void Begin(float dt, float scale);
|
||||
|
|
Loading…
Reference in New Issue