OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::FilamentGroupUtils::Color Struct Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/FilamentGroupUtils.hpp>

Public Member Functions

 Color (unsigned char r_=0, unsigned char g_=0, unsigned char b_=0, unsigned a_=255)
 Color (const std::string &hexstr)
bool operator< (const Color &other) const
bool operator== (const Color &other) const
bool operator!= (const Color &other) const
std::string to_hex_str (bool include_alpha=false) const

Public Attributes

unsigned char r = 0
unsigned char g = 0
unsigned char b = 0
unsigned char a = 255

Detailed Description

Constructor & Destructor Documentation

◆ Color() [1/2]

Slic3r::FilamentGroupUtils::Color::Color ( unsigned char r_ = 0,
unsigned char g_ = 0,
unsigned char b_ = 0,
unsigned a_ = 255 )
inline
25:r(r_), g(g_), b(b_), a(a_) {}
unsigned char b
Definition FilamentGroupUtils.hpp:23
unsigned char r
Definition FilamentGroupUtils.hpp:21
unsigned char a
Definition FilamentGroupUtils.hpp:24
unsigned char g
Definition FilamentGroupUtils.hpp:22

References a, b, g, and r.

Referenced by operator!=(), operator<(), and operator==().

Here is the caller graph for this function:

◆ Color() [2/2]

Slic3r::FilamentGroupUtils::Color::Color ( const std::string & hexstr)
25 {
26 if (hexstr.empty() || (hexstr.length() != 9 && hexstr.length() != 7) || hexstr[0] != '#')
27 {
28 assert(false);
29 r = 0, g = 0, b = 0, a = 255;
30 return;
31 }
32
33 auto hexToByte = [](const std::string& hex)->unsigned char
34 {
35 unsigned int byte;
36 std::istringstream(hex) >> std::hex >> byte;
37 return static_cast<unsigned char>(byte);
38 };
39 r = hexToByte(hexstr.substr(1, 2));
40 g = hexToByte(hexstr.substr(3, 2));
41 b = hexToByte(hexstr.substr(5, 2));
42 if (hexstr.size() == 9)
43 a = hexToByte(hexstr.substr(7, 2));
44 }

References a, b, g, and r.

Member Function Documentation

◆ operator!=()

bool Slic3r::FilamentGroupUtils::Color::operator!= ( const Color & other) const
61 {
62 return r != other.r || g != other.g || b != other.b || a != other.a;
63 }

References Color(), a, b, g, and r.

Here is the call graph for this function:

◆ operator<()

bool Slic3r::FilamentGroupUtils::Color::operator< ( const Color & other) const
47 {
48 if (r != other.r) return r < other.r;
49 if (g != other.g) return g < other.g;
50 if (b != other.b) return b < other.b;
51 return a < other.a;
52 }

References Color(), a, b, g, and r.

Here is the call graph for this function:

◆ operator==()

bool Slic3r::FilamentGroupUtils::Color::operator== ( const Color & other) const
55 {
56 return r == other.r && g == other.g && b == other.b && a == other.a;
57
58 }

References Color(), a, b, g, and r.

Here is the call graph for this function:

◆ to_hex_str()

std::string Slic3r::FilamentGroupUtils::Color::to_hex_str ( bool include_alpha = false) const
65 {
66 std::ostringstream oss;
67 oss << "#" << std::hex << std::setfill('0')
68 << std::setw(2) << static_cast<int>(r)
69 << std::setw(2) << static_cast<int>(g)
70 << std::setw(2) << static_cast<int>(b);
71
72 if (include_alpha) {
73 oss << std::setw(2) << static_cast<int>(a);
74 }
75 return oss.str();
76 }

References a, b, g, and r.

Referenced by Slic3r::FilamentGroup::try_merge_filaments().

Here is the caller graph for this function:

Member Data Documentation

◆ a

unsigned char Slic3r::FilamentGroupUtils::Color::a = 255

◆ b

unsigned char Slic3r::FilamentGroupUtils::Color::b = 0

◆ g

unsigned char Slic3r::FilamentGroupUtils::Color::g = 0

◆ r

unsigned char Slic3r::FilamentGroupUtils::Color::r = 0

The documentation for this struct was generated from the following files: