Skip to content

Commit

Permalink
#5746: Move more logic from TexTool view to TextureToolSelectionSystem.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 17, 2021
1 parent fe15ad0 commit a9d347b
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 84 deletions.
6 changes: 6 additions & 0 deletions include/itexturetoolmodel.h
Expand Up @@ -100,6 +100,12 @@ class ITextureToolSelectionSystem :
virtual void setActiveManipulator(selection::IManipulator::Type manipulatorType) = 0;

virtual sigc::signal<void, selection::IManipulator::Type>& signal_activeManipulatorChanged() = 0;

virtual Matrix4 getPivot2World() = 0;
virtual void onManipulationStart() = 0;
virtual void onManipulationChanged() = 0;
virtual void onManipulationFinished() = 0;
virtual void onManipulationCancelled() = 0;
};

}
Expand Down
72 changes: 2 additions & 70 deletions radiant/textool/TexTool.cpp
Expand Up @@ -59,8 +59,7 @@ TexTool::TexTool() :
_grid(GRID_DEFAULT),
_gridActive(registry::getValue<bool>(RKEY_GRID_STATE)),
_updateNeeded(false),
_selectionRescanNeeded(false),
_pivot2World(Matrix4::getIdentity())
_selectionRescanNeeded(false)
{
Bind(wxEVT_IDLE, &TexTool::onIdle, this);
Bind(wxEVT_KEY_DOWN, &TexTool::onKeyPress, this);
Expand Down Expand Up @@ -391,29 +390,6 @@ void TexTool::testSelect(SelectionTest& test)
auto bestSelectable = *selectionPool.begin();
bestSelectable.second->setSelected(true);
#endif

// Check the centerpoint of all selected items
Vector2 sum;
std::size_t count = 0;

GlobalTextureToolSelectionSystem().foreachSelectedNode([&](const textool::INode::Ptr& node)
{
auto bounds = node->localAABB();
sum += Vector2(bounds.origin.x(), bounds.origin.y());
count++;

return true;
});

if (count > 0)
{
sum /= count;
_pivot2World = Matrix4::getTranslation(Vector3(sum.x(), sum.y(), 0));
}
else
{
_pivot2World = Matrix4::getIdentity();
}
}

