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

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

Inheritance diagram for Slic3r::GUI::CapsuleButton:
Collaboration diagram for Slic3r::GUI::CapsuleButton:

Public Member Functions

 CapsuleButton (wxWindow *parent, wxWindowID id, const wxString &label, bool selected)
void Select (bool selected)
bool IsSelected () const

Protected Member Functions

void OnPaint (wxPaintEvent &event)

Private Member Functions

void OnEnterWindow (wxMouseEvent &event)
void OnLeaveWindow (wxMouseEvent &event)
void UpdateStatus ()

Private Attributes

wxBitmapButton * m_btn
Label * m_label
wxBitmap tag_on_bmp
wxBitmap tag_off_bmp
bool m_hovered
bool m_selected

Detailed Description

Constructor & Destructor Documentation

◆ CapsuleButton()

Slic3r::GUI::CapsuleButton::CapsuleButton ( wxWindow * parent,
wxWindowID id,
const wxString & label,
bool selected )
27 : wxPanel(parent, id)
28{
29 SetBackgroundColour(*wxWHITE);
30 SetBackgroundStyle(wxBG_STYLE_PAINT);
31
32 m_hovered = false;
33 m_selected = selected;
34
35 auto sizer = new wxBoxSizer(wxHORIZONTAL);
36
37 tag_on_bmp = create_scaled_bitmap("capsule_tag_on", nullptr, FromDIP(16));
38 tag_off_bmp = create_scaled_bitmap("capsule_tag_off", nullptr, FromDIP(16));
39
40 m_btn = new wxBitmapButton(this, wxID_ANY, selected?tag_on_bmp:tag_off_bmp, wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
41 m_btn->SetBackgroundColour(*wxWHITE);
42
43 m_label = new Label(this, label);
44
45 sizer->AddSpacer(FromDIP(8));
46 sizer->Add(m_btn, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, FromDIP(6));
47 sizer->AddSpacer(FromDIP(8));
48 sizer->Add(m_label, 0, wxALIGN_CENTER);
49 sizer->AddSpacer(FromDIP(8));
50
51 SetSizer(sizer);
52 Layout();
53 Fit();
54
55 auto forward_click_to_parent = [this](auto &event) {
56 wxCommandEvent click_event(wxEVT_BUTTON, GetId());
57 click_event.SetEventObject(this);
58 this->ProcessEvent(click_event);
59 };
60
61 m_btn->Bind(wxEVT_LEFT_DOWN, forward_click_to_parent);
62 m_label->Bind(wxEVT_LEFT_DOWN, forward_click_to_parent);
63 this->Bind(wxEVT_LEFT_DOWN, forward_click_to_parent);
64
65 Bind(wxEVT_PAINT, &CapsuleButton::OnPaint, this);
66 Bind(wxEVT_ENTER_WINDOW, &CapsuleButton::OnEnterWindow, this);
67 Bind(wxEVT_LEAVE_WINDOW, &CapsuleButton::OnLeaveWindow, this);
68
70}
void OnPaint(wxPaintEvent &event)
Definition CapsuleButton.cpp:71
void UpdateStatus()
Definition CapsuleButton.cpp:120
wxBitmapButton * m_btn
Definition CapsuleButton.hpp:26
wxBitmap tag_off_bmp
Definition CapsuleButton.hpp:30
bool m_hovered
Definition CapsuleButton.hpp:32
bool m_selected
Definition CapsuleButton.hpp:33
void OnEnterWindow(wxMouseEvent &event)
Definition CapsuleButton.cpp:98
wxBitmap tag_on_bmp
Definition CapsuleButton.hpp:29
Label * m_label
Definition CapsuleButton.hpp:27
void OnLeaveWindow(wxMouseEvent &event)
Definition CapsuleButton.cpp:108
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_btn, m_hovered, m_label, m_selected, OnEnterWindow(), OnLeaveWindow(), OnPaint(), tag_off_bmp, tag_on_bmp, and UpdateStatus().

Here is the call graph for this function:

Member Function Documentation

◆ IsSelected()

bool Slic3r::GUI::CapsuleButton::IsSelected ( ) const
inline
18{ return m_selected; }

References m_selected.

◆ OnEnterWindow()

void Slic3r::GUI::CapsuleButton::OnEnterWindow ( wxMouseEvent & event)
private
99{
100 if (!m_hovered) {
101 m_hovered = true;
102 UpdateStatus();
103 Refresh();
104 }
105 event.Skip();
106}

References m_hovered, UpdateStatus(), and Slic3r::GUI::wxMouseEvent.

Referenced by CapsuleButton().

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

◆ OnLeaveWindow()

void Slic3r::GUI::CapsuleButton::OnLeaveWindow ( wxMouseEvent & event)
private
109{
110 if (m_hovered) {
111 wxPoint pos = this->ScreenToClient(wxGetMousePosition());
112 if (this->GetClientRect().Contains(pos)) return;
113 m_hovered = false;
114 UpdateStatus();
115 Refresh();
116 }
117 event.Skip();
118}
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16

References m_hovered, UpdateStatus(), and Slic3r::GUI::wxMouseEvent.

Referenced by CapsuleButton().

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

◆ OnPaint()

void Slic3r::GUI::CapsuleButton::OnPaint ( wxPaintEvent & event)
protected
72{
73 wxAutoBufferedPaintDC dc(this);
74 wxGraphicsContext *gc = wxGraphicsContext::Create(dc);
75
76 if (gc) {
77 dc.Clear();
78 wxRect rect = GetClientRect();
79 gc->SetBrush(wxTransparentColour);
80 gc->DrawRoundedRectangle(0, 0, rect.width, rect.height, 0);
82 wxColour border_color = m_hovered || m_selected ? BorderSelectColor : BorderNormalColor;
84 border_color = StateColor::darkModeColorFor(border_color);
85 gc->SetBrush(wxBrush(bg_color));
86 gc->SetPen(wxPen(border_color, 1));
87 gc->DrawRoundedRectangle(1, 1, rect.width - 2, rect.height - 2, 5);
88 delete gc;
89 }
90}
static wxColour darkModeColorFor(wxColour const &color)
Definition StateColor.cpp:219
wxColour bg_color()
Definition SpeedDialDialog.cpp:69
static const wxColour BorderNormalColor
Definition CapsuleButton.cpp:24
static const wxColour BgNormalColor
Definition CapsuleButton.cpp:18
static const wxColour BgSelectColor
Definition CapsuleButton.cpp:19
static const wxColour BorderSelectColor
Definition CapsuleButton.cpp:25

References Slic3r::GUI::BgNormalColor, Slic3r::GUI::BgSelectColor, Slic3r::GUI::BorderNormalColor, Slic3r::GUI::BorderSelectColor, StateColor::darkModeColorFor(), m_hovered, and m_selected.

Referenced by CapsuleButton().

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

◆ Select()

void Slic3r::GUI::CapsuleButton::Select ( bool selected)
92{
93 m_selected = selected;
95 Refresh();
96}

References m_selected, and UpdateStatus().

Here is the call graph for this function:

◆ UpdateStatus()

void Slic3r::GUI::CapsuleButton::UpdateStatus ( )
private
121{
122 if (m_selected) {
123 m_btn->SetBitmap(tag_on_bmp);
124 m_label->SetForegroundColour(TextSelectColor);
125 m_label->SetBackgroundColour(BgSelectColor);
126 m_btn->SetBackgroundColour(BgSelectColor);
127 } else {
128 m_btn->SetBitmap(tag_off_bmp);
129 m_label->SetForegroundColour(TextNormalColor);
130 m_label->SetBackgroundColour(BgNormalColor);
131 m_btn->SetBackgroundColour(BgNormalColor);
132 }
133
134 GUI::wxGetApp().UpdateDarkUIWin(this);
135}
static const wxColour TextNormalColor
Definition CapsuleButton.cpp:21
static const wxColour TextSelectColor
Definition CapsuleButton.cpp:22

References Slic3r::GUI::BgNormalColor, Slic3r::GUI::BgSelectColor, m_btn, m_label, m_selected, tag_off_bmp, tag_on_bmp, Slic3r::GUI::TextNormalColor, and Slic3r::GUI::TextSelectColor.

Referenced by CapsuleButton(), OnEnterWindow(), OnLeaveWindow(), and Select().

Here is the caller graph for this function:

Member Data Documentation

◆ m_btn

wxBitmapButton* Slic3r::GUI::CapsuleButton::m_btn
private

Referenced by CapsuleButton(), and UpdateStatus().

◆ m_hovered

bool Slic3r::GUI::CapsuleButton::m_hovered
private

◆ m_label

Label* Slic3r::GUI::CapsuleButton::m_label
private

Referenced by CapsuleButton(), and UpdateStatus().

◆ m_selected

bool Slic3r::GUI::CapsuleButton::m_selected
private

◆ tag_off_bmp

wxBitmap Slic3r::GUI::CapsuleButton::tag_off_bmp
private

Referenced by CapsuleButton(), and UpdateStatus().

◆ tag_on_bmp

wxBitmap Slic3r::GUI::CapsuleButton::tag_on_bmp
private

Referenced by CapsuleButton(), and UpdateStatus().


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