Skip to content

Commit

Permalink
#5746: Eliminate more redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 16, 2021
1 parent 0bf8b3d commit 962b373
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 84 deletions.
41 changes: 41 additions & 0 deletions radiant/selection/ManipulateMouseTool.cpp
Expand Up @@ -80,6 +80,47 @@ unsigned int ManipulateMouseTool::getRefreshMode()
return RefreshMode::Force | RefreshMode::AllViews; // update cam view too
}

bool ManipulateMouseTool::selectManipulator(const render::View& view, const Vector2& devicePoint, const Vector2& deviceEpsilon)
{
auto activeManipulator = getActiveManipulator();
assert(activeManipulator);

if (manipulationIsPossible())
{
// Unselect any currently selected manipulators to be sure
activeManipulator->setSelected(false);

auto pivot2World = getPivot2World();

// Perform a selection test on this manipulator's components
render::View scissored(view);
ConstructSelectionTest(scissored, selection::Rectangle::ConstructFromPoint(devicePoint, deviceEpsilon));

SelectionVolume test(scissored);
activeManipulator->testSelect(test, pivot2World);

// Save the pivot2world matrix
_pivot2worldStart = pivot2World;

onManipulationStart();

// This is true, if a manipulator could be selected
_manipulationActive = activeManipulator->isSelected();

// is a manipulator selected / the pivot moving?
if (_manipulationActive)
{
activeManipulator->getActiveComponent()->beginTransformation(_pivot2worldStart, view, devicePoint);

_deviceStart = devicePoint;

_undoBegun = false;
}
}

return _manipulationActive;
}

void ManipulateMouseTool::handleMouseMove(const render::View& view, const Vector2& devicePoint)
{
auto activeManipulator = getActiveManipulator();
Expand Down
7 changes: 6 additions & 1 deletion radiant/selection/ManipulateMouseTool.h
Expand Up @@ -4,6 +4,7 @@
#include "imousetool.h"
#include "render/View.h"
#include "math/Vector2.h"
#include "math/Matrix4.h"

namespace ui
{
Expand Down Expand Up @@ -50,12 +51,16 @@ class ManipulateMouseTool :

protected:
virtual selection::IManipulator::Ptr getActiveManipulator() = 0;
virtual bool selectManipulator(const render::View& view, const Vector2& devicePoint, const Vector2& deviceEpsilon) = 0;
virtual bool selectManipulator(const render::View& view, const Vector2& devicePoint, const Vector2& deviceEpsilon);

virtual void onManipulationStart() = 0;
virtual void onManipulationChanged() = 0;
virtual void onManipulationCancelled() = 0;
virtual void onManipulationFinished() = 0;

virtual bool manipulationIsPossible() = 0;
virtual Matrix4 getPivot2World() = 0;

private:
void handleMouseMove(const render::View& view, const Vector2& devicePoint);
void endMove();
Expand Down
43 changes: 10 additions & 33 deletions radiant/selection/SceneManipulateMouseTool.cpp
Expand Up @@ -25,48 +25,25 @@ selection::IManipulator::Ptr SceneManipulateMouseTool::getActiveManipulator()
return GlobalSelectionSystem().getActiveManipulator();
}

bool SceneManipulateMouseTool::selectManipulator(const render::View& view, const Vector2& devicePoint, const Vector2& deviceEpsilon)
bool SceneManipulateMouseTool::manipulationIsPossible()
{
auto activeManipulator = getActiveManipulator();
assert(activeManipulator);

bool dragComponentMode = activeManipulator->getType() == selection::IManipulator::Drag &&
GlobalSelectionSystem().Mode() == SelectionSystem::eComponent;

if (!nothingSelected() || dragComponentMode)
{
// Unselect any currently selected manipulators to be sure
activeManipulator->setSelected(false);

const Matrix4& pivot2World = GlobalSelectionSystem().getPivot2World();

// Perform a selection test on this manipulator's components
render::View scissored(view);
ConstructSelectionTest(scissored, selection::Rectangle::ConstructFromPoint(devicePoint, deviceEpsilon));

SelectionVolume test(scissored);
activeManipulator->testSelect(test, pivot2World);

// Save the pivot2world matrix
_pivot2worldStart = pivot2World;

GlobalSelectionSystem().onManipulationStart();

// This is true, if a manipulator could be selected
_manipulationActive = activeManipulator->isSelected();

// is a manipulator selected / the pivot moving?
if (_manipulationActive)
{
activeManipulator->getActiveComponent()->beginTransformation(_pivot2worldStart, view, devicePoint);

_deviceStart = devicePoint;
return dragComponentMode || !nothingSelected();
}

_undoBegun = false;
}
}
Matrix4 SceneManipulateMouseTool::getPivot2World()
{
return GlobalSelectionSystem().getPivot2World();
}

return _manipulationActive;
void SceneManipulateMouseTool::onManipulationStart()
{
GlobalSelectionSystem().onManipulationStart();
}

void SceneManipulateMouseTool::onManipulationChanged()
Expand Down
6 changes: 3 additions & 3 deletions radiant/selection/SceneManipulateMouseTool.h
@@ -1,7 +1,5 @@
#pragma once

#include "render/View.h"
#include "math/Vector2.h"
#include "selection/ManipulateMouseTool.h"

namespace ui
Expand All @@ -20,12 +18,14 @@ class SceneManipulateMouseTool :

protected:
selection::IManipulator::Ptr getActiveManipulator() override;
bool selectManipulator(const render::View& view, const Vector2& devicePoint, const Vector2& deviceEpsilon) override;

void onManipulationStart() override;
void onManipulationChanged() override;
void onManipulationCancelled() override;
void onManipulationFinished() override;

bool manipulationIsPossible() override;
Matrix4 getPivot2World() override;
private:
bool nothingSelected() const;
};
Expand Down
54 changes: 10 additions & 44 deletions radiant/textool/tools/TextureToolManipulateMouseTool.cpp
@@ -1,10 +1,6 @@
#include "TextureToolManipulateMouseTool.h"

