ImGuiEngine updates & use ImGui stdlib functions

This commit is contained in:
Luke Street 2021-06-02 07:49:03 -04:00
parent 89f58beeb1
commit 281da0bfd4
6 changed files with 52 additions and 38 deletions

View File

@ -220,7 +220,6 @@ private:
hecl::CVarCommons& m_cvarCommons; hecl::CVarCommons& m_cvarCommons;
ImGuiConsole m_imGuiConsole; ImGuiConsole m_imGuiConsole;
std::string m_errorString; std::string m_errorString;
std::string m_configPath;
boo::ObjToken<boo::ITextureR> m_renderTex; boo::ObjToken<boo::ITextureR> m_renderTex;
hecl::SystemString m_deferredProject; hecl::SystemString m_deferredProject;
@ -392,10 +391,8 @@ public:
} }
} }
if (!m_imGuiInitialized) { if (!m_imGuiInitialized) {
ImGuiEngine::Initialize(gfxF, m_window.get(), scale); hecl::SystemUTF8Conv configDir{m_fileMgr.getStoreRoot()};
m_configPath = hecl::SystemUTF8Conv(m_fileMgr.getStoreRoot()).str(); ImGuiEngine::Initialize(gfxF, m_window.get(), scale, configDir.str());
m_configPath += "/imgui.ini";
ImGui::GetIO().IniFilename = m_configPath.c_str();
m_imGuiInitialized = true; m_imGuiInitialized = true;
} }

View File