void TexTool::flipSelected(int axis) {
Expand Down Expand Up @@ -1003,12 +979,7 @@ bool TexTool::onGLDraw()
// Draw the u/v coordinates
drawUVCoords();

auto activeManipulator = GlobalTextureToolSelectionSystem().getActiveManipulator();

if (activeManipulator)
{
activeManipulator->renderComponents(_pivot2World);
}
GlobalTextureToolSelectionSystem().getActiveManipulator()->renderComponents(GlobalTextureToolSelectionSystem().getPivot2World());

if (!_activeMouseTools.empty())
{
Expand Down Expand Up @@ -1262,43 +1233,4 @@ TextureToolMouseEvent TexTool::createMouseEvent(const Vector2& point, const Vect
return TextureToolMouseEvent(*this, normalisedDeviceCoords, delta);
}

Matrix4 TexTool::getPivot2World()
{
return _pivot2World;
}

void TexTool::onManipulationStart()
{
GlobalTextureToolSelectionSystem().foreachSelectedNode([&] (const textool::INode::Ptr& node)
{
node->beginTransformation();
return true;
});
}

void TexTool::onManipulationChanged()
{
}

void TexTool::onManipulationEnd()
{
GlobalTextureToolSelectionSystem().foreachSelectedNode([&](const textool::INode::Ptr& node)
{
node->commitTransformation();
return true;
});

GlobalTextureToolSelectionSystem().getActiveManipulator()->setSelected(false);
}

void TexTool::onManipulationCancelled()
{
GlobalTextureToolSelectionSystem().foreachSelectedNode([&](const textool::INode::Ptr& node)
{
node->revertTransformation();
return true;
});
}


} // namespace ui
9 changes: 0 additions & 9 deletions radiant/textool/TexTool.h
Expand Up @@ -90,8 +90,6 @@ class TexTool :
sigc::connection _undoHandler;
sigc::connection _redoHandler;

Matrix4 _pivot2World;

private:
// This is where the static shared_ptr of the singleton instance is held.
static TexToolPtr& InstancePtr();
Expand Down Expand Up @@ -277,13 +275,6 @@ class TexTool :
*/
int countSelected();

Matrix4 getPivot2World();

void onManipulationStart();
void onManipulationChanged();
void onManipulationEnd();
void onManipulationCancelled();

protected:
MouseTool::Result processMouseDownEvent(const MouseToolPtr& tool, const Vector2& point) override;
MouseTool::Result processMouseUpEvent(const MouseToolPtr& tool, const Vector2& point) override;
Expand Down
10 changes: 5 additions & 5 deletions radiant/textool/tools/TextureToolManipulateMouseTool.cpp
Expand Up @@ -31,27 +31,27 @@ bool TextureToolManipulateMouseTool::manipulationIsPossible()

Matrix4 TextureToolManipulateMouseTool::getPivot2World()
{
return TexTool::Instance().getPivot2World();
return GlobalTextureToolSelectionSystem().getPivot2World();
}

void TextureToolManipulateMouseTool::onManipulationStart()
{
TexTool::Instance().onManipulationStart();
GlobalTextureToolSelectionSystem().onManipulationStart();
}

void TextureToolManipulateMouseTool::onManipulationChanged()
{
TexTool::Instance().onManipulationChanged();
GlobalTextureToolSelectionSystem().onManipulationChanged();
}

void TextureToolManipulateMouseTool::onManipulationFinished()
{
TexTool::Instance().onManipulationEnd();
GlobalTextureToolSelectionSystem().onManipulationFinished();
}

void TextureToolManipulateMouseTool::onManipulationCancelled()
{
TexTool::Instance().onManipulationCancelled();
GlobalTextureToolSelectionSystem().onManipulationCancelled();
}

}
62 changes: 62 additions & 0 deletions radiantcore/selection/textool/TextureToolSelectionSystem.cpp
Expand Up @@ -23,6 +23,7 @@ void TextureToolSelectionSystem::initialiseModule(const IApplicationContext& ctx
{
rMessage() << getName() << "::initialiseModule called." << std::endl;

_pivot2World = Matrix4::getIdentity();
registerManipulator(std::make_shared<selection::TextureToolRotateManipulator>());

_defaultManipulatorType = selection::IManipulator::Rotate;
Expand Down Expand Up @@ -136,6 +137,67 @@ void TextureToolSelectionSystem::setActiveManipulator(selection::IManipulator::T
rError() << "Cannot activate non-existent manipulator by type " << manipulatorType << std::endl;
}

Matrix4 TextureToolSelectionSystem::getPivot2World()
{
// Check the centerpoint of all selected items
Vector2 sum;
std::size_t count = 0;

foreachSelectedNode([&](const textool::INode::Ptr& node)
{
auto bounds = node->localAABB();
sum += Vector2(bounds.origin.x(), bounds.origin.y());
count++;

return true;
});

if (count > 0)
{
sum /= count;
_pivot2World = Matrix4::getTranslation(Vector3(sum.x(), sum.y(), 0));
}
else
{
_pivot2World = Matrix4::getIdentity();
}

return _pivot2World;
}

void TextureToolSelectionSystem::onManipulationStart()
{
foreachSelectedNode([&](const textool::INode::Ptr& node)
{
node->beginTransformation();
return true;
});
}

void TextureToolSelectionSystem::onManipulationChanged()
{
}

void TextureToolSelectionSystem::onManipulationFinished()
{
foreachSelectedNode([&](const textool::INode::Ptr& node)
{
node->commitTransformation();
return true;
});

getActiveManipulator()->setSelected(false);
}

void TextureToolSelectionSystem::onManipulationCancelled()
{
foreachSelectedNode([&](const textool::INode::Ptr& node)
{
node->revertTransformation();
return true;
});
}

sigc::signal<void, selection::IManipulator::Type>& TextureToolSelectionSystem::signal_activeManipulatorChanged()
{
return _sigActiveManipulatorChanged;
Expand Down
7 changes: 7 additions & 0 deletions radiantcore/selection/textool/TextureToolSelectionSystem.h
Expand Up @@ -16,6 +16,7 @@ class TextureToolSelectionSystem :
selection::IManipulator::Type _defaultManipulatorType;

sigc::signal<void, selection::IManipulator::Type> _sigActiveManipulatorChanged;
Matrix4 _pivot2World;

public:
const std::string& getName() const override;
Expand All @@ -35,6 +36,12 @@ class TextureToolSelectionSystem :
void setActiveManipulator(selection::IManipulator::Type manipulatorType) override;

sigc::signal<void, selection::IManipulator::Type>& signal_activeManipulatorChanged() override;

Matrix4 getPivot2World() override;
void onManipulationStart() override;
void onManipulationChanged() override;
void onManipulationFinished() override;
void onManipulationCancelled() override;
};

}

0 comments on commit a9d347b

Please sign in to comment.