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

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

Inheritance diagram for SwitchBoard:
Collaboration diagram for SwitchBoard:

Public Member Functions

 SwitchBoard (wxWindow *parent=NULL, wxString leftL="", wxString right="", wxSize size=wxDefaultSize)
void updateState (wxString target)
bool Enable (bool enable=true) override
bool Disable ()
bool IsEnabled ()
void SetClientData (void *data)
void * GetClientData ()
void SetAutoDisableWhenSwitch ()

Public Attributes

wxString leftLabel
wxString rightLabel
bool switch_left {false}
bool switch_right {false}
bool is_enable {true}
void * client_data = nullptr

Protected Member Functions

void paintEvent (wxPaintEvent &evt)
void render (wxDC &dc)
void doRender (wxDC &dc)
void on_left_down (wxMouseEvent &evt)

Private Attributes

bool auto_disable_when_switch = false

Detailed Description

Constructor & Destructor Documentation

◆ SwitchBoard()

SwitchBoard::SwitchBoard ( wxWindow * parent = NULL,
wxString leftL = "",
wxString right = "",
wxSize size = wxDefaultSize )
486 : wxWindow(parent, wxID_ANY, wxDefaultPosition, size)
487{
488#ifdef __WINDOWS__
489 SetDoubleBuffered(true);
490#endif //__WINDOWS__
491
492 SetBackgroundColour(*wxWHITE);
493 leftLabel = leftL;
495
496 SetMinSize(size);
497 SetMaxSize(size);
498
499 Bind(wxEVT_PAINT, &SwitchBoard::paintEvent, this);
500 Bind(wxEVT_LEFT_DOWN, &SwitchBoard::on_left_down, this);
501
502 Bind(wxEVT_ENTER_WINDOW, [this](auto &e) { SetCursor(wxCURSOR_HAND); });
503 Bind(wxEVT_LEAVE_WINDOW, [this](auto &e) { SetCursor(wxCURSOR_ARROW); });
504}
void paintEvent(wxPaintEvent &evt)
Definition SwitchButton.cpp:536
wxString leftLabel
Definition SwitchButton.hpp:105
void on_left_down(wxMouseEvent &evt)
Definition SwitchButton.cpp:608
wxString rightLabel
Definition SwitchButton.hpp:106
@ right
Definition MarchingSquares.hpp:190

References leftLabel, on_left_down(), paintEvent(), and rightLabel.

Here is the call graph for this function:

Member Function Documentation

◆ Disable()

bool SwitchBoard::Disable ( )
inline
118{ return Enable(false); }
bool Enable(bool enable=true) override
Definition SwitchButton.cpp:638

References Enable().

Here is the call graph for this function:

◆ doRender()

void SwitchBoard::doRender ( wxDC & dc)
protected
564{
565 wxColour disable_color = wxColour(0xCECECE);
566
567 dc.SetPen(*wxTRANSPARENT_PEN);
568
569 if (is_enable) {dc.SetBrush(wxBrush(0xeeeeee));
570 } else {dc.SetBrush(disable_color);}
571 dc.DrawRoundedRectangle(0, 0, GetSize().x, GetSize().y, 8);
572
573 /*left*/
574 if (switch_left) {
575 is_enable ? dc.SetBrush(wxBrush(wxColour(0, 150, 136))) : dc.SetBrush(disable_color);
576 dc.DrawRoundedRectangle(0, 0, GetSize().x / 2, GetSize().y, 8);
577 }
578
579 if (switch_left) {
580 dc.SetTextForeground(*wxWHITE);
581 } else {
582 dc.SetTextForeground(0x333333);
583 }
584
585 dc.SetFont(::Label::Body_13);
586 Slic3r::GUI::WxFontUtils::get_suitable_font_size(0.6 * GetSize().GetHeight(), dc);
587
588 auto left_txt_size = dc.GetTextExtent(leftLabel);
589 dc.DrawText(leftLabel, wxPoint((GetSize().x / 2 - left_txt_size.x) / 2, (GetSize().y - left_txt_size.y) / 2));
590
591 /*right*/
592 if (switch_right) {
593 if (is_enable) {dc.SetBrush(wxBrush(wxColour(0, 150, 136)));
594 } else {dc.SetBrush(disable_color);}
595 dc.DrawRoundedRectangle(GetSize().x / 2, 0, GetSize().x / 2, GetSize().y, 8);
596 }
597
598 auto right_txt_size = dc.GetTextExtent(rightLabel);
599 if (switch_right) {
600 dc.SetTextForeground(*wxWHITE);
601 } else {
602 dc.SetTextForeground(0x333333);
603 }
604 dc.DrawText(rightLabel, wxPoint((GetSize().x / 2 - right_txt_size.x) / 2 + GetSize().x / 2, (GetSize().y - right_txt_size.y) / 2));
605
606}
static wxFont Body_13
Definition Label.hpp:54
static void get_suitable_font_size(int max_height, wxDC &dc)
Definition WxFontUtils.cpp:309
bool switch_left
Definition SwitchButton.hpp:110
bool is_enable
Definition SwitchButton.hpp:112
bool switch_right
Definition SwitchButton.hpp:111

