summaryrefslogtreecommitdiffstats
path: root/Project/ControlElement.cpp
diff options
context:
space:
mode:
authorThales1330 <thaleslima.ufu@gmail.com>2017-03-03 18:50:40 -0300
committerThales1330 <thaleslima.ufu@gmail.com>2017-03-03 18:50:40 -0300
commit4ddc7be64451db873e49169e951532ce8893e359 (patch)
treede034defff5a76a71249d53d8b0abb2a4eab17f9 /Project/ControlElement.cpp
parenta54f50d0bf86c7c4d400e8b4d30cbc6091cfd9df (diff)
downloadPSP.git-4ddc7be64451db873e49169e951532ce8893e359.tar.gz
PSP.git-4ddc7be64451db873e49169e951532ce8893e359.tar.xz
PSP.git-4ddc7be64451db873e49169e951532ce8893e359.zip
More connection line methods implemented
Diffstat (limited to 'Project/ControlElement.cpp')
-rw-r--r--Project/ControlElement.cpp59
1 files changed, 49 insertions, 10 deletions
diff --git a/Project/ControlElement.cpp b/Project/ControlElement.cpp
index c7ce3c2..a1f2fc1 100644
--- a/Project/ControlElement.cpp
+++ b/Project/ControlElement.cpp
@@ -20,6 +20,9 @@ void Node::SetPosition(wxPoint2DDouble position)
m_triPts[0] = GetPosition() + wxPoint2DDouble(-m_radius - m_rect.GetSize().GetWidth() / 2, m_radius);
m_triPts[1] = GetPosition() + wxPoint2DDouble(-m_radius - m_rect.GetSize().GetWidth() / 2, -m_radius);
m_triPts[2] = GetPosition() + wxPoint2DDouble(-m_radius + 1, 0);
+
+ // Rotate according to the angle (node rect center as reference)
+ if(m_angle != 0.0) RotateTriPt(m_angle);
}
void Node::StartMove(wxPoint2DDouble position)
@@ -28,16 +31,52 @@ void Node::StartMove(wxPoint2DDouble position)
m_movePos = m_rect.GetPosition() - wxPoint2DDouble(-m_rect.m_width / 2, -m_rect.m_height / 2);
}
-void Node::Move(wxPoint2DDouble position)
-{
- SetPosition(m_movePos + position - m_moveStartPt);
-}
+void Node::Move(wxPoint2DDouble position) { SetPosition(m_movePos + position - m_moveStartPt); }
wxPoint2DDouble Node::GetPosition() const
{
return m_rect.GetPosition() + wxPoint2DDouble(m_rect.GetSize().GetWidth() / 2, m_rect.GetSize().GetHeight() / 2);
}
+void Node::RotateTriPt(double angle)
+{
+ double radAngle = wxDegToRad(angle);
+ wxPoint2DDouble rectCenter =
+ m_rect.GetPosition() + wxPoint2DDouble(m_rect.GetSize().GetWidth() / 2.0, m_rect.GetSize().GetHeight() / 2.0);
+ m_triPts[0] = wxPoint2DDouble(std::cos(radAngle) * (m_triPts[0].m_x - rectCenter.m_x) -
+ std::sin(radAngle) * (m_triPts[0].m_y - rectCenter.m_y) + rectCenter.m_x,
+ std::sin(radAngle) * (m_triPts[0].m_x - rectCenter.m_x) +
+ std::cos(radAngle) * (m_triPts[0].m_y - rectCenter.m_y) + rectCenter.m_y);
+ m_triPts[1] = wxPoint2DDouble(std::cos(radAngle) * (m_triPts[1].m_x - rectCenter.m_x) -
+ std::sin(radAngle) * (m_triPts[1].m_y - rectCenter.m_y) + rectCenter.m_x,
+ std::sin(radAngle) * (m_triPts[1].m_x - rectCenter.m_x) +
+ std::cos(radAngle) * (m_triPts[1].m_y - rectCenter.m_y) + rectCenter.m_y);
+ m_triPts[2] = wxPoint2DDouble(std::cos(radAngle) * (m_triPts[2].m_x - rectCenter.m_x) -
+ std::sin(radAngle) * (m_triPts[2].m_y - rectCenter.m_y) + rectCenter.m_x,
+ std::sin(radAngle) * (m_triPts[2].m_x - rectCenter.m_x) +
+ std::cos(radAngle) * (m_triPts[2].m_y - rectCenter.m_y) + rectCenter.m_y);
+}
+
+void Node::Rotate(bool clockwise)
+{
+ if(clockwise)
+ m_angle += 90.0;
+ else
+ m_angle -= 90.0;
+ if(m_angle >= 360.0)
+ m_angle = 0.0;
+ else if(m_angle < 0)
+ m_angle = 270.0;
+
+ // Update input triangle points.
+ m_triPts[0] = GetPosition() + wxPoint2DDouble(-m_radius - m_rect.GetSize().GetWidth() / 2, m_radius);
+ m_triPts[1] = GetPosition() + wxPoint2DDouble(-m_radius - m_rect.GetSize().GetWidth() / 2, -m_radius);
+ m_triPts[2] = GetPosition() + wxPoint2DDouble(-m_radius + 1, 0);
+
+ // Rotate according to the angle (node rect center as reference)
+ if(m_angle != 0.0) RotateTriPt(m_angle);
+}
+
ControlElement::ControlElement()
: Element()
{
@@ -48,10 +87,10 @@ ControlElement::~ControlElement() {}
void ControlElement::DrawNodes() const
{
for(auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) {
- Node node = *it;
- DrawCircle(node.GetPosition(), node.GetRadius(), 10, GL_POLYGON);
- if(node.GetNodeType() == Node::NODE_IN) {
- DrawTriangle(node.GetInTrianglePts());
+ Node* node = *it;
+ DrawCircle(node->GetPosition(), node->GetRadius(), 10, GL_POLYGON);
+ if(node->GetNodeType() == Node::NODE_IN) {
+ DrawTriangle(node->GetInTrianglePts());
}
}
}
@@ -61,7 +100,7 @@ void ControlElement::StartMove(wxPoint2DDouble position)
m_moveStartPt = position;
m_movePos = m_position;
for(int i = 0; i < (int)m_nodeList.size(); ++i) {
- m_nodeList[i].StartMove(position);
+ m_nodeList[i]->StartMove(position);
}
}
@@ -69,6 +108,6 @@ void ControlElement::Move(wxPoint2DDouble position)
{
SetPosition(m_movePos + position - m_moveStartPt);
for(int i = 0; i < (int)m_nodeList.size(); ++i) {
- m_nodeList[i].Move(position);
+ m_nodeList[i]->Move(position);
}
}