Try to render wxBitmap instead of wxIcon in wxDataViewCtrl

This commit is contained in:
YuSanka 2018-09-12 11:29:59 +02:00
parent dbf18ed8d4
commit fc5d62e76e
3 changed files with 99 additions and 41 deletions

View File

@ -29,9 +29,9 @@ wxCollapsiblePane *m_collpane_settings = nullptr;
PrusaDoubleSlider *m_slider = nullptr; PrusaDoubleSlider *m_slider = nullptr;
wxGLCanvas *m_preview_canvas = nullptr; wxGLCanvas *m_preview_canvas = nullptr;
wxIcon m_icon_modifiermesh; wxBitmap/*Icon*/ m_icon_modifiermesh;
wxIcon m_icon_solidmesh; wxBitmap/*Icon*/ m_icon_solidmesh;
wxIcon m_icon_manifold_warning; wxBitmap/*Icon*/ m_icon_manifold_warning;
wxBitmap m_bmp_cog; wxBitmap m_bmp_cog;
wxBitmap m_bmp_split; wxBitmap m_bmp_split;
@ -141,11 +141,11 @@ void set_objects_from_model(Model &model) {
} }
void init_mesh_icons(){ void init_mesh_icons(){
m_icon_modifiermesh = wxIcon(Slic3r::GUI::from_u8(Slic3r::var("lambda.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("plugin.png")), wxBITMAP_TYPE_PNG); m_icon_modifiermesh = wxBitmap/*wxIcon*/(Slic3r::GUI::from_u8(Slic3r::var("lambda.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("plugin.png")), wxBITMAP_TYPE_PNG);
m_icon_solidmesh = wxIcon(Slic3r::GUI::from_u8(Slic3r::var("object.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("package.png")), wxBITMAP_TYPE_PNG); m_icon_solidmesh = wxBitmap/*wxIcon*/(Slic3r::GUI::from_u8(Slic3r::var("object.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("package.png")), wxBITMAP_TYPE_PNG);
// init icon for manifold warning // init icon for manifold warning
m_icon_manifold_warning = wxIcon(Slic3r::GUI::from_u8(Slic3r::var("exclamation_mark_.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("error.png")), wxBITMAP_TYPE_PNG); m_icon_manifold_warning = wxBitmap/*wxIcon*/(Slic3r::GUI::from_u8(Slic3r::var("exclamation_mark_.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("error.png")), wxBITMAP_TYPE_PNG);
// init bitmap for "Split to sub-objects" context menu // init bitmap for "Split to sub-objects" context menu
m_bmp_split = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("split.png")), wxBITMAP_TYPE_PNG); m_bmp_split = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("split.png")), wxBITMAP_TYPE_PNG);
@ -249,7 +249,7 @@ void create_objects_ctrl(wxWindow* win, wxBoxSizer*& objects_sz)
#endif // wxUSE_DRAG_AND_DROP && wxUSE_UNICODE #endif // wxUSE_DRAG_AND_DROP && wxUSE_UNICODE
// column 0(Icon+Text) of the view control: // column 0(Icon+Text) of the view control:
m_objects_ctrl->AppendColumn(new wxDataViewColumn(_(L("Name")), new PrusaIconTextRenderer(), m_objects_ctrl->AppendColumn(new wxDataViewColumn(_(L("Name")), new PrusaBitmapTextRenderer(),
0, 200, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE)); 0, 200, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE));
// m_objects_ctrl->AppendIconTextColumn(_(L("Name")), 0, wxDATAVIEW_CELL_INERT, 200, // m_objects_ctrl->AppendIconTextColumn(_(L("Name")), 0, wxDATAVIEW_CELL_INERT, 200,
// wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE); // wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE);
@ -668,7 +668,8 @@ void add_object_to_list(const std::string &name, ModelObject* model_object)
int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed + int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
stats.facets_added + stats.facets_reversed + stats.backwards_edges; stats.facets_added + stats.facets_reversed + stats.backwards_edges;
if (errors > 0) { if (errors > 0) {
const wxDataViewIconText data(item_name, m_icon_manifold_warning); // const wxDataViewIconText data(item_name, m_icon_manifold_warning);
const PrusaDataViewBitmapText data(item_name, m_icon_manifold_warning);
wxVariant variant; wxVariant variant;
variant << data; variant << data;
m_objects_model->SetValue(variant, item, 0); m_objects_model->SetValue(variant, item, 0);

View File

@ -358,10 +358,6 @@ void PrusaObjectDataViewModelNode::set_part_action_icon() {
m_action_icon = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("cog.png")), wxBITMAP_TYPE_PNG); m_action_icon = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("cog.png")), wxBITMAP_TYPE_PNG);
} }
void PrusaObjectDataViewModelNode::set_settings_list_icon(const wxIcon& icon) {
m_icon = icon;
}
Slic3r::GUI::BitmapCache *m_bitmap_cache = nullptr; Slic3r::GUI::BitmapCache *m_bitmap_cache = nullptr;
bool PrusaObjectDataViewModelNode::update_settings_digest(const std::vector<std::string>& categories) bool PrusaObjectDataViewModelNode::update_settings_digest(const std::vector<std::string>& categories)
{ {
@ -386,12 +382,9 @@ bool PrusaObjectDataViewModelNode::update_settings_digest(const std::vector<std:
bmp = m_bitmap_cache->insert(m_name.ToStdString(), bmps); bmp = m_bitmap_cache->insert(m_name.ToStdString(), bmps);
} }
#ifdef __WXOSX__ m_bmp = *bmp;
if (bmp->GetWidth() != bmp->GetHeight()) // m_icon.CopyFromBitmap(*bmp);
bmp->SetHeight(bmp->GetWidth());
#endif // __WXOSX__
m_icon.CopyFromBitmap(*bmp);
return true; return true;
} }
@ -437,7 +430,8 @@ wxDataViewItem PrusaObjectDataViewModel::Add(const wxString &name, const int ins
wxDataViewItem PrusaObjectDataViewModel::AddChild( const wxDataViewItem &parent_item, wxDataViewItem PrusaObjectDataViewModel::AddChild( const wxDataViewItem &parent_item,
const wxString &name, const wxString &name,
const wxIcon& icon, // const wxIcon& icon,
const wxBitmap& icon,
const int extruder/* = 0*/, const int extruder/* = 0*/,
const bool create_frst_child/* = true*/) const bool create_frst_child/* = true*/)
{ {
@ -636,6 +630,12 @@ wxIcon& PrusaObjectDataViewModel::GetIcon(const wxDataViewItem &item) const
return node->m_icon; return node->m_icon;
} }
wxBitmap& PrusaObjectDataViewModel::GetBitmap(const wxDataViewItem &item) const
{
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
return node->m_bmp;
}
void PrusaObjectDataViewModel::GetValue(wxVariant &variant, const wxDataViewItem &item, unsigned int col) const void PrusaObjectDataViewModel::GetValue(wxVariant &variant, const wxDataViewItem &item, unsigned int col) const
{ {
wxASSERT(item.IsOk()); wxASSERT(item.IsOk());
@ -644,8 +644,9 @@ void PrusaObjectDataViewModel::GetValue(wxVariant &variant, const wxDataViewItem
switch (col) switch (col)
{ {
case 0:{ case 0:{
const wxDataViewIconText data(node->m_name, node->m_icon); // const wxDataViewIconText data(node->m_name, node->m_icon);
variant << data; const PrusaDataViewBitmapText data(node->m_name, node->m_bmp);
variant << data;
break;} break;}
case 1: case 1:
variant = node->m_copy; variant = node->m_copy;
@ -851,30 +852,31 @@ void PrusaObjectDataViewModel::UpdateSettingsDigest(const wxDataViewItem &item,
ItemChanged(item); ItemChanged(item);
} }
IMPLEMENT_VARIANT_OBJECT(PrusaDataViewBitmapText)
// --------------------------------------------------------- // ---------------------------------------------------------
// PrusaIconTextRenderer // PrusaIconTextRenderer
// --------------------------------------------------------- // ---------------------------------------------------------
bool PrusaIconTextRenderer::SetValue(const wxVariant &value) bool PrusaBitmapTextRenderer::SetValue(const wxVariant &value)
{ {
m_value << value; m_value << value;
return true; return true;
} }
bool PrusaIconTextRenderer::GetValue(wxVariant& WXUNUSED(value)) const bool PrusaBitmapTextRenderer::GetValue(wxVariant& WXUNUSED(value)) const
{ {
return false; return false;
} }
bool PrusaIconTextRenderer::Render(wxRect rect, wxDC *dc, int state) bool PrusaBitmapTextRenderer::Render(wxRect rect, wxDC *dc, int state)
{ {
int xoffset = 0; int xoffset = 0;
const wxIcon& icon = m_value.GetIcon(); const /*wxIcon*/wxBitmap& icon = m_value.GetBitmap();// GetIcon();
if (icon.IsOk()) if (icon.IsOk())
{ {
dc->DrawIcon(icon, rect.x, rect.y + (rect.height - icon.GetHeight()) / 2); // dc->DrawIcon(icon, rect.x, rect.y + (rect.height - icon.GetHeight()) / 2);
dc->DrawBitmap(icon, rect.x, rect.y + (rect.height - icon.GetHeight()) / 2);
xoffset = icon.GetWidth() + 4; xoffset = icon.GetWidth() + 4;
} }
@ -883,14 +885,14 @@ bool PrusaIconTextRenderer::Render(wxRect rect, wxDC *dc, int state)
return true; return true;
} }
wxSize PrusaIconTextRenderer::GetSize() const wxSize PrusaBitmapTextRenderer::GetSize() const
{ {
if (!m_value.GetText().empty()) if (!m_value.GetText().empty())
{ {
wxSize size = GetTextExtent(m_value.GetText()); wxSize size = GetTextExtent(m_value.GetText());
if (m_value.GetIcon().IsOk()) if (m_value.GetBitmap()/*GetIcon()*/.IsOk())
size.x += m_value.GetIcon().GetWidth() + 4; size.x += m_value.GetBitmap()/*GetIcon()*/.GetWidth() + 4;
return size; return size;
} }
return wxSize(80, 20); return wxSize(80, 20);

View File

@ -144,6 +144,49 @@ public:
#endif //__WXMSW__ #endif //__WXMSW__
// ***************************************************************************** // *****************************************************************************
// ----------------------------------------------------------------------------
// PrusaDataViewBitmapText: helper class used by PrusaBitmapTextRenderer
// ----------------------------------------------------------------------------
class PrusaDataViewBitmapText : public wxObject
{
public:
PrusaDataViewBitmapText(const wxString &text = wxEmptyString,
const wxBitmap& bmp = wxNullBitmap) :
m_text(text), m_bmp(bmp)
{ }
PrusaDataViewBitmapText(const PrusaDataViewBitmapText &other)
: wxObject(),
m_text(other.m_text),
m_bmp(other.m_bmp)
{ }
void SetText(const wxString &text) { m_text = text; }
wxString GetText() const { return m_text; }
void SetBitmap(const wxIcon &icon) { m_bmp = icon; }
const wxBitmap &GetBitmap() const { return m_bmp; }
bool IsSameAs(const PrusaDataViewBitmapText& other) const {
return m_text == other.m_text && m_bmp.IsSameAs(other.m_bmp);
}
bool operator==(const PrusaDataViewBitmapText& other) const {
return IsSameAs(other);
}
bool operator!=(const PrusaDataViewBitmapText& other) const {
return !IsSameAs(other);
}
private:
wxString m_text;
wxBitmap m_bmp;
};
DECLARE_VARIANT_OBJECT(PrusaDataViewBitmapText)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// PrusaObjectDataViewModelNode: a node inside PrusaObjectDataViewModel // PrusaObjectDataViewModelNode: a node inside PrusaObjectDataViewModel
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -156,6 +199,7 @@ class PrusaObjectDataViewModelNode
PrusaObjectDataViewModelNode* m_parent; PrusaObjectDataViewModelNode* m_parent;
MyObjectTreeModelNodePtrArray m_children; MyObjectTreeModelNodePtrArray m_children;
wxIcon m_empty_icon; wxIcon m_empty_icon;
wxBitmap m_empty_bmp;
std::vector< std::string > m_opt_categories; std::vector< std::string > m_opt_categories;
public: public:
PrusaObjectDataViewModelNode(const wxString &name, const int instances_count=1) { PrusaObjectDataViewModelNode(const wxString &name, const int instances_count=1) {
@ -175,13 +219,15 @@ public:
PrusaObjectDataViewModelNode( PrusaObjectDataViewModelNode* parent, PrusaObjectDataViewModelNode( PrusaObjectDataViewModelNode* parent,
const wxString& sub_obj_name, const wxString& sub_obj_name,
const wxIcon& icon, const wxBitmap& bmp,
// const wxIcon& icon,
const wxString& extruder, const wxString& extruder,
const int volume_id=-1) { const int volume_id=-1) {
m_parent = parent; m_parent = parent;
m_name = sub_obj_name; m_name = sub_obj_name;
m_copy = wxEmptyString; m_copy = wxEmptyString;
m_icon = icon; // m_icon = icon;
m_bmp = bmp;
m_type = "volume"; m_type = "volume";
m_volume_id = volume_id; m_volume_id = volume_id;
m_extruder = extruder; m_extruder = extruder;
@ -214,6 +260,7 @@ public:
wxString m_name; wxString m_name;
wxIcon& m_icon = m_empty_icon; wxIcon& m_icon = m_empty_icon;
wxBitmap& m_bmp = m_empty_bmp;
wxString m_copy; wxString m_copy;
std::string m_type; std::string m_type;
int m_volume_id = -2; int m_volume_id = -2;
@ -274,9 +321,11 @@ public:
switch (col) switch (col)
{ {
case 0:{ case 0:{
wxDataViewIconText data; // wxDataViewIconText data;
PrusaDataViewBitmapText data;
data << variant; data << variant;
m_icon = data.GetIcon(); // m_icon = data.GetIcon();
m_bmp = data.GetBitmap();
m_name = data.GetText(); m_name = data.GetText();
return true;} return true;}
case 1: case 1:
@ -298,6 +347,11 @@ public:
m_icon = icon; m_icon = icon;
} }
void SetBitmap(const wxBitmap &icon)
{
m_bmp = icon;
}
void SetType(const std::string& type){ void SetType(const std::string& type){
m_type = type; m_type = type;
} }
@ -342,7 +396,6 @@ public:
// Set action icons for node // Set action icons for node
void set_object_action_icon(); void set_object_action_icon();
void set_part_action_icon(); void set_part_action_icon();
void set_settings_list_icon(const wxIcon& icon);
bool update_settings_digest(const std::vector<std::string>& categories); bool update_settings_digest(const std::vector<std::string>& categories);
}; };
@ -361,7 +414,8 @@ public:
wxDataViewItem Add(const wxString &name, const int instances_count); wxDataViewItem Add(const wxString &name, const int instances_count);
wxDataViewItem AddChild(const wxDataViewItem &parent_item, wxDataViewItem AddChild(const wxDataViewItem &parent_item,
const wxString &name, const wxString &name,
const wxIcon& icon, // const wxIcon& icon,
const wxBitmap& icon,
const int extruder = 0, const int extruder = 0,
const bool create_frst_child = true); const bool create_frst_child = true);
wxDataViewItem AddSettingsChild(const wxDataViewItem &parent_item); wxDataViewItem AddSettingsChild(const wxDataViewItem &parent_item);
@ -378,6 +432,7 @@ public:
wxString GetName(const wxDataViewItem &item) const; wxString GetName(const wxDataViewItem &item) const;
wxString GetCopy(const wxDataViewItem &item) const; wxString GetCopy(const wxDataViewItem &item) const;
wxIcon& GetIcon(const wxDataViewItem &item) const; wxIcon& GetIcon(const wxDataViewItem &item) const;
wxBitmap& GetBitmap(const wxDataViewItem &item) const;
// helper methods to change the model // helper methods to change the model
@ -414,17 +469,16 @@ public:
void UpdateSettingsDigest(const wxDataViewItem &item, const std::vector<std::string>& categories); void UpdateSettingsDigest(const wxDataViewItem &item, const std::vector<std::string>& categories);
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// PrusaIconTextRenderer // PrusaBitmapTextRenderer
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class PrusaIconTextRenderer : public wxDataViewCustomRenderer class PrusaBitmapTextRenderer : public wxDataViewCustomRenderer
{ {
public: public:
PrusaIconTextRenderer( wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, PrusaBitmapTextRenderer( wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT): int align = wxDVR_DEFAULT_ALIGNMENT):
wxDataViewCustomRenderer(wxT("wxDataViewIconText"), mode, align) {} wxDataViewCustomRenderer(wxT("PrusaDataViewIconBitmapText"/*"wxDataViewIconText"*/), mode, align) {}
bool SetValue(const wxVariant &value); bool SetValue(const wxVariant &value);
bool GetValue(wxVariant &value) const; bool GetValue(wxVariant &value) const;
@ -435,7 +489,8 @@ public:
virtual bool HasEditorCtrl() const { return false; } virtual bool HasEditorCtrl() const { return false; }
private: private:
wxDataViewIconText m_value; // wxDataViewIconText m_value;
PrusaDataViewBitmapText m_value;
}; };