From 713ea9a18602dd436470efa2bb536a94c4c19dc7 Mon Sep 17 00:00:00 2001 From: codereader Date: Fri, 10 Sep 2021 19:47:56 +0200 Subject: [PATCH] #5746: More work on getting the ISelectable interfaces into play --- include/itexturetoolview.h | 5 +++ .../selection/SelectionPool.h | 5 +++ radiant/selection/SelectionMouseTools.cpp | 24 +++++++++----- radiant/selection/SelectionMouseTools.h | 12 ++++++- radiant/textool/Selectable.h | 25 ++++++++++----- radiant/textool/TexTool.cpp | 31 +++++++++++++++++++ radiant/textool/TexTool.h | 1 + .../textool/tools/TextureToolSelectionTool.h | 8 +++-- .../selection/RadiantSelectionSystem.cpp | 2 +- tools/msvc/DarkRadiantCore.vcxproj | 1 - tools/msvc/DarkRadiantCore.vcxproj.filters | 3 -- tools/msvc/libs.vcxproj | 1 + tools/msvc/libs.vcxproj.filters | 3 ++ 13 files changed, 97 insertions(+), 24 deletions(-) rename {radiantcore => libs}/selection/SelectionPool.h (99%) diff --git a/include/itexturetoolview.h b/include/itexturetoolview.h index c06cb3c12c..31659813e0 100644 --- a/include/itexturetoolview.h +++ b/include/itexturetoolview.h @@ -2,6 +2,8 @@ #include "iorthoview.h" +class SelectionTest; + namespace ui { @@ -10,6 +12,9 @@ class ITextureToolView : { public: virtual ~ITextureToolView() {} + + // Perform a selection test using the given test instance + virtual void testSelect(SelectionTest& test) = 0; }; } diff --git a/radiantcore/selection/SelectionPool.h b/libs/selection/SelectionPool.h similarity index 99% rename from radiantcore/selection/SelectionPool.h rename to libs/selection/SelectionPool.h index bca640f62a..7465c9efbe 100644 --- a/radiantcore/selection/SelectionPool.h +++ b/libs/selection/SelectionPool.h @@ -4,6 +4,9 @@ #include "iselectiontest.h" #include "iselectable.h" +namespace selection +{ + /** * Selector implementation which sorts the incoming selectables by * their respective intersection values. @@ -123,3 +126,5 @@ class SelectionPool : return _pool.empty(); } }; + +} diff --git a/radiant/selection/SelectionMouseTools.cpp b/radiant/selection/SelectionMouseTools.cpp index e2bd48facb..217747c6b2 100644 --- a/radiant/selection/SelectionMouseTools.cpp +++ b/radiant/selection/SelectionMouseTools.cpp @@ -124,10 +124,20 @@ void BasicSelectionTool::renderOverlay() glDisable(GL_BLEND); } -void BasicSelectionTool::testSelect(MouseTool::Event& ev) +void BasicSelectionTool::performSelectionTest(SelectionVolume& volume, SelectionType type, MouseTool::Event& ev) { - bool isFaceOperation = selectFacesOnly(); + if (type == SelectionType::Area) + { + GlobalSelectionSystem().selectArea(volume, SelectionSystem::eToggle, selectFacesOnly()); + } + else + { + GlobalSelectionSystem().selectPoint(volume, SelectionSystem::eToggle, selectFacesOnly()); + } +} +void BasicSelectionTool::testSelect(MouseTool::Event& ev) +{ // Get the distance of the mouse pointer from the starting point Vector2 delta(ev.getDevicePosition() - _start); @@ -139,12 +149,12 @@ void BasicSelectionTool::testSelect(MouseTool::Event& ev) ConstructSelectionTest(scissored, selection::Rectangle::ConstructFromArea(_start, delta)); SelectionVolume volume(scissored); - - // Call the selectArea command that does the actual selecting - GlobalSelectionSystem().selectArea(volume, SelectionSystem::eToggle, isFaceOperation); + performSelectionTest(volume, SelectionType::Area, ev); } else { + // Mouse has barely moved, call the point selection routine + // // Copy the view to create a scissored volume render::View scissored(_view); // Create a volume out of a small box with 2*epsilon edge length @@ -153,9 +163,7 @@ void BasicSelectionTool::testSelect(MouseTool::Event& ev) // Create a selection test using that volume SelectionVolume volume(scissored); - - // Mouse has barely moved, call the point selection routine - GlobalSelectionSystem().selectPoint(volume, SelectionSystem::eToggle, isFaceOperation); + performSelectionTest(volume, SelectionType::Point, ev); } // Reset the mouse position to zero, this mouse operation is finished so far diff --git a/radiant/selection/SelectionMouseTools.h b/radiant/selection/SelectionMouseTools.h index 1c96de616f..8ec737c105 100644 --- a/radiant/selection/SelectionMouseTools.h +++ b/radiant/selection/SelectionMouseTools.h @@ -4,6 +4,8 @@ #include "render/View.h" #include "Rectangle.h" +class SelectionVolume; + namespace ui { @@ -53,12 +55,18 @@ class SelectMouseTool: public MouseTool */ class BasicSelectionTool: public SelectMouseTool { -private: +protected: Vector2 _start; // Position at mouseDown Vector2 _current; // Position during mouseMove selection::Rectangle _dragSelectionRect; + enum class SelectionType + { + Point, + Area, + }; + public: virtual const std::string& getName() override; virtual const std::string& getDisplayName() override; @@ -82,6 +90,8 @@ class BasicSelectionTool: public SelectMouseTool // Recalculates the rectangle used to draw the GUI overlay void updateDragSelectionRectangle(Event& ev); + + virtual void performSelectionTest(SelectionVolume& volume, SelectionType type, MouseTool::Event& ev); }; /** diff --git a/radiant/textool/Selectable.h b/radiant/textool/Selectable.h index 4e58e995cf..0ca96fee17 100644 --- a/radiant/textool/Selectable.h +++ b/radiant/textool/Selectable.h @@ -1,13 +1,17 @@ -#ifndef TEXTOOL_SELECTABLE_H_ -#define TEXTOOL_SELECTABLE_H_ +#pragma once +#include "iselectable.h" +#include "iselectiontest.h" #include "math/Vector2.h" #include "math/AABB.h" #include "Rectangle.h" -namespace textool { +namespace textool +{ -class Selectable +class Selectable : + public ISelectable, + public SelectionTestable { protected: bool _selected; @@ -20,6 +24,11 @@ class Selectable virtual ~Selectable() {} + virtual void testSelect(Selector& selector, SelectionTest& test) + { + // empty default for the moment being + } + /** greebo: Tests if this can be selected within the given * rectangle (s/t coordinates). * @@ -33,13 +42,15 @@ class Selectable /** greebo: Sets the selection status to */ - virtual void setSelected(bool selected) { + virtual void setSelected(bool selected) override + { _selected = selected; } /** greebo: Returns TRUE if this object is selected */ - virtual bool isSelected() const { + virtual bool isSelected() const override + { return _selected; } @@ -62,5 +73,3 @@ class Selectable }; // class Selectable } // namespace textool - -#endif /*TEXTOOL_SELECTABLE_H_*/ diff --git a/radiant/textool/TexTool.cpp b/radiant/textool/TexTool.cpp index e5463524ec..08a5641e8e 100644 --- a/radiant/textool/TexTool.cpp +++ b/radiant/textool/TexTool.cpp @@ -17,6 +17,7 @@ #include "wxutil/GLWidget.h" #include "selection/Device.h" #include "selection/SelectionVolume.h" +#include "selection/SelectionPool.h" #include "Rectangle.h" #include "textool/Selectable.h" @@ -345,6 +346,36 @@ void TexTool::scrollByPixels(int x, int y) updateProjection(); } +void TexTool::testSelect(SelectionTest& test) +{ + textool::TexToolItemVec selectables; + selection::SelectionPool selectionPool; + + // Cycle through all the toplevel items and test them for selectability + for (const auto& item : _items) + { + item->testSelect(selectionPool, test); + } + +#if 0 + // Cycle through all the items and ask them to deliver the list of child selectables + // residing within the test rectangle + for (const auto& item : _items) + { + // Get the list from each item + auto found = item->getSelectableChildren(rectangle); + + // and append the vector to the existing vector + selectables.insert(selectables.end(), found.begin(), found.end()); + } +#endif + + if (selectionPool.empty()) return; + + auto bestSelectable = *selectionPool.begin(); + bestSelectable.second->setSelected(true); +} + void TexTool::flipSelected(int axis) { if (countSelected() > 0) { beginOperation(); diff --git a/radiant/textool/TexTool.h b/radiant/textool/TexTool.h index 97c98224f0..991a35e76a 100644 --- a/radiant/textool/TexTool.h +++ b/radiant/textool/TexTool.h @@ -236,6 +236,7 @@ class TexTool : void forceRedraw() override; void scrollByPixels(int x, int y) override; + void testSelect(SelectionTest& test) override; /** greebo: Updates the GL window */ diff --git a/radiant/textool/tools/TextureToolSelectionTool.h b/radiant/textool/tools/TextureToolSelectionTool.h index 1e2e864bbe..a5279460ba 100644 --- a/radiant/textool/tools/TextureToolSelectionTool.h +++ b/radiant/textool/tools/TextureToolSelectionTool.h @@ -3,6 +3,7 @@ #include "i18n.h" #include "math/Vector2.h" #include "selection/SelectionMouseTools.h" +#include "selection/SelectionVolume.h" namespace ui { @@ -30,9 +31,12 @@ class TextureToolSelectionTool : return displayName; } - virtual void testSelect(Event& ev) override + virtual void performSelectionTest(SelectionVolume& volume, SelectionType type, MouseTool::Event& ev) override { - int i = 6; + auto mouseEvent = dynamic_cast(&ev); + if (mouseEvent == nullptr) return; + + mouseEvent->getView().testSelect(volume); } }; diff --git a/radiantcore/selection/RadiantSelectionSystem.cpp b/radiantcore/selection/RadiantSelectionSystem.cpp index f6ea71610f..3178910069 100644 --- a/radiantcore/selection/RadiantSelectionSystem.cpp +++ b/radiantcore/selection/RadiantSelectionSystem.cpp @@ -8,7 +8,7 @@ #include "iradiant.h" #include "ieventmanager.h" #include "ipreferencesystem.h" -#include "SelectionPool.h" +#include "selection/SelectionPool.h" #include "module/StaticModule.h" #include "brush/csg/CSG.h" #include "selection/algorithm/General.h" diff --git a/tools/msvc/DarkRadiantCore.vcxproj b/tools/msvc/DarkRadiantCore.vcxproj index cbc368fa1f..4360acf89e 100644 --- a/tools/msvc/DarkRadiantCore.vcxproj +++ b/tools/msvc/DarkRadiantCore.vcxproj @@ -1014,7 +1014,6 @@ - diff --git a/tools/msvc/DarkRadiantCore.vcxproj.filters b/tools/msvc/DarkRadiantCore.vcxproj.filters index f476565b02..e58fed1608 100644 --- a/tools/msvc/DarkRadiantCore.vcxproj.filters +++ b/tools/msvc/DarkRadiantCore.vcxproj.filters @@ -1890,9 +1890,6 @@ src\selection - - src\selection - src\selection diff --git a/tools/msvc/libs.vcxproj b/tools/msvc/libs.vcxproj index 431d10c192..d53be1e14e 100644 --- a/tools/msvc/libs.vcxproj +++ b/tools/msvc/libs.vcxproj @@ -222,6 +222,7 @@ + diff --git a/tools/msvc/libs.vcxproj.filters b/tools/msvc/libs.vcxproj.filters index 2fc7b898e0..2960791af7 100644 --- a/tools/msvc/libs.vcxproj.filters +++ b/tools/msvc/libs.vcxproj.filters @@ -299,6 +299,9 @@ selection + + selection +