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

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

Inheritance diagram for Button:
Collaboration diagram for Button:

Public Member Functions

 Button ()
 Button (wxWindow *parent, wxString text, wxString icon="", long style=0, int iconSize=0, wxWindowID btn_id=wxID_ANY)
bool Create (wxWindow *parent, wxString text, wxString icon="", long style=0, int iconSize=0, wxWindowID btn_id=wxID_ANY)
void SetLabel (const wxString &label) override
bool SetFont (const wxFont &font) override
void SetIcon (const wxString &icon)
void SetIcon (const wxBitmap &icon)
void SetMinSize (const wxSize &size) override
void SetMaxSize (const wxSize &size) override
void SetPaddingSize (const wxSize &size)
void SetIconSpacing (int spacing)
void SetStyle (const ButtonStyle style, const ButtonType type)
void SetTextColor (StateColor const &color)
void SetTextColorNormal (wxColor const &color)
void SetSelected (bool selected=true)
void SetIndicator (bool on)
ButtonStyle GetStyle () const
ButtonType GetType () const
bool IsSelected () const
bool Enable (bool enable=true) override
void EnableTooltipEvenDisabled ()
void SetCanFocus (bool canFocus) override
void SetValue (bool state)
bool GetValue () const
void SetCenter (bool isCenter)
void SetVertical (bool vertical=true)
void Rescale ()
bool Create (wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
void SetCornerRadius (double radius)
void SetBorderWidth (int width)
void SetTopMargin (int margin)
void SetBorderColor (StateColor const &color)
void SetBorderColorNormal (wxColor const &color)
void SetBorderStyle (wxPenStyle style)
void SetBackgroundColor (StateColor const &color)
void SetBackgroundColorNormal (wxColor const &color)
void SetBackgroundColor2 (StateColor const &color)
void ShowBadge (bool show)

Static Public Member Functions

static wxColor GetParentBackgroundColor (wxWindow *parent)

Protected Member Functions

bool AcceptsFocus () const override
void eraseEvent (wxEraseEvent &evt)
void sizeEvent (wxSizeEvent &evt)
virtual void doRender (wxDC &dc)

Protected Attributes

double radius
int border_width = 1
int top_margin = 0
wxPenStyle border_style = wxPENSTYLE_SOLID
StateHandler state_handler
StateColor border_color
StateColor background_color
StateColor background_color2
ScalableBitmap badge

Private Member Functions

void paintEvent (wxPaintEvent &evt)
void render (wxDC &dc)
void messureSize ()
void mouseDown (wxMouseEvent &event)
void mouseReleased (wxMouseEvent &event)
void mouseCaptureLost (wxMouseCaptureLostEvent &event)
void keyDownUp (wxKeyEvent &event)
void sendButtonEvent ()
void OnParentMotion (wxMouseEvent &event)
void OnParentLeave (wxMouseEvent &event)

Private Attributes

wxTipWindow::Ref tipWindow
wxRect textSize
wxSize minSize
wxSize paddingSize
int m_icon_spacing = 5
ScalableBitmap active_icon
StateColor text_color
bool pressedDown = false
bool m_selected = true
bool canFocus = true
bool isCenter = true
bool vertical = false
bool m_show_indicator = false
wxColour m_indicator_color = wxColour("#009688")
bool m_has_style = false
ButtonStyle m_style
ButtonType m_type

Static Private Attributes

static const int buttonWidth = 200
static const int buttonHeight = 50

Detailed Description

Constructor & Destructor Documentation

◆ Button() [1/2]

Button::Button ( )
43 : paddingSize(10, 8)
44{
45 background_color = StateColor(std::make_pair(0xF0F0F1, (int) StateColor::Disabled),
46 std::make_pair(0x52c7b8, (int) StateColor::Hovered | StateColor::Checked),
47 std::make_pair(0x009688, (int) StateColor::Checked),
48 std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered),
49 std::make_pair(*wxWHITE, (int) StateColor::Normal));
50 text_color = StateColor(std::make_pair(*wxLIGHT_GREY, (int) StateColor::Disabled), std::make_pair(*wxBLACK, (int) StateColor::Normal));
51}
wxSize paddingSize
Definition Button.hpp:46
StateColor text_color
Definition Button.hpp:50
@ Hovered
Definition StateColor.hpp:20
@ Normal
Definition StateColor.hpp:16
@ Disabled
Definition StateColor.hpp:22
@ Checked
Definition StateColor.hpp:18
StateColor background_color
Definition StaticBox.hpp:73

References Button(), StaticBox::background_color, StateColor::Checked, StateColor::Disabled, StateColor::Hovered, StateColor::Normal, paddingSize, and text_color.

Referenced by Button(), Button(), and Slic3r::GUI::CaliPageButton::CaliPageButton().

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

◆ Button() [2/2]

Button::Button ( wxWindow * parent,
wxString text,
wxString icon = "",
long style = 0,
int iconSize = 0,
wxWindowID btn_id = wxID_ANY )
53 : Button()
54{ Create(parent, text, icon, style, iconSize, btn_id); }
#define style
Definition WipeTowerDialog.cpp:101
Button()
Definition Button.cpp:43
bool Create(wxWindow *parent, wxString text, wxString icon="", long style=0, int iconSize=0, wxWindowID btn_id=wxID_ANY)
Definition Button.cpp:56

References Button(), Create(), and style.

Here is the call graph for this function:

Member Function Documentation

◆ AcceptsFocus()

bool Button::AcceptsFocus ( ) const
overrideprotected
534{ return canFocus; }
bool canFocus
Definition Button.hpp:54

References canFocus.

◆ Create() [1/2]

