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
|
|
|
|
|
2021-12-22 09:45:35 +00:00
|
|
|
#include "libslic3r/Color.hpp"
|
|
|
|
|
2021-11-19 16:00:38 +00:00
|
|
|
struct NSVGimage;
|
|
|
|
|
2021-12-22 09:45:35 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
namespace GUI {
|
2018-03-12 15:04:32 +00:00
|
|
|
|
|
|
|
class BitmapCache
|
|
|
|
{
|
|
|
|
public:
|
2021-11-11 10:22:57 +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
|
|
|
|
2022-05-10 10:24:04 +00:00
|
|
|
wxBitmapBundle* find_bndl(const std::string &name) { auto it = m_bndl_map.find(name); return (it == m_bndl_map.end()) ? nullptr : it->second; }
|
|
|
|
const wxBitmapBundle* find_bndl(const std::string &name) const { return const_cast<BitmapCache*>(this)->find_bndl(name); }
|
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); }
|
|
|
|
|
2022-05-10 10:24:04 +00:00
|
|
|
wxBitmapBundle* insert_bndl(const std::string& bitmap_key, const char* data, size_t width, size_t height);
|
|
|
|
wxBitmapBundle* insert_bndl(const std::string& bitmap_key, const wxBitmapBundle &bmp);
|
|
|
|
wxBitmapBundle* insert_bndl(const std::string& bitmap_key, const wxVector<wxBitmap>& bmps);
|
|
|
|
wxBitmapBundle* insert_bndl(const std::string& name, const std::vector<wxBitmapBundle*>& bmps);
|
|
|
|
wxBitmapBundle* insert_raw_rgba_bndl(const std::string &bitmap_key, unsigned width, unsigned height, const unsigned char *raw_data, const bool grayscale = false);
|
|
|
|
|
|
|
|
wxBitmap* insert(const std::string &name, size_t width, size_t height, double scale = -1.0);
|
2018-03-12 15:04:32 +00:00
|
|
|
wxBitmap* insert(const std::string &name, const wxBitmap &bmp);
|
2020-01-31 15:50:11 +00:00
|
|
|
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);
|
2021-11-19 16:00:38 +00:00
|
|
|
|
|
|
|
// Parses SVG file from a file, returns SVG image as paths.
|
|
|
|
// And makes replases befor parsing
|
|
|
|
// replace_map containes old_value->new_value
|
|
|
|
static NSVGimage* nsvgParseFromFileWithReplace(const char* filename, const char* units, float dpi, const std::map<std::string, std::string>& replaces);
|
2022-05-10 10:24:04 +00:00
|
|
|
// Gets a data from SVG file and makes replases
|
|
|
|
// replace_map containes old_value->new_value
|
|
|
|
static void nsvgGetDataFromFileWithReplace(const char* filename, std::string& data_str, const std::map<std::string, std::string>& replaces);
|
|
|
|
wxBitmapBundle* from_svg(const std::string& bitmap_name, unsigned target_width, unsigned target_height, const bool dark_mode, const std::string& new_color = "");
|
|
|
|
wxBitmapBundle* from_png(const std::string& bitmap_name, unsigned width, unsigned height);
|
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.
|
2021-11-09 16:00:57 +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, const std::string& new_color = "");
|
2018-03-12 15:04:32 +00:00
|
|
|
|
2022-05-10 10:24:04 +00:00
|
|
|
wxBitmapBundle mksolid(size_t width, size_t height, unsigned char r, unsigned char g, unsigned char b, unsigned char transparency, size_t border_width = 0, bool dark_mode = false);
|
|
|
|
wxBitmapBundle* mksolid_bndl(size_t width, size_t height, const std::string& color = std::string(), size_t border_width = 0, bool dark_mode = false);
|
|
|
|
wxBitmapBundle* mkclear_bndl(size_t width, size_t height) { return mksolid_bndl(width, height); }
|
2018-03-12 15:04:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::map<std::string, wxBitmap*> m_map;
|
2022-05-10 10:24:04 +00:00
|
|
|
std::map<std::string, wxBitmapBundle*> m_bndl_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 */
|