Skip to content

Commit

Permalink
#5746: Move IComponentSelectable implementation to NodeBase, since it…
Browse files Browse the repository at this point in the history
…'s the exact same code
  • Loading branch information
codereader committed Sep 19, 2021
1 parent beca99c commit 2027a79
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 129 deletions.
4 changes: 2 additions & 2 deletions include/itexturetoolmodel.h
Expand Up @@ -87,7 +87,7 @@ class INode :
// Node representing a single brush face
class IFaceNode :
public virtual INode,
public IComponentSelectable
public virtual IComponentSelectable
{
public:
virtual ~IFaceNode() {}
Expand All @@ -100,7 +100,7 @@ class IFaceNode :
// Node representing a patch
class IPatchNode :
public virtual INode,
public IComponentSelectable
public virtual IComponentSelectable
{
public:
virtual ~IPatchNode() {}
Expand Down
65 changes: 1 addition & 64 deletions radiantcore/selection/textool/FaceNode.h
Expand Up @@ -16,8 +16,6 @@ class FaceNode :
IFace& _face;
mutable AABB _bounds;

std::vector<SelectableVertex> _vertices;

public:
FaceNode(IFace& face) :
_face(face)
Expand Down Expand Up @@ -95,44 +93,6 @@ class FaceNode :
}
}

bool hasSelectedComponents() const override
{
for (auto& vertex : _vertices)
{
if (vertex.isSelected())
{
return true;
}
}

return false;
}

void clearComponentSelection() override
{
for (auto& vertex : _vertices)
{
vertex.setSelected(false);
}
}

void testSelectComponents(Selector& selector, SelectionTest& test) override
{
test.BeginMesh(Matrix4::getIdentity(), true);

for (auto& vertex : _vertices)
{
SelectionIntersection intersection;

test.TestPoint(Vector3(vertex.getVertex().x(), vertex.getVertex().y(), 0), intersection);

if (intersection.isValid())
{
Selector_add(selector, vertex);
}
}
}

void render(SelectionMode mode) override
{
glEnable(GL_BLEND);
Expand Down Expand Up @@ -164,31 +124,8 @@ class FaceNode :

if (mode == SelectionMode::Vertex)
{
glPointSize(5);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glBegin(GL_POINTS);

for (const auto& vertex : _vertices)
{
if (vertex.isSelected())
{
glColor3f(1, 0.5f, 0);
}
else
{
glColor3f(0.8f, 0.8f, 0.8f);
}

// Move the selected vertices a bit up in the Z area
glVertex3d(vertex.getVertex().x(), vertex.getVertex().y(), vertex.isSelected() ? 0.1f : 0);
}

glEnd();
glDisable(GL_DEPTH_TEST);
renderComponents();
}

glDisable(GL_BLEND);
}
};

Expand Down
72 changes: 71 additions & 1 deletion radiantcore/selection/textool/NodeBase.h
@@ -1,17 +1,23 @@
#pragma once

#include <vector>
#include "itexturetoolmodel.h"
#include "../BasicSelectable.h"
#include "SelectableVertex.h"

namespace textool
{

class NodeBase :
public virtual INode
public virtual INode,
public virtual IComponentSelectable
{
private:
selection::BasicSelectable _selectable;

protected:
std::vector<SelectableVertex> _vertices;

public:
virtual void setSelected(bool select) override
{
Expand All @@ -22,6 +28,70 @@ class NodeBase :
{
return _selectable.isSelected();
}

virtual bool hasSelectedComponents() const override
{
for (auto& vertex : _vertices)
{
if (vertex.isSelected())
{
return true;
}
}

return false;
}

virtual void clearComponentSelection() override
{
for (auto& vertex : _vertices)
{
vertex.setSelected(false);
}
}

virtual void testSelectComponents(Selector& selector, SelectionTest& test) override
{
test.BeginMesh(Matrix4::getIdentity(), true);

for (auto& vertex : _vertices)
{
SelectionIntersection intersection;
test.TestPoint(Vector3(vertex.getVertex().x(), vertex.getVertex().y(), 0), intersection);

if (intersection.isValid())
{
Selector_add(selector, vertex);
}
}
}

protected:
virtual void renderComponents()
{
glPointSize(5);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glBegin(GL_POINTS);

for (const auto& vertex : _vertices)
{
if (vertex.isSelected())
{
glColor3f(1, 0.5f, 0);
}
else
{
glColor3f(0.8f, 0.8f, 0.8f);
}

// Move the selected vertices a bit up in the Z area
glVertex3d(vertex.getVertex().x(), vertex.getVertex().y(), vertex.isSelected() ? 0.1f : 0);
}

glEnd();
glDisable(GL_DEPTH_TEST);
}
};

}
63 changes: 1 addition & 62 deletions radiantcore/selection/textool/PatchNode.h
Expand Up @@ -16,8 +16,6 @@ class PatchNode :
IPatch& _patch;
mutable AABB _bounds;

std::vector<SelectableVertex> _vertices;

public:
PatchNode(IPatch& patch) :
_patch(patch)
Expand Down Expand Up @@ -105,44 +103,6 @@ class PatchNode :
}
}

bool hasSelectedComponents() const override
{
for (auto& vertex : _vertices)
{
if (vertex.isSelected())
{
return true;
}
}

return false;
}

void clearComponentSelection() override
{
for (auto& vertex : _vertices)
{
vertex.setSelected(false);
}
}

void testSelectComponents(Selector& selector, SelectionTest& test) override
{
test.BeginMesh(Matrix4::getIdentity(), true);

for (auto& vertex : _vertices)
{
SelectionIntersection intersection;

test.TestPoint(Vector3(vertex.getVertex().x(), vertex.getVertex().y(), 0), intersection);

if (intersection.isValid())
{
Selector_add(selector, vertex);
}
}
}

void render(SelectionMode mode) override
{
glEnable(GL_BLEND);
Expand Down Expand Up @@ -186,28 +146,7 @@ class PatchNode :

if (mode == SelectionMode::Vertex)
{
glPointSize(5);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glBegin(GL_POINTS);

for (const auto& vertex : _vertices)
{
if (vertex.isSelected())
{
glColor3f(1, 0.5f, 0);
}
else
{
glColor3f(0.8f, 0.8f, 0.8f);
}

// Move the selected vertices a bit up in the Z area
glVertex3d(vertex.getVertex().x(), vertex.getVertex().y(), vertex.isSelected() ? 0.1f : 0);
}

glDisable(GL_DEPTH_TEST);
glEnd();
renderComponents();
}
}

Expand Down

0 comments on commit 2027a79

Please sign in to comment.