Improvements for extruder selector (added possibility to create combobox with thin icons)
Call of an update extruder selector after a change of extruder or filament color
This commit is contained in:
parent
2a5cf689a4
commit
398d20c79b
5 changed files with 26 additions and 15 deletions
|
@ -130,7 +130,7 @@ void ExtruderSequenceDialog::apply_extruder_sequence()
|
|||
for (size_t extruder=0; extruder < m_sequence.extruders.size(); ++extruder)
|
||||
{
|
||||
wxBitmapComboBox* extruder_selector = nullptr;
|
||||
apply_extruder_selector(&extruder_selector, this);
|
||||
apply_extruder_selector(&extruder_selector, this, "", wxDefaultPosition, wxSize(12*wxGetApp().em_unit(), -1));
|
||||
extruder_selector->SetSelection(m_sequence.extruders[extruder]);
|
||||
|
||||
extruder_selector->Bind(wxEVT_COMBOBOX, [this, extruder_selector, extruder](wxCommandEvent& evt)
|
||||
|
|
|
@ -533,6 +533,9 @@ void Preview::on_choice_view_type(wxCommandEvent& evt)
|
|||
if ((0 <= selection) && (selection < (int)GCodePreviewData::Extrusion::Num_View_Types))
|
||||
m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)selection;
|
||||
|
||||
if (m_gcode_preview_data->extrusion.view_type != GCodePreviewData::Extrusion::ColorPrint)
|
||||
m_extruder_selector->SetSelection(0);
|
||||
|
||||
reload_print();
|
||||
}
|
||||
|
||||
|
@ -605,7 +608,7 @@ void Preview::update_view_type(bool slice_completed)
|
|||
|
||||
void Preview::update_extruder_selector()
|
||||
{
|
||||
apply_extruder_selector(&m_extruder_selector, this, L("Whole print"));
|
||||
apply_extruder_selector(&m_extruder_selector, this, L("Whole print"), wxDefaultPosition, wxDefaultSize, true);
|
||||
}
|
||||
|
||||
void Preview::create_double_slider()
|
||||
|
|
|
@ -4868,6 +4868,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
|
|||
filament_colors.push_back(filaments.find_preset(filament_preset, true)->config.opt_string("filament_colour", (unsigned)0));
|
||||
|
||||
p->config->option<ConfigOptionStrings>(opt_key)->values = filament_colors;
|
||||
p->preview->update_extruder_selector();
|
||||
p->sidebar->obj_list()->update_extruder_colors();
|
||||
continue;
|
||||
}
|
||||
|
@ -4894,6 +4895,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
|
|||
else if(opt_key == "extruder_colour") {
|
||||
update_scheduled = true;
|
||||
p->preview->set_number_extruders(p->config->option<ConfigOptionStrings>(opt_key)->values.size());
|
||||
p->preview->update_extruder_selector();
|
||||
p->sidebar->obj_list()->update_extruder_colors();
|
||||
} else if(opt_key == "max_print_height") {
|
||||
update_scheduled = true;
|
||||
|
@ -4945,6 +4947,7 @@ void Plater::force_filament_colors_update()
|
|||
|
||||
if (update_scheduled) {
|
||||
update();
|
||||
p->preview->update_extruder_selector();
|
||||
p->sidebar->obj_list()->update_extruder_colors();
|
||||
}
|
||||
|
||||
|
|
|
@ -450,7 +450,7 @@ wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in,
|
|||
|
||||
|
||||
Slic3r::GUI::BitmapCache* m_bitmap_cache = nullptr;
|
||||
std::vector<wxBitmap*> get_extruder_color_icons()
|
||||
std::vector<wxBitmap*> get_extruder_color_icons(bool thin_icon/* = false*/)
|
||||
{
|
||||
// Create the bitmap with color bars.
|
||||
std::vector<wxBitmap*> bmps;
|
||||
|
@ -466,16 +466,18 @@ std::vector<wxBitmap*> get_extruder_color_icons()
|
|||
* and scale them in respect to em_unit value
|
||||
*/
|
||||
const double em = Slic3r::GUI::wxGetApp().em_unit();
|
||||
const int icon_width = lround(3.2 * em);
|
||||
const int icon_width = lround((thin_icon ? 1 : 3.2) * em);
|
||||
const int icon_height = lround(1.6 * em);
|
||||
|
||||
for (const std::string& color : colors)
|
||||
{
|
||||
wxBitmap* bitmap = m_bitmap_cache->find(color);
|
||||
std::string bitmap_key = color + "-h" + std::to_string(icon_height) + "-w" + std::to_string(icon_width);
|
||||
|
||||
wxBitmap* bitmap = m_bitmap_cache->find(bitmap_key);
|
||||
if (bitmap == nullptr) {
|
||||
// Paint the color icon.
|
||||
Slic3r::PresetBundle::parse_color(color, rgb);
|
||||
bitmap = m_bitmap_cache->insert(color, m_bitmap_cache->mksolid(icon_width, icon_height, rgb));
|
||||
bitmap = m_bitmap_cache->insert(bitmap_key, m_bitmap_cache->mksolid(icon_width, icon_height, rgb));
|
||||
}
|
||||
bmps.emplace_back(bitmap);
|
||||
}
|
||||
|
@ -484,10 +486,10 @@ std::vector<wxBitmap*> get_extruder_color_icons()
|
|||
}
|
||||
|
||||
|
||||
static wxBitmap get_extruder_color_icon(size_t extruder_idx)
|
||||
static wxBitmap get_extruder_color_icon(size_t extruder_idx, bool thin_icon = false)
|
||||
{
|
||||
// Create the bitmap with color bars.
|
||||
std::vector<wxBitmap*> bmps = get_extruder_color_icons();
|
||||
std::vector<wxBitmap*> bmps = get_extruder_color_icons(thin_icon);
|
||||
if (bmps.empty())
|
||||
return wxNullBitmap;
|
||||
|
||||
|
@ -498,9 +500,10 @@ void apply_extruder_selector(wxBitmapComboBox** ctrl,
|
|||
wxWindow* parent,
|
||||
const std::string& first_item/* = ""*/,
|
||||
wxPoint pos/* = wxDefaultPosition*/,
|
||||
wxSize size/* = wxDefaultSize*/)
|
||||
wxSize size/* = wxDefaultSize*/,
|
||||
bool use_thin_icon/* = false*/)
|
||||
{
|
||||
std::vector<wxBitmap*> icons = get_extruder_color_icons();
|
||||
std::vector<wxBitmap*> icons = get_extruder_color_icons(use_thin_icon);
|
||||
if (icons.empty())
|
||||
return;
|
||||
|
||||
|
@ -516,6 +519,7 @@ void apply_extruder_selector(wxBitmapComboBox** ctrl,
|
|||
}
|
||||
|
||||
int i = 0;
|
||||
wxString str = _(L("Extruder"));
|
||||
for (wxBitmap* bmp : icons) {
|
||||
if (i == 0) {
|
||||
if (!first_item.empty())
|
||||
|
@ -523,7 +527,7 @@ void apply_extruder_selector(wxBitmapComboBox** ctrl,
|
|||
++i;
|
||||
}
|
||||
|
||||
(*ctrl)->Append(wxString::Format("%d", i), *bmp);
|
||||
(*ctrl)->Append(wxString::Format("%s %d", str, i), *bmp);
|
||||
++i;
|
||||
}
|
||||
(*ctrl)->SetSelection(0);
|
||||
|
|
|
@ -58,12 +58,13 @@ int em_unit(wxWindow* win);
|
|||
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name,
|
||||
const int px_cnt = 16, const bool is_horizontal = false, const bool grayscale = false);
|
||||
|
||||
std::vector<wxBitmap*> get_extruder_color_icons();
|
||||
std::vector<wxBitmap*> get_extruder_color_icons(bool thin_icon = false);
|
||||
void apply_extruder_selector(wxBitmapComboBox** ctrl,
|
||||
wxWindow* parent,
|
||||
const std::string& first_item = "",
|
||||
wxPoint pos = wxDefaultPosition,
|
||||
wxSize size = wxDefaultSize);
|
||||
wxSize size = wxDefaultSize,
|
||||
bool use_thin_icon = false);
|
||||
|
||||
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
|
||||
{
|
||||
|
@ -964,13 +965,13 @@ private:
|
|||
TICK_CODE operator=(const TICK_CODE& other) const {
|
||||
TICK_CODE ret_val(other.tick, other.gcode, other.extruder);
|
||||
return ret_val;
|
||||
}
|
||||
}/*
|
||||
TICK_CODE& operator=(const TICK_CODE& other) {
|
||||
this->tick = other.tick;
|
||||
this->gcode = other.gcode;
|
||||
this->extruder = other.extruder;
|
||||
return *this;
|
||||
}
|
||||
}*/
|
||||
|
||||
int tick;
|
||||
std::string gcode;
|
||||
|
|
Loading…
Reference in a new issue