mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-11 02:57:39 +00:00
Add filament color next to tab button in filament setting
This commit is contained in:
@@ -505,8 +505,10 @@ size_t PublishSettingsDialog::category_index_for(const wxString& title,
|
||||
if (const auto* colours = full.opt<ConfigOptionStrings>("filament_colour"))
|
||||
if (source_index < colours->size())
|
||||
hex = colours->get_at(source_index);
|
||||
if (wxBitmap* chip = get_extruder_color_icon(hex, "", FromDIP(12), FromDIP(12)))
|
||||
header_sizer->Add(new wxStaticBitmap(category.page, wxID_ANY, *chip), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(4));
|
||||
if (wxBitmap* chip = get_extruder_color_icon(hex, "", FromDIP(12), FromDIP(12))) {
|
||||
category.filament_color_chip = new wxStaticBitmap(category.page, wxID_ANY, *chip);
|
||||
header_sizer->Add(category.filament_color_chip, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(4));
|
||||
}
|
||||
category.master_check = new wxCheckBox(category.page, wxID_ANY, title);
|
||||
category.master_check->SetFont(Label::Head_14);
|
||||
category.master_check->SetToolTip(_L("Export this material"));
|
||||
@@ -535,7 +537,19 @@ size_t PublishSettingsDialog::category_index_for(const wxString& title,
|
||||
const size_t category_index = m_categories.size();
|
||||
m_categories.push_back(std::move(category));
|
||||
m_sections[group].categories.push_back(category_index);
|
||||
m_sections[group].tabs->AppendItem(title);
|
||||
if (section == Section::Material) {
|
||||
std::string hex;
|
||||
const DynamicPrintConfig full = wxGetApp().preset_bundle->full_config();
|
||||
if (const auto* colours = full.opt<ConfigOptionStrings>("filament_colour"))
|
||||
if (source_index < colours->size())
|
||||
hex = colours->get_at(source_index);
|
||||
if (wxBitmap* chip = get_extruder_color_icon(hex, "", FromDIP(12), FromDIP(12)))
|
||||
m_sections[group].tabs->AppendItem(title, *chip);
|
||||
else
|
||||
m_sections[group].tabs->AppendItem(title);
|
||||
} else {
|
||||
m_sections[group].tabs->AppendItem(title);
|
||||
}
|
||||
m_sections[group].page_host_sizer->Add(m_categories[category_index].page, 1, wxEXPAND);
|
||||
if (m_sections[group].selected_inner < 0)
|
||||
m_sections[group].selected_inner = 0;
|
||||
@@ -971,6 +985,15 @@ void PublishSettingsDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||
cat.header->Refresh();
|
||||
if (cat.master_check != nullptr)
|
||||
cat.master_check->Refresh();
|
||||
if (cat.filament_color_chip != nullptr) {
|
||||
std::string hex;
|
||||
const DynamicPrintConfig full = wxGetApp().preset_bundle->full_config();
|
||||
if (const auto* colours = full.opt<ConfigOptionStrings>("filament_colour"))
|
||||
if (cat.filament_slot < colours->size())
|
||||
hex = colours->get_at(cat.filament_slot);
|
||||
if (wxBitmap* chip = get_extruder_color_icon(hex, "", FromDIP(12), FromDIP(12)))
|
||||
cat.filament_color_chip->SetBitmap(*chip);
|
||||
}
|
||||
cat.scroll->FitInside();
|
||||
cat.list_sizer->Layout();
|
||||
}
|
||||
@@ -978,6 +1001,23 @@ void PublishSettingsDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||
for (SectionGroup& section : m_sections)
|
||||
section.tabs->Rescale();
|
||||
|
||||
const DynamicPrintConfig full = wxGetApp().preset_bundle->full_config();
|
||||
for (size_t category_index = 0; category_index < m_categories.size(); ++category_index) {
|
||||
const Category& category = m_categories[category_index];
|
||||
if (category.section != Section::Material)
|
||||
continue;
|
||||
std::string hex;
|
||||
if (const auto* colours = full.opt<ConfigOptionStrings>("filament_colour"))
|
||||
if (category.filament_slot < colours->size())
|
||||
hex = colours->get_at(category.filament_slot);
|
||||
if (wxBitmap* chip = get_extruder_color_icon(hex, "", FromDIP(12), FromDIP(12))) {
|
||||
const SectionGroup& section = m_sections[category.group];
|
||||
const auto iter = std::find(section.categories.begin(), section.categories.end(), category_index);
|
||||
if (iter != section.categories.end())
|
||||
m_sections[category.group].tabs->SetItemBitmap(static_cast<unsigned int>(iter - section.categories.begin()), *chip);
|
||||
}
|
||||
}
|
||||
|
||||
SetMinSize(FromDIP(wxSize(600, 500)));
|
||||
Refresh();
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ private:
|
||||
wxPoint scroll_pos{0, 0};
|
||||
ScalableBitmap icon_bmp; // scalable bitmap for DPI changes
|
||||
wxStaticBitmap* icon{nullptr};
|
||||
wxStaticBitmap* filament_color_chip{nullptr};
|
||||
wxCheckBox* header{nullptr}; // material select-all tri-state; null for Printer/Process
|
||||
// Material opt-in: the master checkbox carries the material title and
|
||||
// gates whether this material's keys may be exported.
|
||||
|
||||
@@ -80,6 +80,7 @@ bool Button::SetFont(const wxFont& font)
|
||||
|
||||
void Button::SetIcon(const wxString& icon)
|
||||
{
|
||||
custom_icon = wxNullBitmap;
|
||||
auto tmpBitmap = ScalableBitmap(this, icon.ToStdString(), this->active_icon.px_cnt());
|
||||
if (!icon.IsEmpty()) {
|
||||
//BBS set button icon default size to 20
|
||||
@@ -95,6 +96,13 @@ void Button::SetIcon(const wxString& icon)
|
||||
}
|
||||
}
|
||||
|
||||
void Button::SetBitmap(const wxBitmap& bitmap)
|
||||
{
|
||||
custom_icon = bitmap;
|
||||
messureSize();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void Button::SetInactiveIcon(const wxString &icon)
|
||||
{
|
||||
if (!icon.IsEmpty()) {
|
||||
@@ -311,7 +319,8 @@ void Button::render(wxDC& dc)
|
||||
}
|
||||
}
|
||||
auto szContent = textSize;
|
||||
if (icon.bmp().IsOk()) {
|
||||
const bool has_custom_icon = custom_icon.IsOk();
|
||||
if (has_custom_icon || icon.bmp().IsOk()) {
|
||||
if (szContent.y > 0) {
|
||||
//BBS norrow size between text and icon
|
||||
if (vertical)
|
||||
@@ -319,7 +328,7 @@ void Button::render(wxDC& dc)
|
||||
else
|
||||
szContent.x += spacing;
|
||||
}
|
||||
szIcon = icon.GetBmpSize();
|
||||
szIcon = has_custom_icon ? custom_icon.GetSize() : icon.GetBmpSize();
|
||||
if (vertical) {
|
||||
szContent.y += szIcon.y;
|
||||
if (szIcon.x > szContent.x) szContent.x = szIcon.x;
|
||||
@@ -342,12 +351,12 @@ void Button::render(wxDC& dc)
|
||||
}
|
||||
// start draw
|
||||
wxPoint pt = rcContent.GetLeftTop();
|
||||
if (icon.bmp().IsOk()) {
|
||||
if (has_custom_icon || icon.bmp().IsOk()) {
|
||||
if (vertical)
|
||||
pt.x += (rcContent.width - szIcon.x) / 2;
|
||||
else
|
||||
pt.y += (rcContent.height - szIcon.y) / 2;
|
||||
dc.DrawBitmap(icon.bmp(), pt);
|
||||
dc.DrawBitmap(has_custom_icon ? custom_icon : icon.bmp(), pt);
|
||||
//BBS norrow size between text and icon
|
||||
if (vertical) {
|
||||
pt.y += szIcon.y + spacing;
|
||||
@@ -380,7 +389,7 @@ void Button::messureSize()
|
||||
wxClientDC dc(this);
|
||||
dc.GetTextExtent(GetLabel(), &textSize.width, &textSize.height, &textSize.x, &textSize.y);
|
||||
wxSize szContent = textSize.GetSize();
|
||||
if (this->active_icon.bmp().IsOk()) {
|
||||
if (custom_icon.IsOk() || this->active_icon.bmp().IsOk()) {
|
||||
if (szContent.y > 0) {
|
||||
//BBS norrow size between text and icon
|
||||
if (vertical)
|
||||
@@ -388,7 +397,7 @@ void Button::messureSize()
|
||||
else
|
||||
szContent.x += 5;
|
||||
}
|
||||
wxSize szIcon = this->active_icon.GetBmpSize();
|
||||
wxSize szIcon = custom_icon.IsOk() ? custom_icon.GetSize() : this->active_icon.GetBmpSize();
|
||||
if (vertical) {
|
||||
szContent.y += szIcon.y;
|
||||
if (szIcon.x > szContent.x) szContent.x = szIcon.x;
|
||||
|
||||
@@ -35,6 +35,7 @@ class Button : public StaticBox
|
||||
wxSize paddingSize;
|
||||
ScalableBitmap active_icon;
|
||||
ScalableBitmap inactive_icon;
|
||||
wxBitmap custom_icon;
|
||||
|
||||
StateColor text_color;
|
||||
|
||||
@@ -61,6 +62,7 @@ public:
|
||||
bool SetFont(const wxFont& font) override;
|
||||
|
||||
void SetIcon(const wxString& icon);
|
||||
void SetBitmap(const wxBitmap& bitmap);
|
||||
|
||||
void SetInactiveIcon(const wxString& icon);
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ void TabCtrl::Rescale()
|
||||
{
|
||||
for (auto & b : btns)
|
||||
b->Rescale();
|
||||
relayout();
|
||||
}
|
||||
|
||||
bool TabCtrl::SetFont(wxFont const& font)
|
||||
@@ -117,6 +118,13 @@ int TabCtrl::AppendItem(const wxString &item,
|
||||
return btns.size() - 1;
|
||||
}
|
||||
|
||||
int TabCtrl::AppendItem(const wxString& item, const wxBitmap& bitmap, void* clientData)
|
||||
{
|
||||
const int index = AppendItem(item, -1, -1, clientData);
|
||||
SetItemBitmap(index, bitmap);
|
||||
return index;
|
||||
}
|
||||
|
||||
bool TabCtrl::DeleteItem(int item)
|
||||
{
|
||||
if (item < 0 || item >= btns.size()) {
|
||||
@@ -170,6 +178,14 @@ void TabCtrl::SetItemText(unsigned int item, wxString const &value)
|
||||
btns[item]->SetLabel(value);
|
||||
}
|
||||
|
||||
void TabCtrl::SetItemBitmap(unsigned int item, const wxBitmap& bitmap)
|
||||
{
|
||||
if (item >= btns.size())
|
||||
return;
|
||||
btns[item]->SetBitmap(bitmap);
|
||||
relayout();
|
||||
}
|
||||
|
||||
bool TabCtrl::GetItemBold(unsigned int item) const
|
||||
{
|
||||
if (item >= btns.size()) return false;
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
|
||||
public:
|
||||
int AppendItem(const wxString &item, int image = -1, int selImage = -1, void *clientData = nullptr);
|
||||
int AppendItem(const wxString &item, const wxBitmap& bitmap, void *clientData = nullptr);
|
||||
|
||||
bool DeleteItem(int item);
|
||||
|
||||
@@ -46,6 +47,7 @@ public:
|
||||
|
||||
wxString GetItemText(unsigned int item) const;
|
||||
void SetItemText(unsigned int item, wxString const &value);
|
||||
void SetItemBitmap(unsigned int item, const wxBitmap& bitmap);
|
||||
|
||||
bool GetItemBold(unsigned int item) const;
|
||||
void SetItemBold(unsigned int item, bool bold);
|
||||
|
||||
Reference in New Issue
Block a user