OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::UVToolButton Class Reference
Inheritance diagram for Slic3r::GUI::UVToolButton:
Collaboration diagram for Slic3r::GUI::UVToolButton:

Public Member Functions

 UVToolButton (wxWindow *parent, wxWindowID id, const std::string &icon, const wxString &label, const wxString &tip, bool toggle, bool accent=false, int size_dip=26)
void SetValue (bool on)
bool GetValue () const
void SetBitmap (const wxBitmap &bmp)
void SetBadge (bool badge)
bool Enable (bool enable=true) override
void SetUnavailable (const wxString &reason)
void SetTip (const wxString &tip)
bool usable () const

Protected Member Functions

wxSize DoGetBestSize () const override

Private Member Functions

void on_paint (wxPaintEvent &)

Private Attributes

std::string m_icon_name
int m_icon_dip = 16
wxBitmap m_icon
double m_icon_scale = 0.
wxBitmap m_bitmap
wxString m_label
bool m_toggle = false
bool m_accent = false
int m_size_dip = 26
wxString m_tip
wxString m_unavailable
bool m_on = false
bool m_badge = false
bool m_hover = false
bool m_pressed = false

Detailed Description

Constructor & Destructor Documentation

◆ UVToolButton()

Slic3r::GUI::UVToolButton::UVToolButton ( wxWindow * parent,
wxWindowID id,
const std::string & icon,
const wxString & label,
const wxString & tip,
bool toggle,
bool accent = false,
int size_dip = 26 )
inline
1805 : wxWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxFULL_REPAINT_ON_RESIZE)
1806 , m_icon_name(icon), m_icon_dip(size_dip >= 26 ? 16 : 14), m_label(label), m_toggle(toggle), m_accent(accent)
1807 , m_size_dip(size_dip), m_tip(tip)
1808 {
1809 SetBackgroundStyle(wxBG_STYLE_PAINT);
1810 SetToolTip(tip);
1811 if (accent) {
1812 wxFont font = GetFont();
1813 font.MakeBold();
1814 SetFont(font);
1815 }
1816 Bind(wxEVT_PAINT, &UVToolButton::on_paint, this);
1817 Bind(wxEVT_ENTER_WINDOW, [this](wxMouseEvent &) { m_hover = true; Refresh(); });
1818 Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent &) { m_hover = false; m_pressed = false; Refresh(); });
1819 Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &) {
1820 if (usable()) {
1821 m_pressed = true;
1822 Refresh();
1823 }
1824 });
1825 Bind(wxEVT_LEFT_UP, [this](wxMouseEvent &e) {
1826 const bool was_pressed = m_pressed;
1827 m_pressed = false;
1828 Refresh();
1829 if (!was_pressed || !usable() || !GetClientRect().Contains(e.GetPosition()))
1830 return;
1831 if (m_toggle)
1832 m_on = !m_on;
1833 wxCommandEvent evt(wxEVT_BUTTON, GetId());
1834 evt.SetEventObject(this);
1835 evt.SetInt(m_on ? 1 : 0);
1836 ProcessWindowEvent(evt);
1837 });
1838 SetMinSize(DoGetBestSize());
1839 }
std::string m_icon_name
Definition UVEditorCanvas.cpp:1962
bool usable() const
Definition UVEditorCanvas.cpp:1892
bool m_toggle
Definition UVEditorCanvas.cpp:1968
void on_paint(wxPaintEvent &)
Definition UVEditorCanvas.cpp:1905
bool m_pressed
Definition UVEditorCanvas.cpp:1976
wxString m_tip
Definition UVEditorCanvas.cpp:1971
wxSize DoGetBestSize() const override
Definition UVEditorCanvas.cpp:1895
wxString m_label
Definition UVEditorCanvas.cpp:1967
bool m_on
Definition UVEditorCanvas.cpp:1973
int m_size_dip
Definition UVEditorCanvas.cpp:1970
bool m_hover
Definition UVEditorCanvas.cpp:1975
int m_icon_dip
Definition UVEditorCanvas.cpp:1963
bool m_accent
Definition UVEditorCanvas.cpp:1969
wxMouseEvent
Definition CameraPopup.cpp:47

References DoGetBestSize(), m_accent, m_hover, m_icon_dip, m_icon_name, m_label, m_on, m_pressed, m_size_dip, m_tip, m_toggle, on_paint(), usable(), and Slic3r::GUI::wxMouseEvent.

Here is the call graph for this function:

Member Function Documentation

