mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Code cleaning and refactoring for 6a8c34dad9
This commit is contained in:
parent
6a8c34dad9
commit
e531b0319f
2 changed files with 23 additions and 34 deletions
|
@ -229,6 +229,12 @@ 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*/, const bool dark_mode/* = false*/)
|
float scale /* = 1.0f */, const bool grayscale/* = false*/, const bool dark_mode/* = false*/)
|
||||||
{
|
{
|
||||||
|
std::string bitmap_key = bitmap_name + ( target_height !=0 ?
|
||||||
|
"-h" + std::to_string(target_height) :
|
||||||
|
"-w" + std::to_string(target_width))
|
||||||
|
+ (scale != 1.0f ? "-s" + std::to_string(scale) : "")
|
||||||
|
+ (grayscale ? "-gs" : "");
|
||||||
|
|
||||||
/* For the Dark mode of any platform, we should draw icons in respect to OS background
|
/* 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,
|
* Note: All standard(regular) icons are collected in "icons" folder,
|
||||||
* SVG-icons, which have "Dark mode" variant, are collected in "icons/white" folder
|
* SVG-icons, which have "Dark mode" variant, are collected in "icons/white" folder
|
||||||
|
@ -241,19 +247,26 @@ wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_
|
||||||
#else
|
#else
|
||||||
folder = "white/";
|
folder = "white/";
|
||||||
#endif
|
#endif
|
||||||
|
auto it = m_map.find(folder + bitmap_key);
|
||||||
|
if (it != m_map.end())
|
||||||
|
return it->second;
|
||||||
|
else {
|
||||||
|
it = m_map.find(bitmap_key);
|
||||||
|
if (it != m_map.end())
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
if (!boost::filesystem::exists(Slic3r::var(folder + bitmap_name + ".svg")))
|
if (!boost::filesystem::exists(Slic3r::var(folder + bitmap_name + ".svg")))
|
||||||
folder.clear();
|
folder.clear();
|
||||||
|
else
|
||||||
|
bitmap_key = folder + bitmap_key;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto it = m_map.find(bitmap_key);
|
||||||
|
if (it != m_map.end())
|
||||||
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string bitmap_key = folder + bitmap_name + ( target_height !=0 ?
|
|
||||||
"-h" + std::to_string(target_height) :
|
|
||||||
"-w" + std::to_string(target_width))
|
|
||||||
+ (scale != 1.0f ? "-s" + std::to_string(scale) : "")
|
|
||||||
+ (grayscale ? "-gs" : "");
|
|
||||||
|
|
||||||
auto it = m_map.find(bitmap_key);
|
|
||||||
if (it != m_map.end())
|
|
||||||
return it->second;
|
|
||||||
|
|
||||||
NSVGimage *image = ::nsvgParseFromFile(Slic3r::var(folder + 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)
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include <wx/numformatter.h>
|
#include <wx/numformatter.h>
|
||||||
#include <wx/colordlg.h>
|
#include <wx/colordlg.h>
|
||||||
|
|
||||||
//#include <boost/filesystem.hpp>
|
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
|
|
||||||
#include "BitmapCache.hpp"
|
#include "BitmapCache.hpp"
|
||||||
|
@ -425,29 +424,6 @@ static float get_svg_scale_factor(wxWindow *win)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
|
||||||
{
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
const std::string folder = "white\\";
|
|
||||||
#else
|
|
||||||
const std::string folder = "white/";
|
|
||||||
#endif
|
|
||||||
std::string bmp_name;
|
|
||||||
if (Slic3r::GUI::wxGetApp().dark_mode()) {
|
|
||||||
bmp_name = folder + bmp_name_in;
|
|
||||||
boost::replace_last(bmp_name, ".png", "");
|
|
||||||
if (! boost::filesystem::exists(Slic3r::var(bmp_name + ".svg")))
|
|
||||||
bmp_name.clear();
|
|
||||||
}
|
|
||||||
if (bmp_name.empty()) {
|
|
||||||
bmp_name = bmp_name_in;
|
|
||||||
boost::replace_last(bmp_name, ".png", "");
|
|
||||||
}
|
|
||||||
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*/)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue