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

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

Inheritance diagram for SpinInput:
Collaboration diagram for SpinInput:

Public Member Functions

 SpinInput ()
 SpinInput (wxWindow *parent, wxString text, wxString label="", const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, int min=0, int max=100, int initial=0, const int &step=1)
void Create (wxWindow *parent, wxString text, wxString label="", const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, int min=0, int max=100, int initial=0, int step=1)
void SetCornerRadius (double radius)
void SetLabel (const wxString &label) wxOVERRIDE
void SetLabelColor (StateColor const &color)
void SetTextColor (StateColor const &color)
void SetSize (wxSize const &size)
void Rescale ()
virtual bool Enable (bool enable=true) wxOVERRIDE
wxTextCtrl * GetTextCtrl ()
void SetValue (const wxString &text)
void SetValue (int value)
int GetValue () const
void SetStep (int value)
int GetStep ()
void SetRange (int min, int max)
int GetMin () const
int GetMax () const

Protected Member Functions

void DoSetToolTipText (wxString const &tip) override

Private Member Functions

void paintEvent (wxPaintEvent &evt)
void render (wxDC &dc)
void messureSize ()
Button * createButton (bool inc)
void mouseWheelMoved (wxMouseEvent &event)
void keyPressed (wxKeyEvent &event)
void onTimer (wxTimerEvent &evnet)
void onTextLostFocus (wxEvent &event)
void onTextChanged (wxCommandEvent &event)
void onTextEnter (wxCommandEvent &event)
void sendSpinEvent ()

Private Attributes

wxSize labelSize
StateColor label_color
StateColor text_color
wxTextCtrl * text_ctrl
Button * button_inc
Button * button_dec
wxTimer timer
int val
int min
int max
int delta
int step

Static Private Attributes

static const int SpinInputWidth = 200
static const int SpinInputHeight = 50

Detailed Description

Constructor & Destructor Documentation

◆ SpinInput() [1/2]

SpinInput::SpinInput ( )
44 : label_color(std::make_pair(0x6B6B6B, (int) StateColor::Disabled), std::make_pair(0x6B6B6B, (int) StateColor::Normal))
45 , text_color(std::make_pair(0x6B6B6B, (int) StateColor::Disabled), std::make_pair(0x262E30, (int) StateColor::Normal))
46{
47 radius = 0;
48 border_width = 1;
49 border_color = StateColor(std::make_pair(0xDBDBDB, (int) StateColor::Disabled), std::make_pair(0x009688, (int) StateColor::Hovered),
50 std::make_pair(0xDBDBDB, (int) StateColor::Normal));
51 background_color = StateColor(std::make_pair(0xF0F0F1, (int) StateColor::Disabled), std::make_pair(*wxWHITE, (int) StateColor::Normal));
52}
StateColor label_color
Definition SpinInput.hpp:29
StateColor text_color
Definition SpinInput.hpp:30
@ Hovered
Definition StateColor.hpp:20
@ Normal
Definition StateColor.hpp:16
@ Disabled
Definition StateColor.hpp:22

References SpinInput(), StateColor::Disabled, StateColor::Hovered, label_color, StateColor::Normal, and text_color.

Referenced by SpinInput(), and SpinInput().

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

◆ SpinInput() [2/2]

SpinInput::SpinInput ( wxWindow * parent,
wxString text,
wxString label = "",
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = 0,
int min = 0,
int max = 100,
int initial = 0,
const int & step = 1 )
62 : SpinInput()
63{
64 Create(parent, text, label, pos, size, style, min, max, initial, step);
65}
#define style
Definition WipeTowerDialog.cpp:101
int max
Definition SpinInput.hpp:38
int min
Definition SpinInput.hpp:37
SpinInput()
Definition SpinInput.cpp:43
int step
Definition SpinInput.hpp:40
void Create(wxWindow *parent, wxString text, wxString label="", const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, int min=0, int max=100, int initial=0, int step=1)
Definition SpinInput.cpp:67

References SpinInput(), Create(), max, min, step, and style.

Here is the call graph for this function:

Member Function Documentation

◆ Create()

void SpinInput::Create ( wxWindow * parent,
wxString text,
wxString label = "",
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = 0,
int min = 0,
int max = 100,
int initial = 0,
int step = 1 )
74{
75 StaticBox::Create(parent, wxID_ANY, pos, size);
76 SetFont(Label::Body_12);
77 wxWindow::SetLabel(label);
78 state_handler.attach({&label_color, &text_color});
79 state_handler.update_binds();
80 text_ctrl = new TextCtrl(this, wxID_ANY, text, {20, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER, wxTextValidator(wxFILTER_DIGITS));
81
82#ifdef __WXGTK__
83 Slic3r::GUI::RemoveInputBorder(text_ctrl);
84#endif
85
86 text_ctrl->SetFont(Label::Body_14);
87 text_ctrl->SetBackgroundColour(background_color.colorForStates(state_handler.states()));
88 text_ctrl->SetForegroundColour(text_color.colorForStates(state_handler.states()));
89 text_ctrl->SetInitialSize(text_ctrl->GetBestSize());
90 state_handler.attach_child(text_ctrl);
91 text_ctrl->Bind(wxEVT_KILL_FOCUS, &SpinInput::onTextLostFocus, this);
92 text_ctrl->Bind(wxEVT_TEXT_ENTER, &SpinInput::onTextEnter, this);
93 text_ctrl->Bind(wxEVT_TEXT, &SpinInput::onTextChanged, this);
94 text_ctrl->Bind(wxEVT_KEY_DOWN, &SpinInput::keyPressed, this);
95 text_ctrl->Bind(wxEVT_RIGHT_DOWN, [](auto &e) {}); // disable context menu
97 button_dec = createButton(false);
98 delta = 0;
99 timer.Bind(wxEVT_TIMER, &SpinInput::onTimer, this);
100
101 long initialFromText;
102 if (text.ToLong(&initialFromText)) initial = initialFromText;
103 SetRange(min, max);
104 SetValue(initial);
105 SetStep(step);
106 messureSize();
107}
wxTextCtrl TextCtrl
Definition TextCtrl.h:14
static wxFont Body_12
Definition Label.hpp:55
static wxFont Body_14
Definition Label.hpp:53
void onTimer(wxTimerEvent &evnet)
Definition SpinInput.cpp:284
void onTextChanged(wxCommandEvent &event)
Definition SpinInput.cpp:320
void onTextLostFocus(wxEvent &event)
Definition SpinInput.cpp:293
Button * button_inc
Definition SpinInput.hpp:32
void SetValue(const wxString &text)
Definition SpinInput.cpp:140
void onTextEnter(wxCommandEvent &event)
Definition SpinInput.cpp:308
void keyPressed(wxKeyEvent &event)
Definition SpinInput.cpp:341
Button * button_dec
Definition SpinInput.hpp:33
wxTextCtrl * text_ctrl
Definition SpinInput.hpp:31
void SetRange(int min, int max)
Definition SpinInput.cpp:160
void messureSize()
Definition SpinInput.cpp:227
wxTimer timer
Definition SpinInput.hpp:34
void SetStep(int value)
Definition SpinInput.hpp:89
int delta
Definition SpinInput.hpp:39
Button * createButton(bool inc)
Definition SpinInput.cpp:252
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
Definition StaticBox.cpp:51

References Label::Body_12, Label::Body_14, button_dec, button_inc, StaticBox::Create(), createButton(), delta, keyPressed(), label_color, max, messureSize(), min, onTextChanged(), onTextEnter(), onTextLostFocus(), onTimer(), SetRange(), SetStep(), SetValue(), step, style, text_color, text_ctrl, and timer.

Referenced by SpinInput().

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

◆ createButton()

Button * SpinInput::createButton ( bool inc)
private
253{
254 auto btn = new Button(this, "", inc ? "spin_inc" : "spin_dec", wxBORDER_NONE, 6);
255 btn->SetCornerRadius(0);
256 btn->DisableFocusFromKeyboard();
257 btn->Bind(wxEVT_LEFT_DOWN, [=](auto &e) {
258 delta = inc ? 1 : -1;
259 SetValue(val + delta * step);
260 text_ctrl->SetFocus();
261 if (!btn->HasCapture())
262 btn->CaptureMouse();
263 delta *= 8;
264 timer.Start(100);
266 });
267 btn->Bind(wxEVT_LEFT_DCLICK, [=](auto &e) {
268 delta = inc ? 1 : -1;
269 if (!btn->HasCapture())
270 btn->CaptureMouse();
271 SetValue(val + delta * step);
273 });
274 btn->Bind(wxEVT_LEFT_UP, [=](auto &e) {
275 if (btn->HasCapture())
276 btn->ReleaseMouse();
277 timer.Stop();
278 text_ctrl->SelectAll();
279 delta = 0;
280 });
281 return btn;
282}
int val
Definition SpinInput.hpp:36
void sendSpinEvent()
Definition SpinInput.cpp:362

References delta, sendSpinEvent(), SetValue(), step, text_ctrl, timer, and val.

Referenced by Create().

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

◆ DoSetToolTipText()

void SpinInput::DoSetToolTipText ( wxString const & tip)
overrideprotected
167{
168 wxWindow::DoSetToolTipText(tip);
169 text_ctrl->SetToolTip(tip);
170}

References text_ctrl.

◆ Enable()

bool SpinInput::Enable ( bool enable = true)
virtual
180{
181 bool result = text_ctrl->Enable(enable) && wxWindow::Enable(enable);
182 if (result) {
183 wxCommandEvent e(EVT_ENABLE_CHANGED);
184 e.SetEventObject(this);
185 GetEventHandler()->ProcessEvent(e);
186 text_ctrl->SetBackgroundColour(background_color.colorForStates(state_handler.states()));
187 text_ctrl->SetForegroundColour(text_color.colorForStates(state_handler.states()));
188 button_inc->Enable(enable);
189 button_dec->Enable(enable);
190 }
191 return result;
192}

References button_dec, button_inc, text_color, and text_ctrl.

◆ GetMax()

int SpinInput::GetMax ( ) const
inline
96{ return this->max; }

◆ GetMin()

int SpinInput::GetMin ( ) const
inline
95{ return this->min; }

◆ GetStep()

int SpinInput::GetStep ( )
inline
91{ return step; };

References step.

◆ GetTextCtrl()

wxTextCtrl * SpinInput::GetTextCtrl ( )
inline
81{ return text_ctrl; }

References GetTextCtrl(), and text_ctrl.

Referenced by GetTextCtrl(), Slic3r::GUI::SpinCtrl::msw_rescale(), and Slic3r::GUI::TextureImportDialog::preview_spin_text_value().

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

◆ GetValue()

int SpinInput::GetValue ( ) const
156{
157 return val;
158}

References val.

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

Here is the caller graph for this function:

◆ keyPressed()

void SpinInput::keyPressed ( wxKeyEvent & event)
private
342{
343 switch (event.GetKeyCode()) {
344 case WXK_UP:
345 case WXK_DOWN:
346 long value;
347 if (!text_ctrl->GetValue().ToLong(&value)) { value = val; }
348 if (event.GetKeyCode() == WXK_DOWN && value - step >= min) {
349 value = value - step;
350 } else if (event.GetKeyCode() == WXK_UP && value + step <= max) {
351 value = value + step;
352 }
353 if (value != val) {
354 SetValue(value);
356 }
357 break;
358 default: event.Skip(); break;
359 }
360}

References max, min, sendSpinEvent(), SetValue(), step, text_ctrl, and val.

Referenced by Create(), and wxDEFINE_EVENT().

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

◆ messureSize()

void SpinInput::messureSize ( )
private
228{
229 wxSize size = GetSize();
230 wxSize textSize = text_ctrl->GetSize();
231 int h = textSize.y + 8;
232 if (size.y < h) {
233 size.y = h;
234 }
235 wxSize minSize = size;
236 minSize.x = GetMinWidth();
237 StaticBox::SetSize(size);
238 SetMinSize(size);
239 wxSize btnSize = {14, (size.y - 4) / 2};
240 btnSize.x = btnSize.x * btnSize.y / 10;
241 wxClientDC dc(this);
242 labelSize = dc.GetMultiLineTextExtent(GetLabel());
243 textSize.x = size.x - labelSize.x - btnSize.x - 16;
244 text_ctrl->SetSize(textSize);
245 text_ctrl->SetPosition({6 + btnSize.x, (size.y - textSize.y) / 2});
246 button_inc->SetSize(btnSize);
247 button_dec->SetSize(btnSize);
248 button_inc->SetPosition({3, size.y / 2 - btnSize.y - 1});
249 button_dec->SetPosition({3, size.y / 2 + 1});
250}
wxSize labelSize
Definition SpinInput.hpp:28

References button_dec, button_inc, labelSize, and text_ctrl.

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

Here is the caller graph for this function:

◆ mouseWheelMoved()

void SpinInput::mouseWheelMoved ( wxMouseEvent & event)
private
334{
335 auto delta = event.GetWheelRotation() < 0 ? 1 : -1;
336 SetValue(val + delta * step);
338 text_ctrl->SetFocus();
339}

References delta, sendSpinEvent(), SetValue(), step, text_ctrl, and val.

Here is the call graph for this function:

◆ onTextChanged()

void SpinInput::onTextChanged ( wxCommandEvent & event)
private
321{
322 long value;
323 if (text_ctrl->GetValue().ToLong(&value)) {
324 wxCommandEvent e(EVT_SPINCTRL_TEXT, GetId());
325 e.SetEventObject(this);
326 e.SetInt((int) value);
327 e.SetString(text_ctrl->GetValue());
328 GetEventHandler()->ProcessEvent(e);
329 }
330 event.Skip();
331}

References text_ctrl.

Referenced by Create().

Here is the caller graph for this function:

◆ onTextEnter()

void SpinInput::onTextEnter ( wxCommandEvent & event)
private
309{
310 long value;
311 if (!text_ctrl->GetValue().ToLong(&value)) { value = val; }
312 if (value != val) {
313 SetValue(value);
315 }
316 event.SetId(GetId());
317 ProcessEventLocally(event);
318}

References sendSpinEvent(), SetValue(), text_ctrl, and val.

Referenced by Create(), and onTextLostFocus().

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

◆ onTextLostFocus()

void SpinInput::onTextLostFocus ( wxEvent & event)
private
294{
295 timer.Stop();
296 for (auto * child : GetChildren())
297 if (auto btn = dynamic_cast<Button*>(child))
298 if (btn->HasCapture())
299 btn->ReleaseMouse();
300 wxCommandEvent e;
301 onTextEnter(e);
302 // pass to outer
303 event.SetId(GetId());
304 ProcessEventLocally(event);
305 e.Skip();
306}

References onTextEnter(), and timer.

Referenced by Create().

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

◆ onTimer()

void SpinInput::onTimer ( wxTimerEvent & evnet)
private
284 {
285 if (delta < -1 || delta > 1) {
286 delta /= 2;
287 return;
288 }
289 SetValue(val + delta * step);
291}

References delta, sendSpinEvent(), SetValue(), step, and val.

Referenced by Create().

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

◆ paintEvent()

void SpinInput::paintEvent ( wxPaintEvent & evt)
private
195{
196 // depending on your system you may need to look at double-buffered dcs
197 wxPaintDC dc(this);
198 render(dc);
199}
void render(wxDC &dc)
Definition SpinInput.cpp:206

References render().

Referenced by wxDEFINE_EVENT().

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

◆ render()

void SpinInput::render ( wxDC & dc)
private
207{
209 int states = state_handler.states();
210 wxSize size = GetSize();
211 // draw seperator of buttons
212 wxPoint pt = button_inc->GetPosition();
213 pt.y = size.y / 2;
214 dc.SetPen(wxPen(border_color.defaultColor()));
215 dc.DrawLine(pt, pt + wxSize{button_inc->GetSize().x - 2, 0});
216 // draw label
217 auto label = GetLabel();
218 if (!label.IsEmpty()) {
219 pt.x = size.x - labelSize.x - 5;
220 pt.y = (size.y - labelSize.y) / 2;
221 dc.SetFont(GetFont());
222 dc.SetTextForeground(label_color.colorForStates(states));
223 dc.DrawText(label, pt);
224 }
225}
void render(wxDC &dc)
Definition StaticBox.cpp:181

References button_inc, label_color, labelSize, and StaticBox::render().

Referenced by paintEvent().

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

◆ Rescale()

void SpinInput::Rescale ( )
173{
174 button_inc->Rescale();
175 button_dec->Rescale();
176 messureSize();
177}

References button_dec, button_inc, and messureSize().

Referenced by Slic3r::GUI::SpinCtrl::msw_rescale(), and SetSize().

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

◆ sendSpinEvent()

void SpinInput::sendSpinEvent ( )
private
363{
364 wxCommandEvent event(wxEVT_SPINCTRL, GetId());
365 event.SetEventObject(this);
366 GetEventHandler()->ProcessEvent(event);
367}

Referenced by createButton(), keyPressed(), mouseWheelMoved(), onTextEnter(), and onTimer().

Here is the caller graph for this function:

◆ SetCornerRadius()

void SpinInput::SetCornerRadius ( double radius)
110{
111 this->radius = radius;
112 Refresh();
113}

◆ SetLabel()

void SpinInput::SetLabel ( const wxString & label)
116{
117 wxWindow::SetLabel(label);
118 messureSize();
119 Refresh();
120}

References messureSize().

Here is the call graph for this function:

◆ SetLabelColor()

void SpinInput::SetLabelColor ( StateColor const & color)
123{
124 label_color = color;
125 state_handler.update_binds();
126}

References label_color.

◆ SetRange()

void SpinInput::SetRange ( int min,
int max )
161{
162 this->min = min;
163 this->max = max;
164}

References max, and min.

Referenced by Create().

Here is the caller graph for this function:

◆ SetSize()

void SpinInput::SetSize ( wxSize const & size)
135{
136 StaticBox::SetSize(size);
137 Rescale();
138}
void Rescale()
Definition SpinInput.cpp:172

References Rescale().

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

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

◆ SetStep()

void SpinInput::SetStep ( int value)
inline
89{ step = value; };

References step.

Referenced by Create().

Here is the caller graph for this function:

◆ SetTextColor()

void SpinInput::SetTextColor ( StateColor const & color)
129{
130 text_color = color;
131 state_handler.update_binds();
132}

References text_color.

◆ SetValue() [1/2]

void SpinInput::SetValue ( const wxString & text)
141{
142 long value;
143 if ( text.ToLong(&value) )
144 SetValue(value);
145}

References SetValue().

Referenced by Create(), createButton(), keyPressed(), mouseWheelMoved(), onTextEnter(), onTimer(), Slic3r::GUI::SpinCtrl::set_value(), and SetValue().

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

◆ SetValue() [2/2]

void SpinInput::SetValue ( int value)
148{
149 if (value < min) value = min;
150 else if (value > max) value = max;
151 this->val = value;
152 text_ctrl->SetValue(wxString::FromDouble(value));
153}

References max, min, text_ctrl, and val.

Member Data Documentation

◆ button_dec

Button* SpinInput::button_dec
private

Referenced by Create(), Enable(), messureSize(), and Rescale().

◆ button_inc

Button* SpinInput::button_inc
private

◆ delta

int SpinInput::delta
private

◆ label_color

StateColor SpinInput::label_color
private

◆ labelSize

wxSize SpinInput::labelSize
private

Referenced by messureSize(), and render().

◆ max

int SpinInput::max
private

◆ min

int SpinInput::min
private

◆ SpinInputHeight

const int SpinInput::SpinInputHeight = 50
staticprivate

◆ SpinInputWidth

const int SpinInput::SpinInputWidth = 200
staticprivate

◆ step

int SpinInput::step
private

◆ text_color

StateColor SpinInput::text_color
private

◆ text_ctrl

◆ timer

wxTimer SpinInput::timer
private

◆ val

int SpinInput::val
private

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