summaryrefslogtreecommitdiffstats
path: root/Project/Workspace.cpp
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2016-07-30 00:29:03 -0300
committerThales Lima Oliveira <thaleslima.ufu@gmail.com>2016-07-30 00:29:03 -0300
commit3a246308dcd76f70a1b6c3e6b08f0d597b255dba (patch)
tree62f42b83f39ffb0b32db5c658e0e1da428b8e6c6 /Project/Workspace.cpp
parentd1b893e6757270b0f246a7657d7b6701dcea3b87 (diff)
downloadPSP.git-3a246308dcd76f70a1b6c3e6b08f0d597b255dba.tar.gz
PSP.git-3a246308dcd76f70a1b6c3e6b08f0d597b255dba.tar.xz
PSP.git-3a246308dcd76f70a1b6c3e6b08f0d597b255dba.zip
Adding the basics graphics elements
The base is done, bus under contruction
Diffstat (limited to 'Project/Workspace.cpp')
-rw-r--r--Project/Workspace.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp
new file mode 100644
index 0000000..8e46e06
--- /dev/null
+++ b/Project/Workspace.cpp
@@ -0,0 +1,64 @@
+#include "Workspace.h"
+
+Workspace::Workspace(wxWindow* parent, wxString name) : WorkspaceBase(parent)
+{
+ m_name = name;
+ m_glContext = new wxGLContext(m_glCanvas);
+}
+
+Workspace::~Workspace()
+{
+ std::vector<Element*>::iterator it = m_elementList.begin();
+ while(it != m_elementList.end()) {
+ if(!(*it)) delete *it;
+ it++;
+ }
+}
+
+void Workspace::OnPaint(wxPaintEvent& event)
+{
+ wxPaintDC dc(m_glCanvas);
+ m_glContext->SetCurrent(*m_glCanvas);
+ SetViewport();
+
+ // desenhar
+ std::vector<Element*>::iterator it = m_elementList.begin();
+ while(it != m_elementList.end()) {
+ Element* element = *it;
+ element->Draw(wxPoint2DDouble(0,0), 1);
+ it++;
+ }
+
+ glFlush();
+ m_glCanvas->SwapBuffers();
+}
+
+void Workspace::SetViewport()
+{
+ glClearColor(1.0, 1.0, 1.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glDisable(GL_DEPTH_TEST);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_COLOR_MATERIAL);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_LINE_SMOOTH);
+
+ double width = m_glCanvas->GetSize().x - 1;
+ double height = m_glCanvas->GetSize().y - 1;
+
+ glViewport(0, 0, width, height); // viewport cobrindo toda a tela
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluOrtho2D(0.0, width, height, 0.0);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+void Workspace::OnLeftClickDown(wxMouseEvent& event)
+{
+ Bus* newBus = new Bus(event.GetPosition());
+ m_elementList.push_back(newBus);
+ Redraw();
+}