mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-16 18:12:10 +00:00
NEW: gcode viewer add recommended colour filament widget
Change-Id: I37f38a175bb3f4a574a4855f8fef04e704da259c (cherry picked from commit 4014c61f889f5cf0b7830123fb0a72690ff4e1e5)
This commit is contained in:
@@ -13,11 +13,12 @@
|
||||
#include <wx/mstream.h>
|
||||
#include <wx/rawbmp.h>
|
||||
#endif /* __WXGTK2__ */
|
||||
|
||||
#include <GL/glew.h>
|
||||
#define NANOSVG_IMPLEMENTATION
|
||||
#include "nanosvg/nanosvg.h"
|
||||
#define NANOSVGRAST_IMPLEMENTATION
|
||||
#include "nanosvg/nanosvgrast.h"
|
||||
#include "3DScene.hpp"
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
@@ -553,6 +554,65 @@ bool BitmapCache::parse_color4(const std::string& scolor, unsigned char* rgba_ou
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//BBS Replace svg green with the specified colour
|
||||
bool BitmapCache::load_from_svg_file_change_color(const std::string &filename, unsigned width, unsigned height, ImTextureID &texture_id, const char *hexColor)
|
||||
{
|
||||
NSVGimage* image = nsvgParseFromFile(filename.c_str(), "px", 96.0f);
|
||||
if (image == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int change_color = nsvg__parseColorHex(hexColor);
|
||||
change_color |= (unsigned int) (1.0f * 255) << 24; // opacity
|
||||
unsigned int green_color = 4282560000;
|
||||
for (NSVGshape* shape = image->shapes; shape != nullptr; shape = shape->next) {
|
||||
// find green color
|
||||
if (shape->fill.color == green_color) {
|
||||
shape->fill.color = change_color;
|
||||
}
|
||||
}
|
||||
|
||||
float scale = (float)width / image->width;
|
||||
|
||||
int n_pixels = width * height;
|
||||
|
||||
if (n_pixels <= 0) {
|
||||
nsvgDelete(image);
|
||||
return false;
|
||||
}
|
||||
|
||||
NSVGrasterizer* rast = nsvgCreateRasterizer();
|
||||
if (rast == nullptr) {
|
||||
nsvgDelete(image);
|
||||
return false;
|
||||
}
|
||||
std::vector<unsigned char> data(n_pixels * 4, 0);
|
||||
nsvgRasterize(rast, image, 0, 0, scale, data.data(), width, height, width * 4);
|
||||
|
||||
bool compress = false;
|
||||
GLint last_texture;
|
||||
unsigned m_image_texture{ 0 };
|
||||
unsigned char* pixels = (unsigned char*)(&data[0]);
|
||||
|
||||
glsafe(::glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture));
|
||||
glsafe(::glGenTextures(1, &m_image_texture));
|
||||
glsafe(::glBindTexture(GL_TEXTURE_2D, m_image_texture));
|
||||
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||
glsafe(::glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
|
||||
// Store our identifier
|
||||
texture_id = (ImTextureID)(intptr_t)m_image_texture;
|
||||
|
||||
// Restore state
|
||||
glsafe(::glBindTexture(GL_TEXTURE_2D, last_texture));
|
||||
|
||||
nsvgDeleteRasterizer(rast);
|
||||
nsvgDelete(image);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
Reference in New Issue
Block a user