Checking of icons for dark mode is removed to BitmapCache
This commit is contained in:
parent
9f529e86cc
commit
6a8c34dad9
@ -1,6 +1,7 @@
|
|||||||
#include "BitmapCache.hpp"
|
#include "BitmapCache.hpp"
|
||||||
|
|
||||||
#include "libslic3r/Utils.hpp"
|
#include "libslic3r/Utils.hpp"
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#if ! defined(WIN32) && ! defined(__APPLE__)
|
#if ! defined(WIN32) && ! defined(__APPLE__)
|
||||||
#define BROKEN_ALPHA
|
#define BROKEN_ALPHA
|
||||||
@ -15,7 +16,7 @@
|
|||||||
#include "nanosvg/nanosvg.h"
|
#include "nanosvg/nanosvg.h"
|
||||||
#define NANOSVGRAST_IMPLEMENTATION
|
#define NANOSVGRAST_IMPLEMENTATION
|
||||||
#include "nanosvg/nanosvgrast.h"
|
#include "nanosvg/nanosvgrast.h"
|
||||||
#include "GUI_App.hpp"
|
//#include "GUI_App.hpp"
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
@ -226,24 +227,40 @@ wxBitmap* BitmapCache::load_png(const std::string &bitmap_name, unsigned width,
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_width, unsigned target_height,
|
wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_width, unsigned target_height,
|
||||||
float scale /* = 1.0f */, const bool grayscale/* = false*/)
|
float scale /* = 1.0f */, const bool grayscale/* = false*/, const bool dark_mode/* = false*/)
|
||||||
{
|
{
|
||||||
std::string bitmap_key = bitmap_name + ( target_height !=0 ?
|
/* For the Dark mode of any platform, we should draw icons in respect to OS background
|
||||||
|
* Note: All standard(regular) icons are collected in "icons" folder,
|
||||||
|
* SVG-icons, which have "Dark mode" variant, are collected in "icons/white" folder
|
||||||
|
*/
|
||||||
|
std::string folder;
|
||||||
|
if (dark_mode)
|
||||||
|
{
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
folder = "white\\";
|
||||||
|
#else
|
||||||
|
folder = "white/";
|
||||||
|
#endif
|
||||||
|
if (!boost::filesystem::exists(Slic3r::var(folder + bitmap_name + ".svg")))
|
||||||
|
folder.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string bitmap_key = folder + 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" : "");
|
+ (grayscale ? "-gs" : "");
|
||||||
|
|
||||||
target_height != 0 ? target_height *= scale : target_width *= scale;
|
|
||||||
|
|
||||||
auto it = m_map.find(bitmap_key);
|
auto it = m_map.find(bitmap_key);
|
||||||
if (it != m_map.end())
|
if (it != m_map.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
|
|
||||||
NSVGimage *image = ::nsvgParseFromFile(Slic3r::var(bitmap_name + ".svg").c_str(), "px", 96.0f);
|
NSVGimage *image = ::nsvgParseFromFile(Slic3r::var(folder + bitmap_name + ".svg").c_str(), "px", 96.0f);
|
||||||
if (image == nullptr)
|
if (image == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
target_height != 0 ? target_height *= scale : target_width *= scale;
|
||||||
|
|
||||||
float svg_scale = target_height != 0 ?
|
float svg_scale = target_height != 0 ?
|
||||||
(float)target_height / image->height : target_width != 0 ?
|
(float)target_height / image->height : target_width != 0 ?
|
||||||
(float)target_width / image->width : 1;
|
(float)target_width / image->width : 1;
|
||||||
|
@ -34,7 +34,7 @@ public:
|
|||||||
// 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 width = 0, unsigned height = 0, const bool grayscale = false);
|
wxBitmap* load_png(const std::string &bitmap_key, unsigned width = 0, unsigned 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 width = 0, unsigned height = 0, float scale = 1.0f, const bool grayscale = false);
|
wxBitmap* load_svg(const std::string &bitmap_key, unsigned width = 0, unsigned height = 0, float scale = 1.0f, const bool grayscale = false, const bool dark_mode = 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); }
|
||||||
|
@ -13,9 +13,8 @@
|
|||||||
#include <wx/numformatter.h>
|
#include <wx/numformatter.h>
|
||||||
#include <wx/colordlg.h>
|
#include <wx/colordlg.h>
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
//#include <boost/filesystem.hpp>
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
#include <boost/nowide/cstdio.hpp>
|
|
||||||
|
|
||||||
#include "BitmapCache.hpp"
|
#include "BitmapCache.hpp"
|
||||||
#include "GUI.hpp"
|
#include "GUI.hpp"
|
||||||
@ -427,6 +426,7 @@ static float get_svg_scale_factor(wxWindow *win)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// in the Dark mode of any platform, we should draw icons in respect to OS background
|
// in the Dark mode of any platform, we should draw icons in respect to OS background
|
||||||
|
/*
|
||||||
static std::string icon_name_respected_to_mode(const std::string& bmp_name_in)
|
static std::string icon_name_respected_to_mode(const std::string& bmp_name_in)
|
||||||
{
|
{
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
@ -447,7 +447,7 @@ static std::string icon_name_respected_to_mode(const std::string& bmp_name_in)
|
|||||||
}
|
}
|
||||||
return bmp_name;
|
return bmp_name;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
// 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,
|
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*/)
|
const int px_cnt/* = 16*/, const bool is_horizontal /* = false*/, const bool grayscale/* = false*/)
|
||||||
@ -474,13 +474,13 @@ wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in,
|
|||||||
|
|
||||||
scale_base = (unsigned int)(em_unit(win) * px_cnt * 0.1f + 0.5f);
|
scale_base = (unsigned int)(em_unit(win) * px_cnt * 0.1f + 0.5f);
|
||||||
|
|
||||||
// std::string bmp_name = bmp_name_in;
|
std::string bmp_name = bmp_name_in;
|
||||||
// boost::replace_last(bmp_name, ".png", "");
|
boost::replace_last(bmp_name, ".png", "");
|
||||||
|
|
||||||
std::string bmp_name = icon_name_respected_to_mode(bmp_name_in);
|
// std::string bmp_name = icon_name_respected_to_mode(bmp_name_in);
|
||||||
|
|
||||||
// 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, grayscale);
|
wxBitmap *bmp = cache.load_svg(bmp_name, width, height, scale_factor, grayscale, Slic3r::GUI::wxGetApp().dark_mode());
|
||||||
if (bmp == nullptr) {
|
if (bmp == nullptr) {
|
||||||
bmp = cache.load_png(bmp_name, width, height, grayscale);
|
bmp = cache.load_png(bmp_name, width, height, grayscale);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user