OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::ColorPicker Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/AMSMaterialsSetting.hpp>

Inheritance diagram for Slic3r::GUI::ColorPicker:
Collaboration diagram for Slic3r::GUI::ColorPicker:

Public Member Functions

 ColorPicker (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
 ~ColorPicker ()
void msw_rescale ()
void set_color (wxColour col)
void set_colors (std::vector< wxColour > cols)
void set_selected (bool sel)
void set_show_full (bool full)
void is_empty (bool empty)
void paintEvent (wxPaintEvent &evt)
void render (wxDC &dc)
void doRender (wxDC &dc)

Public Attributes

wxBitmap m_bitmap_border
wxBitmap m_bitmap_border_dark
wxBitmap m_bitmap_transparent
ScalableBitmap m_bitmap_transparent_def
wxColour m_colour
std::vector< wxColour > m_cols
bool m_selected {false}
bool m_show_full {false}
bool m_is_empty {false}
int ctype
bool transparent_changed {false}

Detailed Description

Constructor & Destructor Documentation

◆ ColorPicker()

Slic3r::GUI::ColorPicker::ColorPicker ( wxWindow * parent,
wxWindowID id,
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize )
1789{
1790 wxWindow::Create(parent, id, pos, size);
1791
1792 SetSize(wxSize(FromDIP(25), FromDIP(25)));
1793 SetMinSize(wxSize(FromDIP(25), FromDIP(25)));
1794 SetMaxSize(wxSize(FromDIP(25), FromDIP(25)));
1795
1796 Bind(wxEVT_PAINT, &ColorPicker::paintEvent, this);
1797
1798 m_bitmap_border = create_scaled_bitmap("color_picker_border", nullptr, 25);
1799 m_bitmap_border_dark = create_scaled_bitmap("color_picker_border_dark", nullptr, 25);
1800 m_bitmap_transparent_def = ScalableBitmap(this, "transparent_color_picker", 25);
1801 m_bitmap_transparent = create_scaled_bitmap("transparent_color_picker", nullptr, 25);
1802}
wxBitmap m_bitmap_transparent
Definition AMSMaterialsSetting.hpp:55
ScalableBitmap m_bitmap_transparent_def
Definition AMSMaterialsSetting.hpp:56
void paintEvent(wxPaintEvent &evt)
Definition AMSMaterialsSetting.cpp:1830
wxBitmap m_bitmap_border_dark
Definition AMSMaterialsSetting.hpp:54
wxBitmap m_bitmap_border
Definition AMSMaterialsSetting.hpp:53
wxBitmap create_scaled_bitmap(const std::string &bmp_name_in, wxWindow *win, const int px_cnt, const bool grayscale, const std::string &new_color, const bool menu_bitmap, const bool resize, const bool bitmap2, const std::vector< std::string > &array_new_color)
Definition wxExtensions.cpp:448

References create_scaled_bitmap(), m_bitmap_border, m_bitmap_border_dark, m_bitmap_transparent, m_bitmap_transparent_def, and paintEvent().

Here is the call graph for this function:

◆ ~ColorPicker()

Slic3r::GUI::ColorPicker::~ColorPicker ( )
1804{}

Member Function Documentation

◆ doRender()

void Slic3r::GUI::ColorPicker::doRender ( wxDC & dc)
1858{
1859 wxSize size = GetSize();
1860 auto alpha = m_colour.Alpha();
1861 auto radius = m_show_full ? size.x / 2 - FromDIP(1) : size.x / 2;
1862 if (m_selected) radius -= FromDIP(1);
1863
1864 if (m_show_full && m_cols.size() > 1) {
1865 if (ctype == 0) {
1866 const double center_x = size.x / 2.0;
1867 const double center_y = size.y / 2.0;
1868 const double draw_radius = radius;
1869 dc.SetPen(*wxTRANSPARENT_PEN);
1870 for (int x = 0; x < size.x; ++x) {
1871 const double dx = x + 0.5 - center_x;
1872 if (std::abs(dx) > draw_radius) continue;
1873
1874 const double half_height = std::sqrt(std::max(0.0, draw_radius * draw_radius - dx * dx));
1875 const int top = std::max(0, static_cast<int>(std::ceil(center_y - half_height)));
1876 const int bottom = std::min(size.y - 1, static_cast<int>(std::floor(center_y + half_height)));
1877 const double pos = size.x > 1 ? static_cast<double>(x) / (size.x - 1) : 0.0;
1878 const double scaled = pos * (m_cols.size() - 1);
1879 const size_t idx = std::min(static_cast<size_t>(scaled), m_cols.size() - 2);
1880 const double ratio = scaled - idx;
1881
1882 if (top <= bottom) {
1883 dc.SetBrush(wxBrush(mix_colour(m_cols[idx], m_cols[idx + 1], ratio)));
1884 dc.DrawRectangle(x, top, 1, bottom - top + 1);
1885 }
1886 }
1887 }
1888 else {
1889 float ev_angle = 360.0 / m_cols.size();
1890 const float overlap = 2.0f;
1891 wxPoint center(size.x / 2, size.y / 2);
1892 dc.SetPen(*wxTRANSPARENT_PEN);
1893 dc.SetBrush(wxBrush(m_cols.front()));
1894 dc.DrawCircle(center.x, center.y, radius);
1895 for (int i = 0; i < m_cols.size(); i++) {
1896 dc.SetBrush(m_cols[i]);
1897 float startAngle = 270.0f + i * ev_angle;
1898 float endAngle = startAngle + ev_angle;
1899 dc.DrawEllipticArc(center.x - radius, center.y - radius, 2 * radius, 2 * radius, startAngle - overlap, endAngle + overlap);
1900 }
1901 }
1902 }
1903 else if (alpha == 0) {
1904 wxSize bmp_size = m_bitmap_transparent_def.GetBmpSize();
1905 int center_x = (size.x - bmp_size.x) / 2;
1906 int center_y = (size.y - bmp_size.y) / 2;
1907 dc.DrawBitmap(m_bitmap_transparent_def.bmp(), center_x, center_y);
1908 }
1909 else if (alpha != 254 && alpha != 255) {
1910 if (transparent_changed) {
1911 std::string rgb = (m_colour.GetAsString(wxC2S_HTML_SYNTAX)).ToStdString();
1912 if (rgb.size() == 9) {
1913 //delete alpha value
1914 rgb = rgb.substr(0, rgb.size() - 2);
1915 }
1916 float alpha_f = 0.7 * m_colour.Alpha() / 255.0;
1917 std::vector<std::string> replace;
1918 replace.push_back(rgb);
1919 std::string fill_replace = "fill-opacity=\"" + std::to_string(alpha_f);
1920 replace.push_back(fill_replace);
1921 m_bitmap_transparent = ScalableBitmap(this, "transparent_color_picker", 25, false, false, true, replace).bmp();
1922 transparent_changed = false;
1923 }
1924 wxSize bmp_size = m_bitmap_transparent.GetSize();
1925 int center_x = (size.x - bmp_size.x) / 2;
1926 int center_y = (size.y - bmp_size.y) / 2;
1927 dc.DrawBitmap(m_bitmap_transparent, center_x, center_y);
1928 }
1929 else {
1930 dc.SetPen(wxPen(m_colour));
1931 dc.SetBrush(wxBrush(m_colour));
1932 dc.DrawCircle(size.x / 2, size.y / 2, radius);
1933 }
1934
1935 if (m_selected) {
1936 dc.SetPen(wxPen(m_colour));
1937 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1938 dc.DrawCircle(size.x / 2, size.y / 2, size.x / 2);
1939 }
1940
1941 if (m_show_full) {
1942 dc.SetPen(wxPen(wxColour("#6B6B6B")));
1943 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1944 dc.DrawCircle(size.x / 2, size.y / 2, radius);
1945 }
1946
1947 if (m_is_empty) {
1948 dc.SetTextForeground(*wxBLACK);
1949 auto tsize = dc.GetTextExtent("?");
1950 auto pot = wxPoint((size.x - tsize.x) / 2, (size.y - tsize.y) / 2);
1951 dc.DrawText("?", pot);
1952 }
1953}
bool m_show_full
Definition AMSMaterialsSetting.hpp:61
bool transparent_changed
Definition AMSMaterialsSetting.hpp:65
bool m_is_empty
Definition AMSMaterialsSetting.hpp:62
wxColour m_colour
Definition AMSMaterialsSetting.hpp:58
std::vector< wxColour > m_cols
Definition AMSMaterialsSetting.hpp:59
bool m_selected
Definition AMSMaterialsSetting.hpp:60
int ctype
Definition AMSMaterialsSetting.hpp:63
static wxColour mix_colour(const wxColour &left, const wxColour &right, double ratio)
Definition AMSMaterialsSetting.cpp:95
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16
BoundingBox scaled(const BoundingBoxf &bb)
Definition BoundingBox.hpp:284
void center(ExPolygonsWithIds &e)
Definition Emboss.cpp:1382

References ScalableBitmap::bmp(), Slic3r::center(), ctype, m_bitmap_transparent, m_bitmap_transparent_def, m_colour, m_cols, m_is_empty, m_selected, m_show_full, Slic3r::GUI::mix_colour(), Slic3r::scaled(), and transparent_changed.

Referenced by render().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_empty()

void Slic3r::GUI::ColorPicker::is_empty ( bool empty)
inline
75{m_is_empty = empty;};
bool empty(const BoundingBoxBase< PointType, PointsType > &bb)
Definition BoundingBox.hpp:273

References Slic3r::empty(), and m_is_empty.

Here is the call graph for this function:

◆ msw_rescale()

void Slic3r::GUI::ColorPicker::msw_rescale ( )
1807{
1808 m_bitmap_border = create_scaled_bitmap("color_picker_border", nullptr, 25);
1809 m_bitmap_border_dark = create_scaled_bitmap("color_picker_border_dark", nullptr, 25);
1810 m_bitmap_transparent_def.msw_rescale();
1811
1812 Refresh();
1813}

References create_scaled_bitmap(), m_bitmap_border, m_bitmap_border_dark, and m_bitmap_transparent_def.

Here is the call graph for this function:

◆ paintEvent()

void Slic3r::GUI::ColorPicker::paintEvent ( wxPaintEvent & evt)
1831{
1832 wxPaintDC dc(this);
1833 render(dc);
1834}
void render(wxDC &dc)
Definition AMSMaterialsSetting.cpp:1836

References render().

Referenced by ColorPicker().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render()

void Slic3r::GUI::ColorPicker::render ( wxDC & dc)
1837{
1838#ifdef __WXMSW__
1839 wxSize size = GetSize();
1840 wxMemoryDC memdc;
1841 wxBitmap bmp(size.x, size.y);
1842 memdc.SelectObject(bmp);
1843 memdc.Blit({ 0, 0 }, size, &dc, { 0, 0 });
1844
1845 {
1846 wxGCDC dc2(memdc);
1847 doRender(dc2);
1848 }
1849
1850 memdc.SelectObject(wxNullBitmap);
1851 dc.DrawBitmap(bmp, 0, 0);
1852#else
1853 doRender(dc);
1854#endif
1855}
void doRender(wxDC &dc)
Definition AMSMaterialsSetting.cpp:1857

References doRender().

Referenced by paintEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_color()

void Slic3r::GUI::ColorPicker::set_color ( wxColour col)
1816{
1817 if (m_colour != col && col.Alpha() != 0 && col.Alpha() != 255 && col.Alpha() != 254) {
1818 transparent_changed = true;
1819 }
1820 m_colour = col;
1821 Refresh();
1822}

References m_colour, and transparent_changed.

◆ set_colors()

void Slic3r::GUI::ColorPicker::set_colors ( std::vector< wxColour > cols)
1825{
1826 m_cols = cols;
1827 Refresh();
1828}
size_t cols(const T &raster)
Definition MarchingSquares.hpp:173

References m_cols.

◆ set_selected()

void Slic3r::GUI::ColorPicker::set_selected ( bool sel)
inline
73{m_selected = sel;Refresh();};

References m_selected.

◆ set_show_full()

void Slic3r::GUI::ColorPicker::set_show_full ( bool full)
inline
74{m_show_full = full;Refresh();};

References m_show_full.

Member Data Documentation

◆ ctype

int Slic3r::GUI::ColorPicker::ctype

Referenced by doRender().

◆ m_bitmap_border

wxBitmap Slic3r::GUI::ColorPicker::m_bitmap_border

Referenced by ColorPicker(), and msw_rescale().

◆ m_bitmap_border_dark

wxBitmap Slic3r::GUI::ColorPicker::m_bitmap_border_dark

Referenced by ColorPicker(), and msw_rescale().

◆ m_bitmap_transparent

wxBitmap Slic3r::GUI::ColorPicker::m_bitmap_transparent

Referenced by ColorPicker(), and doRender().

◆ m_bitmap_transparent_def

ScalableBitmap Slic3r::GUI::ColorPicker::m_bitmap_transparent_def

Referenced by ColorPicker(), doRender(), and msw_rescale().

◆ m_colour

wxColour Slic3r::GUI::ColorPicker::m_colour

Referenced by doRender(), and set_color().

◆ m_cols

std::vector<wxColour> Slic3r::GUI::ColorPicker::m_cols

Referenced by doRender(), and set_colors().

◆ m_is_empty

bool Slic3r::GUI::ColorPicker::m_is_empty {false}
62{false};

Referenced by doRender(), and is_empty().

◆ m_selected

bool Slic3r::GUI::ColorPicker::m_selected {false}
60{false};

Referenced by doRender(), and set_selected().

◆ m_show_full

bool Slic3r::GUI::ColorPicker::m_show_full {false}
61{false};

Referenced by doRender(), and set_show_full().

◆ transparent_changed

bool Slic3r::GUI::ColorPicker::transparent_changed {false}
65{false};

Referenced by doRender(), and set_color().


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