OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
AccentSlider Class Reference
Inheritance diagram for AccentSlider:
Collaboration diagram for AccentSlider:

Public Member Functions

 AccentSlider (wxWindow *parent, int value, int minVal, int maxVal, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
 ~AccentSlider () override
int GetValue () const
void SetValue (int val)
bool Enable (bool enable=true) override

Private Member Functions

void OnPaint (wxPaintEvent &)
void OnMouse (wxMouseEvent &)
int xFromValue () const
int valueFromX (int x) const

Private Attributes

int m_value
int m_min
int m_max
bool m_dragging = false

Detailed Description

Constructor & Destructor Documentation

◆ AccentSlider()

AccentSlider::AccentSlider ( wxWindow * parent,
int value,
int minVal,
int maxVal,
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize )
231 : wxPanel(parent, wxID_ANY, pos, size.IsFullySpecified() ? size : wxSize(-1, parent->FromDIP(24)),
232 wxTAB_TRAVERSAL | wxFULL_REPAINT_ON_RESIZE)
233 , m_value(std::clamp(value, minVal, maxVal)), m_min(minVal), m_max(maxVal)
234{
235 SetBackgroundStyle(wxBG_STYLE_PAINT);
236 SetMinSize(wxSize(-1, FromDIP(24)));
237
238 Bind(wxEVT_PAINT, &AccentSlider::OnPaint, this);
239 Bind(wxEVT_SIZE, [this](wxSizeEvent& evt) {
240 evt.Skip();
241 Refresh();
242 });
243 Bind(wxEVT_LEFT_DOWN, &AccentSlider::OnMouse, this);
244 Bind(wxEVT_LEFT_UP, &AccentSlider::OnMouse, this);
245 Bind(wxEVT_MOTION, &AccentSlider::OnMouse, this);
246 Bind(wxEVT_MOUSE_CAPTURE_LOST, [this](wxMouseCaptureLostEvent&) { m_dragging = false; });
247}
void OnPaint(wxPaintEvent &)
Definition TextureImportDialog.cpp:291
int m_max
Definition TextureImportDialog.cpp:225
int m_value
Definition TextureImportDialog.cpp:225
void OnMouse(wxMouseEvent &)
Definition TextureImportDialog.cpp:325
int m_min
Definition TextureImportDialog.cpp:225
bool m_dragging
Definition TextureImportDialog.cpp:226

References m_dragging, m_max, m_min, m_value, OnMouse(), and OnPaint().

Here is the call graph for this function:

◆ ~AccentSlider()

AccentSlider::~AccentSlider ( )
override
250{
251 // See MixedFilamentDialog::~MixedFilamentDialog: a widget destroyed while it
252 // still holds the capture wedges mouse input for the whole application.
253 if (HasCapture())
254 ReleaseMouse();
255}

Member Function Documentation

◆ Enable()

bool AccentSlider::Enable ( bool enable = true)
override
266{
267 bool ok = wxPanel::Enable(enable);
268 Refresh();
269 return ok;
270}

◆ GetValue()

int AccentSlider::GetValue ( ) const
257{ return m_value; }

References m_value.

◆ OnMouse()

void AccentSlider::OnMouse ( wxMouseEvent & evt)
private
326{
327 if (!IsEnabled()) return;
328
329 auto update = [&](int x) {
330 int nv = valueFromX(x);
331 if (nv != m_value) {
332 m_value = nv;
333 Refresh();
334 wxCommandEvent e(wxEVT_SLIDER, GetId());
335 e.SetEventObject(this);
336 ProcessWindowEvent(e);
337 }
338 };
339
340 if (evt.LeftDown()) {
341 m_dragging = true;
342 if (!HasCapture()) CaptureMouse();
343 update(evt.GetX());
344 } else if (evt.LeftUp()) {
345 m_dragging = false;
346 if (HasCapture()) ReleaseMouse();
347 } else if (evt.Dragging() && m_dragging) {
348 update(evt.GetX());
349 }
350}
int valueFromX(int x) const
Definition TextureImportDialog.cpp:281
bool IsEnabled()
Definition dark_mode.cpp:32

References m_dragging, m_value, and valueFromX().

Referenced by AccentSlider().

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

◆ OnPaint()

void AccentSlider::OnPaint ( wxPaintEvent & )
private
292{
293 wxAutoBufferedPaintDC dc(this);
294 wxSize sz = GetClientSize();
295
296 dc.SetBackground(wxBrush(GetParent()->GetBackgroundColour()));
297 dc.Clear();
298
299 int margin = FromDIP(6);
300 int track_y = sz.y / 2;
301 int ts = FromDIP(8);
302 int pen_w = FromDIP(2);
303
304 wxColour accent_clr = IsEnabled() ? wxColour("#009688") : StateColor::darkModeColorFor(wxColour("#ACACAC")); // use original accent color here to make it more readable
305 wxColour track_clr = StateColor::darkModeColorFor(IsEnabled() ? wxColour("#CECECE") : wxColour("#DFDFDF"));
306
307 int tx = xFromValue();
308
309 dc.SetPen(wxPen(accent_clr, pen_w));
310 dc.DrawLine(margin, track_y, tx, track_y);
311
312 dc.SetPen(wxPen(track_clr, pen_w));
313 dc.DrawLine(tx, track_y, sz.x - margin, track_y);
314
315 wxPoint tri[3] = {
316 {tx, track_y + FromDIP(1)},
317 {tx - ts / 2, track_y + FromDIP(1) + ts},
318 {tx + ts / 2, track_y + FromDIP(1) + ts}
319 };
320 dc.SetBrush(wxBrush(accent_clr));
321 dc.SetPen(*wxTRANSPARENT_PEN);
322 dc.DrawPolygon(3, tri);
323}
int xFromValue() const
Definition TextureImportDialog.cpp:272
static wxColour darkModeColorFor(wxColour const &color)
Definition StateColor.cpp:219

References StateColor::darkModeColorFor(), and xFromValue().

Referenced by AccentSlider().

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

◆ SetValue()

void AccentSlider::SetValue ( int val)
260{
261 val = std::clamp(val, m_min, m_max);
262 if (val != m_value) { m_value = val; Refresh(); }
263}

References m_max, m_min, and m_value.

Referenced by Slic3r::GUI::TextureImportDialog::preview_spin_text_value().

Here is the caller graph for this function:

◆ valueFromX()

int AccentSlider::valueFromX ( int x) const
private
282{
283 wxSize sz = GetClientSize();
284 int margin = FromDIP(6);
285 int track_w = sz.x - 2 * margin;
286 if (track_w <= 0 || m_max <= m_min) return m_min;
287 int val = m_min + (x - margin) * (m_max - m_min) / track_w;
288 return std::clamp(val, m_min, m_max);
289}

References m_max, and m_min.

Referenced by OnMouse().

Here is the caller graph for this function:

◆ xFromValue()

int AccentSlider::xFromValue ( ) const
private
273{
274 wxSize sz = GetClientSize();
275 int margin = FromDIP(6);
276 int track_w = sz.x - 2 * margin;
277 if (m_max <= m_min || track_w <= 0) return margin;
278 return margin + (m_value - m_min) * track_w / (m_max - m_min);
279}

References m_max, m_min, and m_value.

Referenced by OnPaint().

Here is the caller graph for this function:

Member Data Documentation

◆ m_dragging

bool AccentSlider::m_dragging = false
private

Referenced by AccentSlider(), and OnMouse().

◆ m_max

int AccentSlider::m_max
private

◆ m_min

int AccentSlider::m_min
private

◆ m_value

int AccentSlider::m_value
private

The documentation for this class was generated from the following file: