Event.hpp: Set event object

This commit is contained in:
Vojtech Kral 2018-10-03 14:07:10 +02:00
parent 770d944283
commit 83f55b608c
3 changed files with 23 additions and 14 deletions

View file

@ -1,6 +1,7 @@
#ifndef slic3r_Events_hpp_ #ifndef slic3r_Events_hpp_
#define slic3r_Events_hpp_ #define slic3r_Events_hpp_
#include <wx/event.h> #include <wx/event.h>
@ -11,11 +12,14 @@ namespace GUI {
struct SimpleEvent : public wxEvent 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 virtual wxEvent* Clone() const
{ {
return new SimpleEvent(GetEventType(), GetId()); return new SimpleEvent(GetEventType(), GetEventObject());
} }
}; };
@ -23,26 +27,30 @@ template<class T, size_t N> struct ArrayEvent : public wxEvent
{ {
std::array<T, N> data; std::array<T, N> data;
ArrayEvent(wxEventType type, std::array<T, N> data, int id = 0) ArrayEvent(wxEventType type, std::array<T, N> data, wxObject* origin = nullptr)
: wxEvent(id, type), data(std::move(data)) : wxEvent(0, type), data(std::move(data))
{} {
SetEventObject(origin);
}
virtual wxEvent* Clone() const virtual wxEvent* Clone() const
{ {
return new ArrayEvent<T, N>(GetEventType(), data, GetId()); return new ArrayEvent<T, N>(GetEventType(), data, GetEventObject());
} }
}; };
template<class T> struct ArrayEvent<T, 1> : public wxEvent template<class T> struct ArrayEvent<T, 1> : public wxEvent
{ {
T data; T data;
ArrayEvent(wxEventType type, T data, int id = 0) ArrayEvent(wxEventType type, T data, wxObject* origin = nullptr)
: wxEvent(id, type), data(std::move(data)) : wxEvent(0, type), data(std::move(data))
{} {
SetEventObject(origin);
}
virtual wxEvent* Clone() const virtual wxEvent* Clone() const
{ {
return new ArrayEvent<T, 1>(GetEventType(), data, GetId()); return new ArrayEvent<T, 1>(GetEventType(), data, GetEventObject());
} }
}; };

View file

@ -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); wxPostEvent(m_canvas, event);
} }

View file

@ -86,8 +86,8 @@ struct ObjectSelectEvent;
wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, ObjectSelectEvent); wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, ObjectSelectEvent);
struct ObjectSelectEvent : public ArrayEvent<ptrdiff_t, 2> struct ObjectSelectEvent : public ArrayEvent<ptrdiff_t, 2>
{ {
ObjectSelectEvent(ptrdiff_t object_id, ptrdiff_t volume_id, int id = 0) ObjectSelectEvent(ptrdiff_t object_id, ptrdiff_t volume_id, wxObject *origin = nullptr)
: ArrayEvent(EVT_GLCANVAS_OBJECT_SELECT, {object_id, volume_id}, id) : ArrayEvent(EVT_GLCANVAS_OBJECT_SELECT, {object_id, volume_id}, origin)
{} {}
ptrdiff_t object_id() const { return data[0]; } ptrdiff_t object_id() const { return data[0]; }
@ -546,7 +546,7 @@ class GLCanvas3D
GCodePreviewVolumeIndex m_gcode_preview_volume_index; GCodePreviewVolumeIndex m_gcode_preview_volume_index;
void post_event(const wxEvent &event); void post_event(wxEvent &&event);
void viewport_changed(); void viewport_changed();
public: public:
GLCanvas3D(wxGLCanvas* canvas); GLCanvas3D(wxGLCanvas* canvas);