Added grayscale parameter for create_scaled_bitmap()
This commit is contained in:
parent
f47839e824
commit
bfaa92eabb
4 changed files with 30 additions and 18 deletions
|
@ -174,7 +174,7 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap *beg
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap* BitmapCache::insert_raw_rgba(const std::string &bitmap_key, unsigned width, unsigned height, const unsigned char *raw_data, float scale /* = 1.0f */)
|
wxBitmap* BitmapCache::insert_raw_rgba(const std::string &bitmap_key, unsigned width, unsigned height, const unsigned char *raw_data, float scale /* = 1.0f */, const bool grayscale/* = false*/)
|
||||||
{
|
{
|
||||||
wxImage image(width, height);
|
wxImage image(width, height);
|
||||||
image.InitAlpha();
|
image.InitAlpha();
|
||||||
|
@ -187,14 +187,20 @@ wxBitmap* BitmapCache::insert_raw_rgba(const std::string &bitmap_key, unsigned w
|
||||||
*rgb ++ = *raw_data ++;
|
*rgb ++ = *raw_data ++;
|
||||||
*alpha ++ = *raw_data ++;
|
*alpha ++ = *raw_data ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (grayscale)
|
||||||
|
image.ConvertToGreyscale(m_gs, m_gs, m_gs);
|
||||||
|
|
||||||
return this->insert(bitmap_key, wxImage_to_wxBitmap_with_alpha(std::move(image), scale));
|
return this->insert(bitmap_key, wxImage_to_wxBitmap_with_alpha(std::move(image), scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap* BitmapCache::load_png(const std::string &bitmap_name, unsigned int width, unsigned int height)
|
wxBitmap* BitmapCache::load_png(const std::string &bitmap_name, unsigned int width, unsigned int height,
|
||||||
|
const bool grayscale/* = false*/)
|
||||||
{
|
{
|
||||||
std::string bitmap_key = bitmap_name + ( height !=0 ?
|
std::string bitmap_key = bitmap_name + ( height !=0 ?
|
||||||
"-h" + std::to_string(height) :
|
"-h" + std::to_string(height) :
|
||||||
"-w" + std::to_string(width));
|
"-w" + std::to_string(width))
|
||||||
|
+ (grayscale ? "-gs" : "");
|
||||||
|
|
||||||
auto it = m_map.find(bitmap_key);
|
auto it = m_map.find(bitmap_key);
|
||||||
if (it != m_map.end())
|
if (it != m_map.end())
|
||||||
|
@ -213,15 +219,20 @@ wxBitmap* BitmapCache::load_png(const std::string &bitmap_name, unsigned int wid
|
||||||
if (height != 0 && width != 0)
|
if (height != 0 && width != 0)
|
||||||
image.Rescale(width, height, wxIMAGE_QUALITY_BILINEAR);
|
image.Rescale(width, height, wxIMAGE_QUALITY_BILINEAR);
|
||||||
|
|
||||||
|
if (grayscale)
|
||||||
|
image.ConvertToGreyscale(m_gs, m_gs, m_gs);
|
||||||
|
|
||||||
return this->insert(bitmap_key, wxImage_to_wxBitmap_with_alpha(std::move(image)));
|
return this->insert(bitmap_key, wxImage_to_wxBitmap_with_alpha(std::move(image)));
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_width, unsigned target_height, float scale /* = 1.0f */)
|
wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_width, unsigned target_height,
|
||||||
|
float scale /* = 1.0f */, const bool grayscale/* = false*/)
|
||||||
{
|
{
|
||||||
std::string bitmap_key = bitmap_name + ( target_height !=0 ?
|
std::string bitmap_key = bitmap_name + ( target_height !=0 ?
|
||||||
"-h" + std::to_string(target_height) :
|
"-h" + std::to_string(target_height) :
|
||||||
"-w" + std::to_string(target_width))
|
"-w" + std::to_string(target_width))
|
||||||
+ (scale != 1.0f ? "-s" + std::to_string(scale) : "");
|
+ (scale != 1.0f ? "-s" + std::to_string(scale) : "")
|
||||||
|
+ (grayscale ? "-gs" : "");
|
||||||
|
|
||||||
target_height != 0 ? target_height *= scale : target_width *= scale;
|
target_height != 0 ? target_height *= scale : target_width *= scale;
|
||||||
|
|
||||||
|
@ -256,7 +267,7 @@ wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_
|
||||||
::nsvgDeleteRasterizer(rast);
|
::nsvgDeleteRasterizer(rast);
|
||||||
::nsvgDelete(image);
|
::nsvgDelete(image);
|
||||||
|
|
||||||
return this->insert_raw_rgba(bitmap_key, width, height, data.data(), scale);
|
return this->insert_raw_rgba(bitmap_key, width, height, data.data(), scale, grayscale);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap BitmapCache::mksolid(size_t width, size_t height, unsigned char r, unsigned char g, unsigned char b, unsigned char transparency)
|
wxBitmap BitmapCache::mksolid(size_t width, size_t height, unsigned char r, unsigned char g, unsigned char b, unsigned char transparency)
|
||||||
|
|
|
@ -29,12 +29,12 @@ public:
|
||||||
wxBitmap* insert(const std::string &name, const wxBitmap &bmp, const wxBitmap &bmp2, const wxBitmap &bmp3);
|
wxBitmap* insert(const std::string &name, const wxBitmap &bmp, const wxBitmap &bmp2, const wxBitmap &bmp3);
|
||||||
wxBitmap* insert(const std::string &name, const std::vector<wxBitmap> &bmps) { return this->insert(name, &bmps.front(), &bmps.front() + bmps.size()); }
|
wxBitmap* insert(const std::string &name, const std::vector<wxBitmap> &bmps) { return this->insert(name, &bmps.front(), &bmps.front() + bmps.size()); }
|
||||||
wxBitmap* insert(const std::string &name, const wxBitmap *begin, const wxBitmap *end);
|
wxBitmap* insert(const std::string &name, const wxBitmap *begin, const wxBitmap *end);
|
||||||
wxBitmap* insert_raw_rgba(const std::string &bitmap_key, unsigned width, unsigned height, const unsigned char *raw_data, float scale = 1.0f);
|
wxBitmap* insert_raw_rgba(const std::string &bitmap_key, unsigned width, unsigned height, const unsigned char *raw_data, float scale = 1.0f, const bool grayscale = false);
|
||||||
|
|
||||||
// Load png from resources/icons. bitmap_key is given without the .png suffix. Bitmap will be rescaled to provided height/width if nonzero.
|
// 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);
|
wxBitmap* load_png(const std::string &bitmap_key, unsigned int width = 0, unsigned int height = 0, const bool grayscale = false);
|
||||||
// Load svg from resources/icons. bitmap_key is given without the .svg suffix. SVG will be rasterized to provided height/width.
|
// 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, float scale = 1.0f);
|
wxBitmap* load_svg(const std::string &bitmap_key, unsigned int width = 0, unsigned int height = 0, float scale = 1.0f, const bool grayscale = false);
|
||||||
|
|
||||||
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, 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); }
|
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); }
|
||||||
|
@ -42,6 +42,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, wxBitmap*> m_map;
|
std::map<std::string, wxBitmap*> m_map;
|
||||||
|
double m_gs = 0.2; // value, used for image.ConvertToGreyscale(m_gs, m_gs, m_gs)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // GUI
|
} // GUI
|
||||||
|
|
|
@ -59,11 +59,9 @@ void enable_menu_item(wxUpdateUIEvent& evt, std::function<bool()> const cb_condi
|
||||||
const auto it = msw_menuitem_bitmaps.find(item->GetId());
|
const auto it = msw_menuitem_bitmaps.find(item->GetId());
|
||||||
if (it != msw_menuitem_bitmaps.end())
|
if (it != msw_menuitem_bitmaps.end())
|
||||||
{
|
{
|
||||||
const wxBitmap& item_icon = create_scaled_bitmap(nullptr, it->second);
|
const wxBitmap& item_icon = create_scaled_bitmap(nullptr, it->second, 16, false, !enable);
|
||||||
if (item_icon.IsOk()) {
|
if (item_icon.IsOk())
|
||||||
double g = 0.6;
|
item->SetBitmap(item_icon);
|
||||||
item->SetBitmap(enable ? item_icon : item_icon.ConvertToImage().ConvertToGreyscale(g, g, g));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif // __WXOSX__
|
#endif // __WXOSX__
|
||||||
}
|
}
|
||||||
|
@ -385,7 +383,8 @@ int em_unit(wxWindow* win)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an icon has horizontal orientation (width > height) call this function with is_horizontal = true
|
// If an icon has horizontal orientation (width > height) call this function with is_horizontal = true
|
||||||
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in, const int px_cnt/* = 16*/, const bool is_horizontal /* = false*/)
|
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in,
|
||||||
|
const int px_cnt/* = 16*/, const bool is_horizontal /* = false*/, const bool grayscale/* = false*/)
|
||||||
{
|
{
|
||||||
static Slic3r::GUI::BitmapCache cache;
|
static Slic3r::GUI::BitmapCache cache;
|
||||||
|
|
||||||
|
@ -405,9 +404,9 @@ wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in, con
|
||||||
boost::replace_last(bmp_name, ".png", "");
|
boost::replace_last(bmp_name, ".png", "");
|
||||||
|
|
||||||
// Try loading an SVG first, then PNG if SVG is not found:
|
// Try loading an SVG first, then PNG if SVG is not found:
|
||||||
wxBitmap *bmp = cache.load_svg(bmp_name, width, height, scale_factor);
|
wxBitmap *bmp = cache.load_svg(bmp_name, width, height, scale_factor, grayscale);
|
||||||
if (bmp == nullptr) {
|
if (bmp == nullptr) {
|
||||||
bmp = cache.load_png(bmp_name, width, height);
|
bmp = cache.load_png(bmp_name, width, height, grayscale);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bmp == nullptr) {
|
if (bmp == nullptr) {
|
||||||
|
|
|
@ -45,7 +45,8 @@ void edit_tooltip(wxString& tooltip);
|
||||||
void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector<int>& btn_ids);
|
void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector<int>& btn_ids);
|
||||||
int em_unit(wxWindow* win);
|
int em_unit(wxWindow* win);
|
||||||
|
|
||||||
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name, const int px_cnt = 16, const bool is_horizontal = false);
|
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name,
|
||||||
|
const int px_cnt = 16, const bool is_horizontal = false, const bool grayscale = false);
|
||||||
|
|
||||||
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
|
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue