2018-03-12 15:04:32 +00:00
|
|
|
#ifndef SLIC3R_GUI_BITMAP_CACHE_HPP
|
|
|
|
#define SLIC3R_GUI_BITMAP_CACHE_HPP
|
|
|
|
|
2020-02-03 08:24:58 +00:00
|
|
|
#include <map>
|
2020-02-08 10:42:45 +00:00
|
|
|
#include <vector>
|
2020-02-03 08:24:58 +00:00
|
|
|
|
2018-03-12 15:04:32 +00:00
|
|
|
#include <wx/wxprec.h>
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include <wx/wx.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Slic3r { namespace GUI {
|
|
|
|
|
|
|
|
class BitmapCache
|
|
|
|
{
|
|
|
|
public:
|
2020-01-31 15:50:11 +00:00
|
|
|
BitmapCache();
|
2018-03-12 15:04:32 +00:00
|
|
|
~BitmapCache() { clear(); }
|
|
|
|
void clear();
|
2020-01-31 15:50:11 +00:00
|
|
|
double scale() { return m_scale; }
|
2018-03-12 15:04:32 +00:00
|
|
|
|
|
|
|
wxBitmap* find(const std::string &name) { auto it = m_map.find(name); return (it == m_map.end()) ? nullptr : it->second; }
|
|
|
|
const wxBitmap* find(const std::string &name) const { return const_cast<BitmapCache*>(this)->find(name); }
|
|
|
|
|
2020-01-31 15:50:11 +00:00
|
|
|
wxBitmap* insert(const std::string &name, size_t width, size_t height);
|
2018-03-12 15:04:32 +00:00
|
|
|
wxBitmap* insert(const std::string &name, const wxBitmap &bmp);
|
|
|
|
wxBitmap* insert(const std::string &name, const wxBitmap &bmp, const wxBitmap &bmp2);
|
|
|
|
wxBitmap* insert(const std::string &name, const wxBitmap &bmp, const wxBitmap &bmp2, const wxBitmap &bmp3);
|
2020-01-31 15:50:11 +00:00
|
|
|
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_raw_rgba(const std::string &bitmap_key, unsigned width, unsigned height, const unsigned char *raw_data, const bool grayscale = false);
|
2019-04-04 07:20:11 +00:00
|
|
|
|
2019-04-05 09:18:13 +00:00
|
|
|
// Load png from resources/icons. bitmap_key is given without the .png suffix. Bitmap will be rescaled to provided height/width if nonzero.
|
2019-09-06 11:33:08 +00:00
|
|
|
wxBitmap* load_png(const std::string &bitmap_key, unsigned width = 0, unsigned height = 0, const bool grayscale = false);
|
2019-04-05 09:18:13 +00:00
|
|
|
// Load svg from resources/icons. bitmap_key is given without the .svg suffix. SVG will be rasterized to provided height/width.
|
2020-01-31 15:50:11 +00:00
|
|
|
wxBitmap* load_svg(const std::string &bitmap_key, unsigned width = 0, unsigned height = 0, const bool grayscale = false, const bool dark_mode = false);
|
2018-03-12 15:04:32 +00:00
|
|
|
|
2020-01-31 15:50:11 +00:00
|
|
|
/*static */wxBitmap mksolid(size_t width, size_t height, unsigned char r, unsigned char g, unsigned char b, unsigned char transparency, bool suppress_scaling = false);
|
2020-02-03 20:27:53 +00:00
|
|
|
/*static */wxBitmap mksolid(size_t width, size_t height, const unsigned char rgb[3], bool suppress_scaling = false) { return mksolid(width, height, rgb[0], rgb[1], rgb[2], wxALPHA_OPAQUE, suppress_scaling); }
|
2020-01-31 15:50:11 +00:00
|
|
|
/*static */wxBitmap mkclear(size_t width, size_t height) { return mksolid(width, height, 0, 0, 0, wxALPHA_TRANSPARENT); }
|
2018-03-12 15:04:32 +00:00
|
|
|
|
2020-02-02 21:22:40 +00:00
|
|
|
static bool parse_color(const std::string& scolor, unsigned char* rgb_out);
|
|
|
|
|
2018-03-12 15:04:32 +00:00
|
|
|
private:
|
|
|
|
std::map<std::string, wxBitmap*> m_map;
|
2020-01-31 15:50:11 +00:00
|
|
|
double m_gs = 0.2; // value, used for image.ConvertToGreyscale(m_gs, m_gs, m_gs)
|
|
|
|
double m_scale = 1.0; // value, used for correct scaling of SVG icons on Retina display
|
2018-03-12 15:04:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // GUI
|
|
|
|
} // Slic3r
|
|
|
|
|
|
|
|
#endif /* SLIC3R_GUI_BITMAP_CACHE_HPP */
|