Fix wx issues from upgrade (#3032)

* fix top bar resizing

* Attempt to fix bitmap bundle scaling issues

* Revert "Attempt to fix bitmap bundle scaling issues"

This reverts commit e94ba58d907b1b2da5a9e27ad552e1d7f1288c18.

* Fix AboutDialog and partially fix SwitchButton

* Fix switch button scaling on windows

* Fix dropdown icon size

* fixed sdcard/recording/timelapse icon size in device page

* Set use_legacy_bmp to true by default to it's back compatible

---------

Co-authored-by: Noisyfox <timemanager.rick@gmail.com>
Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
Ocraftyone 2023-12-21 03:27:02 -05:00 committed by GitHub
parent 401ac1adef
commit 53d752b606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 148 additions and 93 deletions

View file

@ -232,7 +232,7 @@ AboutDialog::AboutDialog()
main_sizer->Add(ver_sizer, 0, wxEXPAND | wxALL, 0);
// logo
m_logo_bitmap = ScalableBitmap(this, "OrcaSlicer_about", 250);
m_logo_bitmap = ScalableBitmap(this, "OrcaSlicer_about", {562,250});
m_logo = new wxStaticBitmap(this, wxID_ANY, m_logo_bitmap.bmp(), wxDefaultPosition,wxDefaultSize, 0);
m_logo->SetSizer(vesizer);

View file

@ -29,6 +29,11 @@ enum CUSTOM_ID
ID_AMS_NOTEBOOK,
};
static bool IsThemeDark()
{
return wxSystemSettings::GetAppearance().IsDark();
}
class BBLTopbarArt : public wxAuiDefaultToolBarArt
{
public:
@ -130,18 +135,18 @@ void BBLTopbarArt::DrawButton(wxDC& dc, wxWindow* wnd, const wxAuiToolBarItem& i
if (item.GetState() & wxAUI_BUTTON_STATE_PRESSED)
{
dc.SetPen(wxPen(m_highlightColour));
dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(20)));
dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(IsThemeDark() ? 20 : 150)));
dc.DrawRectangle(rect);
}
else if ((item.GetState() & wxAUI_BUTTON_STATE_HOVER) || item.IsSticky())
{
dc.SetPen(wxPen(m_highlightColour));
dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(40)));
dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(IsThemeDark() ? 40 : 170)));
// draw an even lighter background for checked item hovers (since
// the hover background is the same color as the check background)
if (item.GetState() & wxAUI_BUTTON_STATE_CHECKED)
dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(50)));
dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(IsThemeDark() ? 50 : 180)));
dc.DrawRectangle(rect);
}
@ -150,7 +155,7 @@ void BBLTopbarArt::DrawButton(wxDC& dc, wxWindow* wnd, const wxAuiToolBarItem& i
// it's important to put this code in an else statement after the
// hover, otherwise hovers won't draw properly for checked items
dc.SetPen(wxPen(m_highlightColour));
dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(40)));
dc.SetBrush(wxBrush(m_highlightColour.ChangeLightness(IsThemeDark() ? 40 : 170)));
dc.DrawRectangle(rect);
}
}
@ -195,23 +200,25 @@ void BBLTopbar::Init(wxFrame* parent)
m_skip_popup_dropdown_menu = false;
m_skip_popup_calib_menu = false;
m_font.Scale(parent->GetDPIScaleFactor());
wxInitAllImageHandlers();
this->AddSpacer(5);
/*wxBitmap logo_bitmap = create_scaled_bitmap("topbar_logo", nullptr, TOPBAR_ICON_SIZE);
/*wxBitmap logo_bitmap = *get_bmp_bundle("topbar_logo", TOPBAR_ICON_SIZE);
wxAuiToolBarItem* logo_item = this->AddTool(ID_LOGO, "", logo_bitmap);
logo_item->SetHoverBitmap(logo_bitmap);
logo_item->SetActive(false);*/
wxBitmap file_bitmap = create_scaled_bitmap("topbar_file", nullptr, TOPBAR_ICON_SIZE);
wxBitmapBundle file_bitmap = *get_bmp_bundle("topbar_file", TOPBAR_ICON_SIZE);
m_file_menu_item = this->AddTool(ID_TOP_FILE_MENU, _L("File"), file_bitmap, wxEmptyString, wxITEM_NORMAL);
this->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
this->AddSpacer(FromDIP(5));
wxBitmap dropdown_bitmap = create_scaled_bitmap("topbar_dropdown", nullptr, TOPBAR_ICON_SIZE);
wxBitmapBundle dropdown_bitmap = *get_bmp_bundle("topbar_dropdown", TOPBAR_ICON_SIZE);
m_dropdown_menu_item = this->AddTool(ID_TOP_DROPDOWN_MENU, "",
dropdown_bitmap, wxEmptyString);
@ -219,32 +226,32 @@ void BBLTopbar::Init(wxFrame* parent)
this->AddSeparator();
this->AddSpacer(FromDIP(5));
//wxBitmap open_bitmap = create_scaled_bitmap("topbar_open", nullptr, TOPBAR_ICON_SIZE);
//wxBitmap open_bitmap = *get_bmp_bundle("topbar_open", TOPBAR_ICON_SIZE);
//wxAuiToolBarItem* tool_item = this->AddTool(wxID_OPEN, "", open_bitmap);
this->AddSpacer(FromDIP(10));
wxBitmap save_bitmap = create_scaled_bitmap("topbar_save", nullptr, TOPBAR_ICON_SIZE);
wxBitmapBundle save_bitmap = *get_bmp_bundle("topbar_save", TOPBAR_ICON_SIZE);
wxAuiToolBarItem* save_btn = this->AddTool(wxID_SAVE, "", save_bitmap);
this->AddSpacer(FromDIP(10));
wxBitmap undo_bitmap = create_scaled_bitmap("topbar_undo", nullptr, TOPBAR_ICON_SIZE);
wxBitmapBundle undo_bitmap = *get_bmp_bundle("topbar_undo", TOPBAR_ICON_SIZE);
m_undo_item = this->AddTool(wxID_UNDO, "", undo_bitmap);
wxBitmap undo_inactive_bitmap = create_scaled_bitmap("topbar_undo_inactive", nullptr, TOPBAR_ICON_SIZE);
wxBitmapBundle undo_inactive_bitmap = *get_bmp_bundle("topbar_undo_inactive", TOPBAR_ICON_SIZE);
m_undo_item->SetDisabledBitmap(undo_inactive_bitmap);
this->AddSpacer(FromDIP(10));
wxBitmap redo_bitmap = create_scaled_bitmap("topbar_redo", nullptr, TOPBAR_ICON_SIZE);
wxBitmapBundle redo_bitmap = *get_bmp_bundle("topbar_redo", TOPBAR_ICON_SIZE);
m_redo_item = this->AddTool(wxID_REDO, "", redo_bitmap);
wxBitmap redo_inactive_bitmap = create_scaled_bitmap("topbar_redo_inactive", nullptr, TOPBAR_ICON_SIZE);
wxBitmapBundle redo_inactive_bitmap = *get_bmp_bundle("topbar_redo_inactive", TOPBAR_ICON_SIZE);
m_redo_item->SetDisabledBitmap(redo_inactive_bitmap);
this->AddSpacer(FromDIP(10));
wxBitmap calib_bitmap = create_scaled_bitmap("calib_sf", nullptr, TOPBAR_ICON_SIZE);
wxBitmap calib_bitmap_inactive = create_scaled_bitmap("calib_sf_inactive", nullptr, TOPBAR_ICON_SIZE);
wxBitmapBundle calib_bitmap = *get_bmp_bundle("calib_sf", TOPBAR_ICON_SIZE);
wxBitmapBundle calib_bitmap_inactive = *get_bmp_bundle("calib_sf_inactive", TOPBAR_ICON_SIZE);
m_calib_item = this->AddTool(ID_CALIB, _L("Calibration"), calib_bitmap);
m_calib_item->SetDisabledBitmap(calib_bitmap_inactive);
@ -257,14 +264,14 @@ void BBLTopbar::Init(wxFrame* parent)
this->AddSpacer(FromDIP(10));
this->AddStretchSpacer(1);
m_publish_bitmap = create_scaled_bitmap("topbar_publish", nullptr, TOPBAR_ICON_SIZE);
m_publish_bitmap = *get_bmp_bundle("topbar_publish", TOPBAR_ICON_SIZE);
m_publish_item = this->AddTool(ID_PUBLISH, "", m_publish_bitmap);
m_publish_disable_bitmap = create_scaled_bitmap("topbar_publish_disable", nullptr, TOPBAR_ICON_SIZE);
m_publish_disable_bitmap = *get_bmp_bundle("topbar_publish_disable", TOPBAR_ICON_SIZE);
m_publish_item->SetDisabledBitmap(m_publish_disable_bitmap);
this->EnableTool(m_publish_item->GetId(), false);
this->AddSpacer(FromDIP(4));
/*wxBitmap model_store_bitmap = create_scaled_bitmap("topbar_store", nullptr, TOPBAR_ICON_SIZE);
/*wxBitmap model_store_bitmap = *get_bmp_bundle("topbar_store", TOPBAR_ICON_SIZE);
m_model_store_item = this->AddTool(ID_MODEL_STORE, "", model_store_bitmap);
this->AddSpacer(12);
*/
@ -272,13 +279,13 @@ void BBLTopbar::Init(wxFrame* parent)
//this->AddSeparator();
this->AddSpacer(FromDIP(4));
wxBitmap iconize_bitmap = create_scaled_bitmap("topbar_min", nullptr, TOPBAR_ICON_SIZE);
wxBitmapBundle iconize_bitmap = *get_bmp_bundle("topbar_min", TOPBAR_ICON_SIZE);
wxAuiToolBarItem* iconize_btn = this->AddTool(wxID_ICONIZE_FRAME, "", iconize_bitmap);
this->AddSpacer(FromDIP(4));
maximize_bitmap = create_scaled_bitmap("topbar_max", nullptr, TOPBAR_ICON_SIZE);
window_bitmap = create_scaled_bitmap("topbar_win", nullptr, TOPBAR_ICON_SIZE);
maximize_bitmap = *get_bmp_bundle("topbar_max", TOPBAR_ICON_SIZE);
window_bitmap = *get_bmp_bundle("topbar_win", TOPBAR_ICON_SIZE);
if (m_frame->IsMaximized()) {
maximize_btn = this->AddTool(wxID_MAXIMIZE_FRAME, "", window_bitmap);
}
@ -288,7 +295,7 @@ void BBLTopbar::Init(wxFrame* parent)
this->AddSpacer(FromDIP(4));
wxBitmap close_bitmap = create_scaled_bitmap("topbar_close", nullptr, TOPBAR_ICON_SIZE);
wxBitmapBundle close_bitmap = *get_bmp_bundle("topbar_close", TOPBAR_ICON_SIZE);
wxAuiToolBarItem* close_btn = this->AddTool(wxID_CLOSE_FRAME, "", close_bitmap);
Realize();
@ -464,49 +471,51 @@ void BBLTopbar::Rescale() {
int em = em_unit(this);
wxAuiToolBarItem* item;
m_font.Scale(m_frame->GetDPIScaleFactor());
/*item = this->FindTool(ID_LOGO);
item->SetBitmap(create_scaled_bitmap("topbar_logo", nullptr, TOPBAR_ICON_SIZE));*/
item->SetBitmap(*get_bmp_bundle("topbar_logo", TOPBAR_ICON_SIZE));*/
item = this->FindTool(ID_TOP_FILE_MENU);
item->SetBitmap(create_scaled_bitmap("topbar_file", this, TOPBAR_ICON_SIZE));
item->SetBitmap(*get_bmp_bundle("topbar_file", TOPBAR_ICON_SIZE));
item = this->FindTool(ID_TOP_DROPDOWN_MENU);
item->SetBitmap(create_scaled_bitmap("topbar_dropdown", this, TOPBAR_ICON_SIZE));
item->SetBitmap(*get_bmp_bundle("topbar_dropdown", TOPBAR_ICON_SIZE));
//item = this->FindTool(wxID_OPEN);
//item->SetBitmap(create_scaled_bitmap("topbar_open", nullptr, TOPBAR_ICON_SIZE));
//item->SetBitmap(*get_bmp_bundle("topbar_open", nullptr, TOPBAR_ICON_SIZE));
item = this->FindTool(wxID_SAVE);
item->SetBitmap(create_scaled_bitmap("topbar_save", this, TOPBAR_ICON_SIZE));
item->SetBitmap(*get_bmp_bundle("topbar_save", TOPBAR_ICON_SIZE));
item = this->FindTool(wxID_UNDO);
item->SetBitmap(create_scaled_bitmap("topbar_undo", this, TOPBAR_ICON_SIZE));
item->SetDisabledBitmap(create_scaled_bitmap("topbar_undo_inactive", nullptr, TOPBAR_ICON_SIZE));
item->SetBitmap(*get_bmp_bundle("topbar_undo", TOPBAR_ICON_SIZE));
item->SetDisabledBitmap(*get_bmp_bundle("topbar_undo_inactive", TOPBAR_ICON_SIZE));
item = this->FindTool(wxID_REDO);
item->SetBitmap(create_scaled_bitmap("topbar_redo", this, TOPBAR_ICON_SIZE));
item->SetDisabledBitmap(create_scaled_bitmap("topbar_redo_inactive", nullptr, TOPBAR_ICON_SIZE));
item->SetBitmap(*get_bmp_bundle("topbar_redo", TOPBAR_ICON_SIZE));
item->SetDisabledBitmap(*get_bmp_bundle("topbar_redo_inactive", TOPBAR_ICON_SIZE));
item = this->FindTool(ID_CALIB);
item->SetBitmap(create_scaled_bitmap("calib_sf", nullptr, TOPBAR_ICON_SIZE));
item->SetDisabledBitmap(create_scaled_bitmap("calib_sf_inactive", nullptr, TOPBAR_ICON_SIZE));
item->SetBitmap(*get_bmp_bundle("calib_sf", TOPBAR_ICON_SIZE));
item->SetDisabledBitmap(*get_bmp_bundle("calib_sf_inactive", TOPBAR_ICON_SIZE));
item = this->FindTool(ID_TITLE);
/*item = this->FindTool(ID_PUBLISH);
item->SetBitmap(create_scaled_bitmap("topbar_publish", this, TOPBAR_ICON_SIZE));
item->SetDisabledBitmap(create_scaled_bitmap("topbar_publish_disable", nullptr, TOPBAR_ICON_SIZE));*/
item->SetBitmap(*get_bmp_bundle("topbar_publish", TOPBAR_ICON_SIZE));
item->SetDisabledBitmap(*get_bmp_bundle("topbar_publish_disable", TOPBAR_ICON_SIZE));*/
/*item = this->FindTool(ID_MODEL_STORE);
item->SetBitmap(create_scaled_bitmap("topbar_store", this, TOPBAR_ICON_SIZE));
item->SetBitmap(*get_bmp_bundle("topbar_store", TOPBAR_ICON_SIZE));
*/
item = this->FindTool(wxID_ICONIZE_FRAME);
item->SetBitmap(create_scaled_bitmap("topbar_min", this, TOPBAR_ICON_SIZE));
item->SetBitmap(*get_bmp_bundle("topbar_min", TOPBAR_ICON_SIZE));
item = this->FindTool(wxID_MAXIMIZE_FRAME);
maximize_bitmap = create_scaled_bitmap("topbar_max", this, TOPBAR_ICON_SIZE);
window_bitmap = create_scaled_bitmap("topbar_win", this, TOPBAR_ICON_SIZE);
maximize_bitmap = *get_bmp_bundle("topbar_max", TOPBAR_ICON_SIZE);
window_bitmap = *get_bmp_bundle("topbar_win", TOPBAR_ICON_SIZE);
if (m_frame->IsMaximized()) {
item->SetBitmap(window_bitmap);
}
@ -515,7 +524,7 @@ void BBLTopbar::Rescale() {
}
item = this->FindTool(wxID_CLOSE_FRAME);
item->SetBitmap(create_scaled_bitmap("topbar_close", this, TOPBAR_ICON_SIZE));
item->SetBitmap(*get_bmp_bundle("topbar_close", TOPBAR_ICON_SIZE));
Realize();
}

