diff --git a/resources/images/badge.svg b/resources/images/badge.svg new file mode 100644 index 000000000..62e8c5506 --- /dev/null +++ b/resources/images/badge.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 298c721b0..29f5b11c3 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -38,6 +38,8 @@ set(SLIC3R_GUI_SOURCES GUI/Widgets/ScrolledWindow.hpp GUI/Widgets/StaticBox.cpp GUI/Widgets/StaticBox.hpp + GUI/Widgets/StaticGroup.cpp + GUI/Widgets/StaticGroup.hpp GUI/Widgets/ImageSwitchButton.cpp GUI/Widgets/ImageSwitchButton.hpp GUI/Widgets/SwitchButton.cpp diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c217c53cd..315753e86 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -120,6 +120,7 @@ #include "Widgets/RadioBox.hpp" #include "Widgets/CheckBox.hpp" #include "Widgets/Button.hpp" +#include "Widgets/StaticGroup.hpp" #include "GUI_ObjectTable.hpp" #include "libslic3r/Thread.hpp" @@ -882,6 +883,8 @@ Sidebar::Sidebar(Plater *parent) p->m_panel_printer_content->SetBackgroundColour(wxColour(255, 255, 255)); PlaterPresetComboBox* combo_printer = new PlaterPresetComboBox(p->m_panel_printer_content, Preset::TYPE_PRINTER); + combo_printer->SetBorderWidth(0); + combo_printer->ShowBadge(true); ScalableButton* edit_btn = new ScalableButton(p->m_panel_printer_content, wxID_ANY, "edit"); edit_btn->SetToolTip(_L("Click to edit preset")); edit_btn->Bind(wxEVT_BUTTON, [this, combo_printer](wxCommandEvent) @@ -975,9 +978,10 @@ Sidebar::Sidebar(Plater *parent) p->m_dual_extruder_sizer = new wxBoxSizer(wxHORIZONTAL); auto add_extruder = [this](int index, wxString const & title) { - wxStaticBox * static_box = new wxStaticBox(p->m_panel_printer_content, wxID_ANY, title); + StaticGroup *static_box = new StaticGroup(p->m_panel_printer_content, wxID_ANY, title); static_box->SetFont(Label::Body_10); static_box->SetForegroundColour("#909090"); + static_box->ShowBadge(true); wxStaticBoxSizer *static_box_sizer = new wxStaticBoxSizer(static_box, wxVERTICAL); // Nozzle wxBoxSizer * nozzle_sizer = new wxBoxSizer(wxHORIZONTAL); @@ -1329,6 +1333,7 @@ void Sidebar::create_printer_preset() void Sidebar::init_filament_combo(PlaterPresetComboBox **combo, const int filament_idx) { *combo = new PlaterPresetComboBox(p->m_panel_filament_content, Slic3r::Preset::TYPE_FILAMENT); + (*combo)->ShowBadge(true); (*combo)->set_filament_idx(filament_idx); auto combo_and_btn_sizer = new wxBoxSizer(wxHORIZONTAL); diff --git a/src/slic3r/GUI/Widgets/StaticBox.cpp b/src/slic3r/GUI/Widgets/StaticBox.cpp index 6eae5b3d6..968fc7a89 100644 --- a/src/slic3r/GUI/Widgets/StaticBox.cpp +++ b/src/slic3r/GUI/Widgets/StaticBox.cpp @@ -22,7 +22,7 @@ StaticBox::StaticBox() , radius(8) { border_color = StateColor( - std::make_pair(0xF0F0F1, (int) StateColor::Disabled), + std::make_pair(0xF0F0F1, (int) StateColor::Disabled), std::make_pair(0x303A3C, (int) StateColor::Normal)); } @@ -110,6 +110,15 @@ wxColor StaticBox::GetParentBackgroundColor(wxWindow* parent) return *wxWHITE; } +void StaticBox::ShowBadge(bool show) +{ + if (show) + badge = ScalableBitmap(this, "badge", 18); + else + badge = ScalableBitmap {}; + Refresh(); +} + void StaticBox::eraseEvent(wxEraseEvent& evt) { // for transparent background, but not work @@ -218,4 +227,9 @@ void StaticBox::doRender(wxDC& dc) lb += db; while (lb >= size.y) { ++b, lb -= size.y; } while (lb <= -size.y) { --b, lb += size.y; } } } + + if (badge.bmp().IsOk()) { + auto s = badge.bmp().GetScaledSize(); + dc.DrawBitmap(badge.bmp(), size.x - s.x, 0); + } } diff --git a/src/slic3r/GUI/Widgets/StaticBox.hpp b/src/slic3r/GUI/Widgets/StaticBox.hpp index 871c5651d..56989df0e 100644 --- a/src/slic3r/GUI/Widgets/StaticBox.hpp +++ b/src/slic3r/GUI/Widgets/StaticBox.hpp @@ -14,13 +14,13 @@ public: StaticBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint & pos = wxDefaultPosition, - const wxSize & size = wxDefaultSize, + const wxSize & size = wxDefaultSize, long style = 0); bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint & pos = wxDefaultPosition, - const wxSize & size = wxDefaultSize, + const wxSize & size = wxDefaultSize, long style = 0); void SetCornerRadius(double radius); @@ -39,6 +39,8 @@ public: static wxColor GetParentBackgroundColor(wxWindow * parent); + void ShowBadge(bool show); + protected: void eraseEvent(wxEraseEvent& evt); @@ -55,6 +57,7 @@ protected: StateColor border_color; StateColor background_color; StateColor background_color2; + ScalableBitmap badge; DECLARE_EVENT_TABLE() }; diff --git a/src/slic3r/GUI/Widgets/StaticGroup.cpp b/src/slic3r/GUI/Widgets/StaticGroup.cpp new file mode 100644 index 000000000..222fd9dde --- /dev/null +++ b/src/slic3r/GUI/Widgets/StaticGroup.cpp @@ -0,0 +1,33 @@ +#include "StaticGroup.hpp" + +StaticGroup::StaticGroup(wxWindow *parent, wxWindowID id, const wxString &label) + : wxStaticBox(parent, id, label) +{ +#ifdef __WXMSW__ + Bind(wxEVT_PAINT, &StaticGroup::OnPaint, this); +#else +#endif +} + +void StaticGroup::ShowBadge(bool show) +{ + if (show) + badge = ScalableBitmap(this, "badge", 18); + else + badge = ScalableBitmap{}; + Refresh(); +} + +#ifdef __WXMSW__ + +void StaticGroup::OnPaint(wxPaintEvent &evt) +{ + wxStaticBox::OnPaint(evt); + if (badge.bmp().IsOk()) { + auto s = badge.bmp().GetScaledSize(); + wxPaintDC dc(this); + dc.DrawBitmap(badge.bmp(), GetSize().x - s.x, 8); + } +} + +#endif diff --git a/src/slic3r/GUI/Widgets/StaticGroup.hpp b/src/slic3r/GUI/Widgets/StaticGroup.hpp new file mode 100644 index 000000000..fb4ed3afc --- /dev/null +++ b/src/slic3r/GUI/Widgets/StaticGroup.hpp @@ -0,0 +1,25 @@ +#ifndef slic3r_GUI_StaticGroup_hpp_ +#define slic3r_GUI_StaticGroup_hpp_ + +#include "../wxExtensions.hpp" + +#include + +class StaticGroup : public wxStaticBox +{ +public: + StaticGroup(wxWindow *parent, wxWindowID id, const wxString &label); + +public: + void ShowBadge(bool show); + +private: +#ifdef __WXMSW__ + void OnPaint(wxPaintEvent &evt); +#endif + +private: + ScalableBitmap badge; +}; + +#endif // !slic3r_GUI_StaticGroup_hpp_