#include "i18n.h"
#include "selection/Device.h"
#include "Rectangle.h"
#include "selection/Pivot2World.h"
#include "selection/SelectionVolume.h"
#include "textool/TexTool.h"

namespace ui
Expand All @@ -27,49 +23,19 @@ selection::IManipulator::Ptr TextureToolManipulateMouseTool::getActiveManipulato
return TexTool::Instance().getActiveManipulator();
}

bool TextureToolManipulateMouseTool::selectManipulator(const render::View& view, const Vector2& devicePoint, const Vector2& deviceEpsilon)
bool TextureToolManipulateMouseTool::manipulationIsPossible()
{
auto activeManipulator = getActiveManipulator();
assert(activeManipulator);

if (true)
{
// Unselect any currently selected manipulators to be sure
activeManipulator->setSelected(false);

const Matrix4& pivot2World = TexTool::Instance().getPivot2World();

// Perform a selection test on this manipulator's components
render::View scissored(view);
ConstructSelectionTest(scissored, selection::Rectangle::ConstructFromPoint(devicePoint, deviceEpsilon));

SelectionVolume test(scissored);

// The manipulator class checks on its own, if any of its components can be selected
activeManipulator->testSelect(test, pivot2World);

// Save the pivot2world matrix
_pivot2worldStart = pivot2World;

TexTool::Instance().onManipulationStart();

// This is true, if a manipulator could be selected
_manipulationActive = activeManipulator->isSelected();

// is a manipulator selected / the pivot moving?
if (_manipulationActive)
{
activeManipulator->getActiveComponent()->beginTransformation(_pivot2worldStart, view, devicePoint);

_deviceStart = devicePoint;

_undoBegun = false;
return true;
}

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

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

void TextureToolManipulateMouseTool::onManipulationChanged()
Expand Down
7 changes: 4 additions & 3 deletions radiant/textool/tools/TextureToolManipulateMouseTool.h
@@ -1,7 +1,5 @@
#pragma once

#include "render/View.h"
#include "math/Vector2.h"
#include "selection/ManipulateMouseTool.h"

namespace ui
Expand All @@ -19,11 +17,14 @@ class TextureToolManipulateMouseTool :

protected:
selection::IManipulator::Ptr getActiveManipulator() override;
bool selectManipulator(const render::View& view, const Vector2& devicePoint, const Vector2& deviceEpsilon) override;

void onManipulationStart() override;
void onManipulationChanged() override;
void onManipulationCancelled() override;
void onManipulationFinished() override;

bool manipulationIsPossible() override;
Matrix4 getPivot2World() override;
};

}

0 comments on commit 962b373

Please sign in to comment.