View file

@ -75,11 +75,11 @@ private:
wxAuiToolBarItem* m_calib_item;
wxAuiToolBarItem* maximize_btn;
wxBitmap m_publish_bitmap;
wxBitmap m_publish_disable_bitmap;
wxBitmapBundle m_publish_bitmap;
wxBitmapBundle m_publish_disable_bitmap;
wxBitmap maximize_bitmap;
wxBitmap window_bitmap;
wxBitmapBundle maximize_bitmap;
wxBitmapBundle window_bitmap;
int m_toolbar_h;
bool m_skip_popup_file_menu;

View file

@ -913,15 +913,15 @@ void StatusBasePanel::init_bitmaps()
m_bitmap_extruder_empty_unload = *cache.load_png("monitor_extruder_empty_unload", FromDIP(28), FromDIP(70), false, false);
m_bitmap_extruder_filled_unload = *cache.load_png("monitor_extruder_filled_unload", FromDIP(28), FromDIP(70), false, false);
m_bitmap_sdcard_state_abnormal = ScalableBitmap(this, wxGetApp().dark_mode() ? "sdcard_state_abnormal_dark" : "sdcard_state_abnormal", 20);
m_bitmap_sdcard_state_normal = ScalableBitmap(this, wxGetApp().dark_mode() ? "sdcard_state_normal_dark" : "sdcard_state_normal", 20);
m_bitmap_sdcard_state_no = ScalableBitmap(this, wxGetApp().dark_mode() ? "sdcard_state_no_dark" : "sdcard_state_no", 20);
m_bitmap_recording_on = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_recording_on_dark" : "monitor_recording_on", 20);
m_bitmap_recording_off = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_recording_off_dark" : "monitor_recording_off", 20);
m_bitmap_timelapse_on = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_timelapse_on_dark" : "monitor_timelapse_on", 20);
m_bitmap_timelapse_off = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_timelapse_off_dark" : "monitor_timelapse_off", 20);
m_bitmap_vcamera_on = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_vcamera_on_dark" : "monitor_vcamera_on", 20);
m_bitmap_vcamera_off = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_vcamera_off_dark" : "monitor_vcamera_off", 20);
m_bitmap_sdcard_state_abnormal = ScalableBitmap(this, wxGetApp().dark_mode() ? "sdcard_state_abnormal_dark" : "sdcard_state_abnormal",{38, 20});
m_bitmap_sdcard_state_normal = ScalableBitmap(this, wxGetApp().dark_mode() ? "sdcard_state_normal_dark" : "sdcard_state_normal", {38, 20});
m_bitmap_sdcard_state_no = ScalableBitmap(this, wxGetApp().dark_mode() ? "sdcard_state_no_dark" : "sdcard_state_no", {38, 20});
m_bitmap_recording_on = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_recording_on_dark" : "monitor_recording_on", {38, 20});
m_bitmap_recording_off = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_recording_off_dark" : "monitor_recording_off", {38, 20});
m_bitmap_timelapse_on = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_timelapse_on_dark" : "monitor_timelapse_on", {38, 20});
m_bitmap_timelapse_off = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_timelapse_off_dark" : "monitor_timelapse_off", {38, 20});
m_bitmap_vcamera_on = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_vcamera_on_dark" : "monitor_vcamera_on", {38, 20});
m_bitmap_vcamera_off = ScalableBitmap(this, wxGetApp().dark_mode() ? "monitor_vcamera_off_dark" : "monitor_vcamera_off", {38, 20});
}
@ -4001,15 +4001,15 @@ void StatusPanel::rescale_camera_icons()
m_setting_button->msw_rescale();
m_bitmap_sdcard_state_abnormal = ScalableBitmap(this, wxGetApp().dark_mode()?"sdcard_state_abnormal_dark":"sdcard_state_abnormal", 20);
m_bitmap_sdcard_state_normal = ScalableBitmap(this, wxGetApp().dark_mode()?"sdcard_state_normal_dark":"sdcard_state_normal", 20);
m_bitmap_sdcard_state_no = ScalableBitmap(this, wxGetApp().dark_mode()?"sdcard_state_no_dark":"sdcard_state_no", 20);
m_bitmap_recording_on = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_recording_on_dark":"monitor_recording_on", 20);
m_bitmap_recording_off = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_recording_off_dark":"monitor_recording_off", 20);
m_bitmap_timelapse_on = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_timelapse_on_dark":"monitor_timelapse_on", 20);
m_bitmap_timelapse_off = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_timelapse_off_dark":"monitor_timelapse_off", 20);
m_bitmap_vcamera_on = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_vcamera_on_dark":"monitor_vcamera_on", 20);
m_bitmap_vcamera_off = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_vcamera_off_dark":"monitor_vcamera_off", 20);
m_bitmap_sdcard_state_abnormal = ScalableBitmap(this, wxGetApp().dark_mode()?"sdcard_state_abnormal_dark":"sdcard_state_abnormal", {38, 20});
m_bitmap_sdcard_state_normal = ScalableBitmap(this, wxGetApp().dark_mode()?"sdcard_state_normal_dark":"sdcard_state_normal", {38, 20});
m_bitmap_sdcard_state_no = ScalableBitmap(this, wxGetApp().dark_mode()?"sdcard_state_no_dark":"sdcard_state_no", {38, 20});
m_bitmap_recording_on = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_recording_on_dark":"monitor_recording_on", {38, 20});
m_bitmap_recording_off = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_recording_off_dark":"monitor_recording_off", {38, 20});
m_bitmap_timelapse_on = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_timelapse_on_dark":"monitor_timelapse_on", {38, 20});
m_bitmap_timelapse_off = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_timelapse_off_dark":"monitor_timelapse_off", {38, 20});
m_bitmap_vcamera_on = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_vcamera_on_dark":"monitor_vcamera_on", {38, 20});
m_bitmap_vcamera_off = ScalableBitmap(this, wxGetApp().dark_mode()?"monitor_vcamera_off_dark":"monitor_vcamera_off", {38, 20});
if (m_media_play_ctrl->IsStreaming()) {
m_bitmap_vcamera_img->SetBitmap(m_bitmap_vcamera_on.bmp());

View file

@ -9,8 +9,8 @@
SwitchButton::SwitchButton(wxWindow* parent, wxWindowID id)
: wxBitmapToggleButton(parent, id, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxBU_EXACTFIT)
, m_on(this, "toggle_on", 16, false, false, true)
, m_off(this, "toggle_off", 16, false, false, true)
, m_on(this, "toggle_on", {28, 16})
, m_off(this, "toggle_off", {28, 16})
, text_color(std::pair{0xfffffe, (int) StateColor::Checked}, std::pair{0x6B6B6B, (int) StateColor::Normal})
, track_color(0xD9D9D9)
, thumb_color(std::pair{0x009688, (int) StateColor::Checked}, std::pair{0xD9D9D9, (int) StateColor::Normal})
@ -101,7 +101,8 @@ void SwitchButton::Rescale()
for (int i = 0; i < 2; ++i) {
wxMemoryDC memdc(&dc);
#ifdef __WXMSW__
wxBitmap bmp(trackSize.x, trackSize.y);
wxBitmap bmp;
bmp.CreateWithDIPSize(ToDIP(trackSize), GetDPIScaleFactor());
memdc.SelectObject(bmp);
memdc.SetBackground(wxBrush(GetBackgroundColour()));
memdc.Clear();
@ -145,4 +146,5 @@ void SwitchButton::Rescale()
void SwitchButton::update()
{
SetBitmap((GetValue() ? m_on : m_off).bmp());
}

View file

@ -76,7 +76,7 @@ void TextInput::Create(wxWindow * parent,
});
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu
if (!icon.IsEmpty()) {
this->icon = ScalableBitmap(this, icon.ToStdString(), 16);
this->drop_down_icon = ScalableBitmap(this, icon.ToStdString(), 16);
}
messureSize();
}
@ -96,9 +96,7 @@ void TextInput::SetLabel(const wxString& label)
void TextInput::SetIcon(const wxBitmapBundle &icon_in)
{
this->icon = ScalableBitmap();
this->icon.bmp() = icon_in;
Rescale();
icon = icon_in;
}
void TextInput::SetLabelColor(StateColor const &color)
@ -115,8 +113,9 @@ void TextInput::SetTextColor(StateColor const& color)
void TextInput::Rescale()
{
if (!this->icon.name().empty())
this->icon.sys_color_changed();
if (text_ctrl)
text_ctrl->SetInitialSize(text_ctrl->GetBestSize());
messureSize();
Refresh();
}
@ -152,16 +151,22 @@ void TextInput::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if (sizeFlags & wxSIZE_USE_EXISTING) return;
wxSize size = GetSize();
wxPoint textPos = {5, 0};
if (this->icon.bmp().IsOk()) {
wxSize szIcon = this->icon.GetSize();
if (this->icon.IsOk()) {
wxSize szIcon = get_preferred_size(icon, m_parent);
textPos.x += szIcon.x;
}
wxSize dd_icon_size = wxSize(0,0);
if (this->drop_down_icon.bmp().IsOk())
dd_icon_size = this->drop_down_icon.GetSize();
bool align_right = GetWindowStyle() & wxRIGHT;
if (align_right)
textPos.x += labelSize.x;
if (text_ctrl) {
wxSize textSize = text_ctrl->GetSize();
textSize.x = size.x - textPos.x - labelSize.x - 10;
wxClientDC dc(this);
const int r_shift = int((dd_icon_size.x == 0 ? 3. : 2.) * dc.GetContentScaleFactor());
textSize.x = size.x - textPos.x - labelSize.x - dd_icon_size.x - r_shift;
text_ctrl->SetSize(textSize);
text_ctrl->SetPosition({textPos.x, (size.y - textSize.y) / 2});
}
@ -193,12 +198,26 @@ void TextInput::render(wxDC& dc)
bool align_right = GetWindowStyle() & wxRIGHT;
// start draw
wxPoint pt = {5, 0};
if (icon.bmp().IsOk()) {
wxSize szIcon = get_preferred_size(icon.bmp(), m_parent);
if (icon.IsOk()) {
wxSize szIcon = get_preferred_size(icon, m_parent);
pt.y = (size.y - szIcon.y) / 2;
dc.DrawBitmap(icon.get_bitmap(), pt);
#ifdef __WXGTK3__
dc.DrawBitmap(icon.GetBitmap(szIcon), pt);
#else
dc.DrawBitmap(icon.GetBitmapFor(m_parent), pt);
#endif
pt.x += szIcon.x + 0;
}
// drop_down_icon draw
wxPoint pt_r = {size.x, 0};
if (drop_down_icon.bmp().IsOk()) {
wxSize szIcon = drop_down_icon.GetSize();
pt_r.x -= szIcon.x + 2;
pt_r.y = (size.y - szIcon.y) / 2;
dc.DrawBitmap(drop_down_icon.get_bitmap(), pt_r);
}
auto text = wxWindow::GetLabel();
if (!text.IsEmpty()) {
wxSize textSize = text_ctrl->GetSize();

View file

@ -8,10 +8,11 @@ class TextInput : public wxNavigationEnabled<StaticBox>
{
wxSize labelSize;
ScalableBitmap icon;
wxBitmapBundle icon;
ScalableBitmap drop_down_icon;
StateColor label_color;
StateColor text_color;
wxTextCtrl * text_ctrl;
wxTextCtrl* text_ctrl{nullptr};
static const int TextInputWidth = 200;
static const int TextInputHeight = 50;

View file

@ -413,17 +413,26 @@ static int scale()
}
#endif // __WXGTK2__
wxBitmapBundle* get_bmp_bundle(const std::string& bmp_name_in, int px_cnt/* = 16*/)
wxBitmapBundle* get_bmp_bundle(const std::string& bmp_name_in, int width/* = 16*/, int height/* = -1*/)
{
#ifdef __WXGTK2__
width *= scale();
if (height > 0)
height *= scale();
#endif // __WXGTK2__
static Slic3r::GUI::BitmapCache cache;
std::string bmp_name = bmp_name_in;
boost::replace_last(bmp_name, ".png", "");
if (height < 0)
height = width;
// Try loading an SVG first, then PNG if SVG is not found:
wxBitmapBundle* bmp = cache.from_svg(bmp_name, px_cnt, px_cnt, Slic3r::GUI::wxGetApp().dark_mode());
wxBitmapBundle* bmp = cache.from_svg(bmp_name, width, height, Slic3r::GUI::wxGetApp().dark_mode());
if (bmp == nullptr) {
bmp = cache.from_png(bmp_name, px_cnt, px_cnt);
bmp = cache.from_png(bmp_name, width, height);
if (!bmp)
// Neither SVG nor PNG has been found, raise error
throw Slic3r::RuntimeError("Could not load bitmap: " + bmp_name);
@ -887,7 +896,7 @@ ScalableBitmap::ScalableBitmap( wxWindow *parent,
const bool resize/* = false*/,
const bool use_legacy_bmp/* = false*/):
m_parent(parent), m_icon_name(icon_name), m_legacy_bmp(use_legacy_bmp),
m_px_cnt(px_cnt), m_grayscale(grayscale), m_resize(resize) // BBS: support resize by fill border
m_size({px_cnt, px_cnt}), m_grayscale(grayscale), m_resize(resize) // BBS: support resize by fill border
{
// Orca: there is currently an issue causing the advanced SwitchButton to not scale properly
// when using get_bmp_bundle. This allows for the older method of getting a scaled bitmap to be
@ -895,8 +904,8 @@ ScalableBitmap::ScalableBitmap( wxWindow *parent,
if (m_legacy_bmp) {
m_bmp = create_scaled_bitmap(icon_name, parent, px_cnt, m_grayscale, std::string(), false, resize);
if (px_cnt == 0) {
m_px_cnt = GetHeight(); // scale
unsigned int height = (unsigned int) (parent->FromDIP(m_px_cnt) + 0.5f);
m_size.x = m_size.y = GetHeight(); // scale
unsigned int height = (unsigned int) (parent->FromDIP(px_cnt) + 0.5f);
if (height != GetHeight())
sys_color_changed();
}
@ -905,14 +914,24 @@ ScalableBitmap::ScalableBitmap( wxWindow *parent,
}
}
ScalableBitmap::ScalableBitmap( wxWindow *parent,
const std::string& icon_name,
const wxSize size,
const bool grayscale/* = false*/,
const bool resize/* = false*/):
m_parent(parent), m_icon_name(icon_name),
m_size(size), m_grayscale(grayscale), m_resize(resize) // BBS: support resize by fill border
{
m_bmp = *get_bmp_bundle(icon_name, size.x, size.y);
}
void ScalableBitmap::sys_color_changed()
{
if (m_legacy_bmp) {
// BBS: support resize by fill border
m_bmp = create_scaled_bitmap(m_icon_name, m_parent, m_px_cnt, m_grayscale, std::string(), false, m_resize);
m_bmp = create_scaled_bitmap(m_icon_name, m_parent, m_size.x, m_grayscale, std::string(), false, m_resize);
} else
m_bmp = *get_bmp_bundle(m_icon_name, m_px_cnt);
m_bmp = *get_bmp_bundle(m_icon_name, m_size.x, m_size.y);
}
// ----------------------------------------------------------------------------

View file

@ -55,7 +55,7 @@ void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector<
int em_unit(wxWindow* win);
int mode_icon_px_size();
wxBitmapBundle* get_bmp_bundle(const std::string& bmp_name, int px_cnt = 16);
wxBitmapBundle* get_bmp_bundle(const std::string& bmp_name, int width = 16, int height = -1);
wxBitmapBundle* get_empty_bmp_bundle(int width, int height);
wxBitmapBundle* get_solid_bmp_bundle(int width, int height, const std::string& color);
@ -169,8 +169,13 @@ public:
const std::string& icon_name = "",
const int px_cnt = 16,
const bool grayscale = false,
const bool resize = false, // BBS: support resize by fill border
const bool use_legacy_bmp = false);
const bool resize = false,
const bool use_legacy_bmp = true);
ScalableBitmap( wxWindow *parent,
const std::string& icon_name,
const wxSize size,
const bool grayscale = false,
const bool resize = false);
~ScalableBitmap() {}
@ -183,7 +188,7 @@ public:
wxBitmap get_bitmap() const { return m_bmp.GetBitmapFor(m_parent); }
wxWindow* parent() const { return m_parent;}
const std::string& name() const{ return m_icon_name; }
int px_cnt() const { return m_px_cnt; }
int px_cnt() const { return m_size.x; }
wxSize GetSize() const {
#ifdef __WIN32__
@ -199,7 +204,7 @@ private:
wxWindow* m_parent{ nullptr };
wxBitmapBundle m_bmp = wxBitmapBundle();
std::string m_icon_name = "";
int m_px_cnt {16};
wxSize m_size {16, 16};
bool m_grayscale{ false };
bool m_resize{ false };
bool m_legacy_bmp{ false };