summaryrefslogtreecommitdiffstats
path: root/Project
diff options
context:
space:
mode:
Diffstat (limited to 'Project')
-rw-r--r--Project/Project.mk2
-rw-r--r--Project/Release/PSP-UFU.exebin4140418 -> 4143351 bytes
-rw-r--r--Project/Release/Text.cpp.obin38352 -> 40534 bytes
-rw-r--r--Project/Release/Workspace.cpp.obin205068 -> 206026 bytes
-rw-r--r--Project/Text.cpp69
-rw-r--r--Project/Text.h8
-rw-r--r--Project/Workspace.cpp59
7 files changed, 106 insertions, 32 deletions
diff --git a/Project/Project.mk b/Project/Project.mk
index 350b273..dbbf71e 100644
--- a/Project/Project.mk
+++ b/Project/Project.mk
@@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=Thales
-Date :=23/11/2016
+Date :=24/11/2016
CodeLitePath :="C:/Program Files/CodeLite"
LinkerName :=C:/TDM-GCC-64/bin/g++.exe
SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC
diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe
index 02fc6d6..5c69aba 100644
--- a/Project/Release/PSP-UFU.exe
+++ b/Project/Release/PSP-UFU.exe
Binary files differ
diff --git a/Project/Release/Text.cpp.o b/Project/Release/Text.cpp.o
index ae85016..98d69f5 100644
--- a/Project/Release/Text.cpp.o
+++ b/Project/Release/Text.cpp.o
Binary files differ
diff --git a/Project/Release/Workspace.cpp.o b/Project/Release/Workspace.cpp.o
index f384585..5b3493d 100644
--- a/Project/Release/Workspace.cpp.o
+++ b/Project/Release/Workspace.cpp.o
Binary files differ
diff --git a/Project/Text.cpp b/Project/Text.cpp
index 25c9b85..1a89d17 100644
--- a/Project/Text.cpp
+++ b/Project/Text.cpp
@@ -10,11 +10,7 @@
#include "Inductor.h"
#include "Capacitor.h"
-Text::Text() : Element()
-{
- SetText(m_text);
-}
-
+Text::Text() : Element() { SetText(m_text); }
Text::Text(wxPoint2DDouble position) : Element()
{
SetText(m_text);
@@ -22,32 +18,41 @@ Text::Text(wxPoint2DDouble position) : Element()
}
Text::~Text() {}
-
bool Text::Contains(wxPoint2DDouble position) const
{
wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle);
return m_rect.Contains(ptR);
}
-void Text::Draw(wxPoint2DDouble translation, double scale, wxDC& dc)
+void Text::Draw(wxPoint2DDouble translation, double scale)
{
- if(consolidate) {
- glString.setFont(wxFont(10, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
- glString.consolidate(&dc);
- //glString.bind();
- consolidate = false;
- }
- /*if(m_selected) {
+ wxScreenDC dc;
+
+ // Draw selection rectangle
+
+ // Push the current matrix on stack.
+ glPushMatrix();
+ // Rotate the matrix around the object position.
+ glTranslated(m_position.m_x, m_position.m_y, 0.0);
+ glRotated(m_angle, 0.0, 0.0, 1.0);
+ glTranslated(-m_position.m_x, -m_position.m_y, 0.0);
+
+ if(m_selected) {
glColor4d(0.0, 0.5, 1.0, 0.5);
- wxGLString backSelection(m_text);
- backSelection.setFont(wxFont(10, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
- backSelection.consolidate(&dc);
- backSelection.bind();
- backSelection.render(m_position.m_x, m_position.m_y);
- }*/
+ DrawRectangle(m_position + wxPoint2DDouble(m_borderSize / 2.0, m_borderSize / 2.0), m_rect.m_width,
+ m_rect.m_height);
+ }
+ // Draw text (layer 2)
+
glColor4d(0.0, 0.0, 0.0, 1.0);
- //glString.render(m_position.m_x, m_position.m_y);
+ wxGLString glString(m_text);
+ glString.setFont(wxFont(m_fontSize, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
+ glString.consolidate(&dc);
+ glString.bind();
+ glString.render(m_position.m_x, m_position.m_y);
+
+ glPopMatrix();
}
bool Text::Intersects(wxRect2DDouble rect) const
@@ -59,7 +64,23 @@ bool Text::Intersects(wxRect2DDouble rect) const
void Text::SetText(wxString text)
{
m_text = text;
- glString = text;
-
- consolidate = true;
+
+ // Generate a glString to get the text size.
+ wxGLString glString(m_text);
+ glString.setFont(wxFont(m_fontSize, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
+ wxScreenDC dc;
+ glString.consolidate(&dc);
+ glString.bind();
+
+ m_width = glString.getWidth();
+ m_height = glString.getheight();
+}
+
+void Text::Rotate(bool clockwise)
+{
+ double rotAngle = m_rotationAngle;
+ if(!clockwise) rotAngle = -m_rotationAngle;
+
+ m_angle += rotAngle;
+ if(m_angle >= 360.0) m_angle = 0.0;
}
diff --git a/Project/Text.h b/Project/Text.h
index 0ff8d17..d54d927 100644
--- a/Project/Text.h
+++ b/Project/Text.h
@@ -24,16 +24,16 @@ class Text : public Element
virtual bool AddParent(Element* parent, wxPoint2DDouble position) { return true; };
virtual bool Contains(wxPoint2DDouble position) const;
- virtual void Draw(wxPoint2DDouble translation, double scale, wxDC& dc);
+ virtual void Draw(wxPoint2DDouble translation, double scale);
virtual bool Intersects(wxRect2DDouble rect) const;
+ virtual void Rotate(bool clockwise = true);
virtual wxString GetText() const { return m_text; }
virtual void SetText(wxString text);
protected:
- wxString m_text = _("Text");
- wxGLString glString;
- bool consolidate = true;
+ wxString m_text = _("Barra 1");
+ int m_fontSize = 10;
};
#endif // TEXT_H
diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp
index 029737c..1a91bb0 100644
--- a/Project/Workspace.cpp
+++ b/Project/Workspace.cpp
@@ -101,7 +101,7 @@ void Workspace::OnPaint(wxPaintEvent& event)
// Texts
for(auto it = m_textList.begin(); it != m_textList.end(); ++it) {
Text* text = *it;
- text->Draw(m_camera->GetTranslation(), m_camera->GetScale(), dc);
+ text->Draw(m_camera->GetTranslation(), m_camera->GetScale());
}
// Selection rectangle
@@ -156,8 +156,7 @@ void Workspace::OnLeftClickDown(wxMouseEvent& event)
bool foundElement = false;
if(m_mode == MODE_INSERT_TEXT) {
m_mode = MODE_EDIT;
- }
- else if(m_mode == MODE_INSERT || m_mode == MODE_DRAG_INSERT) {
+ } else if(m_mode == MODE_INSERT || m_mode == MODE_DRAG_INSERT) {
// Get the last element inserted on the list.
Element* newElement = *(m_elementList.end() - 1);
for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) {
@@ -224,6 +223,21 @@ void Workspace::OnLeftClickDown(wxMouseEvent& event)
element->SetOnline(element->IsOnline() ? false : true);
}
}
+
+ // Text element
+ for(auto it = m_textList.begin(); it != m_textList.end(); it++) {
+ Text* text = *it;
+
+ text->StartMove(m_camera->ScreenToWorld(event.GetPosition()));
+
+ if(text->Contains(m_camera->ScreenToWorld(event.GetPosition()))) {
+ if(!foundElement) {
+ text->SetSelected();
+ m_mode = MODE_MOVE_ELEMENT;
+ foundElement = true;
+ }
+ }
+ }
}
if(!foundElement) {
@@ -391,6 +405,23 @@ void Workspace::OnLeftClickUp(wxMouseEvent& event)
}
}
}
+
+ // Text element
+ for(auto it = m_textList.begin(); it != m_textList.end(); it++) {
+ Text* text = *it;
+ if(m_mode == MODE_SELECTION_RECT) {
+ if(text->Intersects(m_selectionRect)) {
+ text->SetSelected();
+ } else {
+ text->SetSelected(false);
+ }
+ } else if(!event.ControlDown()) {
+ if(!text->Contains(m_camera->ScreenToWorld(event.GetPosition()))) {
+ text->SetSelected(false);
+ }
+ }
+ }
+
if(findNewParent) {
std::rotate(itnp, itnp + 1, m_elementList.end());
updateVoltages = true;
@@ -499,6 +530,14 @@ void Workspace::OnMouseMotion(wxMouseEvent& event)
redraw = true;
}
}
+ // Text element motion
+ for(auto it = m_textList.begin(); it != m_textList.end(); it++) {
+ Text* text = *it;
+ if(text->IsSelected()) {
+ text->Move(m_camera->ScreenToWorld(event.GetPosition()));
+ redraw = true;
+ }
+ }
} break;
case MODE_SELECTION_RECT: {
@@ -574,6 +613,11 @@ void Workspace::OnKeyDown(wxKeyEvent& event)
m_mode = MODE_EDIT;
Redraw();
}
+ else if(m_mode == MODE_INSERT_TEXT) {
+ m_textList.pop_back();
+ m_mode = MODE_EDIT;
+ Redraw();
+ }
} break;
case WXK_DELETE: // Delete selected elements
{
@@ -828,6 +872,15 @@ void Workspace::RotateSelectedElements(bool clockwise)
element->StartMove(m_camera->GetMousePosition());
}
}
+
+ //Rotate text element
+ for(auto it = m_textList.begin(); it != m_textList.end(); it++) {
+ Text* text = *it;
+ if(text->IsSelected()) {
+ text->Rotate(clockwise);
+ text->StartMove(m_camera->GetMousePosition());
+ }
+ }
Redraw();
}