From 1f14089d0d6adbd1072b022dfaeb17a1975e8b38 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 19 Mar 2025 01:44:18 +0000 Subject: Replace basic query tool with a ImGui version --- ui/gameMainSelector.cpp | 22 +--------------------- ui/gameMainSelector.h | 2 -- ui/gameMainWindow.cpp | 4 ++++ ui/queryTool.cpp | 39 +++++++++++++++++++++++++++++++++++++++ ui/queryTool.h | 14 ++++++++++++++ 5 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 ui/queryTool.cpp create mode 100644 ui/queryTool.h diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp index d5cbf62..55977ed 100644 --- a/ui/gameMainSelector.cpp +++ b/ui/gameMainSelector.cpp @@ -1,5 +1,4 @@ #include "gameMainSelector.h" -#include "collection.h" #include "text.h" #include "ui/uiComponent.h" #include @@ -8,9 +7,7 @@ #include #include // IWYU pragma: keep #include -#include #include -#include const std::filesystem::path fontpath {"/usr/share/fonts/hack/Hack-Regular.ttf"}; @@ -27,9 +24,6 @@ GameMainSelector::render(const UIShader & shader, const Position & parentPos) co if (target) { target->render(shader, parentPos + position + TargetPos); } - if (!clicked.empty()) { - Text {clicked, font, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos); - } } void @@ -73,22 +67,8 @@ GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos) } void -GameMainSelector::defaultClick(const Ray & ray) +GameMainSelector::defaultClick(const Ray &) { - BaryPosition baryPos {}; - RelativeDistance distance {}; - - if (const auto selected = gameState->world.applyOne(&Selectable::intersectRay, ray, baryPos, distance); - selected != gameState->world.end()) { - const auto & ref = *selected.base()->get(); - clicked = typeid(ref).name(); - } - else if (const auto pos = gameState->terrain->intersectRay(ray)) { - clicked = streamed_string(*pos); - } - else { - clicked.clear(); - } } bool diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h index 16f70eb..df29842 100644 --- a/ui/gameMainSelector.h +++ b/ui/gameMainSelector.h @@ -7,7 +7,6 @@ #include "worldOverlay.h" #include #include -#include class SceneShader; template class Ray; @@ -41,5 +40,4 @@ public: private: const Camera * camera; const Font font; - std::string clicked; }; diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index c1e135b..356d522 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -3,6 +3,7 @@ #include "gameMainSelector.h" #include "imgui_extras.h" #include "manualCameraController.h" +#include "queryTool.h" #include #include #include @@ -29,6 +30,9 @@ public: if (ImGui::ImageButton("Build rails", *buildRailsIcon, TOOLBAR_ICON_SIZE)) { gms->target = std::make_unique>(); } + if (ImGui::ImageButton("Query", *buildRailsIcon, TOOLBAR_ICON_SIZE)) { + gms->target = std::make_unique(); + } IltGui::EndToolbar(); } } diff --git a/ui/queryTool.cpp b/ui/queryTool.cpp new file mode 100644 index 0000000..e48bae1 --- /dev/null +++ b/ui/queryTool.cpp @@ -0,0 +1,39 @@ +#include "queryTool.h" +#include "imgui_wrap.h" +#include +#include +#include +#include +#include +#include + +bool +QueryTool::click(const SDL_MouseButtonEvent & event, const Ray & ray) +{ + if (event.button != SDL_BUTTON_LEFT) { + return false; + } + BaryPosition baryPos {}; + RelativeDistance distance {}; + + if (const auto selected = gameState->world.applyOne(&Selectable::intersectRay, ray, baryPos, distance); + selected != gameState->world.end()) { + const auto & ref = *selected.base()->get(); + clicked = typeid(ref).name(); + } + else if (const auto pos = gameState->terrain->intersectRay(ray)) { + clicked = streamed_string(*pos); + } + else { + clicked.clear(); + } + return true; +} + +void +QueryTool::render(const UIShader &, const UIComponent::Position &) +{ + ImGui::Begin("Query Tool"); + ImGui::TextUnformatted(clicked.c_str()); + ImGui::End(); +} diff --git a/ui/queryTool.h b/ui/queryTool.h new file mode 100644 index 0000000..8462214 --- /dev/null +++ b/ui/queryTool.h @@ -0,0 +1,14 @@ +#pragma once + +#include "gameMainSelector.h" + +class QueryTool : public GameMainSelector::Component { +protected: + using GameMainSelector::Component::render; + + bool click(const SDL_MouseButtonEvent &, const Ray &) override; + void render(const UIShader & shader, const UIComponent::Position & pos) override; + +private: + std::string clicked; +}; -- cgit v1.2.3