bool Button::Create ( wxWindow * parent,
wxString text,
wxString icon = "",
long style = 0,
int iconSize = 0,
wxWindowID btn_id = wxID_ANY )
57{
58 StaticBox::Create(parent, btn_id, wxDefaultPosition, wxDefaultSize, style);
59 state_handler.attach(std::vector<StateColor const*>{&text_color});
60 state_handler.update_binds();
61 // BBS set default font
63 wxWindow::SetLabel(text);
64 if (!icon.IsEmpty()) {
65 // BBS set button icon default size to 20
66 this->active_icon = ScalableBitmap(this, icon.ToStdString(), iconSize > 0 ? iconSize : 20);
67 }
69 return true;
70}
ScalableBitmap active_icon
Definition Button.hpp:48
bool SetFont(const wxFont &font) override
Definition Button.cpp:81
void messureSize()
Definition Button.cpp:410
static wxFont Body_14
Definition Label.hpp:53
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
Definition StaticBox.cpp:51
StateHandler state_handler
Definition StaticBox.hpp:71

References active_icon, Label::Body_14, StaticBox::Create(), messureSize(), SetFont(), StaticBox::state_handler, style, and text_color.

Referenced by Button(), TabCtrl::AppendItem(), and MultiSwitchButton::AppendOption().

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

◆ Create() [2/2]

bool StaticBox::Create ( wxWindow * parent,
wxWindowID id = wxID_ANY,
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = 0 )
inherited
52{
53 if (style & wxBORDER_NONE)
54 border_width = 0;
55 wxWindow::Create(parent, id, pos, size, style);
57 state_handler.update_binds();
58 SetBackgroundColour(GetParentBackgroundColor(parent));
59 return true;
60}
StateColor border_color
Definition StaticBox.hpp:72
int border_width
Definition StaticBox.hpp:68
static wxColor GetParentBackgroundColor(wxWindow *parent)
Definition StaticBox.cpp:122
StateColor background_color2
Definition StaticBox.hpp:74

References background_color, background_color2, border_color, border_width, GetParentBackgroundColor(), state_handler, and style.

Referenced by FanSwitchButton::FanSwitchButton(), ImageSwitchButton::ImageSwitchButton(), ModeSwitchButton::ModeSwitchButton(), StaticBox(), Button::Create(), SpinInput::Create(), TabButton::Create(), TempInput::Create(), and TextInput::Create().

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

◆ doRender()

void StaticBox::doRender ( wxDC & dc)
protectedvirtualinherited

Reimplemented in FilamentStepIndicator, ModeSwitchButton, StepCtrl, StepIndicator, and TabCtrl.

215{
216 wxSize size = GetSize();
217 int states = state_handler.states();
218 if (background_color2.count() == 0) {
219 if ((border_width && border_color.count() > 0) || background_color.count() > 0) {
220 int topM = top_margin > 0 ? top_margin : 0;
221 wxRect rc(0, topM, size.x, size.y - topM);
222 if (border_width && border_color.count() > 0) {
223 const double scale = dc.GetContentScaleFactor();
224
225 // Snap rect edges to physical pixel boundaries so the 1px pen doesn't straddle a pixel boundary
226 auto snap = [&](int logical) -> int {
227 return (int)(ceil(logical * scale) / scale);
228 };
229
230 int deflate = snap(border_width / 2.0); // at 175%: snap(0.5) = snap→1/1.75 ≈ 1
231 rc.x += deflate;
232 rc.y += deflate;
233 rc.width -= deflate * 2;
234 rc.height -= deflate * 2;
235 dc.SetPen(wxPen(border_color.colorForStates(states), border_width, border_style));
236 } else {
237 dc.SetPen(wxPen(background_color.colorForStates(states)));
238 }
239 if (background_color.count() > 0)
240 dc.SetBrush(wxBrush(background_color.colorForStates(states)));
241 else
242 dc.SetBrush(wxBrush(GetBackgroundColour()));
243 if (radius == 0) {
244 dc.DrawRectangle(rc);
245 }
246 else {
247 dc.DrawRoundedRectangle(rc, radius - border_width);
248 }
249 }
250 }
251 else {
252 wxColor start = background_color.colorForStates(states);
253 wxColor stop = background_color2.colorForStates(states);
254 int r = start.Red(), g = start.Green(), b = start.Blue();
255 int dr = (int) stop.Red() - r, dg = (int) stop.Green() - g, db = (int) stop.Blue() - b;
256 int lr = 0, lg = 0, lb = 0;
257 for (int y = 0; y < size.y; ++y) {
258 dc.SetPen(wxPen(wxColor(r, g, b)));
259 dc.DrawLine(0, y, size.x, y);
260 lr += dr; while (lr >= size.y) { ++r, lr -= size.y; } while (lr <= -size.y) { --r, lr += size.y; }
261 lg += dg; while (lg >= size.y) { ++g, lg -= size.y; } while (lg <= -size.y) { --g, lg += size.y; }
262 lb += db; while (lb >= size.y) { ++b, lb -= size.y; } while (lb <= -size.y) { --b, lb += size.y; }
263 }
264 }
265
266 if (badge.bmp().IsOk()) {
267 auto s = badge.bmp().GetScaledSize();
268 dc.DrawBitmap(badge.bmp(), size.x - s.x, top_margin > 0 ? top_margin : 0);
269 }
270}
int scale(const int val)
Definition WipeTowerDialog.cpp:58
ScalableBitmap badge
Definition StaticBox.hpp:75
int top_margin
Definition StaticBox.hpp:69
double radius
Definition StaticBox.hpp:67
wxPenStyle border_style
Definition StaticBox.hpp:70

References background_color, background_color2, badge, border_color, border_style, border_width, radius, scale(), state_handler, and top_margin.

Referenced by FilamentStepIndicator::doRender(), StepCtrl::doRender(), StepIndicator::doRender(), and render().

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

◆ Enable()

bool Button::Enable ( bool enable = true)
override
151{
152 bool result = wxWindow::Enable(enable);
153 if (result) {
154 wxCommandEvent e(EVT_ENABLE_CHANGED);
155 e.SetEventObject(this);
156 GetEventHandler()->ProcessEvent(e);
157 }
158 return result;
159}

Referenced by Slic3r::GUI::PluginPickerDialog::build_capability_ui(), Slic3r::GUI::PluginPickerDialog::build_ui(), Slic3r::GUI::Tab::compatible_widget_create(), and Slic3r::GUI::Tab::compatible_widget_reload().

Here is the caller graph for this function:

◆ EnableTooltipEvenDisabled()

void Button::EnableTooltipEvenDisabled ( )
537{
538#if defined(_MSC_VER) || defined(_WIN32)
539 auto parent = this->GetParent();
540 if (parent) {
541 parent->Bind(wxEVT_MOTION, &Button::OnParentMotion, this);
542 parent->Bind(wxEVT_LEAVE_WINDOW, &Button::OnParentLeave, this);
543 };
544#endif
545};
void OnParentLeave(wxMouseEvent &event)
Definition Button.cpp:583
void OnParentMotion(wxMouseEvent &event)
Definition Button.cpp:547

References OnParentLeave(), and OnParentMotion().

Here is the call graph for this function:

◆ eraseEvent()

void StaticBox::eraseEvent ( wxEraseEvent & evt)
protectedinherited
153{
154 // for transparent background, but not work
155#ifdef __WXMSW__
156 wxDC *dc = evt.GetDC();
157 wxSize size = GetSize();
158 wxClientDC dc2(GetParent());
159 dc->Blit({0, 0}, size, &dc2, GetPosition());
160#endif
161}

◆ GetParentBackgroundColor()

wxColor StaticBox::GetParentBackgroundColor ( wxWindow * parent)
staticinherited
123{
124 if (auto box = dynamic_cast<StaticBox*>(parent)) {
125 if (box->background_color.count() > 0) {
126 if (box->background_color2.count() == 0)
127 return box->background_color.defaultColor();
128 auto s = box->background_color.defaultColor();
129 auto e = box->background_color2.defaultColor();
130 int r = (s.Red() + e.Red()) / 2;
131 int g = (s.Green() + e.Green()) / 2;
132 int b = (s.Blue() + e.Blue()) / 2;
133 return wxColor(r, g, b);
134 }
135 }
136 if (parent)
137 return parent->GetBackgroundColour();
138 return *wxWHITE;
139}
StaticBox()
Definition StaticBox.cpp:33

References StaticBox().

Referenced by Label::Label(), ModeSwitchButton::ModeSwitchButton(), ScalableButton::ScalableButton(), SwitchButton::SwitchButton(), Create(), and SwitchButton::Rescale().

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

◆ GetStyle()

ButtonStyle Button::GetStyle ( ) const
inline
97{ return m_style; }
ButtonStyle m_style
Definition Button.hpp:125

References m_style.

Referenced by CustomWidgetsPlugin::addButtonProps().

Here is the caller graph for this function:

◆ GetType()

ButtonType Button::GetType ( ) const
inline
98{ return m_type; }
ButtonType m_type
Definition Button.hpp:126

References m_type.

Referenced by CustomWidgetsPlugin::addButtonProps().

Here is the caller graph for this function:

◆ GetValue()

bool Button::GetValue ( ) const
174{ return state_handler.states() & StateHandler::Checked; }
@ Checked
Definition StateHandler.hpp:19

References StateHandler::Checked, and StaticBox::state_handler.

Referenced by SetValue().

Here is the caller graph for this function:

◆ IsSelected()

bool Button::IsSelected ( ) const
inline
99{ return m_selected; }
bool m_selected
Definition Button.hpp:53

References m_selected.

Referenced by CustomWidgetsPlugin::addButtonProps().

Here is the caller graph for this function:

◆ keyDownUp()

void Button::keyDownUp ( wxKeyEvent & event)
private
491{
492 if (event.GetKeyCode() == WXK_SPACE || event.GetKeyCode() == WXK_RETURN) {
493 wxMouseEvent evt(event.GetEventType() == wxEVT_KEY_UP ? wxEVT_LEFT_UP : wxEVT_LEFT_DOWN);
494 event.SetEventObject(this);
495 GetEventHandler()->ProcessEvent(evt);
496 return;
497 }
498 if (event.GetEventType() == wxEVT_KEY_DOWN &&
499 (event.GetKeyCode() == WXK_TAB || event.GetKeyCode() == WXK_LEFT || event.GetKeyCode() == WXK_RIGHT ||
500 event.GetKeyCode() == WXK_UP || event.GetKeyCode() == WXK_DOWN))
501 HandleAsNavigationKey(event);
502 else
503 event.Skip();
504}
wxMouseEvent
Definition CameraPopup.cpp:47

◆ messureSize()

void Button::messureSize ( )
private
411{
412 wxClientDC dc(this);
413 dc.GetTextExtent(GetLabel(), &textSize.width, &textSize.height, &textSize.x, &textSize.y);
414 wxSize szContent = textSize.GetSize();
415 if (this->active_icon.bmp().IsOk()) {
416 if (szContent.y > 0) {
417 // BBS narrow size between text and icon
418 int spacing_after_icon = !GetLabel().IsEmpty() ? 0 : m_icon_spacing; // ORCA check empty string instead text size. fixes icon centering on linux
419 if (vertical)
420 szContent.y += spacing_after_icon;
421 else
422 szContent.x += spacing_after_icon;
423 }
424 wxSize szIcon = this->active_icon.GetBmpSize();
425 if (vertical) {
426 szContent.y += szIcon.y;
427 if (szIcon.x > szContent.x)
428 szContent.x = szIcon.x;
429 } else {
430 szContent.x += szIcon.x;
431 if (szIcon.y > szContent.y)
432 szContent.y = szIcon.y;
433 }
434 }
435 if (m_show_indicator) {
436 // Indicator dot sits to the right of the label: its diameter plus the gap from the text.
437 const int dot = FromDIP(6);
438 if (vertical)
439 szContent.y += dot + FromDIP(6);
440 else
441 szContent.x += dot + FromDIP(6);
442 }
443 wxSize size = szContent + paddingSize * 2;
444 if (minSize.GetHeight() > 0)
445 size.SetHeight(minSize.GetHeight());
446
447 if (auto w = GetMaxWidth(); w > 0 && size.GetWidth() > w) {
448 size.SetWidth(GetMaxWidth());
449
450 const wxString& tip_str = GetToolTipText();
451 if (tip_str.IsEmpty()) {
452 SetToolTip(GetLabel());
453 }
454 }
455
456 if (minSize.GetWidth() > size.GetWidth())
457 wxWindow::SetMinSize(minSize);
458 else
459 wxWindow::SetMinSize(size);
460}
bool m_show_indicator
Definition Button.hpp:57
wxSize minSize
Definition Button.hpp:45
wxRect textSize
Definition Button.hpp:44
int m_icon_spacing
Definition Button.hpp:47
bool vertical
Definition Button.hpp:56
T dot(const boost::geometry::model::d2::point_xy< T > &v1, const boost::geometry::model::d2::point_xy< T > &v2)
Definition ExtrusionSimulator.cpp:154

References active_icon, m_icon_spacing, m_show_indicator, minSize, paddingSize, textSize, and vertical.

Referenced by Create(), Rescale(), SetFont(), SetIcon(), SetIconSpacing(), SetIndicator(), SetLabel(), SetMaxSize(), SetMinSize(), SetPaddingSize(), and SetVertical().

Here is the caller graph for this function:

◆ mouseCaptureLost()

void Button::mouseCaptureLost ( wxMouseCaptureLostEvent & event)
private
485{
486 wxMouseEvent evt;
487 mouseReleased(evt);
488}
void mouseReleased(wxMouseEvent &event)
Definition Button.cpp:472

References mouseReleased().

Here is the call graph for this function:

◆ mouseDown()

void Button::mouseDown ( wxMouseEvent & event)
private
463{
464 event.Skip();
465 pressedDown = true;
466 if (canFocus)
467 SetFocus();
468 if (!HasCapture())
469 CaptureMouse();
470}
bool pressedDown
Definition Button.hpp:52

References canFocus, and pressedDown.

◆ mouseReleased()

void Button::mouseReleased ( wxMouseEvent & event)
private
473{
474 event.Skip();
475 if (pressedDown) {
476 pressedDown = false;
477 if (HasCapture())
478 ReleaseMouse();
479 if (wxRect({0, 0}, GetSize()).Contains(event.GetPosition()))
481 }
482}
void sendButtonEvent()
Definition Button.cpp:506

References pressedDown, and sendButtonEvent().

Referenced by mouseCaptureLost().

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

◆ OnParentLeave()

void Button::OnParentLeave ( wxMouseEvent & event)
private
584{
585 auto parent = this->GetParent();
586 if (!parent)
587 return event.Skip();
588
589 if (tipWindow) {
590 wxPoint pos = parent->ClientToScreen(event.GetPosition());
591 wxRect screen_rect = this->GetScreenRect();
592 wxString tip = this->GetToolTipText();
593 if (!screen_rect.Contains(pos)) {
594 tipWindow->Dismiss();
595 tipWindow->Destroy();
596 tipWindow = nullptr;
597 }
598 }
599
600 event.Skip();
601}
wxTipWindow::Ref tipWindow
Definition Button.hpp:43
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16

References tipWindow.

Referenced by EnableTooltipEvenDisabled().

Here is the caller graph for this function:

◆ OnParentMotion()

void Button::OnParentMotion ( wxMouseEvent & event)
private
548{
549 auto parent = this->GetParent();
550 if (!parent)
551 return event.Skip();
552
553 wxPoint pos = parent->ClientToScreen(event.GetPosition());
554 wxRect screen_rect = this->GetScreenRect();
555 wxString tip = this->GetToolTipText();
556 if (!tip.IsEmpty() && !this->IsEnabled() && screen_rect.Contains(pos)) {
557 if (!tipWindow) {
558 tipWindow = wxTipWindow::New(this, tip);
559 if (!tipWindow)
560 return event.Skip();
561 tipWindow->Enable(false);
562 }
563
564 if (tipWindow->GetLabel() != tip) {
565 tipWindow->SetLabel(tip);
566 }
567
568 // Position tooltip relative to the button widget itself rather than
569 // using wxGetMousePosition() which returns (0,0) on Wayland.
570 tipWindow->Position(this->ClientToScreen(wxPoint(0, 0)), this->GetSize());
571 tipWindow->Popup();
572 } else {
573 if (tipWindow) {
574 tipWindow->Dismiss();
575 tipWindow->Destroy();
576 tipWindow = nullptr;
577 }
578 }
579
580 event.Skip();
581}

References tipWindow.

Referenced by EnableTooltipEvenDisabled().

Here is the caller graph for this function:

◆ paintEvent()

void Button::paintEvent ( wxPaintEvent & evt)
private
287{
288 // depending on your system you may need to look at double-buffered dcs
289 wxPaintDC dc(this);
290 render(dc);
291}
void render(wxDC &dc)
Definition Button.cpp:298

References render().

Here is the call graph for this function:

◆ render()

