OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
SideButton Class Reference

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

Inheritance diagram for SideButton:
Collaboration diagram for SideButton:

Public Types

enum  EHorizontalOrientation : unsigned char { HO_Left , HO_Center , HO_Right , Num_Horizontal_Orientations }

Public Member Functions

 SideButton (wxWindow *parent, wxString text, wxString icon="", long style=0, int iconSize=0)
void SetCornerRadius (double radius)
void SetCornerEnable (const std::vector< bool > &enable)
void SetTextLayout (EHorizontalOrientation orient, int margin=15)
void SetLayoutStyle (int style)
void SetLabel (const wxString &label) override
bool SetForegroundColour (wxColour const &colour) override
bool SetBackgroundColour (wxColour const &color) override
bool SetBottomColour (wxColour const &color)
void SetMinSize (const wxSize &size) override
void SetBorderColor (StateColor const &color)
void SetForegroundColor (StateColor const &color)
void SetBackgroundColor (StateColor const &color)
bool Enable (bool enable=true) override
void Rescale ()
void SetExtraSize (const wxSize &size)
void SetIconOffset (const int offset)

Private Member Functions

void paintEvent (wxPaintEvent &evt)
void dorender (wxDC &dc, wxDC &text_dc)
void messureSize ()
void mouseDown (wxMouseEvent &event)
void mouseReleased (wxMouseEvent &event)
void mouseCaptureLost (wxMouseCaptureLostEvent &event)
void sendButtonEvent ()

Private Attributes

wxSize textSize
wxSize minSize
ScalableBitmap icon
double radius
wxSize extra_size
int icon_offset
std::vector< bool > radius_enable
StateHandler state_handler
StateColor text_color
StateColor border_color
StateColor background_color
wxColour bottom_color
bool pressedDown = false
int layout_style = 0
EHorizontalOrientation text_orientation
int text_margin

Detailed Description

Member Enumeration Documentation

◆ EHorizontalOrientation

enum SideButton::EHorizontalOrientation : unsigned char
Enumerator
HO_Left 
HO_Center 
HO_Right 
Num_Horizontal_Orientations 
25 {
26 HO_Left,
30 };
@ HO_Center
Definition SideButton.hpp:27
@ HO_Left
Definition SideButton.hpp:26
@ HO_Right
Definition SideButton.hpp:28
@ Num_Horizontal_Orientations
Definition SideButton.hpp:29

Constructor & Destructor Documentation

◆ SideButton()

SideButton::SideButton ( wxWindow * parent,
wxString text,
wxString icon = "",
long style = 0,
int iconSize = 0 )
25 : wxWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, stlye)
26 , state_handler(this)
27{
28 radius = 12;
29#ifdef __APPLE__
30 extra_size = wxSize(38 + FromDIP(20), 10);
31 text_margin = 15 + FromDIP(20);
32#else
33 extra_size = wxSize(38, 10);
34 text_margin = 15;
35#endif
36
37 icon_offset = 0;
39
40 border_color.append(0x6B6B6B, StateColor::Disabled);
41 border_color.append(wxColour(0, 137, 123), StateColor::Pressed);
42 border_color.append(wxColour(38, 166, 154), StateColor::Hovered);
43 border_color.append(0x009688, StateColor::Normal);
44 border_color.setTakeFocusedAsHovered(false);
45
46 text_color.append(0xACACAC, StateColor::Disabled);
47 text_color.append(0xFEFEFE, StateColor::Pressed);
48 text_color.append(0xFEFEFE, StateColor::Hovered);
49 text_color.append(0xFEFEFE, StateColor::Normal);
50
51 background_color.append(0x6B6B6B, StateColor::Disabled);
52 background_color.append(wxColour(0, 137, 123), StateColor::Pressed);
53 background_color.append(wxColour(38, 166, 154), StateColor::Hovered);
54 background_color.append(0x009688, StateColor::Normal);
55 background_color.setTakeFocusedAsHovered(false);
56
57 SetBottomColour(wxColour("#3B4446"));
58
60 state_handler.update_binds();
61
62 // icon only
63 if (!icon.IsEmpty()) {
64 this->icon = ScalableBitmap(this, icon.ToStdString(), iconSize > 0 ? iconSize : 14);
65 }
66
67 SetFont(Label::Body_14);
68 wxWindow::SetLabel(text);
69
71}
static wxFont Body_14
Definition Label.hpp:53
int text_margin
Definition SideButton.hpp:86
int icon_offset
Definition SideButton.hpp:73
ScalableBitmap icon
Definition SideButton.hpp:70
void messureSize()
Definition SideButton.cpp:299
StateHandler state_handler
Definition SideButton.hpp:76
wxSize extra_size
Definition SideButton.hpp:72
EHorizontalOrientation text_orientation
Definition SideButton.hpp:85
double radius
Definition SideButton.hpp:71
StateColor border_color
Definition SideButton.hpp:78
bool SetBottomColour(wxColour const &color)
Definition SideButton.cpp:123
StateColor text_color
Definition SideButton.hpp:77
StateColor background_color
Definition SideButton.hpp:79
@ Hovered
Definition StateColor.hpp:20
@ Normal
Definition StateColor.hpp:16
@ Disabled
Definition StateColor.hpp:22
@ Pressed
Definition StateColor.hpp:21

References SideButton(), background_color, Label::Body_14, border_color, StateColor::Disabled, extra_size, HO_Left, StateColor::Hovered, icon, icon_offset, messureSize(), StateColor::Normal, StateColor::Pressed, radius, SetBottomColour(), state_handler, text_color, text_margin, and text_orientation.

Referenced by SideButton().

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

Member Function Documentation

◆ dorender()

void SideButton::dorender ( wxDC & dc,
wxDC & text_dc )
private
206{
207 wxSize size = GetSize();
208
209 // draw background
210 dc.SetPen(wxNullPen);
212 dc.DrawRectangle(0, 0, size.x, size.y);
213
214 int states = state_handler.states();
215 dc.SetBrush(wxBrush(background_color.colorForStates(states)));
216
217 dc.SetPen(wxPen(border_color.colorForStates(states)));
218 int pen_width = dc.GetPen().GetWidth();
219
220
221 // draw icon style
222 if (icon.bmp().IsOk()) {
223 if (radius > 1e-5) {
224 dc.DrawRoundedRectangle(0, 0, size.x, size.y, radius);
225 dc.DrawRectangle(radius, 0, size.x - radius, size.y);
226 dc.SetPen(wxNullPen);
227 dc.DrawRectangle(radius - pen_width, pen_width, radius, size.y - 2 * pen_width);
228 }
229 else {
230 dc.DrawRectangle(0, 0, size.x, size.y);
231 }
232 }
233 // draw text style
234 else {
235 if (radius > 1e-5) {
236 if (layout_style == 1) {
237 dc.DrawRoundedRectangle(0, 0, size.x, size.y, radius);
238 dc.SetPen(wxNullPen);
239 } else {
240 dc.DrawRoundedRectangle(0, 0, size.x, size.y, radius);
241 dc.DrawRectangle(0, 0, radius, size.y);
242 dc.SetPen(wxNullPen);
243 dc.DrawRectangle(pen_width, pen_width, size.x - radius, size.y - 2 * pen_width);
244 }
245 } else {
246 dc.DrawRectangle(0, 0, size.x, size.y);
247 }
248 }
249
250 dc.SetBrush(*wxTRANSPARENT_BRUSH);
251 // calc content size
252 wxSize szIcon;
253 wxSize szContent = textSize;
254 if (icon.bmp().IsOk()) {
255 if (szContent.y > 0) {
256 //BBS norrow size between text and icon
257 szContent.x += 5;
258 }
259 szIcon = icon.GetBmpSize();
260 szContent.x += szIcon.x;
261 if (szIcon.y > szContent.y)
262 szContent.y = szIcon.y;
263 }
264 // move to center
265 wxRect rcContent = { {0, 0}, size };
267 wxSize offset = (size - szContent) / 2;
268 rcContent.Deflate(offset.x, offset.y);
270 wxSize offset = (size - szContent) / 2;
271 rcContent.Deflate(text_margin, offset.y);
273 wxSize offset = (size - szContent) / 2;
274 rcContent.Deflate(size.x - text_margin, offset.y);
275 }
276
277 // start draw
278 wxPoint pt = rcContent.GetLeftTop();
279 if (icon.bmp().IsOk()) {
280 //BBS extra pixels for icon
281 pt.x += icon_offset;
282 pt.y += (rcContent.height - szIcon.y) / 2;
283 dc.DrawBitmap(icon.bmp(), pt);
284 //BBS norrow size between text and icon
285 pt.x += szIcon.x + 5;
286 pt.y = rcContent.y;
287 }
288
289 auto text = GetLabel();
290 if (!text.IsEmpty()) {
291 pt.y += (rcContent.height - textSize.y) / 2;
292 text_dc.SetFont(GetFont());
293 text_dc.SetTextForeground(text_color.colorForStates(states));
294 text_dc.DrawText(text, pt);
295 }
296
297}
int layout_style
Definition SideButton.hpp:83
wxSize textSize
Definition SideButton.hpp:68
wxColour bottom_color
Definition SideButton.hpp:80
static wxColour darkModeColorFor(wxColour const &color)
Definition StateColor.cpp:219
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:582

References background_color, border_color, bottom_color, StateColor::darkModeColorFor(), HO_Center, HO_Left, HO_Right, icon, icon_offset, layout_style, radius, state_handler, text_color, text_margin, text_orientation, and textSize.

Referenced by paintEvent().

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

◆ Enable()

bool SideButton::Enable ( bool enable = true)
override
157{
158 bool result = wxWindow::Enable(enable);
159 if (result) {
160 wxCommandEvent e(EVT_ENABLE_CHANGED);
161 e.SetEventObject(this);
162 GetEventHandler()->ProcessEvent(e);
163 }
164 return result;
165}

◆ messureSize()

void SideButton::messureSize ( )
private
300{
301 textSize = GetTextExtent(GetLabel());
302 if (minSize.GetWidth() > 0) {
303 wxWindow::SetMinSize(minSize);
304 return;
305 }
306
307 wxSize szContent = textSize;
308 if (this->icon.bmp().IsOk()) {
309 if (szContent.y > 0) {
310 szContent.x += 5;
311 }
312 wxSize szIcon = this->icon.GetBmpSize();
313 szContent.x += szIcon.x;
314 if (szIcon.y > szContent.y)
315 szContent.y = szIcon.y;
316 //BBS icon only
317 wxWindow::SetMinSize(szContent + wxSize(szContent.GetX() + extra_size.GetX(), minSize.GetHeight()));
318 }
319 else {
320 if (minSize.GetHeight() > 0) {
321 //BBS with text size
322 wxWindow::SetMinSize(wxSize(szContent.GetX() + extra_size.GetX(), minSize.GetHeight()));
323 } else {
324 //BBS with text size
325 wxWindow::SetMinSize(szContent + extra_size);
326 }
327 }
328}
wxSize minSize
Definition SideButton.hpp:69

References extra_size, icon, minSize, and textSize.

Referenced by SideButton(), Rescale(), SetExtraSize(), SetIconOffset(), SetLabel(), SetLayoutStyle(), SetMinSize(), and SetTextLayout().

Here is the caller graph for this function:

◆ mouseCaptureLost()

void SideButton::mouseCaptureLost ( wxMouseCaptureLostEvent & event)
private
355{
356 pressedDown = false;
357}
bool pressedDown
Definition SideButton.hpp:82

References pressedDown.

◆ mouseDown()

void SideButton::mouseDown ( wxMouseEvent & event)
private
331{
332 event.Skip();
333 pressedDown = true;
334 SetFocus();
335 // Capturing twice pushes this button onto the capture stack twice, and the
336 // release would then hand the capture straight back to it.
337 if (!HasCapture())
338 CaptureMouse();
339}

References pressedDown.

◆ mouseReleased()

void SideButton::mouseReleased ( wxMouseEvent & event)
private
342{
343 event.Skip();
344 // A press whose release went elsewhere still holds the capture.
345 if (HasCapture())
346 ReleaseMouse();
347 if (pressedDown) {
348 pressedDown = false;
349 if (wxRect({0, 0}, GetSize()).Contains(event.GetPosition()))
351 }
352}
void sendButtonEvent()
Definition SideButton.cpp:359

References pressedDown, and sendButtonEvent().

Here is the call graph for this function:

◆ paintEvent()

void SideButton::paintEvent ( wxPaintEvent & evt)
private
187{
188 // depending on your system you may need to look at double-buffered dcs
189 wxPaintDC dc(this);
190#ifdef __WXMSW__
191 wxGCDC dc2(dc);
192#else
193 wxDC & dc2(dc);
194#endif
195
196 wxDC & dctext(dc);
197 dorender(dc2, dctext);
198}
void dorender(wxDC &dc, wxDC &text_dc)
Definition SideButton.cpp:205

References dorender().

Here is the call graph for this function:

◆ Rescale()

void SideButton::Rescale ( )
168{
169 if (this->icon.bmp().IsOk())
170 this->icon.msw_rescale();
171 messureSize();
172}

References icon, and messureSize().

Here is the call graph for this function:

◆ sendButtonEvent()

void SideButton::sendButtonEvent ( )
private
360{
361 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
362 event.SetEventObject(this);
363 GetEventHandler()->ProcessEvent(event);
364}

Referenced by mouseReleased().

Here is the caller graph for this function:

◆ SetBackgroundColor()

void SideButton::SetBackgroundColor ( StateColor const & color)
150{
151 background_color = color;
152 state_handler.update_binds();
153 Refresh();
154}

References background_color, and state_handler.

◆ SetBackgroundColour()

bool SideButton::SetBackgroundColour ( wxColour const & color)
override
117{
118 background_color = StateColor(color);
119 state_handler.update_binds();
120 return true;
121}

References background_color, and state_handler.

◆ SetBorderColor()

void SideButton::SetBorderColor ( StateColor const & color)
136{
137 border_color = color;
138 state_handler.update_binds();
139 Refresh();
140}

References border_color, and state_handler.

◆ SetBottomColour()

bool SideButton::SetBottomColour ( wxColour const & color)
124{
125 bottom_color = color;
126 return true;
127}

References bottom_color.

Referenced by SideButton().

Here is the caller graph for this function:

◆ SetCornerEnable()

void SideButton::SetCornerEnable ( const std::vector< bool > & enable)
80{
81 radius_enable.clear();
82 for (auto en : enable) {
83 radius_enable.push_back(en);
84 }
85}
std::vector< bool > radius_enable
Definition SideButton.hpp:74

References radius_enable.

◆ SetCornerRadius()

void SideButton::SetCornerRadius ( double radius)
74{
75 this->radius = radius;
76 Refresh();
77}

References radius.

Referenced by Slic3r::GUI::MainFrame::create_side_tools().

Here is the caller graph for this function:

◆ SetExtraSize()

void SideButton::SetExtraSize ( const wxSize & size)
175{
176 extra_size = size;
177 messureSize();
178}

References extra_size, and messureSize().

Here is the call graph for this function:

◆ SetForegroundColor()

void SideButton::SetForegroundColor ( StateColor const & color)
143{
144 text_color = color;
145 state_handler.update_binds();
146 Refresh();
147}

References state_handler, and text_color.

◆ SetForegroundColour()

bool SideButton::SetForegroundColour ( wxColour const & colour)
override
110{
111 text_color = StateColor(color);
112 state_handler.update_binds();
113 return true;
114}

References state_handler, and text_color.

◆ SetIconOffset()

void SideButton::SetIconOffset ( const int offset)
181{
183 messureSize();
184}

References icon_offset, and messureSize().

Here is the call graph for this function:

◆ SetLabel()

void SideButton::SetLabel ( const wxString & label)
override
103{
104 wxWindow::SetLabel(label);
105 messureSize();
106 Refresh();
107}

References messureSize().

Here is the call graph for this function:

◆ SetLayoutStyle()

void SideButton::SetLayoutStyle ( int style)
96{
99 Refresh();
100}
#define style
Definition WipeTowerDialog.cpp:101

References layout_style, messureSize(), and style.

Here is the call graph for this function:

◆ SetMinSize()

void SideButton::SetMinSize ( const wxSize & size)
override
130{
131 minSize = size;
132 messureSize();
133}

References messureSize(), and minSize.

Here is the call graph for this function:

◆ SetTextLayout()

void SideButton::SetTextLayout ( EHorizontalOrientation orient,
int margin = 15 )
88{
90 text_margin = margin;
92 Refresh();
93}
void orient(OrientMeshs &arrangables, const OrientMeshs &excludes, const OrientParams &params)
Orients the input polygons.
Definition Orient.cpp:613

References messureSize(), text_margin, and text_orientation.

Here is the call graph for this function:

Member Data Documentation

◆ background_color

StateColor SideButton::background_color
private

◆ border_color

StateColor SideButton::border_color
private

◆ bottom_color

wxColour SideButton::bottom_color
private

Referenced by dorender(), and SetBottomColour().

◆ extra_size

wxSize SideButton::extra_size
private

◆ icon

ScalableBitmap SideButton::icon
private

◆ icon_offset

int SideButton::icon_offset
private

Referenced by SideButton(), dorender(), and SetIconOffset().

◆ layout_style

int SideButton::layout_style = 0
private

Referenced by dorender(), and SetLayoutStyle().

◆ minSize

wxSize SideButton::minSize
private

Referenced by messureSize(), and SetMinSize().

◆ pressedDown

bool SideButton::pressedDown = false
private

◆ radius

double SideButton::radius
private

◆ radius_enable

std::vector<bool> SideButton::radius_enable
private

Referenced by SetCornerEnable().

◆ state_handler

◆ text_color

StateColor SideButton::text_color
private

◆ text_margin

int SideButton::text_margin
private

Referenced by SideButton(), dorender(), and SetTextLayout().

◆ text_orientation

EHorizontalOrientation SideButton::text_orientation
private

Referenced by SideButton(), dorender(), and SetTextLayout().

◆ textSize

wxSize SideButton::textSize
private

Referenced by dorender(), and messureSize().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Widgets/SideButton.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Widgets/SideButton.cpp