summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.codelite/.tern-port2
-rw-r--r--.codelite/.tern-project2
-rw-r--r--.codelite/PSP.session38
-rw-r--r--.codelite/PSP.tagsbin80401408 -> 80412672 bytes
-rw-r--r--.codelite/compilation.dbbin21504 -> 21504 bytes
-rw-r--r--.codelite/compile_commands.json8
-rw-r--r--.codelite/refactoring.dbbin378880 -> 393216 bytes
-rw-r--r--Project/Bus.cpp44
-rw-r--r--Project/Bus.h3
-rw-r--r--Project/Element.cpp11
-rw-r--r--Project/Element.h32
-rw-r--r--Project/MainFrame.cpp4
-rw-r--r--Project/MainFrame.h3
-rw-r--r--Project/Project.mk7
-rw-r--r--Project/Release/Bus.cpp.obin13972 -> 14297 bytes
-rw-r--r--Project/Release/Element.cpp.obin4511 -> 4898 bytes
-rw-r--r--Project/Release/MainFrame.cpp.obin116477 -> 117620 bytes
-rw-r--r--Project/Release/PSP-UFU.exebin3238405 -> 3241173 bytes
-rw-r--r--Project/Release/Workspace.cpp.obin86265 -> 87410 bytes
-rw-r--r--Project/Workspace.cpp195
-rw-r--r--Project/Workspace.h54
21 files changed, 235 insertions, 168 deletions
diff --git a/.codelite/.tern-port b/.codelite/.tern-port
index 013f236..7b204a1 100644
--- a/.codelite/.tern-port
+++ b/.codelite/.tern-port
@@ -1 +1 @@
-60393 \ No newline at end of file
+49710 \ No newline at end of file
diff --git a/.codelite/.tern-project b/.codelite/.tern-project
index d5969c6..09b6465 100644
--- a/.codelite/.tern-project
+++ b/.codelite/.tern-project
@@ -8,8 +8,6 @@
"node_resolve": {
},
"node": {
- },
- "complete_strings": {
}
}
} \ No newline at end of file
diff --git a/.codelite/PSP.session b/.codelite/PSP.session
index 8811242..872b5ce 100644
--- a/.codelite/PSP.session
+++ b/.codelite/PSP.session
@@ -1,61 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<Session Name="C:\Users\Thales\Documents\GitHub\PSP\PSP.workspace">
- <int Value="4" Name="m_selectedTab"/>
+ <int Value="0" Name="m_selectedTab"/>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\PSP.workspace" Name="m_workspaceName"/>
<TabInfoArray Name="TabInfoArray">
<TabInfo>
- <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\MainFrame.cpp" Name="FileName"/>
- <int Value="93" Name="FirstVisibleLine"/>
- <int Value="103" Name="CurrentLine"/>
- <wxArrayString Name="Bookmarks"/>
- <IntVector Name="CollapsedFolds"/>
- </TabInfo>
- <TabInfo>
- <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\MainFrame.h" Name="FileName"/>
- <int Value="17" Name="FirstVisibleLine"/>
- <int Value="0" Name="CurrentLine"/>
- <wxArrayString Name="Bookmarks"/>
- <IntVector Name="CollapsedFolds"/>
- </TabInfo>
- <TabInfo>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Workspace.cpp" Name="FileName"/>
- <int Value="215" Name="FirstVisibleLine"/>
- <int Value="240" Name="CurrentLine"/>
+ <int Value="123" Name="FirstVisibleLine"/>
+ <int Value="148" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
<TabInfo>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Workspace.h" Name="FileName"/>
- <int Value="18" Name="FirstVisibleLine"/>
- <int Value="17" Name="CurrentLine"/>
+ <int Value="48" Name="FirstVisibleLine"/>
+ <int Value="48" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
<TabInfo>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Bus.cpp" Name="FileName"/>
- <int Value="102" Name="FirstVisibleLine"/>
- <int Value="131" Name="CurrentLine"/>
+ <int Value="57" Name="FirstVisibleLine"/>
+ <int Value="73" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
<TabInfo>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Bus.h" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
- <int Value="3" Name="CurrentLine"/>
+ <int Value="12" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
<TabInfo>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Element.cpp" Name="FileName"/>
- <int Value="0" Name="FirstVisibleLine"/>
- <int Value="4" Name="CurrentLine"/>
+ <int Value="56" Name="FirstVisibleLine"/>
+ <int Value="75" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
<TabInfo>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Element.h" Name="FileName"/>
- <int Value="34" Name="FirstVisibleLine"/>
- <int Value="73" Name="CurrentLine"/>
+ <int Value="41" Name="FirstVisibleLine"/>
+ <int Value="45" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
diff --git a/.codelite/PSP.tags b/.codelite/PSP.tags
index 2907d31..8ab6deb 100644
--- a/.codelite/PSP.tags
+++ b/.codelite/PSP.tags
Binary files differ
diff --git a/.codelite/compilation.db b/.codelite/compilation.db
index f17b297..a363395 100644
--- a/.codelite/compilation.db
+++ b/.codelite/compilation.db
Binary files differ
diff --git a/.codelite/compile_commands.json b/.codelite/compile_commands.json
index c4e61b3..747a12e 100644
--- a/.codelite/compile_commands.json
+++ b/.codelite/compile_commands.json
@@ -1,9 +1,9 @@
[{
"directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project",
- "command": "C:/TDM-GCC-64/bin/g++.exe -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -I. -I. -MG -MP -MT./Release/Bus.cpp.o -MF./Release/Bus.cpp.o.d -MM Bus.cpp",
- "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\Bus.cpp"
+ "command": "C:/TDM-GCC-64/bin/g++.exe -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -I. -I. -MG -MP -MT./Release/Workspace.cpp.o -MF./Release/Workspace.cpp.o.d -MM Workspace.cpp",
+ "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\Workspace.cpp"
}, {
"directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project",
- "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/Bus.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/Bus.cpp.o -I. -I.",
- "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\Bus.cpp"
+ "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/Workspace.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/Workspace.cpp.o -I. -I.",
+ "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\Workspace.cpp"
}] \ No newline at end of file
diff --git a/.codelite/refactoring.db b/.codelite/refactoring.db
index 7f41429..573449d 100644
--- a/.codelite/refactoring.db
+++ b/.codelite/refactoring.db
Binary files differ
diff --git a/Project/Bus.cpp b/Project/Bus.cpp
index fe12c5b..064f481 100644
--- a/Project/Bus.cpp
+++ b/Project/Bus.cpp
@@ -1,5 +1,6 @@
#include "Bus.h"
+Bus::Bus() : Element() {}
Bus::Bus(wxPoint2DDouble position) : Element()
{
m_width = 100.0;
@@ -8,7 +9,6 @@ Bus::Bus(wxPoint2DDouble position) : Element()
}
Bus::~Bus() {}
-
void Bus::Draw(wxPoint2DDouble translation, double scale) const
{
// Draw selection (layer 1)
@@ -76,24 +76,27 @@ bool Bus::Contains(wxPoint2DDouble position) const
bool Bus::PickboxContains(wxPoint2DDouble position)
{
- wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle);
+ m_activePickboxID = ID_PB_NONE;
+ wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle);
+
wxPoint2DDouble center(m_position.m_x + m_width / 2.0, m_position.m_y);
wxRect2DDouble rectRight(center.m_x - 5.0, center.m_y - 5.0, 10.0, 10.0);
center = wxPoint2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y);
wxRect2DDouble rectLeft(center.m_x - 5.0, center.m_y - 5.0, 10.0, 10.0);
-
- if(rectRight.Contains(ptR)){
- m_activePickboxID = ID_PB_RIGHT;
- return true;
+
+ if(rectRight.Contains(ptR)) {
+ m_activePickboxID = ID_PB_RIGHT;
+ return true;
}
- else if(rectLeft.Contains(ptR)){
- m_activePickboxID = ID_PB_LEFT;
- return true;
+ if(rectLeft.Contains(ptR))
+ {
+ m_activePickboxID = ID_PB_LEFT;
+ return true;
}
- return false;
+ return false;
}
wxCursor Bus::GetBestPickboxCursor() const
@@ -115,23 +118,26 @@ wxCursor Bus::GetBestPickboxCursor() const
void Bus::MovePickbox(wxPoint2DDouble position)
{
- wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle);
+ if(m_activePickboxID == ID_PB_NONE) return;
+
+ wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle);
double dx = 0.0;
if(m_activePickboxID == ID_PB_RIGHT)
dx = ptR.m_x - m_position.m_x - m_width / 2.0;
else if(m_activePickboxID == ID_PB_LEFT)
- dx = m_position.m_x - m_width / 2.0 - ptR.m_x ;
+ dx = m_position.m_x - m_width / 2.0 - ptR.m_x;
if(m_width + dx < 20.0) return;
-
- if(m_activePickboxID == ID_PB_RIGHT) {
- m_position.m_x += (dx / 2.0) * std::cos(wxDegToRad(m_angle));
- m_position.m_y += (dx / 2.0) * std::sin(wxDegToRad(m_angle));
+
+ if(m_activePickboxID == ID_PB_RIGHT) {
+ m_position.m_x += (dx / 2.0) * std::cos(wxDegToRad(m_angle));
+ m_position.m_y += (dx / 2.0) * std::sin(wxDegToRad(m_angle));
}
- else if(m_activePickboxID == ID_PB_LEFT) {
- m_position.m_x -= (dx / 2.0) * std::cos(wxDegToRad(m_angle));
- m_position.m_y -= (dx / 2.0) * std::sin(wxDegToRad(m_angle));
+ else if(m_activePickboxID == ID_PB_LEFT)
+ {
+ m_position.m_x -= (dx / 2.0) * std::cos(wxDegToRad(m_angle));
+ m_position.m_y -= (dx / 2.0) * std::sin(wxDegToRad(m_angle));
}
m_width += dx;
diff --git a/Project/Bus.h b/Project/Bus.h
index 6725fd7..095a72d 100644
--- a/Project/Bus.h
+++ b/Project/Bus.h
@@ -6,11 +6,12 @@
class Bus : public Element
{
public:
+ Bus();
Bus(wxPoint2DDouble position);
~Bus();
virtual bool Contains(wxPoint2DDouble position) const;
virtual void Draw(wxPoint2DDouble translation, double scale) const;
- virtual void Rotate();
+ virtual void Rotate();
virtual wxCursor GetBestPickboxCursor() const;
virtual void MovePickbox(wxPoint2DDouble position);
virtual bool PickboxContains(wxPoint2DDouble position);
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
diff --git a/Project/Element.h b/Project/Element.h
index bb74910..1196f64 100644
--- a/Project/Element.h
+++ b/Project/Element.h
@@ -7,13 +7,13 @@
enum PickboxID
{
- ID_PB_NONE = 0,
- ID_PB_RIGHT,
- ID_PB_LEFT,
- ID_PB_RIGHT_BOTTOM,
- ID_PB_RIGHT_TOP,
- ID_PB_LEFT_BOTTOM,
- ID_PB_LEFT_TOP
+ ID_PB_NONE = 0,
+ ID_PB_RIGHT,
+ ID_PB_LEFT,
+ ID_PB_RIGHT_BOTTOM,
+ ID_PB_RIGHT_TOP,
+ ID_PB_LEFT_BOTTOM,
+ ID_PB_LEFT_TOP
};
class Element
@@ -49,17 +49,20 @@ class Element
virtual wxCursor GetBestPickboxCursor() const = 0;
// General methods
+ virtual void StartMove(wxPoint2DDouble position);
+ virtual void Move(wxPoint2DDouble position);
+ void ResetPickboxes() { m_activePickboxID = ID_PB_NONE; }
wxPoint2DDouble WorldToScreen(wxPoint2DDouble translation,
double scale,
double offsetX = 0.0,
double offsetY = 0.0) const;
void DrawCircle(wxPoint2DDouble position, double radius, int numSegments, GLenum mode = GL_LINE_LOOP) const;
void DrawRectangle(wxPoint2DDouble position, double width, double height, GLenum mode = GL_QUADS) const;
- void DrawRectangle(wxPoint2DDouble* points, GLenum mode = GL_QUADS) const;
- void DrawPickbox(wxPoint2DDouble position) const;
+ void DrawRectangle(wxPoint2DDouble* points, GLenum mode = GL_QUADS) const;
+ void DrawPickbox(wxPoint2DDouble position) const;
wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees = true) const;
-
- protected:
+
+ protected:
wxRect2DDouble m_rect;
wxPoint2DDouble m_position;
double m_width = 0.0;
@@ -70,8 +73,11 @@ class Element
bool m_selected = false;
bool m_dragging = false;
bool m_showPickbox = false;
-
- PickboxID m_activePickboxID = ID_PB_NONE;
+
+ int m_activePickboxID = ID_PB_NONE;
+
+ wxPoint2DDouble m_moveStartPt;
+ wxPoint2DDouble m_movePos;
};
#endif // ELEMENT_H
diff --git a/Project/MainFrame.cpp b/Project/MainFrame.cpp
index 9769a1f..aa9164e 100644
--- a/Project/MainFrame.cpp
+++ b/Project/MainFrame.cpp
@@ -2,6 +2,10 @@
#include "ArtMetro.h"
#include "Workspace.h"
+MainFrame::MainFrame() : MainFrameBase(NULL)
+{
+}
+
MainFrame::MainFrame(wxWindow* parent, wxLocale* locale) : MainFrameBase(parent)
{
m_locale = locale;
diff --git a/Project/MainFrame.h b/Project/MainFrame.h
index 22c49ab..241551f 100644
--- a/Project/MainFrame.h
+++ b/Project/MainFrame.h
@@ -26,6 +26,7 @@ enum
class MainFrame : public MainFrameBase
{
public:
+ MainFrame();
MainFrame(wxWindow* parent, wxLocale* locale);
~MainFrame();
@@ -65,7 +66,7 @@ class MainFrame : public MainFrameBase
private:
std::vector<Workspace*> m_workspaceList;
- int m_projectNumber = 1;
+ int m_projectNumber = 1;
wxRibbonMetroArtProvider* m_artMetro;
wxMenu* m_addElementsMenu;
diff --git a/Project/Project.mk b/Project/Project.mk
index 5862e1b..4ab79c8 100644
--- a/Project/Project.mk
+++ b/Project/Project.mk
@@ -13,8 +13,8 @@ CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=Thales
-Date :=02/08/2016
-CodeLitePath :="C:/Program Files (x86)/CodeLite"
+Date :=03/08/2016
+CodeLitePath :="C:/Program Files/CodeLite"
LinkerName :=C:/TDM-GCC-64/bin/g++.exe
SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC
ObjectSuffix :=.o
@@ -61,8 +61,7 @@ AS := C:/TDM-GCC-64/bin/as.exe
##
## User defined environment variables
##
-CodeLiteDir:=C:\Program Files (x86)\CodeLite
-UNIT_TEST_PP_SRC_DIR:=C:\UnitTest++-1.3
+CodeLiteDir:=C:\Program Files\CodeLite
WXWIN:=C:\wxWidgets-3.1.0
WXCFG:=gcc_dll\mswu
Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IntermediateDirectory)/win_resources.rc$(ObjectSuffix) $(IntermediateDirectory)/Element.cpp$(ObjectSuffix) $(IntermediateDirectory)/Bus.cpp$(ObjectSuffix) $(IntermediateDirectory)/ArtMetro.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrame.cpp$(ObjectSuffix) $(IntermediateDirectory)/Workspace.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrameBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/WorkspaceBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrameBase.cpp$(ObjectSuffix) \
diff --git a/Project/Release/Bus.cpp.o b/Project/Release/Bus.cpp.o
index 8458037..8f5a654 100644
--- a/Project/Release/Bus.cpp.o
+++ b/Project/Release/Bus.cpp.o
Binary files differ
diff --git a/Project/Release/Element.cpp.o b/Project/Release/Element.cpp.o
index 44786c5..3f07424 100644
--- a/Project/Release/Element.cpp.o
+++ b/Project/Release/Element.cpp.o
Binary files differ
diff --git a/Project/Release/MainFrame.cpp.o b/Project/Release/MainFrame.cpp.o
index 70680c4..569d5cb 100644
--- a/Project/Release/MainFrame.cpp.o
+++ b/Project/Release/MainFrame.cpp.o
Binary files differ
diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe
index 319dd3e..e248987 100644
--- a/Project/Release/PSP-UFU.exe
+++ b/Project/Release/PSP-UFU.exe
Binary files differ
diff --git a/Project/Release/Workspace.cpp.o b/Project/Release/Workspace.cpp.o
index f9aaf30..c952bbc 100644
--- a/Project/Release/Workspace.cpp.o
+++ b/Project/Release/Workspace.cpp.o
Binary files differ
diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp
index bae40e6..08f66c7 100644
--- a/Project/Workspace.cpp
+++ b/Project/Workspace.cpp
@@ -60,7 +60,6 @@ Workspace::~Workspace()
if(!(*it)) delete *it;
it++;
}
- // if(!m_statusBar) delete m_statusBar;
if(!m_camera) delete m_camera;
}
@@ -119,19 +118,43 @@ void Workspace::OnLeftClickDown(wxMouseEvent& event)
}
else
{
+ bool clickPickbox = false;
std::vector<Element*>::iterator it = m_elementList.begin();
while(it != m_elementList.end()) {
Element* element = *it;
+ element->ResetPickboxes(); // Reset pickbox state.
+ element->StartMove(m_camera->ScreenToWorld(event.GetPosition()));
+
if(element->Contains(m_camera->ScreenToWorld(event.GetPosition()))) {
element->SetSelected();
element->ShowPickbox();
+
+ if(element->PickboxContains(m_camera->ScreenToWorld(event.GetPosition()))) {
+ m_mode = MODE_MOVE_PICKBOX;
+ clickPickbox = true;
+ }
+ if(!clickPickbox) {
+ m_mode = MODE_MOVE_ELEMENT;
+ }
}
- else if(!event.ControlDown())
- {
- element->SetSelected(false);
- }
+ /*else if(!event.ControlDown() && m_mode != MODE_MOVE_ELEMENT)
+ {
+ element->SetSelected(false);
+ }*/
it++;
}
+
+ // Deselect elements.
+ if(!event.ControlDown() && m_mode != MODE_MOVE_ELEMENT) {
+ it = m_elementList.begin();
+ while(it != m_elementList.end()) {
+ Element* element = *it;
+ if(!element->Contains(m_camera->ScreenToWorld(event.GetPosition()))) {
+ element->SetSelected(false);
+ }
+ it++;
+ }
+ }
}
Redraw();
UpdateStatusBar();
@@ -140,57 +163,25 @@ void Workspace::OnLeftClickDown(wxMouseEvent& event)
void Workspace::OnLeftClickUp(wxMouseEvent& event)
{
- if(m_mode == MODE_EDIT_ELEMENT) {
- m_mode = MODE_EDIT;
- }
-}
+ m_mode = MODE_EDIT;
-void Workspace::OnKeyDown(wxKeyEvent& event)
-{
- char key = event.GetUnicodeKey();
- if(key != WXK_NONE) {
- switch(key)
- {
- case WXK_ESCAPE: // Cancel operations.
- {
- if(m_mode == MODE_INSERT) {
- m_elementList.pop_back(); // Removes the last element being inserted.
- m_mode = MODE_EDIT;
- Redraw();
- }
- }
- break;
- case 'R': // Rotate the selected elements.
- {
- std::vector<Element*>::iterator it = m_elementList.begin();
- while(it != m_elementList.end()) {
- Element* element = *it;
- if(element->IsSelected()) {
- element->Rotate();
- }
- it++;
- }
- Redraw();
- }
- break;
- case 'B': // Insert a bus.
- {
- if(m_mode != MODE_INSERT) {
- Bus* newBus = new Bus(m_camera->ScreenToWorld(event.GetPosition()));
- m_elementList.push_back(newBus);
- m_mode = MODE_INSERT;
- m_statusBar->SetStatusText(_("Insert Bus: Click to insert, ESC to cancel."));
- Redraw();
- }
- }
- break;
- default:
- break;
+ bool foundPickbox = false;
+ std::vector<Element*>::iterator it = m_elementList.begin();
+ while(it != m_elementList.end()) {
+ Element* element = *it;
+
+ if(element->PickboxContains(m_camera->ScreenToWorld(event.GetPosition()))) {
+ foundPickbox = true;
}
+
+ it++;
+ }
+
+ if(!foundPickbox) {
+ SetCursor(wxCURSOR_ARROW);
}
UpdateStatusBar();
- event.Skip();
}
void Workspace::OnMouseMotion(wxMouseEvent& event)
@@ -213,31 +204,21 @@ void Workspace::OnMouseMotion(wxMouseEvent& event)
}
break;
- case MODE_EDIT_ELEMENT:
case MODE_EDIT:
{
bool foundPickbox = false;
+ bool redraw = false;
std::vector<Element*>::iterator it = m_elementList.begin();
while(it != m_elementList.end()) {
Element* element = *it;
if(element->IsSelected()) {
- // MODE_EDIT_ELEMENT is a flag which indicates that a pickbox is being dragged. He
- // will work like a shortcut to method Element::MovePickbox until a mouse button is
- // released.
- if(element->Contains(m_camera->ScreenToWorld(event.GetPosition())) ||
- m_mode == MODE_EDIT_ELEMENT)
- {
+ if(element->Contains(m_camera->ScreenToWorld(event.GetPosition()))) {
element->ShowPickbox();
- if(element->PickboxContains(m_camera->ScreenToWorld(event.GetPosition())) ||
- m_mode == MODE_EDIT_ELEMENT)
- {
+ redraw = true;
+
+ if(element->PickboxContains(m_camera->ScreenToWorld(event.GetPosition()))) {
foundPickbox = true;
SetCursor(element->GetBestPickboxCursor());
- if(event.Dragging()) {
- m_mode = MODE_EDIT_ELEMENT;
- element->MovePickbox(
- m_camera->ScreenToWorld(event.GetPosition()));
- }
}
else if(!foundPickbox)
{
@@ -246,17 +227,44 @@ void Workspace::OnMouseMotion(wxMouseEvent& event)
}
else if(!foundPickbox)
{
+ if(element->IsPickboxShown()) redraw = true;
+
element->ShowPickbox(false);
SetCursor(wxCURSOR_ARROW);
}
}
it++;
}
- Redraw();
+ if(redraw) Redraw();
+ }
+ break;
+
+ case MODE_MOVE_PICKBOX:
+ {
+ std::vector<Element*>::iterator it = m_elementList.begin();
+ while(it != m_elementList.end()) {
+ Element* element = *it;
+ if(element->IsSelected()) {
+ element->MovePickbox(m_camera->ScreenToWorld(event.GetPosition()));
+ Redraw();
+ }
+ it++;
+ }
}
break;
- default:
+ case MODE_MOVE_ELEMENT:
+ {
+ std::vector<Element*>::iterator it = m_elementList.begin();
+ while(it != m_elementList.end()) {
+ Element* element = *it;
+ if(element->IsSelected()) {
+ element->Move(m_camera->ScreenToWorld(event.GetPosition()));
+ Redraw();
+ }
+ it++;
+ }
+ }
break;
}
m_camera->UpdateMousePosition(event.GetPosition());
@@ -288,6 +296,54 @@ void Workspace::OnScroll(wxMouseEvent& event)
Redraw();
}
+void Workspace::OnKeyDown(wxKeyEvent& event)
+{
+ char key = event.GetUnicodeKey();
+ if(key != WXK_NONE) {
+ switch(key)
+ {
+ case WXK_ESCAPE: // Cancel operations.
+ {
+ if(m_mode == MODE_INSERT) {
+ m_elementList.pop_back(); // Removes the last element being inserted.
+ m_mode = MODE_EDIT;
+ Redraw();
+ }
+ }
+ break;
+ case 'R': // Rotate the selected elements.
+ {
+ std::vector<Element*>::iterator it = m_elementList.begin();
+ while(it != m_elementList.end()) {
+ Element* element = *it;
+ if(element->IsSelected()) {
+ element->Rotate();
+ }
+ it++;
+ }
+ Redraw();
+ }
+ break;
+ case 'B': // Insert a bus.
+ {
+ if(m_mode != MODE_INSERT) {
+ Bus* newBus = new Bus(m_camera->ScreenToWorld(event.GetPosition()));
+ m_elementList.push_back(newBus);
+ m_mode = MODE_INSERT;
+ m_statusBar->SetStatusText(_("Insert Bus: Click to insert, ESC to cancel."));
+ Redraw();
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ UpdateStatusBar();
+ event.Skip();
+}
+
void Workspace::UpdateStatusBar()
{
switch(m_mode)
@@ -304,7 +360,8 @@ void Workspace::UpdateStatusBar()
}
break;
- case MODE_EDIT_ELEMENT:
+ case MODE_MOVE_ELEMENT:
+ case MODE_MOVE_PICKBOX:
case MODE_EDIT:
{
m_statusBar->SetStatusText(wxT(""));
diff --git a/Project/Workspace.h b/Project/Workspace.h
index 3c847a3..a7eca1b 100644
--- a/Project/Workspace.h
+++ b/Project/Workspace.h
@@ -14,14 +14,24 @@ class Element;
enum WorkspaceMode
{
- MODE_EDIT = 0,
- MODE_EDIT_ELEMENT,
- MODE_DRAG,
- MODE_INSERT
+ MODE_EDIT = 0,
+ MODE_MOVE_ELEMENT,
+ MODE_MOVE_PICKBOX,
+ MODE_DRAG,
+ MODE_INSERT
};
class Workspace : public WorkspaceBase
{
+ public:
+ Workspace();
+ Workspace(wxWindow* parent, wxString name = wxEmptyString, wxStatusBar* statusBar = NULL);
+ ~Workspace();
+
+ wxString GetName() const { return m_name; }
+ void SetName(wxString name) { m_name = name; }
+ std::vector<Element*> GetElementList() { return m_elementList; }
+ void Redraw() { m_glCanvas->Refresh(); }
protected:
virtual void OnLeftClickUp(wxMouseEvent& event);
virtual void OnScroll(wxMouseEvent& event);
@@ -35,38 +45,19 @@ class Workspace : public WorkspaceBase
void SetViewport();
wxGLContext* m_glContext;
- wxStatusBar* m_statusBar;
+ wxStatusBar* m_statusBar;
Camera* m_camera;
wxString m_name;
- //bool m_insertMode = false;
- //bool m_dragMode = false;
- WorkspaceMode m_mode = MODE_EDIT;
+ WorkspaceMode m_mode = MODE_EDIT;
std::vector<Element*> m_elementList;
-
- void UpdateStatusBar();
- public:
- Workspace();
- Workspace(wxWindow* parent, wxString name = wxEmptyString, wxStatusBar* statusBar = NULL);
- ~Workspace();
-
- wxString GetName() const { return m_name; }
- void SetName(wxString name) { m_name = name; }
- std::vector<Element*> GetElementList() { return m_elementList; }
- void Redraw() { m_glCanvas->Refresh(); }
+ void UpdateStatusBar();
};
class Camera
{
- protected:
- wxPoint2DDouble m_translation;
- wxPoint2DDouble m_translationStartPt;
- double m_scale;
-
- wxPoint2DDouble m_mousePosition;
-
public:
Camera();
~Camera();
@@ -74,11 +65,18 @@ class Camera
void SetScale(wxPoint2DDouble screenPoint, double delta);
void SetTranslation(wxPoint2DDouble screenPoint);
void StartTranslation(wxPoint2DDouble startPoint) { this->m_translationStartPt = startPoint; }
- void UpdateMousePosition(wxPoint2DDouble mousePosition) {this->m_mousePosition = mousePosition;}
+ void UpdateMousePosition(wxPoint2DDouble mousePosition) { this->m_mousePosition = mousePosition; }
double GetScale() const { return m_scale; }
wxPoint2DDouble GetTranslation() const { return m_translation; }
- wxPoint2DDouble GetMousePosition(bool worldCoords = true) const;
+ wxPoint2DDouble GetMousePosition(bool worldCoords = true) const;
wxPoint2DDouble ScreenToWorld(wxPoint2DDouble screenCoords) const;
+
+ protected:
+ wxPoint2DDouble m_translation;
+ wxPoint2DDouble m_translationStartPt;
+ double m_scale;
+
+ wxPoint2DDouble m_mousePosition;
};
#endif // WORKSPACE_H