@ -254,10 +254,10 @@ void ImGuiConsole::ShowInspectWindow(bool* isOpen) {
} }
} }
if (ImGui::Button("Clear")) { if (ImGui::Button("Clear")) {
m_inspectFilterText[0] = '\0'; m_inspectFilterText.clear();
} }
ImGui::SameLine(); ImGui::SameLine();
ImGui::InputText("Filter", m_inspectFilterText.data(), m_inspectFilterText.size()); ImGui::InputText("Filter", &m_inspectFilterText);
ImGui::Checkbox("Active", &m_inspectActiveOnly); ImGui::Checkbox("Active", &m_inspectActiveOnly);
ImGui::SameLine(); ImGui::SameLine();
ImGui::Checkbox("Current area", &m_inspectCurrentAreaOnly); ImGui::Checkbox("Current area", &m_inspectCurrentAreaOnly);
@ -284,8 +284,7 @@ void ImGuiConsole::ShowInspectWindow(bool* isOpen) {
// since that's how we iterate over CObjectList // since that's how we iterate over CObjectList
(sortSpecs->Specs[0].ColumnUserID != 'id' || (sortSpecs->Specs[0].ColumnUserID != 'id' ||
sortSpecs->Specs[0].SortDirection != ImGuiSortDirection_Ascending); sortSpecs->Specs[0].SortDirection != ImGuiSortDirection_Ascending);
std::string_view search{m_inspectFilterText.data(), strlen(m_inspectFilterText.data())}; if (!m_inspectFilterText.empty() || m_inspectActiveOnly || m_inspectCurrentAreaOnly || hasSortSpec) {
if (!search.empty() || m_inspectActiveOnly || m_inspectCurrentAreaOnly || hasSortSpec) {
std::vector<s16> sortedList; std::vector<s16> sortedList;
sortedList.reserve(list.size()); sortedList.reserve(list.size());
s16 uid = list.GetFirstObjectIndex(); s16 uid = list.GetFirstObjectIndex();
@ -300,8 +299,8 @@ void ImGuiConsole::ShowInspectWindow(bool* isOpen) {
ImGuiEntityEntry& entry = ImGuiConsole::entities[uid]; ImGuiEntityEntry& entry = ImGuiConsole::entities[uid];
if ((!m_inspectActiveOnly || entry.active) && if ((!m_inspectActiveOnly || entry.active) &&
(!m_inspectCurrentAreaOnly || entry.ent->x4_areaId == currAreaId) && (!m_inspectCurrentAreaOnly || entry.ent->x4_areaId == currAreaId) &&
(search.empty() || ContainsCaseInsensitive(entry.type, search) || (m_inspectFilterText.empty() || ContainsCaseInsensitive(entry.type, m_inspectFilterText) ||
ContainsCaseInsensitive(entry.name, search))) { ContainsCaseInsensitive(entry.name, m_inspectFilterText))) {
sortedList.push_back(uid); sortedList.push_back(uid);
} }
uid = list.GetNextObjectIndex(uid); uid = list.GetNextObjectIndex(uid);
@ -366,10 +365,10 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
ImGui::SetNextWindowSize(ImVec2{initialWindowSize, initialWindowSize}, ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2{initialWindowSize, initialWindowSize}, ImGuiCond_FirstUseEver);
if (ImGui::Begin("Console Variables", &m_showConsoleVariablesWindow)) { if (ImGui::Begin("Console Variables", &m_showConsoleVariablesWindow)) {
if (ImGui::Button("Clear")) { if (ImGui::Button("Clear")) {
m_cvarFiltersText[0] = '\0'; m_cvarFiltersText.clear();
} }
ImGui::SameLine(); 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); auto cvars = m_cvarMgr.cvars(hecl::CVar::EFlags::Any & ~hecl::CVar::EFlags::Hidden);
if (ImGui::BeginTable("ConsoleVariables", 2, if (ImGui::BeginTable("ConsoleVariables", 2,
@ -387,14 +386,13 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
bool hasSortSpec = sortSpecs != nullptr && bool hasSortSpec = sortSpecs != nullptr &&
// no multi-sort // no multi-sort
sortSpecs->SpecsCount == 1; sortSpecs->SpecsCount == 1;
std::string_view search{m_cvarFiltersText.data(), strlen(m_cvarFiltersText.data())};
std::vector<hecl::CVar*> sortedList; std::vector<hecl::CVar*> sortedList;
sortedList.reserve(cvars.size()); sortedList.reserve(cvars.size());
for (auto* cvar : cvars) { for (auto* cvar : cvars) {
if (!search.empty()) { if (!m_cvarFiltersText.empty()) {
if (ContainsCaseInsensitive(magic_enum::enum_name(cvar->type()), search) || if (ContainsCaseInsensitive(magic_enum::enum_name(cvar->type()), m_cvarFiltersText) ||
ContainsCaseInsensitive(cvar->name(), search)) { ContainsCaseInsensitive(cvar->name(), m_cvarFiltersText)) {
sortedList.push_back(cvar); sortedList.push_back(cvar);
} }
} else { } else {
@ -1126,7 +1124,6 @@ void ImGuiConsole::PreUpdate() {
} }
if (ImGui::IsKeyReleased(TranslateBooSpecialKey(boo::ESpecialKey::F5))) { if (ImGui::IsKeyReleased(TranslateBooSpecialKey(boo::ESpecialKey::F5))) {
m_paused ^= 1; m_paused ^= 1;
fmt::print(FMT_STRING("PAUSE {}\n"), m_paused);
g_Main->SetPaused(m_paused); g_Main->SetPaused(m_paused);
} }
bool canInspect = g_StateManager != nullptr && g_StateManager->GetObjectList(); bool canInspect = g_StateManager != nullptr && g_StateManager->GetObjectList();
@ -1419,14 +1416,14 @@ void ImGuiConsole::ShowLayersWindow() {
if (ImGui::Begin("Layers", &m_showLayersWindow)) { if (ImGui::Begin("Layers", &m_showLayersWindow)) {
if (ImGui::Button("Clear")) { if (ImGui::Button("Clear")) {
m_layersFilterText[0] = '\0'; m_layersFilterText.clear();
} }
ImGui::SameLine(); ImGui::SameLine();
ImGui::InputText("Filter", m_layersFilterText.data(), m_layersFilterText.size()); ImGui::InputText("Filter", &m_layersFilterText);
std::string_view search{m_layersFilterText.data(), strlen(m_layersFilterText.data())}; bool hasSearch = !m_layersFilterText.empty();
if (!search.empty()) { if (hasSearch) {
// kinda hacky way reset the tree state when search changes // 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()) { for (const auto& world : ListWorlds()) {
const auto& layers = dummyWorlds[world.second]->GetWorldLayers(); const auto& layers = dummyWorlds[world.second]->GetWorldLayers();
@ -1438,7 +1435,7 @@ void ImGuiConsole::ShowLayersWindow() {
auto areas = ListAreas(world.second); auto areas = ListAreas(world.second);
auto iter = areas.begin(); auto iter = areas.begin();
while (iter != areas.end()) { while (iter != areas.end()) {
if (!search.empty() && !ContainsCaseInsensitive(iter->first, search)) { if (hasSearch && !ContainsCaseInsensitive(iter->first, m_layersFilterText)) {
iter = areas.erase(iter); iter = areas.erase(iter);
} else { } else {
iter++; iter++;
@ -1448,7 +1445,7 @@ void ImGuiConsole::ShowLayersWindow() {
continue; 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) { for (const auto& area : areas) {
u32 layerCount = worldLayerState->GetAreaLayerCount(area.second); u32 layerCount = worldLayerState->GetAreaLayerCount(area.second);
if (layerCount == 0) { if (layerCount == 0) {
@ -1475,7 +1472,7 @@ void ImGuiConsole::ShowLayersWindow() {
ImGui::TreePop(); ImGui::TreePop();
} }
} }
if (!search.empty()) { if (hasSearch) {
ImGui::PopID(); ImGui::PopID();
} }
} }

View File

@ -65,9 +65,9 @@ private:
bool m_inspectActiveOnly = false; bool m_inspectActiveOnly = false;
bool m_inspectCurrentAreaOnly = false; bool m_inspectCurrentAreaOnly = false;
std::array<char, 40> m_inspectFilterText{}; std::string m_inspectFilterText;
std::array<char, 40> m_layersFilterText{}; std::string m_layersFilterText;
std::array<char, 40> m_cvarFiltersText{}; std::string m_cvarFiltersText;
// Debug overlays // Debug overlays
bool m_frameCounter = m_cvarCommons.m_debugOverlayShowFrameCounter->toBoolean(); bool m_frameCounter = m_cvarCommons.m_debugOverlayShowFrameCounter->toBoolean();

View File

@ -4,6 +4,7 @@ add_library(imgui
../extern/imgui/imgui_draw.cpp ../extern/imgui/imgui_draw.cpp
../extern/imgui/imgui_tables.cpp ../extern/imgui/imgui_tables.cpp
../extern/imgui/imgui_widgets.cpp ../extern/imgui/imgui_widgets.cpp
../extern/imgui/misc/cpp/imgui_stdlib.cpp
ImGuiEngine.cpp ImGuiEngine.cpp
ImGuiEngine.hpp ImGuiEngine.hpp
NotoMono.cpp NotoMono.cpp

View File

@ -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::IShaderDataBinding>, ImGuiUserTextureID_MAX> ShaderDataBindings;
static std::array<boo::ObjToken<boo::ITextureS>, ImGuiUserTextureID_MAX> Textures; static std::array<boo::ObjToken<boo::ITextureS>, ImGuiUserTextureID_MAX> Textures;
static boo::SWindowRect WindowRect; static boo::SWindowRect WindowRect;
static std::string IniFilePath;
static std::string LogFilePath;
struct Uniform { struct Uniform {
zeus::CMatrix4f xf; zeus::CMatrix4f xf;
@ -59,11 +61,16 @@ void setClipboardText(void* userData, const char* text) {
ImFont* ImGuiEngine::fontNormal; ImFont* ImGuiEngine::fontNormal;
ImFont* ImGuiEngine::fontLarge; 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_factory = factory;
m_window = window; m_window = window;
WindowRect = window->getWindowFrame(); WindowRect = window->getWindowFrame();
std::string dir{configDir};
IniFilePath = dir + "/imgui.ini";
LogFilePath = dir + "/imgui.log";
ImGui::CreateContext(); ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset;
@ -71,6 +78,10 @@ void ImGuiEngine::Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* w
io.GetClipboardTextFn = getClipboardText; io.GetClipboardTextFn = getClipboardText;
io.SetClipboardTextFn = setClipboardText; io.SetClipboardTextFn = setClipboardText;
io.ClipboardUserData = window; 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_Tab] = 256 + static_cast<int>(boo::ESpecialKey::Tab);
io.KeyMap[ImGuiKey_LeftArrow] = 256 + static_cast<int>(boo::ESpecialKey::Left); io.KeyMap[ImGuiKey_LeftArrow] = 256 + static_cast<int>(boo::ESpecialKey::Left);
@ -150,6 +161,8 @@ void ImGuiEngine::Shutdown() {
IndexBuffer.reset(); IndexBuffer.reset();
UniformBuffer.reset(); UniformBuffer.reset();
ShaderPipeline.reset(); ShaderPipeline.reset();
IniFilePath.clear();
LogFilePath.clear();
} }
void ImGuiEngine::Begin(float dt, float scale) { void ImGuiEngine::Begin(float dt, float scale) {
@ -256,17 +269,21 @@ void ImGuiEngine::End() {
m_factory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) { m_factory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) {
bool rebind = false; bool rebind = false;
if (drawData->TotalIdxCount > IndexBufferSize) { 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); drawData->TotalIdxCount);
IndexBuffer = ctx.newDynamicBuffer(boo::BufferUse::Index, sizeof(ImDrawIdx), drawData->TotalIdxCount); #endif
IndexBufferSize = drawData->TotalIdxCount; IndexBufferSize = drawData->TotalIdxCount + 1000;
IndexBuffer = ctx.newDynamicBuffer(boo::BufferUse::Index, sizeof(ImDrawIdx), IndexBufferSize);
rebind = true; rebind = true;
} }
if (drawData->TotalVtxCount > VertexBufferSize) { 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); drawData->TotalVtxCount);
VertexBuffer = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(ImDrawVert), drawData->TotalVtxCount); #endif
VertexBufferSize = drawData->TotalVtxCount; VertexBufferSize = drawData->TotalVtxCount + 1000;
VertexBuffer = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(ImDrawVert), VertexBufferSize);
rebind = true; rebind = true;
} }
if (rebind) { if (rebind) {

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "imgui.h" #include "imgui.h"
#include "misc/cpp/imgui_stdlib.h"
#include <boo/IWindow.hpp> #include <boo/IWindow.hpp>
#include <boo/graphicsdev/IGraphicsDataFactory.hpp> #include <boo/graphicsdev/IGraphicsDataFactory.hpp>
@ -20,7 +21,8 @@ public:
static ImFont* fontNormal; static ImFont* fontNormal;
static ImFont* fontLarge; 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 Shutdown();
static void Begin(float dt, float scale); static void Begin(float dt, float scale);
@ -45,6 +47,6 @@ struct ImGuiWindowCallback : boo::IWindowCallback {
void charKeyUp(unsigned long charCode, boo::EModifierKey mods) override; void charKeyUp(unsigned long charCode, boo::EModifierKey mods) override;
void specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat) override; void specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat) override;
void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods) override; void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods) override;
void resized(const boo::SWindowRect &rect, bool sync) override; void resized(const boo::SWindowRect& rect, bool sync) override;
}; };
} // namespace metaforce } // namespace metaforce