◆ DoGetBestSize()

wxSize Slic3r::GUI::UVToolButton::DoGetBestSize ( ) const
inlineoverrideprotected
1896 {
1897 const int h = FromDIP(m_size_dip);
1898 if (m_label.empty())
1899 return wxSize(h, h);
1900 const int icon_w = m_icon_name.empty() ? 0 : FromDIP(m_icon_dip) + FromDIP(6);
1901 return wxSize(FromDIP(9) + icon_w + GetTextExtent(m_label).x + FromDIP(10), h);
1902 }

References m_icon_dip, m_icon_name, m_label, and m_size_dip.

Referenced by UVToolButton().

Here is the caller graph for this function:

◆ Enable()

bool Slic3r::GUI::UVToolButton::Enable ( bool enable = true)
inlineoverride
1863 {
1864 const bool changed = wxWindow::Enable(enable);
1865 if (changed)
1866 Refresh();
1867 return changed;
1868 }

◆ GetValue()

bool Slic3r::GUI::UVToolButton::GetValue ( ) const
inline
1848{ return m_on; }

References m_on.

◆ on_paint()

void Slic3r::GUI::UVToolButton::on_paint ( wxPaintEvent & )
inlineprivate
1906 {
1907 wxAutoBufferedPaintDC dc(this);
1908 const PaneColors c = PaneColors::current();
1909 const wxRect r = GetClientRect();
1910 const wxColour teal(0x00, 0x96, 0x88);
1911 const bool enabled = usable();
1912
1913 wxColour fill = c.bg, border = c.frame, text = c.ink;
1914 if (m_accent) {
1915 fill = (m_hover && enabled) ? wxColour(0x26, 0xa6, 0x9a) : teal;
1916 border = fill;
1917 text = *wxWHITE;
1918 } else if (m_on) {
1919 fill = mix(c.bg, teal, 0.22);
1920 border = teal;
1921 } else if (m_hover && enabled) {
1922 fill = c.hover;
1923 }
1924 if (m_pressed)
1925 fill = mix(fill, teal, 0.18);
1926
1927 dc.SetBackground(wxBrush(c.bg));
1928 dc.Clear();
1929 dc.SetBrush(wxBrush(fill));
1930 dc.SetPen(wxPen(border, 1));
1931 dc.DrawRoundedRectangle(r, FromDIP(2));
1932
1933 // Rasterised on first paint rather than in the constructor: the content scale is only reliable once the
1934 // window is on screen, and it changes when the window moves to a screen with a different one.
1935 if (!m_icon_name.empty() && (!m_icon.IsOk() || m_icon_scale != GetContentScaleFactor())) {
1936 m_icon_scale = GetContentScaleFactor();
1938 }
1939 const wxBitmap &bmp = m_bitmap.IsOk() ? m_bitmap : m_icon;
1940 int x = 0;
1941 if (bmp.IsOk()) {
1942 const wxSize bs = drawn_size(bmp);
1943 x = m_label.empty() ? (r.width - bs.x) / 2 : FromDIP(9);
1944 dc.DrawBitmap(enabled ? bmp : faded(bmp, 0.35), x, (r.height - bs.y) / 2, true);
1945 x += bs.x + FromDIP(6);
1946 } else {
1947 x = FromDIP(9);
1948 }
1949 if (!m_label.empty()) {
1950 dc.SetFont(GetFont());
1951 dc.SetTextForeground(enabled ? text : mix(text, c.bg, 0.55));
1952 dc.DrawText(m_label, x, (r.height - dc.GetTextExtent(m_label).y) / 2);
1953 }
1954 if (m_badge) {
1955 const int d = FromDIP(9);
1956 dc.SetPen(wxPen(c.bg, FromDIP(2)));
1957 dc.SetBrush(wxBrush(wxColour(0xe0, 0xa4, 0x4a)));
1958 dc.DrawCircle(r.width - d / 2 - 1, d / 2 + 1, d / 2);
1959 }
1960 }
wxBitmap m_bitmap
Definition UVEditorCanvas.cpp:1966
wxBitmap m_icon
Definition UVEditorCanvas.cpp:1964
bool m_badge
Definition UVEditorCanvas.cpp:1974
double m_icon_scale
Definition UVEditorCanvas.cpp:1965
wxBitmap pane_icon(wxWindow *win, const std::string &name, int size_dip)
Definition UVEditorCanvas.cpp:1737
wxBitmap faded(const wxBitmap &bmp, double alpha)
Definition UVEditorCanvas.cpp:1761
wxColour mix(const wxColour &a, const wxColour &b, double t)
Definition UVEditorCanvas.cpp:1786
wxSize drawn_size(const wxBitmap &bmp)
Definition UVEditorCanvas.cpp:1751