References Label::Body_13, Slic3r::GUI::WxFontUtils::get_suitable_font_size(), is_enable, leftLabel, rightLabel, switch_left, and switch_right.

Referenced by render().

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

◆ Enable()

bool SwitchBoard::Enable ( bool enable = true)
override
639{
640 if (is_enable == enable)
641 {
642 return false;
643 }
644
645 is_enable = enable;
646 Refresh();
647 return true;
648}

References is_enable.

Referenced by Disable().

Here is the caller graph for this function:

◆ GetClientData()

void * SwitchBoard::GetClientData ( )
inline
122{ return client_data; };
void * client_data
Definition SwitchButton.hpp:114

References client_data.

◆ IsEnabled()

bool SwitchBoard::IsEnabled ( )
inline
119{return is_enable;};

References is_enable.

◆ on_left_down()

void SwitchBoard::on_left_down ( wxMouseEvent & evt)
protected
609{
610 if (!is_enable) {
611 return;
612 }
613 int index = -1;
614 auto pos = ClientToScreen(evt.GetPosition());
615 auto rect = ClientToScreen(wxPoint(0, 0));
616
617 if (pos.x > 0 && pos.x < rect.x + GetSize().x / 2) {
618 switch_left = true;
619 switch_right = false;
620 index = 1;
621 } else {
622 switch_left = false;
623 switch_right = true;
624 index = 0;
625 }
626
628 {
629 is_enable = false;// make it disable while switching
630 }
631 Refresh();
632
633 wxCommandEvent event(wxCUSTOMEVT_SWITCH_POS);
634 event.SetInt(index);
635 wxPostEvent(this, event);
636}
bool auto_disable_when_switch
Definition SwitchButton.hpp:133
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16

References auto_disable_when_switch, is_enable, switch_left, and switch_right.

Referenced by SwitchBoard().

Here is the caller graph for this function:

◆ paintEvent()

void SwitchBoard::paintEvent ( wxPaintEvent & evt)
protected
537{
538 wxPaintDC dc(this);
539 render(dc);
540}
void render(wxDC &dc)
Definition SwitchButton.cpp:542

References render().

Referenced by SwitchBoard().

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

◆ render()

void SwitchBoard::render ( wxDC & dc)
protected
543{
544#ifdef __WXMSW__
545 wxSize size = GetSize();
546 wxMemoryDC memdc;
547 wxBitmap bmp(size.x, size.y);
548 memdc.SelectObject(bmp);
549 memdc.Blit({0, 0}, size, &dc, {0, 0});
550
551 {
552 wxGCDC dc2(memdc);
553 doRender(dc2);
554 }
555
556 memdc.SelectObject(wxNullBitmap);
557 dc.DrawBitmap(bmp, 0, 0);
558#else
559 doRender(dc);
560#endif
561}
void doRender(wxDC &dc)
Definition SwitchButton.cpp:563

References doRender().

Referenced by paintEvent().

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

◆ SetAutoDisableWhenSwitch()

void SwitchBoard::SetAutoDisableWhenSwitch ( )
inline

◆ SetClientData()

void SwitchBoard::SetClientData ( void * data)
inline
121{ client_data = data; };

References client_data.

◆ updateState()

void SwitchBoard::updateState ( wxString target)
507{
508 if (target.empty()) {
509 if (!switch_left && !switch_right) {
510 return;
511 }
512
513 switch_left = false;
514 switch_right = false;
515 } else {
516 if (target == "left") {
517 if (switch_left && !switch_right) {
518 return;
519 }
520
521 switch_left = true;
522 switch_right = false;
523 } else if (target == "right") {
524 if (!switch_left && switch_right) {
525 return;
526 }
527
528 switch_left = false;
529 switch_right = true;
530 }
531 }
532
533 Refresh();
534}

References switch_left, and switch_right.

Member Data Documentation

◆ auto_disable_when_switch

bool SwitchBoard::auto_disable_when_switch = false
private

◆ client_data

void* SwitchBoard::client_data = nullptr

Referenced by GetClientData(), and SetClientData().

◆ is_enable

bool SwitchBoard::is_enable {true}
112{true};

Referenced by doRender(), Enable(), IsEnabled(), and on_left_down().

◆ leftLabel

wxString SwitchBoard::leftLabel

Referenced by SwitchBoard(), and doRender().

◆ rightLabel

wxString SwitchBoard::rightLabel

Referenced by SwitchBoard(), and doRender().

◆ switch_left

bool SwitchBoard::switch_left {false}
110{false};

Referenced by doRender(), on_left_down(), and updateState().

◆ switch_right

bool SwitchBoard::switch_right {false}
111{false};

Referenced by doRender(), on_left_down(), and updateState().


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