From 830fdd434bc4d04abb275008ffc0718ff2ffd288 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Tue, 4 Mar 2025 00:56:39 +0100 Subject: [PATCH] Added task loop for async stuff and getters for the loop and the VFS. --- private/raid/application.cpp | 2 ++ public/raid/imraid.hpp | 25 +++++++++++++++++++++++-- public/raid/raid.hpp | 8 ++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/private/raid/application.cpp b/private/raid/application.cpp index aaa78fc..dd78e91 100644 --- a/private/raid/application.cpp +++ b/private/raid/application.cpp @@ -96,6 +96,8 @@ int Application::run(int argc, char** argv) ImGui::Begin("##main", nullptr, mMainWindowFlags); render(); + + mTaskLoop.tick(); ImGui::End(); ImGui::Render(); diff --git a/public/raid/imraid.hpp b/public/raid/imraid.hpp index 376c388..179e858 100644 --- a/public/raid/imraid.hpp +++ b/public/raid/imraid.hpp @@ -8,13 +8,34 @@ namespace ImRaid { -inline bool ToggleImageButton(const char* strId, ImTextureID textureId, const ImVec2& imageSize, bool& toggled) +inline bool ToggleButton(const char* label, bool& toggled, const ImVec2& size = ImVec2(0, 0)) { if (toggled) { ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive)); } - const bool clicked = ImGui::ImageButton(strId, textureId, imageSize); + const bool clicked = ImGui::Button(label, size); + if (toggled) + { + ImGui::PopStyleColor(); + } + + if (clicked) + { + toggled = !toggled; + } + return clicked; +} + +inline bool ToggleImageButton(const char* strId, ImTextureID textureId, const ImVec2& imageSize, bool& toggled, + const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), + const ImVec4& bgCol = ImVec4(0, 0, 0, 0), const ImVec4& tintCol = ImVec4(1, 1, 1, 1)) +{ + if (toggled) + { + ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive)); + } + const bool clicked = ImGui::ImageButton(strId, textureId, imageSize, uv0, uv1, bgCol, tintCol); if (toggled) { ImGui::PopStyleColor(); diff --git a/public/raid/raid.hpp b/public/raid/raid.hpp index d3a5b99..9c8d7ec 100644 --- a/public/raid/raid.hpp +++ b/public/raid/raid.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ private: SDL_GLContext mGLContext = nullptr; mijin::StackedFileSystemAdapter mFS; + mijin::SimpleTaskLoop mTaskLoop; std::unordered_map mTextures; bool mRunning = true; @@ -72,6 +74,12 @@ private: public: virtual ~Application() = default; + [[nodiscard]] + const mijin::StackedFileSystemAdapter& getFS() const { return mFS; } + + [[nodiscard]] + mijin::SimpleTaskLoop& getLoop() { return mTaskLoop; } + [[nodiscard]] ImGuiWindowFlags getMainWindowFlags() const { return mMainWindowFlags; }