FIX: fix the filament map dialog cannot open on mac
jira: none Change-Id: I73bd2d41b46f4a7212c24e829423ff67fa07b22d
This commit is contained in:
parent
5d9a7eaadc
commit
96197d8abd
|
@ -3,65 +3,57 @@
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
|
struct CustomData
|
||||||
|
{
|
||||||
|
int filament_id;
|
||||||
|
unsigned char r, g, b;
|
||||||
|
};
|
||||||
|
|
||||||
// Custom data object used to store information that needs to be backed up during drag and drop
|
// Custom data object used to store information that needs to be backed up during drag and drop
|
||||||
class ColorDataObject : public wxDataObjectSimple
|
class ColorDataObject : public wxCustomDataObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ColorDataObject(wxPanel *color_block = nullptr, wxPanel *parent = nullptr, const wxColour &color = *wxBLACK, int filament_id = 0)
|
ColorDataObject(const wxColour &color = *wxBLACK, int filament_id = 0)
|
||||||
: wxDataObjectSimple(wxDF_PRIVATE)
|
: wxCustomDataObject(wxDataFormat("application/customize_format"))
|
||||||
, m_parent(parent)
|
{
|
||||||
, m_source_block(color_block)
|
std::memset(&m_data, 0, sizeof(m_data));
|
||||||
, m_color(color)
|
set_custom_data_filament_id(filament_id);
|
||||||
, m_filament_id(filament_id) {}
|
set_custom_data_color(color);
|
||||||
|
}
|
||||||
|
|
||||||
wxColour GetColor() const { return m_color; }
|
wxColour GetColor() const { return wxColor(m_data.r, m_data.g, m_data.b); }
|
||||||
void SetColor(const wxColour &color) { m_color = color; }
|
void SetColor(const wxColour &color) { set_custom_data_color(color); }
|
||||||
|
|
||||||
int GetFilament() const { return m_filament_id; }
|
int GetFilament() const { return m_data.filament_id; }
|
||||||
void SetFilament(int label) { m_filament_id = label; }
|
void SetFilament(int label) { set_custom_data_filament_id(label); }
|
||||||
|
|
||||||
wxPanel *GetParent() const { return m_parent; }
|
void set_custom_data_filament_id(int filament_id) {
|
||||||
void SetParent(wxPanel * parent) { m_parent = parent; }
|
m_data.filament_id = filament_id;
|
||||||
|
}
|
||||||
|
|
||||||
wxPanel *GetSourceBlock() const { return m_source_block; }
|
void set_custom_data_color(const wxColor& color) {
|
||||||
void SetSourceBlock(wxPanel *source_block) { m_source_block = source_block; }
|
m_data.r = color.Red();
|
||||||
|
m_data.g = color.Green();
|
||||||
|
m_data.b = color.Blue();
|
||||||
|
}
|
||||||
|
|
||||||
virtual size_t GetDataSize() const override { return sizeof(m_color) + sizeof(int) + sizeof(m_parent) + sizeof(m_source_block); }
|
virtual size_t GetDataSize() const override { return sizeof(m_data); }
|
||||||
virtual bool GetDataHere(void *buf) const override
|
virtual bool GetDataHere(void *buf) const override
|
||||||
{
|
{
|
||||||
char *ptr = static_cast<char *>(buf);
|
char *ptr = static_cast<char *>(buf);
|
||||||
wxColour * colorBuf = static_cast<wxColour *>(buf);
|
std::memcpy(buf, &m_data, sizeof(m_data));
|
||||||
*colorBuf = m_color;
|
|
||||||
|
|
||||||
std::memcpy(ptr + sizeof(m_color), &m_filament_id, sizeof(int));
|
|
||||||
|
|
||||||
wxPanel **panelBuf = reinterpret_cast<wxPanel **>(static_cast<char *>(buf) + sizeof(m_color) + sizeof(int));
|
|
||||||
*panelBuf = m_parent;
|
|
||||||
|
|
||||||
wxPanel **blockBuf = reinterpret_cast<wxPanel **>(static_cast<char *>(buf) + sizeof(m_color) + sizeof(int) + sizeof(m_parent));
|
|
||||||
*blockBuf = m_source_block;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
virtual bool SetData(size_t len, const void *buf) override
|
virtual bool SetData(size_t len, const void *buf) override
|
||||||
{
|
{
|
||||||
if (len == GetDataSize()) {
|
if (len == GetDataSize()) {
|
||||||
const char *ptr = static_cast<const char *>(buf);
|
std::memcpy(&m_data, buf, sizeof(m_data));
|
||||||
m_color = *static_cast<const wxColour *>(buf);
|
|
||||||
|
|
||||||
std::memcpy(&m_filament_id, ptr + sizeof(m_color), sizeof(int));
|
|
||||||
|
|
||||||
m_parent = *reinterpret_cast<wxPanel *const *>(static_cast<const char *>(buf) + sizeof(m_color) + sizeof(int));
|
|
||||||
|
|
||||||
m_source_block = *reinterpret_cast<wxPanel *const *>(static_cast<const char *>(buf) + sizeof(m_color) + sizeof(int) + sizeof(m_parent));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
int m_filament_id;
|
CustomData m_data;
|
||||||
wxColour m_color;
|
|
||||||
wxPanel *m_parent;
|
|
||||||
wxPanel *m_source_block;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////// ColorPanel start ////////////////////////
|
/////////////// ColorPanel start ////////////////////////
|
||||||
|
@ -100,12 +92,10 @@ void ColorPanel::OnPaint(wxPaintEvent &event)
|
||||||
class ColorDropSource : public wxDropSource
|
class ColorDropSource : public wxDropSource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ColorDropSource(wxPanel *parent, wxPanel *color_block, const wxColour &color, int filament_id) : wxDropSource()
|
ColorDropSource(wxPanel *parent, wxPanel *color_block, const wxColour &color, int filament_id) : wxDropSource(parent)
|
||||||
{
|
{
|
||||||
m_data.SetColor(color);
|
m_data.SetColor(color);
|
||||||
m_data.SetFilament(filament_id);
|
m_data.SetFilament(filament_id);
|
||||||
m_data.SetParent(parent);
|
|
||||||
m_data.SetSourceBlock(color_block);
|
|
||||||
SetData(m_data); // Set drag source data
|
SetData(m_data); // Set drag source data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,15 +129,6 @@ wxDragResult ColorDropTarget::OnData(wxCoord x, wxCoord y, wxDragResult def)
|
||||||
if (!GetData())
|
if (!GetData())
|
||||||
return wxDragNone;
|
return wxDragNone;
|
||||||
|
|
||||||
if (m_data->GetParent() == m_panel) {
|
|
||||||
return wxDragNone;
|
|
||||||
}
|
|
||||||
|
|
||||||
DragDropPanel * parent_panel = dynamic_cast<DragDropPanel *>(m_data->GetParent());
|
|
||||||
ColorPanel * color_block = dynamic_cast<ColorPanel *>(m_data->GetSourceBlock());
|
|
||||||
assert(parent_panel && color_block);
|
|
||||||
parent_panel->RemoveColorBlock(color_block);
|
|
||||||
|
|
||||||
ColorDataObject *dataObject = dynamic_cast<ColorDataObject *>(GetDataObject());
|
ColorDataObject *dataObject = dynamic_cast<ColorDataObject *>(GetDataObject());
|
||||||
m_panel->AddColorBlock(m_data->GetColor(), m_data->GetFilament());
|
m_panel->AddColorBlock(m_data->GetColor(), m_data->GetFilament());
|
||||||
|
|
||||||
|
@ -221,7 +202,9 @@ void DragDropPanel::DoDragDrop(ColorPanel *panel, const wxColour &color, int fil
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ColorDropSource source(this, panel, color, filament_id);
|
ColorDropSource source(this, panel, color, filament_id);
|
||||||
source.DoDragDrop(wxDrag_CopyOnly);
|
if (source.DoDragDrop(wxDrag_CopyOnly) == wxDragResult::wxDragCopy) {
|
||||||
|
this->RemoveColorBlock(panel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> DragDropPanel::GetAllFilaments() const
|
std::vector<int> DragDropPanel::GetAllFilaments() const
|
||||||
|
|
Loading…
Reference in New Issue