void Button::render ( wxDC & dc)
private
299{
301 int states = state_handler.states();
302 wxSize size = GetSize();
303 dc.SetBrush(*wxTRANSPARENT_BRUSH);
304 // calc content size
305 wxSize szIcon;
306 wxSize textSize = this->textSize.GetSize();
307
308 const ScalableBitmap& icon = active_icon;
309 wxSize padding = this->paddingSize;
310 int spacing = m_icon_spacing;
311 // Wrap text
312 auto text = GetLabel();
313 if (vertical && textSize.x + padding.x * 2 > size.x) {
314 Label::split_lines(dc, size.x - padding.x * 2, text, text, 2);
315 textSize = dc.GetMultiLineTextExtent(text);
316 if (padding.x * 2 + textSize.x > size.x) {
317 text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - padding.x * 2);
318 textSize = dc.GetMultiLineTextExtent(text);
319 }
320 }
321 auto szContent = textSize;
322 // Whether the measured content reserved the text/icon gap. macOS measures an empty label
323 // as 0-high, so the gap is skipped there; the dot must not advance past it in that case.
324 const bool gap_reserved = !text.IsEmpty(); // ORCA check empty string instead text size. fixes icon centering on linux
325 if (icon.bmp().IsOk()) {
326 if (gap_reserved) {
327 // BBS norrow size between text and icon
328 if (vertical)
329 szContent.y += spacing;
330 else
331 szContent.x += spacing;
332 }
333 szIcon = icon.GetBmpSize();
334 if (vertical) {
335 szContent.y += szIcon.y;
336 if (szIcon.x > szContent.x)
337 szContent.x = szIcon.x;
338 } else {
339 szContent.x += szIcon.x;
340 if (szIcon.y > szContent.y)
341 szContent.y = szIcon.y;
342 }
343 if (szContent.x > size.x) {
344 int d = std::min(padding.x, (szContent.x - size.x) / 2);
345 padding.x -= d;
346 szContent.x -= d;
347 }
348 }
349 if (m_show_indicator) {
350 const int dot = FromDIP(6);
351 if (vertical)
352 szContent.y += dot + FromDIP(6);
353 else
354 szContent.x += dot + FromDIP(6);
355 }
356 // move to center
357 wxRect rcContent = {{0, 0}, size};
358 if (isCenter) {
359 wxSize offset = (size - szContent) / 2;
360 if (offset.x < 0)
361 offset.x = 0;
362 rcContent.Deflate(offset.x, offset.y);
363 }
364 // start draw
365 wxPoint pt = rcContent.GetLeftTop();
366 if (icon.bmp().IsOk()) {
367 if (vertical)
368 pt.x += (rcContent.width - szIcon.x) / 2;
369 else
370 pt.y += (rcContent.height - szIcon.y) / 2;
371 dc.DrawBitmap(icon.bmp(), pt);
372 // BBS norrow size between text and icon
373 if (vertical) {
374 pt.y += szIcon.y + (gap_reserved ? spacing : 0);
375 pt.x = rcContent.x;
376 } else {
377 pt.x += szIcon.x + (gap_reserved ? spacing : 0);
378 pt.y = rcContent.y;
379 }
380 }
381 if (!text.IsEmpty()) {
382 if (vertical) {
383 pt.x += (rcContent.width - textSize.x) / 2;
384 } else {
385 if (pt.x + textSize.x > size.x)
386 text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - pt.x);
387 pt.y += (rcContent.height - textSize.y) / 2;
388 }
389 dc.SetTextForeground(text_color.colorForStates(states));
390#if 0
391 dc.SetBrush(*wxLIGHT_GREY);
392 dc.SetPen(wxPen(*wxLIGHT_GREY));
393 dc.DrawRectangle(pt, textSize.GetSize());
394#endif
395 dc.DrawText(text, pt);
396 }
397 if (m_show_indicator) {
398 const int dot = FromDIP(6); // diameter
399 wxPoint dot_pt;
400 dot_pt.x = pt.x + (text.IsEmpty() ? 0 : textSize.x) + FromDIP(6) + dot / 2;
401 // Centre on the content vertically; a bitmap-only (empty-label) tab has no text row.
402 dot_pt.y = text.IsEmpty() ? rcContent.y + rcContent.height / 2 : pt.y + textSize.y / 2;
404 dc.SetBrush(wxBrush(c));
405 dc.SetPen(wxPen(c));
406 dc.DrawCircle(dot_pt, dot / 2);
407 }
408}
bool isCenter
Definition Button.hpp:55
wxColour m_indicator_color
Definition Button.hpp:58
static wxSize split_lines(wxDC &dc, int width, const wxString &text, wxString &multiline_text, int max_count=0)
Definition Label.cpp:293
wxSize GetBmpSize() const
Definition wxExtensions.cpp:959
const wxBitmap & bmp() const
Definition wxExtensions.hpp:189
static wxColour darkModeColorFor(wxColour const &color)
Definition StateColor.cpp:219
void render(wxDC &dc)
Definition StaticBox.cpp:181
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:582

References active_icon, ScalableBitmap::bmp(), StateColor::darkModeColorFor(), ScalableBitmap::GetBmpSize(), isCenter, m_icon_spacing, m_indicator_color, m_show_indicator, paddingSize, StaticBox::render(), Label::split_lines(), StaticBox::state_handler, text_color, textSize, and vertical.

Referenced by paintEvent().

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

◆ Rescale()

void Button::Rescale ( )
273{
274 // Only a named icon can be re-rasterized; one set from a wxBitmap has no source file,
275 if (!this->active_icon.name().empty())
276 this->active_icon.msw_rescale();
277
278 messureSize();
279
280 if (m_has_style)
282
283 Refresh();
284}
void SetStyle(const ButtonStyle style, const ButtonType type)
Definition Button.cpp:200
bool m_has_style
Definition Button.hpp:124

References active_icon, m_has_style, m_style, m_type, messureSize(), and SetStyle().

Referenced by Slic3r::GUI::CaliPageButton::msw_rescale().

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

◆ sendButtonEvent()

void Button::sendButtonEvent ( )
private
507{
508 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
509 event.SetEventObject(this);
510 GetEventHandler()->ProcessEvent(event);
511}

Referenced by mouseReleased().

Here is the caller graph for this function:

◆ SetBackgroundColor()

◆ SetBackgroundColor2()

void StaticBox::SetBackgroundColor2 ( StateColor const & color)
inherited
116{
117 background_color2 = color;
118 state_handler.update_binds();
119 Refresh();
120}

References background_color2, and state_handler.

◆ SetBackgroundColorNormal()

void StaticBox::SetBackgroundColorNormal ( wxColor const & color)
inherited
110{
111 background_color.setColorForStates(color, 0);
112 Refresh();
113}

References background_color.

Referenced by Slic3r::GUI::ShortcutCaptureDialog::ShortcutCaptureDialog(), and Slic3r::GUI::HotEndTable::CreateNozzleBox().

Here is the caller graph for this function:

◆ SetBorderColor()

◆ SetBorderColorNormal()

void StaticBox::SetBorderColorNormal ( wxColor const & color)
inherited
97{
98 border_color.setColorForStates(color, 0);
99 Refresh();
100}

References border_color.

Referenced by Slic3r::GUI::ShortcutCaptureDialog::ShortcutCaptureDialog(), and Slic3r::GUI::HotEndTable::CreateNozzleBox().

Here is the caller graph for this function:

◆ SetBorderStyle()

void StaticBox::SetBorderStyle ( wxPenStyle style)
inherited
76{
78 Refresh();
79}

References border_style, and style.

◆ SetBorderWidth()

void StaticBox::SetBorderWidth ( int width)
inherited
82{
84 Refresh();
85}
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:1184

References border_width.

Referenced by MultiSwitchButton::MultiSwitchButton(), Slic3r::GUI::KBShortcutsDialog::create_page(), and Button::SetStyle().

Here is the caller graph for this function:

◆ SetCanFocus()

void Button::SetCanFocus ( bool canFocus)
override
162{
163 StaticBox::SetCanFocus(canFocus);
164 this->canFocus = canFocus;
165}

References canFocus.

◆ SetCenter()

void Button::SetCenter ( bool isCenter)
176{ this->isCenter = isCenter; }

References isCenter.

◆ SetCornerRadius()

◆ SetFont()

bool Button::SetFont ( const wxFont & font)
override
82{
83 wxWindow::SetFont(font);
85 Refresh();
86 return true;
87}

References messureSize().

Referenced by Slic3r::GUI::CaliPageButton::CaliPageButton(), TabCtrl::AppendItem(), MultiSwitchButton::AppendOption(), Create(), Slic3r::GUI::DeviceErrorDialog::init_button(), Slic3r::GUI::MediaFilePanel::modeChanged(), and SetStyle().

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

◆ SetIcon() [1/2]

void Button::SetIcon ( const wxBitmap & icon)
105{
106 this->active_icon = ScalableBitmap();
107 this->active_icon.bmp() = icon;
108 messureSize();
109 Refresh();
110}

References active_icon, and messureSize().

Here is the call graph for this function:

◆ SetIcon() [2/2]

void Button::SetIcon ( const wxString & icon)
90{
91 auto tmpBitmap = ScalableBitmap(this, icon.ToStdString(), this->active_icon.px_cnt());
92 if (!icon.IsEmpty()) {
93 // BBS set button icon default size to 20
94 if (!tmpBitmap.bmp().IsSameAs(this->active_icon.bmp())) {
95 this->active_icon = tmpBitmap;
96 Refresh();
97 }
98 } else {
99 this->active_icon = ScalableBitmap();
100 Refresh();
101 }
102}

References active_icon.

Referenced by ButtonsListCtrl::InsertPage().

Here is the caller graph for this function:

◆ SetIconSpacing()

void Button::SetIconSpacing ( int spacing)
131{
132 m_icon_spacing = spacing;
133 messureSize();
134 Refresh();
135}

References m_icon_spacing, and messureSize().

Referenced by ButtonsListCtrl::InsertPage().

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

◆ SetIndicator()

void Button::SetIndicator ( bool on)
179{
180 if (m_show_indicator == on)
181 return;
182 m_show_indicator = on;
183 messureSize();
184 Refresh();
185}

References m_show_indicator, and messureSize().

Here is the call graph for this function:

◆ SetLabel()

void Button::SetLabel ( const wxString & label)
override
73{
74 if (label != wxWindow::GetLabel()) {
75 wxWindow::SetLabel(label);
77 Refresh();
78 }
79}

References messureSize().

Referenced by Slic3r::GUI::CaliPageButton::CaliPageButton(), Slic3r::GUI::CreatePresetSuccessfulDialog::CreatePresetSuccessfulDialog(), Slic3r::GUI::EditCalibrationHistoryDialog::EditCalibrationHistoryDialog(), Slic3r::GUI::PurgeModeDialog::PurgeModeDialog(), Slic3r::GUI::RecenterDialog::RecenterDialog(), Slic3r::GUI::CreatePrinterPresetDialog::create_page2_dialog_buttons(), ButtonsListCtrl::SetCompact(), and ButtonsListCtrl::SetPageText().

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

◆ SetMaxSize()

void Button::SetMaxSize ( const wxSize & size)
override
119{
120 wxWindow::SetMaxSize(size);
121 messureSize();
122}

References messureSize().

Referenced by Slic3r::GUI::DeviceErrorDialog::init_button(), Slic3r::GUI::PrintErrorDialog::init_button(), and SetStyle().

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

◆ SetMinSize()

void Button::SetMinSize ( const wxSize & size)
override
113{
114 minSize = size;
115 messureSize();
116}

References messureSize(), and minSize.

Referenced by Slic3r::GUI::CaliPageButton::CaliPageButton(), Slic3r::GUI::DeviceErrorDialog::init_button(), Slic3r::GUI::PrintErrorDialog::init_button(), ButtonsListCtrl::InsertPage(), Slic3r::GUI::CaliPageButton::msw_rescale(), ButtonsListCtrl::SetCompact(), SetStyle(), and Slic3r::GUI::style_sidebar_icon_btn().

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

◆ SetPaddingSize()

void Button::SetPaddingSize ( const wxSize & size)
125{
126 paddingSize = size;
127 messureSize();
128}

References messureSize(), and paddingSize.

Referenced by TabCtrl::AppendItem(), MultiSwitchButton::AppendOption(), SetStyle(), and Slic3r::GUI::style_sidebar_icon_btn().

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

◆ SetSelected()

void Button::SetSelected ( bool selected = true)
inline
90{ m_selected = selected; }

References m_selected.

Referenced by CustomWidgetsPlugin::addButtonProps().

Here is the caller graph for this function:

◆ SetStyle()

void Button::SetStyle ( const ButtonStyle style,
const ButtonType type )
201{
202 if (type == ButtonType::Compact) {
203 this->SetPaddingSize(FromDIP(wxSize(8, 3)));
204 this->SetCornerRadius(this->FromDIP(8));
205 this->SetFont(Label::Body_10);
206 } else if (type == ButtonType::Window) {
207 this->SetSize(FromDIP(wxSize(58, 24)));
208 this->SetMinSize(FromDIP(wxSize(58, 24)));
209 this->SetCornerRadius(this->FromDIP(12));
210 this->SetFont(Label::Body_12);
211 } else if (type == ButtonType::Choice) {
212 this->SetMinSize(FromDIP(wxSize(100, 32)));
213 this->SetPaddingSize(FromDIP(wxSize(12, 8)));
214 this->SetCornerRadius(this->FromDIP(4));
215 this->SetFont(Label::Body_14);
216 } else if (type == ButtonType::Parameter) {
217 this->SetMinSize(FromDIP(wxSize(120, 26)));
218 this->SetSize(FromDIP(wxSize(120, 26)));
219 this->SetCornerRadius(this->FromDIP(4));
220 this->SetFont(Label::Body_14);
221 } else if (type == ButtonType::Icon) {
222 this->SetPaddingSize(FromDIP(wxSize(5, 5)));
223 this->SetMinSize(FromDIP(wxSize(26, 26)));
224 this->SetSize(FromDIP(wxSize(26, 26)));
225 this->SetCornerRadius(this->FromDIP(4));
226 } else if (type == ButtonType::Circle) {
227 this->SetPaddingSize(FromDIP(wxSize(6, 6)));
228 this->SetMinSize(FromDIP(wxSize(25, 25)));
229 this->SetMaxSize(FromDIP(wxSize(25, 25)));
230 this->SetSize(FromDIP(wxSize(25, 25)));
231 this->SetCornerRadius(this->FromDIP(12));
232 } else if (type == ButtonType::Expanded) {
233 this->SetMinSize(FromDIP(wxSize(-1, 32)));
234 this->SetPaddingSize(FromDIP(wxSize(12, 8)));
235 this->SetCornerRadius(this->FromDIP(4));
236 this->SetFont(Label::Body_14);
237 }
238
239 this->SetBorderWidth(this->FromDIP(1));
240
241 bool is_dark = StateColor::darkModeColorFor("#FFFFFF") != wxColour("#FFFFFF");
242
243 auto clr_arr = style == ButtonStyle::Regular ? btn_regular :
248
249 auto bg_color = StateColor(std::pair(wxColour(clr_arr[0]), (int) StateColor::Disabled),
250 std::pair(wxColour(clr_arr[1]), (int) StateColor::Pressed),
251 std::pair(wxColour(clr_arr[2]), (int) StateColor::Hovered),
252 std::pair(wxColour(clr_arr[3]), (int) StateColor::Normal),
253 std::pair(wxColour(clr_arr[4]), (int) StateColor::Enabled));
254 bg_color.setTakeFocusedAsHovered(false);
255 this->SetBackgroundColor(bg_color);
256 wxColour focus_clr = clr_arr[is_dark ? 8 : 9];
257 auto border_color = StateColor(std::pair(wxColour(clr_arr[0]), (int) StateColor::Disabled),
258 std::pair(wxColour(clr_arr[2]), (int) (StateColor::Hovered | ~StateColor::Focused)),
259 std::pair(wxColour(focus_clr), (int) StateColor::Focused),
260 std::pair(wxColour(clr_arr[3]), (int) StateColor::Normal));
261 border_color.setTakeFocusedAsHovered(false);
263 this->SetTextColor(StateColor(std::pair(wxColour(clr_arr[5]), (int) StateColor::Disabled),
264 std::pair(wxColour(clr_arr[7]), (int) StateColor::Hovered),
265 std::pair(wxColour(clr_arr[6]), (int) StateColor::Normal)));
266
267 m_has_style = true;
268 m_style = style;
269 m_type = type;
270}
wxString btn_regular[10]
Definition Button.cpp:195
wxString btn_confirm[10]
Definition Button.cpp:196
wxString btn_disabled[10]
Definition Button.cpp:198
wxString btn_alert[10]
Definition Button.cpp:197
@ Confirm
Definition Button.hpp:25
@ Alert
Definition Button.hpp:26
@ Disabled
Definition Button.hpp:27
@ Regular
Definition Button.hpp:24
@ Circle
Definition Button.hpp:37
@ Choice
Definition Button.hpp:33
@ Expanded
Definition Button.hpp:38
@ Icon
Definition Button.hpp:35
@ Parameter
Definition Button.hpp:34
@ Compact
Definition Button.hpp:31
@ Window
Definition Button.hpp:32
static bool is_dark()
Definition TextureImportDialog.cpp:85
void SetMinSize(const wxSize &size) override
Definition Button.cpp:112
void SetTextColor(StateColor const &color)
Definition Button.cpp:137
void SetMaxSize(const wxSize &size) override
Definition Button.cpp:118
void SetPaddingSize(const wxSize &size)
Definition Button.cpp:124
static wxFont Body_12
Definition Label.hpp:55
static wxFont Body_10
Definition Label.hpp:56
@ Pressed
Definition StateColor.hpp:21
@ Enabled
Definition StateColor.hpp:17
@ Focused
Definition StateColor.hpp:19
void SetCornerRadius(double radius)
Definition StaticBox.cpp:62
void SetBorderWidth(int width)
Definition StaticBox.cpp:81
void SetBorderColor(StateColor const &color)
Definition StaticBox.cpp:87
void SetBackgroundColor(StateColor const &color)
Definition StaticBox.cpp:102
wxColour bg_color()
Definition SpeedDialDialog.cpp:69

References Alert, Label::Body_10, Label::Body_12, Label::Body_14, StaticBox::border_color, btn_alert, btn_confirm, btn_disabled, btn_regular, Choice, Circle, Compact, Confirm, StateColor::darkModeColorFor(), Disabled, StateColor::Disabled, StateColor::Enabled, Expanded, StateColor::Focused, StateColor::Hovered, Icon, is_dark(), m_has_style, m_style, m_type, StateColor::Normal, Parameter, StateColor::Pressed, Regular, StaticBox::SetBackgroundColor(), StaticBox::SetBorderColor(), StaticBox::SetBorderWidth(), StaticBox::SetCornerRadius(), SetFont(), SetMaxSize(), SetMinSize(), SetPaddingSize(), SetTextColor(), style, and Window.

