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

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

Inheritance diagram for TabButton:
Collaboration diagram for TabButton:

Public Member Functions

 TabButton ()
 TabButton (wxWindow *parent, wxString text, ScalableBitmap &icon, long style=0, int iconSize=0)
bool Create (wxWindow *parent, wxString text, ScalableBitmap &icon, long style=0, int iconSize=0)
void SetLabel (const wxString &label) override
void SetMinSize (const wxSize &size) override
void SetPaddingSize (const wxSize &size)
const wxSize & GetPaddingSize ()
void SetTextColor (StateColor const &color)
void SetBorderColor (StateColor const &color)
void SetBGColor (StateColor const &color)
void SetBitmap (ScalableBitmap &bitmap)
bool Enable (bool enable=true) override
void Rescale ()
void ShowNewTag (bool tag=false)
bool GetShowNewTag () const
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 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

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 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 sendButtonEvent ()

Private Attributes

wxSize textSize
wxSize minSize
wxSize paddingSize
ScalableBitmap icon
ScalableBitmap newtag_img
StateColor text_color
StateColor border_color
bool pressedDown = false
bool show_new_tag = false

Detailed Description

Constructor & Destructor Documentation

◆ TabButton() [1/2]

TabButton::TabButton ( )
35 : paddingSize(18, 16) // ORCA reduce / match left margin buttons on sidebars
36 , text_color(*wxBLACK)
37{
38 background_color = StateColor(
39 std::make_pair(TAB_BUTTON_SEL, (int) StateColor::Checked),
40 std::make_pair(wxColour("#FEFFFF"), (int) StateColor::Hovered),
41 std::make_pair(wxColour("#FEFFFF"), (int) StateColor::Normal));
42
43 border_color = StateColor(
44 std::make_pair(TAB_BUTTON_SEL, (int) StateColor::Checked), // ORCA use same color for border to prevent 1px blank border
45 std::make_pair(BORDER_HOVER_COL, (int) StateColor::Hovered),
46 std::make_pair(wxColour("#FEFFFF"), (int)StateColor::Normal));
47}
static wxColour BORDER_HOVER_COL
Definition TabButton.cpp:29
static const wxColour TAB_BUTTON_SEL
Definition Tabbook.cpp:27
@ Hovered
Definition StateColor.hpp:20
@ Normal
Definition StateColor.hpp:16
@ Checked
Definition StateColor.hpp:18
StateColor background_color
Definition StaticBox.hpp:73
StateColor text_color
Definition TabButton.hpp:23
wxSize paddingSize
Definition TabButton.hpp:19
StateColor border_color
Definition TabButton.hpp:24

References TabButton(), StaticBox::background_color, border_color, BORDER_HOVER_COL, StateColor::Checked, StateColor::Hovered, StateColor::Normal, paddingSize, TAB_BUTTON_SEL, and text_color.

Referenced by TabButton(), and TabButton().

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

◆ TabButton() [2/2]

TabButton::TabButton ( wxWindow * parent,
wxString text,
ScalableBitmap & icon,
long style = 0,
int iconSize = 0 )
50 : TabButton()
51{
52 Create(parent, text, bmp, style, iconSize);
53}
#define style
Definition WipeTowerDialog.cpp:101
TabButton()
Definition TabButton.cpp:34
bool Create(wxWindow *parent, wxString text, ScalableBitmap &icon, long style=0, int iconSize=0)
Definition TabButton.cpp:55

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

Here is the call graph for this function:

Member Function Documentation

◆ Create() [1/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
StateHandler state_handler
Definition StaticBox.hpp:71
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:

◆ Create() [2/2]

bool TabButton::Create ( wxWindow * parent,
wxString text,
ScalableBitmap & icon,
long style = 0,
int iconSize = 0 )
56{
57 StaticBox::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style);
58 newtag_img = ScalableBitmap(this, "monitor_hms_new",7);
60 state_handler.update_binds();
61 //BBS set default font
62 SetFont(Label::Body_14);
63 wxWindow::SetLabel(text);
64 this->icon = bmp;
66 return true;
67}
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
ScalableBitmap icon
Definition TabButton.hpp:20
void messureSize()
Definition TabButton.cpp:200
ScalableBitmap newtag_img
Definition TabButton.hpp:21

References Label::Body_14, border_color, StaticBox::Create(), icon, messureSize(), newtag_img, StaticBox::state_handler, style, and text_color.

