From 83f55b608c49993ee3279f5b598748a36b04d979 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Wed, 3 Oct 2018 14:07:10 +0200 Subject: [PATCH] Event.hpp: Set event object --- src/slic3r/GUI/Event.hpp | 28 ++++++++++++++++++---------- src/slic3r/GUI/GLCanvas3D.cpp | 3 ++- src/slic3r/GUI/GLCanvas3D.hpp | 6 +++--- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/slic3r/GUI/Event.hpp b/src/slic3r/GUI/Event.hpp index ffcad7f9f..63800fa00 100644 --- a/src/slic3r/GUI/Event.hpp +++ b/src/slic3r/GUI/Event.hpp @@ -1,6 +1,7 @@ #ifndef slic3r_Events_hpp_ #define slic3r_Events_hpp_ + #include @@ -11,11 +12,14 @@ namespace GUI { struct SimpleEvent : public wxEvent { - SimpleEvent(wxEventType type, int id = 0) : wxEvent(id, type) {} + SimpleEvent(wxEventType type, wxObject* origin = nullptr) : wxEvent(0, type) + { + SetEventObject(origin); + } virtual wxEvent* Clone() const { - return new SimpleEvent(GetEventType(), GetId()); + return new SimpleEvent(GetEventType(), GetEventObject()); } }; @@ -23,26 +27,30 @@ template struct ArrayEvent : public wxEvent { std::array data; - ArrayEvent(wxEventType type, std::array data, int id = 0) - : wxEvent(id, type), data(std::move(data)) - {} + ArrayEvent(wxEventType type, std::array data, wxObject* origin = nullptr) + : wxEvent(0, type), data(std::move(data)) + { + SetEventObject(origin); + } virtual wxEvent* Clone() const { - return new ArrayEvent(GetEventType(), data, GetId()); + return new ArrayEvent(GetEventType(), data, GetEventObject()); } }; template struct ArrayEvent : public wxEvent { T data; - ArrayEvent(wxEventType type, T data, int id = 0) - : wxEvent(id, type), data(std::move(data)) - {} + ArrayEvent(wxEventType type, T data, wxObject* origin = nullptr) + : wxEvent(0, type), data(std::move(data)) + { + SetEventObject(origin); + } virtual wxEvent* Clone() const { - return new ArrayEvent(GetEventType(), data, GetId()); + return new ArrayEvent(GetEventType(), data, GetEventObject()); } }; diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index b6de0d820..328d5af39 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2007,8 +2007,9 @@ GLCanvas3D::~GLCanvas3D() } } -void GLCanvas3D::post_event(const wxEvent &event) +void GLCanvas3D::post_event(wxEvent &&event) { + event.SetEventObject(m_canvas); wxPostEvent(m_canvas, event); } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 055d62b6a..04da72995 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -86,8 +86,8 @@ struct ObjectSelectEvent; wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, ObjectSelectEvent); struct ObjectSelectEvent : public ArrayEvent { - ObjectSelectEvent(ptrdiff_t object_id, ptrdiff_t volume_id, int id = 0) - : ArrayEvent(EVT_GLCANVAS_OBJECT_SELECT, {object_id, volume_id}, id) + ObjectSelectEvent(ptrdiff_t object_id, ptrdiff_t volume_id, wxObject *origin = nullptr) + : ArrayEvent(EVT_GLCANVAS_OBJECT_SELECT, {object_id, volume_id}, origin) {} ptrdiff_t object_id() const { return data[0]; } @@ -546,7 +546,7 @@ class GLCanvas3D GCodePreviewVolumeIndex m_gcode_preview_volume_index; - void post_event(const wxEvent &event); + void post_event(wxEvent &&event); void viewport_changed(); public: GLCanvas3D(wxGLCanvas* canvas);