summaryrefslogtreecommitdiffstats
path: root/Project/ControlEditorDC.cpp
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2020-06-10 09:35:32 -0300
committerThales Lima Oliveira <thaleslima.ufu@gmail.com>2020-06-10 09:35:32 -0300
commit196389a70ef3a03aa8764b9532812a17dd55014b (patch)
tree5fd95e9295ccb9e92a660e7864ce332480716009 /Project/ControlEditorDC.cpp
parent4fdcfe16959a610a928064df73281f509425cbbf (diff)
downloadPSP.git-196389a70ef3a03aa8764b9532812a17dd55014b.tar.gz
PSP.git-196389a70ef3a03aa8764b9532812a17dd55014b.tar.xz
PSP.git-196389a70ef3a03aa8764b9532812a17dd55014b.zip
Control editor DC fixes
Diffstat (limited to 'Project/ControlEditorDC.cpp')
-rw-r--r--Project/ControlEditorDC.cpp79
1 files changed, 65 insertions, 14 deletions
diff --git a/Project/ControlEditorDC.cpp b/Project/ControlEditorDC.cpp
index 84e212d..8695580 100644
--- a/Project/ControlEditorDC.cpp
+++ b/Project/ControlEditorDC.cpp
@@ -1,31 +1,82 @@
#include "ControlEditorDC.h"
#include "Camera.h"
+#include "ConnectionLine.h"
-ControlEditorDC::ControlEditorDC(wxWindow* parent, int ioflags) : ControlEditor(parent, nullptr, ioflags)
+ControlEditorDC::ControlEditorDC(wxWindow* parent, int ioflags) : ControlEditor(parent)
{
BuildControlElementPanel();
m_camera = new Camera();
m_selectionRect = wxRect2DDouble(0, 0, 0, 0);
- // m_camera->SetScale(1.2);
m_ioFlags = ioflags;
-
- this->GetSizer()->Remove(this->GetSizer()->GetChildren()[0]->GetId()); // remove m_glCanvas object from sizer
-
- delete m_glCanvas; // Delete GLCanvas to allow drawing with wxDC
- m_glCanvas = nullptr;
- SetBackgroundColour(wxColour(255, 255, 255));
- SetBackgroundStyle(wxBG_STYLE_PAINT); // To allow wxBufferedPaintDC works properly.
- Redraw();
+
+ // Disconnect events from GLCanvas
+ m_glCanvas->Disconnect(wxEVT_PAINT, wxPaintEventHandler(ControlEditor::OnPaint), NULL, this);
+ m_glCanvas->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ControlEditor::OnLeftClickDown), NULL, this);
+ m_glCanvas->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(ControlEditor::OnKeyDown), NULL, this);
+ m_glCanvas->Disconnect(wxEVT_MOTION, wxMouseEventHandler(ControlEditor::OnMouseMotion), NULL, this);
+ m_glCanvas->Disconnect(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(ControlEditor::OnMiddleDown), NULL, this);
+ m_glCanvas->Disconnect(wxEVT_MIDDLE_UP, wxMouseEventHandler(ControlEditor::OnMiddleUp), NULL, this);
+ m_glCanvas->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(ControlEditor::OnLeftClickUp), NULL, this);
+ m_glCanvas->Disconnect(wxEVT_MOUSEWHEEL, wxMouseEventHandler(ControlEditor::OnScroll), NULL, this);
+ m_glCanvas->Disconnect(wxEVT_IDLE, wxIdleEventHandler(ControlEditor::OnIdle), NULL, this);
+
+ // Reconnect events to this
+ m_panelWorkspace->Connect(wxEVT_PAINT, wxPaintEventHandler(ControlEditorDC::OnPaint), NULL, this); // Connect to overloaded method
+ m_panelWorkspace->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ControlEditor::OnLeftClickDown), NULL, this);
+ m_panelWorkspace->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(ControlEditor::OnKeyDown), NULL, this);
+ m_panelWorkspace->Connect(wxEVT_MOTION, wxMouseEventHandler(ControlEditor::OnMouseMotion), NULL, this);
+ m_panelWorkspace->Connect(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(ControlEditor::OnMiddleDown), NULL, this);
+ m_panelWorkspace->Connect(wxEVT_MIDDLE_UP, wxMouseEventHandler(ControlEditor::OnMiddleUp), NULL, this);
+ m_panelWorkspace->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(ControlEditor::OnLeftClickUp), NULL, this);
+ m_panelWorkspace->Connect(wxEVT_MOUSEWHEEL, wxMouseEventHandler(ControlEditor::OnScroll), NULL, this);
+ m_panelWorkspace->Connect(wxEVT_IDLE, wxIdleEventHandler(ControlEditorDC::OnIdle), NULL, this); // Connect to overloaded method
+
+ m_panelWorkspace->GetSizer()->Remove(m_panelWorkspace->GetSizer()->GetChildren()[0]->GetId()); // remove m_glCanvas object from sizer
+
+ delete m_glCanvas; // Delete GLcanvas to allow drawing with wxDC
+ m_glCanvas = nullptr;
+ if (m_glContext) delete m_glContext;
+ m_glContext = nullptr;
+ m_panelWorkspace->SetBackgroundColour(wxColour(255, 255, 255));
+ m_panelWorkspace->SetBackgroundStyle(wxBG_STYLE_PAINT); // To allow wxBufferedPaintDC works properly.
+ Redraw();
}
ControlEditorDC::~ControlEditorDC()
{
- // Recreate the GLCanvas. This is necessary to prevent WorkspaceBase destructor access nullpr.
- // Also avoid the code editing of WorkspaceBase, since is automatically generated by wxCrafter.
- // TODO(?): Find a better way to solve this problem.
- m_glCanvas = new wxGLCanvas(this);
+ // Recreate the GLCanvas. This is necessary to prevent WorkspaceBase destructor access nullptr.
+ // Also avoid the code editing of WorkspaceBase, since is automatically generated by wxCrafter.
+ // TODO(?): Find a better way to solve this problem.
+ m_glCanvas = new wxGLCanvas(this);
}
void ControlEditorDC::OnPaint(wxPaintEvent& event)
{
+ wxBufferedPaintDC dc(m_panelWorkspace);
+ dc.Clear();
+ wxGraphicsContext* gc = wxGraphicsContext::Create(dc);
+
+ // Draw
+ if (gc) {
+
+ gc->Scale(m_camera->GetScale(), m_camera->GetScale());
+ gc->Translate(m_camera->GetTranslation().m_x, m_camera->GetTranslation().m_y);
+
+ for (auto line : m_connectionList) {
+ //ConnectionLine* line = *it;
+ line->DrawDC(m_camera->GetTranslation(), m_camera->GetScale(), gc);
+ }
+
+ for (auto element : m_elementList) {
+ element->DrawDC(m_camera->GetTranslation(), m_camera->GetScale(), gc);
+ }
+
+ // Selection rectangle
+ gc->SetPen(wxPen(wxColour(0, 125, 255, 255)));
+ gc->SetBrush(wxBrush(wxColour(0, 125, 255, 125)));
+ gc->DrawRectangle(m_selectionRect.m_x, m_selectionRect.m_y, m_selectionRect.m_width, m_selectionRect.m_height);
+
+ delete gc;
+ }
+ event.Skip();
}