Some improvements for a loading of icons
This commit is contained in:
parent
a9223aeb5f
commit
ef5281c3c9
5 changed files with 40 additions and 20 deletions
|
@ -178,9 +178,11 @@ wxBitmap* BitmapCache::insert_raw_rgba(const std::string &bitmap_key, unsigned i
|
|||
return this->insert(bitmap_key, wxImage_to_wxBitmap_with_alpha(std::move(image)));
|
||||
}
|
||||
|
||||
wxBitmap* BitmapCache::load_png(const std::string &bitmap_name, unsigned int height)
|
||||
wxBitmap* BitmapCache::load_png(const std::string &bitmap_name, unsigned int width, unsigned int height)
|
||||
{
|
||||
std::string bitmap_key = bitmap_name + "-h" + std::to_string(height);
|
||||
std::string bitmap_key = bitmap_name + ( height !=0 ?
|
||||
"-h" + std::to_string(height) :
|
||||
"-w" + std::to_string(width));
|
||||
auto it = m_map.find(bitmap_key);
|
||||
if (it != m_map.end())
|
||||
return it->second;
|
||||
|
@ -189,14 +191,23 @@ wxBitmap* BitmapCache::load_png(const std::string &bitmap_name, unsigned int hei
|
|||
if (! image.LoadFile(Slic3r::GUI::from_u8(Slic3r::var(bitmap_name + ".png")), wxBITMAP_TYPE_PNG) ||
|
||||
image.GetWidth() == 0 || image.GetHeight() == 0)
|
||||
return nullptr;
|
||||
if (image.GetHeight() != height)
|
||||
image.Rescale(int(0.5f + float(image.GetWidth()) * height / image.GetHeight()), height, wxIMAGE_QUALITY_BILINEAR);
|
||||
|
||||
if (height != 0 && image.GetHeight() != height)
|
||||
width = int(0.5f + float(image.GetWidth()) * height / image.GetHeight());
|
||||
else if (width != 0 && image.GetWidth() != width)
|
||||
height = int(0.5f + float(image.GetHeight()) * width / image.GetWidth());
|
||||
|
||||
if (height != 0 && width != 0)
|
||||
image.Rescale(width, height, wxIMAGE_QUALITY_BILINEAR);
|
||||
|
||||
return this->insert(bitmap_key, wxImage_to_wxBitmap_with_alpha(std::move(image)));
|
||||
}
|
||||
|
||||
wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned int target_height)
|
||||
wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned int target_width, unsigned int target_height)
|
||||
{
|
||||
std::string bitmap_key = bitmap_name + "-h" + std::to_string(target_height);
|
||||
std::string bitmap_key = bitmap_name + (target_height != 0 ?
|
||||
"-h" + std::to_string(target_height) :
|
||||
"-w" + std::to_string(target_width));
|
||||
auto it = m_map.find(bitmap_key);
|
||||
if (it != m_map.end())
|
||||
return it->second;
|
||||
|
@ -205,7 +216,10 @@ wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned int tar
|
|||
if (image == nullptr)
|
||||
return nullptr;
|
||||
|
||||
float scale = (float)target_height / image->height;
|
||||
float scale = target_height != 0 ?
|
||||
(float)target_height / image->height : target_width != 0 ?
|
||||
(float)target_width / image->width : 1;
|
||||
|
||||
int width = (int)(scale * image->width + 0.5f);
|
||||
int height = (int)(scale * image->height + 0.5f);
|
||||
int n_pixels = width * height;
|
||||
|
|
|
@ -31,10 +31,10 @@ public:
|
|||
wxBitmap* insert(const std::string &name, const wxBitmap *begin, const wxBitmap *end);
|
||||
wxBitmap* insert_raw_rgba(const std::string &bitmap_key, unsigned int width, unsigned int height, const unsigned char *raw_data);
|
||||
|
||||
// Load png from resources/icons. bitmap_key is given without the .png suffix. Bitmap will be rescaled to provided height if nonzero.
|
||||
wxBitmap* load_png(const std::string &bitmap_key, unsigned int height = 0);
|
||||
// Load svg from resources/icons. bitmap_key is given without the .svg suffix. SVG will be rasterized to provided height.
|
||||
wxBitmap* load_svg(const std::string &bitmap_key, unsigned int height);
|
||||
// Load png from resources/icons. bitmap_key is given without the .png suffix. Bitmap will be rescaled to provided height/width if nonzero.
|
||||
wxBitmap* load_png(const std::string &bitmap_key, unsigned int width = 0, unsigned int height = 0);
|
||||
// Load svg from resources/icons. bitmap_key is given without the .svg suffix. SVG will be rasterized to provided height/width.
|
||||
wxBitmap* load_svg(const std::string &bitmap_key, unsigned int width = 0, unsigned int height = 0);
|
||||
|
||||
static wxBitmap mksolid(size_t width, size_t height, unsigned char r, unsigned char g, unsigned char b, unsigned char transparency);
|
||||
static wxBitmap mksolid(size_t width, size_t height, const unsigned char rgb[3]) { return mksolid(width, height, rgb[0], rgb[1], rgb[2], wxALPHA_OPAQUE); }
|
||||
|
|
|
@ -1638,7 +1638,8 @@ void TabPrinter::build_printhost(ConfigOptionsGroup *optgroup)
|
|||
}
|
||||
|
||||
auto printhost_browse = [=](wxWindow* parent) {
|
||||
auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||
auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse ")) + dots,
|
||||
wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
|
||||
btn->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
||||
btn->SetBitmap(create_scaled_bitmap("zoom.png"));
|
||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
|
|
@ -423,15 +423,20 @@ void PrusaCollapsiblePaneMSW::Collapse(bool collapse)
|
|||
// PrusaObjectDataViewModelNode
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxBitmap create_scaled_bitmap(const std::string& bmp_name_in)
|
||||
// If an icon has horizontal orientation (width > height) call this function with is_horizontal = true
|
||||
wxBitmap create_scaled_bitmap(const std::string& bmp_name_in, const bool is_horizontal /* = false*/)
|
||||
{
|
||||
static Slic3r::GUI::BitmapCache cache;
|
||||
const auto height = (unsigned int)(Slic3r::GUI::wxGetApp().em_unit() * 1.6f + 0.5f);
|
||||
std::string bmp_name = bmp_name_in;
|
||||
|
||||
unsigned int height, width = height = 0;
|
||||
unsigned int& scale_base = is_horizontal ? width : height;
|
||||
scale_base = (unsigned int)(Slic3r::GUI::wxGetApp().em_unit() * 1.6f + 0.5f);
|
||||
|
||||
std::string bmp_name = bmp_name_in;
|
||||
boost::replace_last(bmp_name, ".png", "");
|
||||
wxBitmap *bmp = cache.load_svg(bmp_name, height);
|
||||
wxBitmap *bmp = cache.load_svg(bmp_name, height, width);
|
||||
if (bmp == nullptr)
|
||||
bmp = cache.load_png(bmp_name, height);
|
||||
bmp = cache.load_png(bmp_name, height, width);
|
||||
return *bmp;
|
||||
}
|
||||
|
||||
|
@ -1481,8 +1486,8 @@ PrusaDoubleSlider::PrusaDoubleSlider(wxWindow *parent,
|
|||
if (!is_osx)
|
||||
SetDoubleBuffered(true);// SetDoubleBuffered exists on Win and Linux/GTK, but is missing on OSX
|
||||
|
||||
m_bmp_thumb_higher = wxBitmap(create_scaled_bitmap(style == wxSL_HORIZONTAL ? "right_half_circle.png" : "up_half_circle.png"));
|
||||
m_bmp_thumb_lower = wxBitmap(create_scaled_bitmap(style == wxSL_HORIZONTAL ? "left_half_circle.png" : "down_half_circle.png"));
|
||||
m_bmp_thumb_higher = wxBitmap(style == wxSL_HORIZONTAL ? create_scaled_bitmap("right_half_circle.png") : create_scaled_bitmap("up_half_circle.png", true));
|
||||
m_bmp_thumb_lower = wxBitmap(style == wxSL_HORIZONTAL ? create_scaled_bitmap("left_half_circle.png" ) : create_scaled_bitmap("down_half_circle.png", true));
|
||||
m_thumb_size = m_bmp_thumb_lower.GetSize();
|
||||
|
||||
m_bmp_add_tick_on = create_scaled_bitmap("colorchange_add_on.png");
|
||||
|
|
|
@ -31,7 +31,7 @@ wxMenuItem* append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, const wxStrin
|
|||
wxMenuItem* append_menu_radio_item(wxMenu* menu, int id, const wxString& string, const wxString& description,
|
||||
std::function<void(wxCommandEvent& event)> cb, wxEvtHandler* event_handler);
|
||||
|
||||
wxBitmap create_scaled_bitmap(const std::string& bmp_name);
|
||||
wxBitmap create_scaled_bitmap(const std::string& bmp_name, const bool is_horizontal = false);
|
||||
|
||||
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue