From db4ceaa5fae5592d4ba5530fcdca9e1dd13f8e71 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 27 Nov 2018 11:08:34 +0100 Subject: [PATCH] DoubleSlider improvement + added thicks selection by mouse in the DoubleSlider + Click on the Unlock icon on DoubleSlider => set Min and Max slider values --- src/slic3r/GUI/wxExtensions.cpp | 38 +++++++++++++++++++++++++++++++++ src/slic3r/GUI/wxExtensions.hpp | 1 + 2 files changed, 39 insertions(+) diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index b14c958ed..5cd2564ed 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -1754,6 +1754,23 @@ bool PrusaDoubleSlider::is_point_in_rect(const wxPoint& pt, const wxRect& rect) return false; } +int PrusaDoubleSlider::is_point_near_tick(const wxPoint& pt) +{ + for (auto tick : m_ticks) { + const wxCoord pos = get_position_from_value(tick); + + if (is_horizontal()) { + if (pos - 4 <= pt.x && pt.x <= pos + 4) + return tick; + } + else { + if (pos - 4 <= pt.y && pt.y <= pos + 4) + return tick; + } + } + return -1; +} + void PrusaDoubleSlider::ChangeOneLayerLock() { m_is_one_layer = !m_is_one_layer; @@ -1781,12 +1798,33 @@ void PrusaDoubleSlider::OnLeftDown(wxMouseEvent& event) m_is_left_down = true; if (is_point_in_rect(pos, m_rect_one_layer_icon)) { m_is_one_layer = !m_is_one_layer; + if (!m_is_one_layer) { + SetLowerValue(m_min_value); + SetHigherValue(m_max_value); + } m_selection == ssLower ? correct_lower_value() : correct_higher_value(); if (!m_selection) m_selection = ssHigher; } else detect_selected_slider(pos); + if (!m_selection) { + const auto tick = is_point_near_tick(pos); + if (tick >= 0) + { + if (abs(tick - m_lower_value) < abs(tick - m_higher_value)) { + SetLowerValue(tick); + correct_lower_value(); + m_selection = ssLower; + } + else { + SetHigherValue(tick); + correct_higher_value(); + m_selection = ssHigher; + } + } + } + Refresh(); Update(); event.Skip(); diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index b035de685..967f3b603 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -719,6 +719,7 @@ protected: void enter_window(wxMouseEvent& event, const bool enter); bool is_point_in_rect(const wxPoint& pt, const wxRect& rect); + int is_point_near_tick(const wxPoint& pt); bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; } double get_scroll_step();