Skip to content

Commit

Permalink
#5746: More work on getting the ISelectable interfaces into play
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 10, 2021
1 parent 1517261 commit 713ea9a
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 24 deletions.
5 changes: 5 additions & 0 deletions include/itexturetoolview.h
Expand Up @@ -2,6 +2,8 @@

#include "iorthoview.h"

class SelectionTest;

namespace ui
{

Expand All @@ -10,6 +12,9 @@ class ITextureToolView :
{
public:
virtual ~ITextureToolView() {}

// Perform a selection test using the given test instance
virtual void testSelect(SelectionTest& test) = 0;
};

}
Expand Up @@ -4,6 +4,9 @@
#include "iselectiontest.h"
#include "iselectable.h"

namespace selection
{

/**
* Selector implementation which sorts the incoming selectables by
* their respective intersection values.
Expand Down Expand Up @@ -123,3 +126,5 @@ class SelectionPool :
return _pool.empty();
}
};

}
24 changes: 16 additions & 8 deletions radiant/selection/SelectionMouseTools.cpp
Expand Up @@ -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);

Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion radiant/selection/SelectionMouseTools.h
Expand Up @@ -4,6 +4,8 @@
#include "render/View.h"
#include "Rectangle.h"

class SelectionVolume;

namespace ui
{

Expand Down Expand Up @@ -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;
Expand All @@ -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);
};

/**
Expand Down
25 changes: 17 additions & 8 deletions 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;
Expand All @@ -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).
*
Expand All @@ -33,13 +42,15 @@ class Selectable

/** greebo: Sets the selection status to <selected>
*/
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;
}

Expand All @@ -62,5 +73,3 @@ class Selectable
}; // class Selectable

} // namespace textool

#endif /*TEXTOOL_SELECTABLE_H_*/
31 changes: 31 additions & 0 deletions radiant/textool/TexTool.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions radiant/textool/TexTool.h
Expand Up @@ -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
*/
Expand Down
8 changes: 6 additions & 2 deletions radiant/textool/tools/TextureToolSelectionTool.h
Expand Up @@ -3,6 +3,7 @@
#include "i18n.h"
#include "math/Vector2.h"
#include "selection/SelectionMouseTools.h"
#include "selection/SelectionVolume.h"

namespace ui
{
Expand Down Expand Up @@ -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<TextureToolMouseEvent*>(&ev);
if (mouseEvent == nullptr) return;

mouseEvent->getView().testSelect(volume);
}
};

Expand Down
2 changes: 1 addition & 1 deletion radiantcore/selection/RadiantSelectionSystem.cpp
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -1014,7 +1014,6 @@
<ClInclude Include="..\..\radiantcore\selection\Renderables.h" />
<ClInclude Include="..\..\radiantcore\selection\SceneWalkers.h" />
<ClInclude Include="..\..\radiantcore\selection\SelectedNodeList.h" />
<ClInclude Include="..\..\radiantcore\selection\SelectionPool.h" />
<ClInclude Include="..\..\radiantcore\selection\selectionset\SelectionSet.h" />
<ClInclude Include="..\..\radiantcore\selection\selectionset\SelectionSetInfoFileModule.h" />
<ClInclude Include="..\..\radiantcore\selection\selectionset\SelectionSetManager.h" />
Expand Down
3 changes: 0 additions & 3 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -1890,9 +1890,6 @@
<ClInclude Include="..\..\radiantcore\selection\SelectedNodeList.h">
<Filter>src\selection</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\selection\SelectionPool.h">
<Filter>src\selection</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\selection\TransformationVisitors.h">
<Filter>src\selection</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/libs.vcxproj
Expand Up @@ -222,6 +222,7 @@
<ClInclude Include="..\..\libs\selection\OccludeSelector.h" />
<ClInclude Include="..\..\libs\selection\Pivot2World.h" />
<ClInclude Include="..\..\libs\selection\SelectedPlaneSet.h" />
<ClInclude Include="..\..\libs\selection\SelectionPool.h" />
<ClInclude Include="..\..\libs\selection\SelectionVolume.h" />
<ClInclude Include="..\..\libs\selection\SingleItemSelector.h" />
<ClInclude Include="..\..\libs\SequentialTaskQueue.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/libs.vcxproj.filters
Expand Up @@ -299,6 +299,9 @@
<ClInclude Include="..\..\libs\selection\SelectedPlaneSet.h">
<Filter>selection</Filter>
</ClInclude>
<ClInclude Include="..\..\libs\selection\SelectionPool.h">
<Filter>selection</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="util">
Expand Down

0 comments on commit 713ea9a

Please sign in to comment.