Referenced by TabButton().

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 TabButton::Enable ( bool enable = true)
override
120{
121 bool result = wxWindow::Enable(enable);
122 if (result) {
123 wxCommandEvent e(EVT_ENABLE_CHANGED);
124 e.SetEventObject(this);
125 GetEventHandler()->ProcessEvent(e);
126 }
127 return result;
128}

◆ 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}

◆ GetPaddingSize()

const wxSize & TabButton::GetPaddingSize ( )
89{
90 return paddingSize;
91}

References paddingSize.

◆ 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:

◆ GetShowNewTag()

bool TabButton::GetShowNewTag ( ) const
inline
56{ return show_new_tag; };
bool show_new_tag
Definition TabButton.hpp:26

References show_new_tag.

◆ messureSize()

void TabButton::messureSize ( )
private
201{
202 wxClientDC dc(this);
203 textSize = dc.GetTextExtent(GetLabel());
204 if (minSize.GetWidth() > 0) {
205 wxWindow::SetMinSize(minSize);
206 return;
207 }
208 wxSize szContent = textSize;
209 if (this->icon.bmp().IsOk()) {
210 if (szContent.y > 0) {
211 // BBS norrow size between text and icon
212 szContent.x += 5;
213 }
214 wxSize szIcon = this->icon.GetBmpSize();
215 szContent.x += szIcon.x;
216 if (szIcon.y > szContent.y) szContent.y = szIcon.y;
217 }
218 wxWindow::SetMinSize(szContent + paddingSize);
219}
wxSize minSize
Definition TabButton.hpp:18
wxSize textSize
Definition TabButton.hpp:17

References icon, minSize, paddingSize, and textSize.

Referenced by Create(), Rescale(), SetLabel(), SetMinSize(), and SetPaddingSize().

Here is the caller graph for this function:

◆ mouseDown()

void TabButton::mouseDown ( wxMouseEvent & event)
private
222{
223 event.Skip();
224 pressedDown = true;
225 SetFocus();
226 CaptureMouse();
227}
bool pressedDown
Definition TabButton.hpp:25

References pressedDown.

◆ mouseReleased()

void TabButton::mouseReleased ( wxMouseEvent & event)
private
230{
231 event.Skip();
232 if (pressedDown) {
233 pressedDown = false;
234 ReleaseMouse();
235 if (wxRect({0, 0}, GetSize()).Contains(event.GetPosition()))
237 }
238}
void sendButtonEvent()
Definition TabButton.cpp:240

References pressedDown, and sendButtonEvent().

Here is the call graph for this function:

◆ paintEvent()

void TabButton::paintEvent ( wxPaintEvent & evt)
private
136{
137 // depending on your system you may need to look at double-buffered dcs
138 wxPaintDC dc(this);
139 render(dc);
140}
void render(wxDC &dc)
Definition TabButton.cpp:147

References render().

Here is the call graph for this function:

◆ render()

void TabButton::render ( wxDC & dc)
private
148{
150 int states = state_handler.states();
151 wxSize size = GetSize();
152
153 dc.SetPen(wxPen(border_color.colorForStates(states)));
154 dc.SetBrush(*wxTRANSPARENT_BRUSH);
155 dc.DrawRectangle(0, 0, size.x, size.y);
156
157 // calc content size
158 wxSize szIcon;
159 wxSize szContent = textSize;
160 if (icon.bmp().IsOk()) {
161 if (szContent.y > 0) {
162 // BBS norrow size between text and icon
163 szContent.x += 5;
164 }
165 szIcon = icon.GetBmpSize();
166 szContent.x += szIcon.x;
167 if (szIcon.y > szContent.y) szContent.y = szIcon.y;
168 }
169 // move to center
170 wxRect rcContent = {{0, 0}, size};
171 wxSize offset = (size - szContent) / 2;
172 rcContent.Deflate(offset.x, offset.y);
173 // start draw
174 wxPoint pt = rcContent.GetLeftTop();
175
176 auto text = GetLabel();
177 if (!text.IsEmpty()) {
178 pt.x = FromDIP(paddingSize.x); // ORCA match padding on scaling
179 pt.y = rcContent.y + (rcContent.height - textSize.y) / 2;
180 dc.SetFont(GetFont());
181 dc.SetTextForeground(text_color.colorForStates(states));
182 dc.DrawText(text, pt);
183 }
184
185 wxBitmap showimg = icon.bmp();
186 int offset_left = 0;
187 if (show_new_tag) {
188 showimg = newtag_img.bmp();
189 offset_left = FromDIP(4);
190 }
191
192 if (showimg.IsOk()) {
193 pt.x = size.x - showimg.GetWidth() - paddingSize.y - offset_left;
194 pt.y = (size.y - showimg.GetHeight()) / 2;
195 dc.DrawBitmap(showimg, pt);
196 }
197
198}
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 border_color, icon, newtag_img, paddingSize, StaticBox::render(), show_new_tag, StaticBox::state_handler, text_color, and textSize.

