Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/slic3r/GUI/BitmapCache.cpp')
-rw-r--r--src/slic3r/GUI/BitmapCache.cpp49
1 files changed, 23 insertions, 26 deletions
diff --git a/src/slic3r/GUI/BitmapCache.cpp b/src/slic3r/GUI/BitmapCache.cpp
index 8627ef4cb..c553f3728 100644
--- a/src/slic3r/GUI/BitmapCache.cpp
+++ b/src/slic3r/GUI/BitmapCache.cpp
@@ -3,23 +3,20 @@
#include "libslic3r/Utils.hpp"
#include "../Utils/MacDarkMode.hpp"
#include "GUI.hpp"
+#include "GUI_Utils.hpp"
#include <boost/filesystem.hpp>
-#if ! defined(WIN32) && ! defined(__APPLE__)
-#define BROKEN_ALPHA
-#endif
-
-#ifdef BROKEN_ALPHA
+#ifdef __WXGTK2__
+ // Broken alpha workaround
#include <wx/mstream.h>
#include <wx/rawbmp.h>
-#endif /* BROKEN_ALPHA */
+#endif /* __WXGTK2__ */
#define NANOSVG_IMPLEMENTATION
#include "nanosvg/nanosvg.h"
#define NANOSVGRAST_IMPLEMENTATION
#include "nanosvg/nanosvgrast.h"
-//#include "GUI_App.hpp"
namespace Slic3r { namespace GUI {
@@ -43,7 +40,8 @@ void BitmapCache::clear()
static wxBitmap wxImage_to_wxBitmap_with_alpha(wxImage &&image, float scale = 1.0f)
{
-#ifdef BROKEN_ALPHA
+#ifdef __WXGTK2__
+ // Broken alpha workaround
wxMemoryOutputStream stream;
image.SaveFile(stream, wxBITMAP_TYPE_PNG);
wxStreamBuffer *buf = stream.GetOutputStreamBuffer();
@@ -67,7 +65,11 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, size_t width, size_
wxBitmap *bitmap = nullptr;
auto it = m_map.find(bitmap_key);
if (it == m_map.end()) {
- bitmap = new wxBitmap(width, height);
+ bitmap = new wxBitmap(width, height
+#ifdef __WXGTK3__
+ , 32
+#endif
+ );
#ifdef __APPLE__
// Contrary to intuition, the `scale` argument isn't "please scale this to such and such"
// but rather "the wxImage is sized for backing scale such and such".
@@ -82,7 +84,8 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, size_t width, size_
if (size_t(bitmap->GetWidth()) != width || size_t(bitmap->GetHeight()) != height)
bitmap->Create(width, height);
}
-#ifndef BROKEN_ALPHA
+#if defined(WIN32) || defined(__APPLE__)
+ // Not needed or harmful for GTK2 and GTK3.
bitmap->UseAlpha();
#endif
return bitmap;
@@ -130,8 +133,8 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap *beg
#endif
}
-#ifdef BROKEN_ALPHA
-
+#ifdef __WXGTK2__
+ // Broken alpha workaround
wxImage image(width, height);
image.InitAlpha();
// Fill in with a white color.
@@ -281,16 +284,19 @@ wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_
auto it = m_map.find(folder + bitmap_key);
if (it != m_map.end())
return it->second;
- else {
+ // It's expensive to check if the bitmap exists every time, but otherwise:
+ // For the case, when application was started in Light mode and then switched to the Dark,
+ // we will never get a white bitmaps, if check m_map.find(bitmap_key)
+ // before boost::filesystem::exists(var(folder + bitmap_name + ".svg"))
+ if (!boost::filesystem::exists(var(folder + bitmap_name + ".svg"))) {
+ folder.clear();
+
it = m_map.find(bitmap_key);
if (it != m_map.end())
return it->second;
}
- if (!boost::filesystem::exists(Slic3r::var(folder + bitmap_name + ".svg")))
- folder.clear();
- else
- bitmap_key = folder + bitmap_key;
+ bitmap_key = folder + bitmap_key;
}
else
{
@@ -351,15 +357,6 @@ wxBitmap BitmapCache::mksolid(size_t width, size_t height, unsigned char r, unsi
return wxImage_to_wxBitmap_with_alpha(std::move(image), scale);
}
-
-static inline int hex_digit_to_int(const char c)
-{
- return
- (c >= '0' && c <= '9') ? int(c - '0') :
- (c >= 'A' && c <= 'F') ? int(c - 'A') + 10 :
- (c >= 'a' && c <= 'f') ? int(c - 'a') + 10 : -1;
-}
-
bool BitmapCache::parse_color(const std::string& scolor, unsigned char* rgb_out)
{
rgb_out[0] = rgb_out[1] = rgb_out[2] = 0;