Referenced by Slic3r::GUI::AboutDialog::AboutDialog(), Slic3r::GUI::HistoryWindow::HistoryWindow(), Slic3r::GUI::MsgDialog::add_button(), Slic3r::GUI::TipsDialog::add_button(), Slic3r::GUI::BedShapePanel::build_panel(), Slic3r::GUI::PhysicalPrinterDialog::build_printhost_settings(), Slic3r::GUI::Tab::compatible_widget_create(), Slic3r::GUI::TabPrinter::create_bed_shape_widget(), Slic3r::GUI::FileArchiveDialog::create_btn_sizer(), Slic3r::GUI::PreferencesDialog::create_debug_page(), Slic3r::GUI::PresetTree::get_child_item(), Slic3r::GUI::TextureImportDialog::highlight_view_button(), Slic3r::GUI::PrintErrorDialog::init_button(), Slic3r::GUI::BedShapePanel::init_model_panel(), Slic3r::GUI::BedShapePanel::init_texture_panel(), Rescale(), Slic3r::GUI::DialogButtons::SetAlertButton(), and Slic3r::GUI::DialogButtons::SetPrimaryButton().

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

◆ SetTextColor()

void Button::SetTextColor ( StateColor const & color)
138{
139 text_color = color;
140 state_handler.update_binds();
141 Refresh();
142}

References StaticBox::state_handler, and text_color.

Referenced by Slic3r::GUI::CaliPageButton::CaliPageButton(), TabCtrl::AppendItem(), MultiSwitchButton::AppendOption(), ButtonsListCtrl::InsertPage(), and SetStyle().

Here is the caller graph for this function:

◆ SetTextColorNormal()

void Button::SetTextColorNormal ( wxColor const & color)
145{
146 text_color.setColorForStates(color, 0);
147 Refresh();
148}

References text_color.

◆ SetTopMargin()

void StaticBox::SetTopMargin ( int margin)
inherited
70{
71 this->top_margin = margin;
72 Refresh();
73}

References top_margin.

Referenced by Slic3r::GUI::ExtruderGroup::ExtruderGroup().

Here is the caller graph for this function:

◆ SetValue()

void Button::SetValue ( bool state)
168{
169 if (GetValue() == state)
170 return;
172}
bool GetValue() const
Definition Button.cpp:174

References StateHandler::Checked, GetValue(), and StaticBox::state_handler.

Referenced by Slic3r::GUI::MediaFilePanel::MediaFilePanel().

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

◆ SetVertical()

void Button::SetVertical ( bool vertical = true)
188{
189 this->vertical = vertical;
190 messureSize();
191}

References messureSize(), and vertical.

Here is the call graph for this function:

◆ ShowBadge()

void StaticBox::ShowBadge ( bool show)
inherited
142{
143 if (show && badge.name() != "badge") {
144 badge = ScalableBitmap(this, "badge", 18);
145 Refresh();
146 } else if (!show && !badge.name().empty()) {
147 badge = ScalableBitmap {};
148 Refresh();
149 }
150}

References badge.

Referenced by Slic3r::GUI::ExtruderGroup::ExtruderGroup().

Here is the caller graph for this function:

◆ sizeEvent()

void StaticBox::sizeEvent ( wxSizeEvent & evt)
protectedinherited
164{
165 Refresh();
166 evt.Skip();
167}

Member Data Documentation

◆ active_icon

ScalableBitmap Button::active_icon
private

◆ background_color

◆ background_color2

StateColor StaticBox::background_color2
protectedinherited

◆ badge

ScalableBitmap StaticBox::badge
protectedinherited

Referenced by doRender(), and ShowBadge().

◆ border_color

◆ border_style

wxPenStyle StaticBox::border_style = wxPENSTYLE_SOLID
protectedinherited

Referenced by doRender(), and SetBorderStyle().

◆ border_width

◆ buttonHeight

const int Button::buttonHeight = 50
staticprivate

◆ buttonWidth

const int Button::buttonWidth = 200
staticprivate

◆ canFocus

bool Button::canFocus = true
private

◆ isCenter

bool Button::isCenter = true
private

Referenced by render(), and SetCenter().

◆ m_has_style

bool Button::m_has_style = false
private

Referenced by Rescale(), and SetStyle().

◆ m_icon_spacing

int Button::m_icon_spacing = 5
private

Referenced by messureSize(), render(), and SetIconSpacing().

◆ m_indicator_color

wxColour Button::m_indicator_color = wxColour("#009688")
private

Referenced by render().

◆ m_selected

bool Button::m_selected = true
private

Referenced by IsSelected(), and SetSelected().

◆ m_show_indicator

bool Button::m_show_indicator = false
private

Referenced by messureSize(), render(), and SetIndicator().

◆ m_style

ButtonStyle Button::m_style
private

Referenced by GetStyle(), Rescale(), and SetStyle().

◆ m_type

ButtonType Button::m_type
private

Referenced by GetType(), Rescale(), and SetStyle().

◆ minSize

wxSize Button::minSize
private

Referenced by messureSize(), and SetMinSize().

◆ paddingSize

wxSize Button::paddingSize
private

◆ pressedDown

bool Button::pressedDown = false
private

Referenced by mouseDown(), and mouseReleased().

◆ radius

◆ state_handler

◆ text_color

StateColor Button::text_color
private

◆ textSize

wxRect Button::textSize
private

Referenced by messureSize(), and render().

◆ tipWindow

wxTipWindow::Ref Button::tipWindow
private

Referenced by OnParentLeave(), and OnParentMotion().

◆ top_margin

int StaticBox::top_margin = 0
protectedinherited

Referenced by doRender(), and SetTopMargin().

◆ vertical

bool Button::vertical = false
private

Referenced by messureSize(), render(), and SetVertical().


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