Referenced by paintEvent().

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

◆ Rescale()

void TabButton::Rescale ( )
131{
132 messureSize();
133}

References messureSize().

Here is the call graph for this function:

◆ sendButtonEvent()

void TabButton::sendButtonEvent ( )
private
241{
242 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
243 event.SetEventObject(this);
244 GetEventHandler()->ProcessEvent(event);
245}

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:

◆ SetBGColor()

void TabButton::SetBGColor ( StateColor const & color)
108{
109 background_color = color;
110 state_handler.update_binds();
111 Refresh();
112}

References StaticBox::background_color, and StaticBox::state_handler.

◆ SetBitmap()

void TabButton::SetBitmap ( ScalableBitmap & bitmap)
115{
116 this->icon = bitmap;
117}

References icon.

◆ SetBorderColor()

void TabButton::SetBorderColor ( StateColor const & color)
101{
102 border_color = color;
103 state_handler.update_binds();
104 Refresh();
105}

References border_color, and StaticBox::state_handler.

◆ 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:

◆ SetCornerRadius()

◆ SetLabel()

void TabButton::SetLabel ( const wxString & label)
override
70{
71 wxWindow::SetLabel(label);
73 Refresh();
74}

References messureSize().

Referenced by TabButtonsListCtrl::SetPageText().

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

◆ SetMinSize()

void TabButton::SetMinSize ( const wxSize & size)
override
77{
78 minSize = size;
80}

References messureSize(), and minSize.

Referenced by TabButtonsListCtrl::InsertPage().

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

◆ SetPaddingSize()

void TabButton::SetPaddingSize ( const wxSize & size)
83{
84 paddingSize = size;
86}

References messureSize(), and paddingSize.

Here is the call graph for this function:

◆ SetTextColor()

void TabButton::SetTextColor ( StateColor const & color)
94{
95 text_color = color;
96 state_handler.update_binds();
97 Refresh();
98}

References StaticBox::state_handler, and text_color.

Referenced by TabButtonsListCtrl::InsertPage().

Here is the caller graph for this function:

◆ 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:

◆ 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:

◆ ShowNewTag()

void TabButton::ShowNewTag ( bool tag = false)
inline
55{show_new_tag = tag; Refresh();};

References show_new_tag.

◆ sizeEvent()

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

Member Data Documentation

◆ background_color

◆ background_color2

StateColor StaticBox::background_color2
protectedinherited

◆ badge

ScalableBitmap StaticBox::badge
protectedinherited

Referenced by doRender(), and ShowBadge().

◆ border_color

StateColor TabButton::border_color
private

◆ border_style

wxPenStyle StaticBox::border_style = wxPENSTYLE_SOLID
protectedinherited

Referenced by doRender(), and SetBorderStyle().

◆ border_width

◆ icon

ScalableBitmap TabButton::icon
private

Referenced by Create(), messureSize(), render(), and SetBitmap().

◆ minSize

wxSize TabButton::minSize
private

Referenced by messureSize(), and SetMinSize().

◆ newtag_img

ScalableBitmap TabButton::newtag_img
private

Referenced by Create(), and render().

◆ paddingSize

wxSize TabButton::paddingSize
private

◆ pressedDown

bool TabButton::pressedDown = false
private

Referenced by mouseDown(), and mouseReleased().

◆ radius

◆ show_new_tag

bool TabButton::show_new_tag = false
private

Referenced by GetShowNewTag(), render(), and ShowNewTag().

◆ state_handler

◆ text_color

StateColor TabButton::text_color
private

◆ textSize

wxSize TabButton::textSize
private

Referenced by messureSize(), and render().

◆ top_margin

int StaticBox::top_margin = 0
protectedinherited

Referenced by doRender(), and SetTopMargin().


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