From 3a246308dcd76f70a1b6c3e6b08f0d597b255dba Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Sat, 30 Jul 2016 00:29:03 -0300 Subject: Adding the basics graphics elements The base is done, bus under contruction --- Project/Element.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Project/Element.cpp (limited to 'Project/Element.cpp') diff --git a/Project/Element.cpp b/Project/Element.cpp new file mode 100644 index 0000000..e5304a0 --- /dev/null +++ b/Project/Element.cpp @@ -0,0 +1,37 @@ +#include "Element.h" + +Element::Element() {} +Element::~Element() {} +void Element::SetPosition(const wxPoint2DDouble position) +{ + m_position = position; + m_rect = + wxRect2DDouble(m_position.m_x - m_width / 2.0 - m_borderSize, m_position.m_y - m_height / 2.0 - m_borderSize, + m_width + 2.0 * m_borderSize, m_height + 2.0 * m_borderSize); +} + +wxPoint2DDouble Element::WorldToScreen(wxPoint2DDouble translation, double scale, double offsetX, double offsetY) const +{ + return wxPoint2DDouble(m_position.m_x + offsetX + translation.m_x, m_position.m_y + offsetY + translation.m_y) * + scale; +} + +void Element::DrawCircle(wxPoint2DDouble position, double radius, int numSegments, GLenum mode) const +{ + glBegin(mode); + for(int i = 0; i < numSegments; i++) { + double theta = 2.0 * 3.1415926 * double(i) / double(numSegments); + glVertex2f(radius * std::cos(theta) + position.m_x, radius * std::sin(theta) + position.m_y); + } + glEnd(); +} + +void Element::DrawRectangle(wxPoint2DDouble position, double width, double height, GLenum mode) const +{ + glBegin(mode); // TODO: GL_QUADS é obsoleto (OpenGL 3.0+), encontrar outra solução. + glVertex2d(position.m_x - width / 2.0, position.m_y - height / 2.0); + glVertex2d(position.m_x - width / 2.0, position.m_y + height / 2.0); + glVertex2d(position.m_x + width / 2.0, position.m_y + height / 2.0); + glVertex2d(position.m_x + width / 2.0, position.m_y - height / 2.0); + glEnd(); +} -- cgit From 78aac544e1e77f5405260797cee4b94d7a0dfe32 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Tue, 2 Aug 2016 17:34:42 -0300 Subject: Bus controllers under implementation Events handler removed --- Project/Element.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'Project/Element.cpp') diff --git a/Project/Element.cpp b/Project/Element.cpp index e5304a0..984eb65 100644 --- a/Project/Element.cpp +++ b/Project/Element.cpp @@ -35,3 +35,31 @@ void Element::DrawRectangle(wxPoint2DDouble position, double width, double heigh glVertex2d(position.m_x + width / 2.0, position.m_y - height / 2.0); glEnd(); } + +void Element::DrawRectangle(wxPoint2DDouble* points, GLenum mode) const +{ + glBegin(mode); // TODO: GL_QUADS é obsoleto (OpenGL 3.0+), encontrar outra solução. + glVertex2d(points[0].m_x, points[0].m_y); + glVertex2d(points[1].m_x, points[1].m_y); + glVertex2d(points[2].m_x, points[2].m_y); + glVertex2d(points[3].m_x, points[3].m_y); + glEnd(); +} + +void Element::DrawPickbox(wxPoint2DDouble position) const +{ + glColor4d(1.0, 1.0, 1.0, 0.8); + DrawRectangle(position, 8.0, 8.0); + glColor4d(0.0, 0.0, 0.0, 1.0); + DrawRectangle(position, 8.0, 8.0, GL_LINE_LOOP); +} + +wxPoint2DDouble Element::RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees) const +{ + double radAngle = angle; + if(degrees) radAngle = wxDegToRad(angle); + return wxPoint2DDouble(std::cos(radAngle) * (pointToRotate.m_x - m_position.m_x) - + std::sin(radAngle) * (pointToRotate.m_y - m_position.m_y) + m_position.m_x, + std::sin(radAngle) * (pointToRotate.m_x - m_position.m_x) + + std::cos(radAngle) * (pointToRotate.m_y - m_position.m_y) + m_position.m_y); +} -- cgit From 46c9d3fe586fb5c8ac75384b62a79971f96a5b88 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Wed, 3 Aug 2016 17:43:25 -0300 Subject: Bus implemented, selection not working Selection to move fail --- Project/Element.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Project/Element.cpp') diff --git a/Project/Element.cpp b/Project/Element.cpp index 984eb65..a485c82 100644 --- a/Project/Element.cpp +++ b/Project/Element.cpp @@ -63,3 +63,14 @@ wxPoint2DDouble Element::RotateAtPosition(wxPoint2DDouble pointToRotate, double std::sin(radAngle) * (pointToRotate.m_x - m_position.m_x) + std::cos(radAngle) * (pointToRotate.m_y - m_position.m_y) + m_position.m_y); } + +void Element::StartMove(wxPoint2DDouble position) +{ + this->m_moveStartPt = position; + this->m_movePos = m_position; +} + +void Element::Move(wxPoint2DDouble position) +{ + SetPosition(m_movePos + position - m_moveStartPt); +} \ No newline at end of file -- cgit From e58cec073cbd982246898c733ae21b9f2b92b2b7 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Wed, 17 Aug 2016 17:19:58 -0300 Subject: Line under implementation --- Project/Element.cpp | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'Project/Element.cpp') diff --git a/Project/Element.cpp b/Project/Element.cpp index a485c82..55cb87d 100644 --- a/Project/Element.cpp +++ b/Project/Element.cpp @@ -46,8 +46,18 @@ void Element::DrawRectangle(wxPoint2DDouble* points, GLenum mode) const glEnd(); } +void Element::DrawLine(std::vector points, GLenum mode) const +{ + glBegin(mode); + for(auto it = points.begin(); it != points.end(); ++it) { + glVertex2d((*it).m_x, (*it).m_y); + } + glEnd(); +} + void Element::DrawPickbox(wxPoint2DDouble position) const { + glLineWidth(1.0); glColor4d(1.0, 1.0, 1.0, 0.8); DrawRectangle(position, 8.0, 8.0); glColor4d(0.0, 0.0, 0.0, 1.0); @@ -66,11 +76,29 @@ wxPoint2DDouble Element::RotateAtPosition(wxPoint2DDouble pointToRotate, double void Element::StartMove(wxPoint2DDouble position) { - this->m_moveStartPt = position; - this->m_movePos = m_position; + this->m_moveStartPt = position; + this->m_movePos = m_position; } -void Element::Move(wxPoint2DDouble position) +void Element::Move(wxPoint2DDouble position) { SetPosition(m_movePos + position - m_moveStartPt); } +wxPoint2DDouble Element::GetSwitchPoint(Element* parent, wxPoint2DDouble parentPoint, wxPoint2DDouble secondPoint) const { - SetPosition(m_movePos + position - m_moveStartPt); -} \ No newline at end of file + double swLineSize = 25.0; + wxPoint2DDouble swPoint = wxPoint2DDouble(parentPoint.m_x, parentPoint.m_y - swLineSize); + + // Rotate the second point (to compare). + double angle = parent->GetAngle(); + + secondPoint = + wxPoint2DDouble(std::cos(wxDegToRad(-angle)) * (secondPoint.m_x - parentPoint.m_x) - + std::sin(wxDegToRad(-angle)) * (secondPoint.m_y - parentPoint.m_y) + parentPoint.m_x, + std::sin(wxDegToRad(-angle)) * (secondPoint.m_x - parentPoint.m_x) + + std::cos(wxDegToRad(-angle)) * (secondPoint.m_y - parentPoint.m_y) + parentPoint.m_y); + + // Rotate + if(secondPoint.m_y > parentPoint.m_y) angle -= 180.0; + return wxPoint2DDouble(std::cos(wxDegToRad(angle)) * (swPoint.m_x - parentPoint.m_x) - + std::sin(wxDegToRad(angle)) * (swPoint.m_y - parentPoint.m_y) + parentPoint.m_x, + std::sin(wxDegToRad(angle)) * (swPoint.m_x - parentPoint.m_x) + + std::cos(wxDegToRad(angle)) * (swPoint.m_y - parentPoint.m_y) + parentPoint.m_y); +} -- cgit From 05525745c0b0d189484da3c45f95356d7558e2cf Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Thu, 18 Aug 2016 19:10:04 -0300 Subject: Line improvements, context menu implemented Line still under construction, contex menu base implemented --- Project/Element.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'Project/Element.cpp') diff --git a/Project/Element.cpp b/Project/Element.cpp index 55cb87d..7f0e211 100644 --- a/Project/Element.cpp +++ b/Project/Element.cpp @@ -10,12 +10,6 @@ void Element::SetPosition(const wxPoint2DDouble position) m_width + 2.0 * m_borderSize, m_height + 2.0 * m_borderSize); } -wxPoint2DDouble Element::WorldToScreen(wxPoint2DDouble translation, double scale, double offsetX, double offsetY) const -{ - return wxPoint2DDouble(m_position.m_x + offsetX + translation.m_x, m_position.m_y + offsetY + translation.m_y) * - scale; -} - void Element::DrawCircle(wxPoint2DDouble position, double radius, int numSegments, GLenum mode) const { glBegin(mode); @@ -102,3 +96,15 @@ wxPoint2DDouble Element::GetSwitchPoint(Element* parent, wxPoint2DDouble parentP std::sin(wxDegToRad(angle)) * (swPoint.m_x - parentPoint.m_x) + std::cos(wxDegToRad(angle)) * (swPoint.m_y - parentPoint.m_y) + parentPoint.m_y); } + +wxPoint2DDouble Element::WorldToScreen(wxPoint2DDouble translation, double scale, double offsetX, double offsetY) const +{ + return wxPoint2DDouble(m_position.m_x + offsetX + translation.m_x, m_position.m_y + offsetY + translation.m_y) * + scale; +} + +wxPoint2DDouble Element::WorldToScreen(wxPoint2DDouble position, wxPoint2DDouble translation, double scale, double offsetX, double offsetY) const +{ + return wxPoint2DDouble(position.m_x + offsetX + translation.m_x, position.m_y + offsetY + translation.m_y) * + scale; +} -- cgit