References m_accent, m_badge, m_bitmap, m_hover, m_icon, m_icon_dip, m_icon_name, m_icon_scale, m_label, m_on, m_pressed, and usable().

Referenced by UVToolButton().

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

◆ SetBadge()

void Slic3r::GUI::UVToolButton::SetBadge ( bool badge)
inline
1856 {
1857 if (badge != m_badge) {
1858 m_badge = badge;
1859 Refresh();
1860 }
1861 }

References m_badge.

◆ SetBitmap()

void Slic3r::GUI::UVToolButton::SetBitmap ( const wxBitmap & bmp)
inline
1851 {
1852 m_bitmap = bmp;
1853 Refresh();
1854 }

References m_bitmap.

◆ SetTip()

void Slic3r::GUI::UVToolButton::SetTip ( const wxString & tip)
inline
1886 {
1887 if (tip == m_tip)
1888 return;
1889 m_tip = tip;
1890 SetToolTip(m_unavailable.empty() || m_tip.empty() ? m_tip : m_tip + "\n\n" + m_unavailable);
1891 }
wxString m_unavailable
Definition UVEditorCanvas.cpp:1972

References m_tip, and m_unavailable.

◆ SetUnavailable()

void Slic3r::GUI::UVToolButton::SetUnavailable ( const wxString & reason)
inline
1875 {
1876 if (reason == m_unavailable)
1877 return;
1878 m_unavailable = reason;
1879 SetToolTip(reason.empty() || m_tip.empty() ? m_tip : m_tip + "\n\n" + reason);
1880 if (!m_unavailable.empty())
1881 m_pressed = false; // a reason appearing mid-press cancels the press
1882 Refresh();
1883 }

References m_pressed, m_tip, and m_unavailable.

◆ SetValue()

void Slic3r::GUI::UVToolButton::SetValue ( bool on)
inline
1842 {
1843 if (on != m_on) {
1844 m_on = on;
1845 Refresh();
1846 }
1847 }

References m_on.

◆ usable()

bool Slic3r::GUI::UVToolButton::usable ( ) const
inline
1892{ return IsEnabled() && m_unavailable.empty(); }
bool IsEnabled()
Definition dark_mode.cpp:32

References m_unavailable.

Referenced by UVToolButton(), and on_paint().

Here is the caller graph for this function:

Member Data Documentation

◆ m_accent

bool Slic3r::GUI::UVToolButton::m_accent = false
private

Referenced by UVToolButton(), and on_paint().

◆ m_badge

bool Slic3r::GUI::UVToolButton::m_badge = false
private

Referenced by on_paint(), and SetBadge().

◆ m_bitmap

wxBitmap Slic3r::GUI::UVToolButton::m_bitmap
private

Referenced by on_paint(), and SetBitmap().

◆ m_hover

bool Slic3r::GUI::UVToolButton::m_hover = false
private

Referenced by UVToolButton(), and on_paint().

◆ m_icon

wxBitmap Slic3r::GUI::UVToolButton::m_icon
private

Referenced by on_paint().

◆ m_icon_dip

int Slic3r::GUI::UVToolButton::m_icon_dip = 16
private

◆ m_icon_name

std::string Slic3r::GUI::UVToolButton::m_icon_name
private

◆ m_icon_scale

double Slic3r::GUI::UVToolButton::m_icon_scale = 0.
private

Referenced by on_paint().

◆ m_label

wxString Slic3r::GUI::UVToolButton::m_label
private

◆ m_on

bool Slic3r::GUI::UVToolButton::m_on = false
private

◆ m_pressed

bool Slic3r::GUI::UVToolButton::m_pressed = false
private

◆ m_size_dip

int Slic3r::GUI::UVToolButton::m_size_dip = 26
private

Referenced by UVToolButton(), and DoGetBestSize().

◆ m_tip

wxString Slic3r::GUI::UVToolButton::m_tip
private

◆ m_toggle

bool Slic3r::GUI::UVToolButton::m_toggle = false
private

Referenced by UVToolButton().

◆ m_unavailable

wxString Slic3r::GUI::UVToolButton::m_unavailable
private

Referenced by SetTip(), SetUnavailable(), and usable().


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