update ScalableBitmap to use bmp bundles

use wxBitmapBundle by default
add flag to use old scaled bitmap function (specifically to solve issue with advanced toggle)
This commit is contained in:
Ocraftyone 2023-11-23 05:05:13 -05:00
parent 7f83f460e1
commit 8a0b3953ed
No known key found for this signature in database
GPG key ID: 85836ED21AD4D125
3 changed files with 27 additions and 21 deletions

View file

@ -9,8 +9,8 @@
SwitchButton::SwitchButton(wxWindow* parent, wxWindowID id) SwitchButton::SwitchButton(wxWindow* parent, wxWindowID id)
: wxBitmapToggleButton(parent, id, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxBU_EXACTFIT) : wxBitmapToggleButton(parent, id, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxBU_EXACTFIT)
, m_on(this, "toggle_on", 16) , m_on(this, "toggle_on", 16, false, false, true)
, m_off(this, "toggle_off", 16) , m_off(this, "toggle_off", 16, false, false, true)
, text_color(std::pair{0xfffffe, (int) StateColor::Checked}, std::pair{0x6B6B6B, (int) StateColor::Normal}) , text_color(std::pair{0xfffffe, (int) StateColor::Checked}, std::pair{0x6B6B6B, (int) StateColor::Normal})
, track_color(0xD9D9D9) , track_color(0xD9D9D9)
, thumb_color(std::pair{0x009688, (int) StateColor::Checked}, std::pair{0xD9D9D9, (int) StateColor::Normal}) , thumb_color(std::pair{0x009688, (int) StateColor::Checked}, std::pair{0xD9D9D9, (int) StateColor::Normal})

View file

@ -865,29 +865,35 @@ ScalableBitmap::ScalableBitmap( wxWindow *parent,
const std::string& icon_name/* = ""*/, const std::string& icon_name/* = ""*/,
const int px_cnt/* = 16*/, const int px_cnt/* = 16*/,
const bool grayscale/* = false*/, const bool grayscale/* = false*/,
const bool resize/* = false*/): const bool resize/* = false*/,
m_parent(parent), m_icon_name(icon_name), 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_px_cnt(px_cnt), m_grayscale(grayscale), m_resize(resize) // BBS: support resize by fill border
{ {
m_bmp = create_scaled_bitmap(icon_name, parent, px_cnt, m_grayscale, std::string(), false, resize); // Orca: there is currently an issue causing the advanced SwitchButton to not scale properly
if (px_cnt == 0) { // when using get_bmp_bundle. This allows for the older method of getting a scaled bitmap to be
m_px_cnt = GetHeight(); // scale // used in this edge case while the underlying issue is determined.
unsigned int height = (unsigned int) (parent->FromDIP(m_px_cnt) + 0.5f); if (m_legacy_bmp) {
if (height != GetHeight()) m_bmp = create_scaled_bitmap(icon_name, parent, px_cnt, m_grayscale, std::string(), false, resize);
sys_color_changed(); if (px_cnt == 0) {
m_px_cnt = GetHeight(); // scale
unsigned int height = (unsigned int) (parent->FromDIP(m_px_cnt) + 0.5f);
if (height != GetHeight())
sys_color_changed();
}
} else {
m_bmp = *get_bmp_bundle(icon_name, px_cnt);
} }
//OcraftyoneTODO: PS replaces this function body with the following code
// m_bmp = *get_bmp_bundle(icon_name, px_cnt);
// m_bitmap = m_bmp.GetBitmapFor(parent);
} }
void ScalableBitmap::sys_color_changed() void ScalableBitmap::sys_color_changed()
{ {
if (m_legacy_bmp) {
// BBS: support resize by fill border // 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_px_cnt, m_grayscale, std::string(), false, m_resize);
// m_bmp = *get_bmp_bundle(m_icon_name, m_px_cnt); // OcraftyoneTODO: enabling this causes issues with advanced toggle } else
m_bmp = *get_bmp_bundle(m_icon_name, m_px_cnt);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -912,8 +918,7 @@ ScalableButton::ScalableButton( wxWindow * parent,
Slic3r::GUI::wxGetApp().UpdateDarkUI(this); Slic3r::GUI::wxGetApp().UpdateDarkUI(this);
if (!icon_name.empty()) { if (!icon_name.empty()) {
SetBitmap(create_scaled_bitmap(icon_name, parent, m_px_cnt)); SetBitmap(*get_bmp_bundle(icon_name, m_px_cnt));
// SetBitmap(*get_bmp_bundle(icon_name, m_px_cnt));
if (!label.empty()) if (!label.empty())
SetBitmapMargins(int(0.5* em_unit(parent)), 0); SetBitmapMargins(int(0.5* em_unit(parent)), 0);
} }

View file

@ -167,9 +167,10 @@ public:
ScalableBitmap() {}; ScalableBitmap() {};
ScalableBitmap( wxWindow *parent, ScalableBitmap( wxWindow *parent,
const std::string& icon_name = "", const std::string& icon_name = "",
const int px_cnt = 16, const int px_cnt = 16,
const bool grayscale = false, const bool grayscale = false,
const bool resize = false); // BBS: support resize by fill border const bool resize = false, // BBS: support resize by fill border
const bool use_legacy_bmp = false);
~ScalableBitmap() {} ~ScalableBitmap() {}
@ -197,11 +198,11 @@ public:
private: private:
wxWindow* m_parent{ nullptr }; wxWindow* m_parent{ nullptr };
wxBitmapBundle m_bmp = wxBitmapBundle(); wxBitmapBundle m_bmp = wxBitmapBundle();
wxBitmap m_bitmap = wxBitmap();
std::string m_icon_name = ""; std::string m_icon_name = "";
int m_px_cnt {16}; int m_px_cnt {16};
bool m_grayscale{ false }; bool m_grayscale{ false };
bool m_resize{ false }; bool m_resize{ false };
bool m_legacy_bmp{ false };
}; };