Skip to content

Commit

Permalink
#5746: Point and area selection algorithms implemented into TextureTo…
Browse files Browse the repository at this point in the history
…olSelectionSystem, modeled after the one in RadiantSelectionSystem - code is a bit redundant at this point
  • Loading branch information
codereader committed Sep 17, 2021
1 parent 618c113 commit eaea086
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 43 deletions.
3 changes: 3 additions & 0 deletions include/itexturetoolmodel.h
Expand Up @@ -88,6 +88,9 @@ class ITextureToolSelectionSystem :
// Collection should not be modified during iteration
virtual void foreachSelectedNode(const std::function<bool(const INode::Ptr&)>& functor) = 0;

virtual void selectPoint(SelectionTest& test, SelectionSystem::EModifier modifier) = 0;
virtual void selectArea(SelectionTest& test, SelectionSystem::EModifier modifier) = 0;

// Returns the ID of the registered manipulator
virtual std::size_t registerManipulator(const selection::ITextureToolManipulator::Ptr& manipulator) = 0;
virtual void unregisterManipulator(const selection::ITextureToolManipulator::Ptr& manipulator) = 0;
Expand Down
3 changes: 0 additions & 3 deletions include/itexturetoolview.h
Expand Up @@ -12,9 +12,6 @@ class ITextureToolView :
{
public:
virtual ~ITextureToolView() {}

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

}
38 changes: 0 additions & 38 deletions radiant/textool/TexTool.cpp
Expand Up @@ -354,44 +354,6 @@ void TexTool::scrollByPixels(int x, int y)
updateProjection();
}

void TexTool::testSelect(SelectionTest& test)
{
textool::TexToolItemVec selectables;
selection::SelectionPool selectionPool;

GlobalTextureToolSceneGraph().foreachNode([&](const textool::INode::Ptr& node)
{
node->testSelect(selectionPool, test);
return true;
});

#if 0
// Cycle through all the toplevel items and test them for selectability
for (const auto& item : _items)
{
item->testSelect(selectionPool, test);
}

// 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 1
if (selectionPool.empty()) return;

auto bestSelectable = *selectionPool.begin();
bestSelectable.second->setSelected(true);
#endif
}

void TexTool::flipSelected(int axis) {
if (countSelected() > 0) {
beginOperation();
Expand Down
1 change: 0 additions & 1 deletion radiant/textool/TexTool.h
Expand Up @@ -225,7 +225,6 @@ class TexTool :
void forceRedraw() override;

void scrollByPixels(int x, int y) override;
void testSelect(SelectionTest& test) override;

/** greebo: Updates the GL window
*/
Expand Down
10 changes: 9 additions & 1 deletion radiant/textool/tools/TextureToolSelectionTool.h
@@ -1,6 +1,7 @@
#pragma once

#include "i18n.h"
#include "itexturetoolmodel.h"
#include "math/Vector2.h"
#include "selection/SelectionMouseTools.h"
#include "selection/SelectionVolume.h"
Expand Down Expand Up @@ -36,7 +37,14 @@ class TextureToolSelectionTool :
auto mouseEvent = dynamic_cast<TextureToolMouseEvent*>(&ev);
if (mouseEvent == nullptr) return;

mouseEvent->getView().testSelect(volume);
if (type == SelectionType::Area)
{
GlobalTextureToolSelectionSystem().selectArea(volume, SelectionSystem::eToggle);
}
else
{
GlobalTextureToolSelectionSystem().selectPoint(volume, SelectionSystem::eToggle);
}
}
};

Expand Down
75 changes: 75 additions & 0 deletions radiantcore/selection/textool/TextureToolSelectionSystem.cpp
Expand Up @@ -3,6 +3,7 @@
#include "itextstream.h"
#include "module/StaticModule.h"
#include "../textool/TextureToolRotateManipulator.h"
#include "selection/SelectionPool.h"

namespace textool
{
Expand Down Expand Up @@ -178,6 +179,80 @@ sigc::signal<void, selection::IManipulator::Type>& TextureToolSelectionSystem::s
return _sigActiveManipulatorChanged;
}

void TextureToolSelectionSystem::selectPoint(SelectionTest& test, SelectionSystem::EModifier modifier)
{
selection::SelectionPool selectionPool;

GlobalTextureToolSceneGraph().foreachNode([&](const INode::Ptr& node)
{
node->testSelect(selectionPool, test);
return true;
});

if (selectionPool.empty()) return;

auto bestSelectable = *selectionPool.begin();

switch (modifier)
{
case SelectionSystem::eToggle:
bestSelectable.second->setSelected(!bestSelectable.second->isSelected());
break;

case SelectionSystem::eReplace:
bestSelectable.second->setSelected(bestSelectable.second->isSelected());
break;

case SelectionSystem::eCycle:
{
// Cycle through the selection pool and activate the item right after the currently selected
auto i = selectionPool.begin();

while (i != selectionPool.end())
{
if (i->second->isSelected())
{
// unselect the currently selected one
i->second->setSelected(false);

// check if there is a "next" item in the list, if not: select the first item
++i;

if (i != selectionPool.end())
{
i->second->setSelected(true);
}
else
{
selectionPool.begin()->second->setSelected(true);
}
break;
}

++i;
}
}
break;
}

}

void TextureToolSelectionSystem::selectArea(SelectionTest& test, SelectionSystem::EModifier modifier)
{
selection::SelectionPool selectionPool;

GlobalTextureToolSceneGraph().foreachNode([&](const INode::Ptr& node)
{
node->testSelect(selectionPool, test);
return true;
});

for (const auto& pair : selectionPool)
{
pair.second->setSelected(!pair.second->isSelected());
}
}

module::StaticModule<TextureToolSelectionSystem> _textureToolSelectionSystemModule;

}
3 changes: 3 additions & 0 deletions radiantcore/selection/textool/TextureToolSelectionSystem.h
Expand Up @@ -28,6 +28,9 @@ class TextureToolSelectionSystem :

void foreachSelectedNode(const std::function<bool(const INode::Ptr&)>& functor) override;

void selectPoint(SelectionTest& test, SelectionSystem::EModifier modifier) override;
void selectArea(SelectionTest& test, SelectionSystem::EModifier modifier) override;

// Returns the ID of the registered manipulator
std::size_t registerManipulator(const selection::ITextureToolManipulator::Ptr& manipulator) override;
void unregisterManipulator(const selection::ITextureToolManipulator::Ptr& manipulator) override;
Expand Down

0 comments on commit eaea086

Please sign in to comment.