Skip to content

Commit

Permalink
#5746: Some refactoring efforts to reduce code redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 16, 2021
1 parent 2a4ee5f commit 193ea54
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 62 deletions.
38 changes: 9 additions & 29 deletions radiant/selection/ManipulateMouseTool.cpp
Expand Up @@ -92,10 +92,14 @@ 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)
selection::IManipulator::Ptr ManipulateMouseTool::getActiveManipulator()
{
const auto& activeManipulator = GlobalSelectionSystem().getActiveManipulator();
return GlobalSelectionSystem().getActiveManipulator();
}

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

bool dragComponentMode = activeManipulator->getType() == selection::IManipulator::Drag &&
Expand Down Expand Up @@ -144,7 +148,7 @@ bool ManipulateMouseTool::selectManipulator(const render::View& view, const Vect

void ManipulateMouseTool::handleMouseMove(const render::View& view, const Vector2& devicePoint)
{
const auto& activeManipulator = GlobalSelectionSystem().getActiveManipulator();
auto activeManipulator = getActiveManipulator();
assert(activeManipulator);

// Check if the active manipulator is selected in the first place
Expand Down Expand Up @@ -202,7 +206,7 @@ void ManipulateMouseTool::endMove()
{
freezeTransforms();

const auto& activeManipulator = GlobalSelectionSystem().getActiveManipulator();
auto activeManipulator = getActiveManipulator();
assert(activeManipulator);

_manipulationActive = false;
Expand Down Expand Up @@ -248,7 +252,7 @@ void ManipulateMouseTool::endMove()

void ManipulateMouseTool::cancelMove()
{
const auto& activeManipulator = GlobalSelectionSystem().getActiveManipulator();
auto activeManipulator = getActiveManipulator();
assert(activeManipulator);

_manipulationActive = false;
Expand Down Expand Up @@ -297,28 +301,4 @@ void ManipulateMouseTool::renderOverlay()
#endif
}

void ManipulateMouseTool::render(RenderSystem& renderSystem, RenderableCollector& collector, const VolumeTest& volume)
{
#if 0
if (nothingSelected()) return;

const selection::ManipulatorPtr& activeManipulator = _selectionSystem.getActiveManipulator();

if (!activeManipulator) return;

if (!_pointShader)
{
_pointShader = renderSystem.capture("$POINT");
}

collector.setHighlightFlag(RenderableCollector::Highlight::Faces, false);
collector.setHighlightFlag(RenderableCollector::Highlight::Primitives, false);

collector.SetState(_pointShader, RenderableCollector::eWireframeOnly);
collector.SetState(_pointShader, RenderableCollector::eFullMaterials);

activeManipulator->render(collector, volume);
#endif
}

}
6 changes: 5 additions & 1 deletion radiant/selection/ManipulateMouseTool.h
Expand Up @@ -29,10 +29,12 @@ class ManipulateMouseTool :
Vector2 _deviceStart;
bool _undoBegun;

protected:
#ifdef _DEBUG
std::string _debugText;
#endif

private:
ShaderPtr _pointShader;

public:
Expand All @@ -52,7 +54,9 @@ class ManipulateMouseTool :
virtual unsigned int getRefreshMode() override;

void renderOverlay() override;
void render(RenderSystem& renderSystem, RenderableCollector& collector, const VolumeTest& volume) override;

protected:
virtual selection::IManipulator::Ptr getActiveManipulator();

private:
bool selectManipulator(const render::View& view, const Vector2& devicePoint, const Vector2& deviceEpsilon);
Expand Down
34 changes: 10 additions & 24 deletions radiant/textool/tools/TextureToolManipulateMouseTool.cpp
Expand Up @@ -93,17 +93,17 @@ unsigned int TextureToolManipulateMouseTool::getRefreshMode()
return RefreshMode::Force | RefreshMode::AllViews;
}

bool TextureToolManipulateMouseTool::selectManipulator(const render::View& view, const Vector2& devicePoint, const Vector2& deviceEpsilon)
selection::IManipulator::Ptr TextureToolManipulateMouseTool::getActiveManipulator()
{
const auto& activeManipulator = TexTool::Instance().getActiveManipulator();
return TexTool::Instance().getActiveManipulator();
}

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

#if 0
bool dragComponentMode = activeManipulator->getType() == selection::Manipulator::Drag &&
GlobalSelectionSystem().Mode() == SelectionSystem::eComponent;
#endif
if (true/*!nothingSelected()/* || dragComponentMode*/)
if (true)
{
// Unselect any currently selected manipulators to be sure
activeManipulator->setSelected(false);
Expand Down Expand Up @@ -148,7 +148,7 @@ bool TextureToolManipulateMouseTool::selectManipulator(const render::View& view,

void TextureToolManipulateMouseTool::handleMouseMove(const render::View& view, const Vector2& devicePoint)
{
const auto& activeManipulator = TexTool::Instance().getActiveManipulator();
auto activeManipulator = getActiveManipulator();
assert(activeManipulator);

// Check if the active manipulator is selected in the first place
Expand Down Expand Up @@ -206,7 +206,7 @@ void TextureToolManipulateMouseTool::endMove()
{
freezeTransforms();

const auto& activeManipulator = TexTool::Instance().getActiveManipulator();
auto activeManipulator = getActiveManipulator();
assert(activeManipulator);

_manipulationActive = false;
Expand All @@ -226,7 +226,7 @@ void TextureToolManipulateMouseTool::endMove()

void TextureToolManipulateMouseTool::cancelMove()
{
const auto& activeManipulator = TexTool::Instance().getActiveManipulator();
auto activeManipulator = getActiveManipulator();
assert(activeManipulator);

_manipulationActive = false;
Expand All @@ -249,18 +249,4 @@ bool TextureToolManipulateMouseTool::nothingSelected() const
return TexTool::Instance().countSelected() == 0;
}

void TextureToolManipulateMouseTool::renderOverlay()
{
#ifdef _DEBUG
std::vector<std::string> lines;
string::split(lines, _debugText, "\n");

for (std::size_t i = 0; i < lines.size(); ++i)
{
glRasterPos3f(1.0f, 15.0f + (12.0f*lines.size() - 1) - 12.0f*i, 0.0f);
GlobalOpenGL().drawString(lines[i]);
}
#endif
}

}
13 changes: 5 additions & 8 deletions radiant/textool/tools/TextureToolManipulateMouseTool.h
Expand Up @@ -4,18 +4,18 @@
#include "imousetool.h"
#include "render/View.h"
#include "math/Vector2.h"
#include "selection/ManipulateMouseTool.h"

namespace ui
{

class TexTool;

/**
* greebo: This is the tool handling the manipulation mouse operations for the texture tool.
* TODO: It's similar to the ManipulateMouseTool, so it could #share a lot of code.
* Specialised manipulation operations for the texture tool
*/
class TextureToolManipulateMouseTool :
public MouseTool
public ManipulateMouseTool
{
private:
float _selectEpsilon;
Expand All @@ -28,10 +28,6 @@ class TextureToolManipulateMouseTool :
Vector2 _deviceStart;
bool _undoBegun;

#ifdef _DEBUG
std::string _debugText;
#endif

ShaderPtr _pointShader;

public:
Expand All @@ -50,7 +46,8 @@ class TextureToolManipulateMouseTool :
virtual unsigned int getPointerMode() override;
virtual unsigned int getRefreshMode() override;

void renderOverlay() override;
protected:
virtual selection::IManipulator::Ptr getActiveManipulator() override;

private:
bool selectManipulator(const render::View& view, const Vector2& devicePoint, const Vector2& deviceEpsilon);
Expand Down

0 comments on commit 193ea54

Please sign in to comment.