Skip to content

Commit

Permalink
Fix AboutDialog and partially fix SwitchButton
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocraftyone committed Dec 7, 2023
1 parent 72d80de commit 78f1e21
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/slic3r/GUI/AboutDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions src/slic3r/GUI/Widgets/SwitchButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -145,4 +145,5 @@ void SwitchButton::Rescale()
void SwitchButton::update()
{
SetBitmap((GetValue() ? m_on : m_off).bmp());

}
35 changes: 27 additions & 8 deletions src/slic3r/GUI/wxExtensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -887,16 +896,16 @@ 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
// used in this edge case while the underlying issue is determined.
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();
}
Expand All @@ -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);
}

// ----------------------------------------------------------------------------
Expand Down
11 changes: 8 additions & 3 deletions src/slic3r/GUI/wxExtensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -171,6 +171,11 @@ class ScalableBitmap
const bool grayscale = false,
const bool resize = false, // BBS: support resize by fill border
const bool use_legacy_bmp = false);
ScalableBitmap( wxWindow *parent,
const std::string& icon_name,
const wxSize size,
const bool grayscale = false,
const bool resize = false);

~ScalableBitmap() {}

Expand All @@ -183,7 +188,7 @@ class ScalableBitmap
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__
Expand All @@ -199,7 +204,7 @@ class ScalableBitmap
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 };
Expand Down

0 comments on commit 78f1e21

Please sign in to comment.