From d90f5fa591d35b930bb3668b9d86381c02ddfe82 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 24 Aug 2018 13:34:38 +0200 Subject: [PATCH] Added "one_layer" mode for PrusaDoubleSlider --- resources/icons/one_layer_lock_off.png | Bin 0 -> 577 bytes resources/icons/one_layer_lock_on.png | Bin 0 -> 528 bytes resources/icons/one_layer_unlock_off.png | Bin 0 -> 508 bytes resources/icons/one_layer_unlock_on.png | Bin 0 -> 483 bytes xs/src/slic3r/GUI/GUI.cpp | 13 -- xs/src/slic3r/GUI/wxExtensions.cpp | 232 ++++++++++++++++------- xs/src/slic3r/GUI/wxExtensions.hpp | 41 ++-- 7 files changed, 197 insertions(+), 89 deletions(-) create mode 100644 resources/icons/one_layer_lock_off.png create mode 100644 resources/icons/one_layer_lock_on.png create mode 100644 resources/icons/one_layer_unlock_off.png create mode 100644 resources/icons/one_layer_unlock_on.png diff --git a/resources/icons/one_layer_lock_off.png b/resources/icons/one_layer_lock_off.png new file mode 100644 index 0000000000000000000000000000000000000000..7dc8b06118fbf0e2e3960e458d2ccaded8dc6398 GIT binary patch literal 577 zcmV-H0>1r;P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0oF-GK~y+TeN$N| zrC}KU<5*H|WNDJ+#-(y)kUJSAS6nOSSW<>rkPD&?Y8ofhIVmJJgsI7vL?>IBL5)ap zA(DN`KGw55-uL|9`Tk$Y(|hqh-}}7Z|8AcGJudcPx54rWW#P{ze^kVxB?~hhxIPvF z54JO+8n8&(yEg+935s@4-j0fTkyD+)q)A+{E<^A9Vd*qq1CGJaR1I2a}a z#w~EWyfM@5F!^#!O+2=ju=ER!sVEI&I?}+w<EqW25` zP(5i#;R~Fa5D0(j=`F(oqUht-17aj6T6LWO4fLDCe|h}PziG)Y7^LO zIj~z{{-|l1(iN^xa!Ty#2nXw2`tB;%M$I_g=4MDuS%d6)`{J5Jn`Vvo8Gap zAG&=bI36+E`QBdt>4D3kYIQRq(EFKe#m_W)KTe|oUq8T-fvL7vg92Uvsz+lDLmI@D P00000NkvXXu0mjfoBjT? literal 0 HcmV?d00001 diff --git a/resources/icons/one_layer_lock_on.png b/resources/icons/one_layer_lock_on.png new file mode 100644 index 0000000000000000000000000000000000000000..41b7ff173f98d36fc3ccbafcfa9ac4cf20a83726 GIT binary patch literal 528 zcmV+r0`L8aP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0i{VqK~y+Tl~PG4 zg<%wx5|NDzSs2P%$-*298Il!iMaD8_+7R`;m*N?UEJ!viC}l_@31uuI#X?>$GDn_S z@s4}ncmMYu7IM0a@7#ON|J{4P-v$52FV8|RjH#&bN3j=bL(!FqrG6=CaPq7S!jOQW zLL6_vyp7#y9Ie8IJ|Cl7tQF&w5XY>lzG+>hy$p3ODEs1FmF!_yRjTo<&& z;CK@wl_>ILN}-SAZfipL+?u4cHqW#{6ja-rK~I)Yis~TlE#FNj`NgA;l~iX2_UABK z2VE53OwpT-g&ydlMbMt2c}lz`MUCBG;Ou}$KiT8iXc^ZgUWO7>1ZbW-S4r7nxni5; zQYb+Q3O(p()0O#3%4%gwnCs$(XN^K%A4K4|hnAyKpC3#KlRDlnEn4B_UIdPL?0d6* zG9|2!pg#vY6GGn}ML_!y4?(?;y*D-Y-Ko&`XRfv;D&{nIsSit^Zh3Vy{lhgMC?0Qc ze#lR!!O62cfaXZ);YS$au{JESZytsDZnP!yzgOUnsz4aiu-GRh4Zl2p0{8;H4zuib SoxZjJ0000hI literal 0 HcmV?d00001 diff --git a/resources/icons/one_layer_unlock_off.png b/resources/icons/one_layer_unlock_off.png new file mode 100644 index 0000000000000000000000000000000000000000..c3931f8b9d11ba5db566066820ac2afb40b87057 GIT binary patch literal 508 zcmVPx#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0g*{WK~y+TeUr

yC2SD3|l|&Ez;vJoVMgJM+xE&%E=Q`wI?- zL#NY8r_+Hzz-F_B!{KZ;+w1jCr;}z_P|o#w9SjB}k@_EzNMt-7OD1@5Ak=C#jemf{ z;b^s5x7$rQbhq2>`Fwu0T2XH@nP3zO1rC*A!Rd5LH?!OAd_EsX%jL3ME@O~dEEW+a zs$LNag^tIgX*3$*&*$@0DkXL-7Nf1l;}Q22)H3mST%6HpluRbM0Oc87sZ@$aqkg|1 z*X#944xp}ayWQfDK`fKW%w{w0$(=Ww4fb?8MWN&XN|-mHl}ZJb0M25uV5HcLOT!in z-PN?fxP()$*HJ|)?EQYPVd;}dB-FF;TJ^b1@rm+k@I<#MT3s~Y(X6#nj;(E9!Um%Sbi yhcb7d904-g?KayWn-&ZPS%_}8`{)0;-+urK-CfHDDVaL}0000Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0eDG7K~y+Tm6FS= zK~WTk?;lSd$Ezge5D76ekrQU5L@1956VDlikpbIx?%K{l>UMvl_4@YSYpwmG{;yA_ z-|v@7rD!x72n6Esc%@Pq4u?ATl*^3A<4h*w`KEk6uZw==GRm0^3&CO;5Mw(K~vUnsf6hP$MW;2~mhtO)ZDi({9PNh<{TFo#FaUF4x zX0q8V{&YGm6be3{kK-9bqtQqvlaWXSHxvp9!=ai927~xikSmwV%jJ@H9*@WUeviFa zEa*@ec+I@_+G@3kAei-feY@ST@Atc8{eC~L&F}yTA;x7BO10ZN5Ua>Eii)7uoA@(EDYPCw;`F!SV5dbSD z^|l{TI2;!2tN44m?v)vhM(K1~m%NLHCzFY;du2quUXRT(AC?=7#aQlOFwnWDKAFFz Z)C1+OrOso1VzU4M002ovPDHLkV1i}d*xLXA literal 0 HcmV?d00001 diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 8701db511..088cbf80b 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -1052,19 +1052,6 @@ void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFl // Object List add_objects_list(parent, sizer); - // experiment with slider - PrusaDoubleSlider* slider_h = new PrusaDoubleSlider(parent, wxID_ANY, 50, 70, 0, 200, wxDefaultPosition, - wxSize(60, wxDefaultSize.y), wxSL_HORIZONTAL); - sizer->AddSpacer(5); - sizer->Add(slider_h, 0, wxEXPAND | wxLEFT, 20); - sizer->AddSpacer(5); - PrusaDoubleSlider* slider_v = new PrusaDoubleSlider(parent, wxID_ANY, 50, 70, 0, 100, wxDefaultPosition, - wxSize(120 ,200), wxSL_VERTICAL); - slider_v->SetKoefForLabels(2.25); - sizer->AddSpacer(5); - sizer->Add(slider_v, 0, wxLEFT, 20); - sizer->AddSpacer(5); - // Frequently Object Settings add_object_settings(parent, sizer); } diff --git a/xs/src/slic3r/GUI/wxExtensions.cpp b/xs/src/slic3r/GUI/wxExtensions.cpp index 43628cb47..7fcad9e65 100644 --- a/xs/src/slic3r/GUI/wxExtensions.cpp +++ b/xs/src/slic3r/GUI/wxExtensions.cpp @@ -771,17 +771,23 @@ PrusaDoubleSlider::PrusaDoubleSlider( wxWindow *parent, SetDoubleBuffered(true); #endif //__WXOSX__ - m_thumb_higher = wxBitmap(style == wxSL_HORIZONTAL ? Slic3r::GUI::from_u8(Slic3r::var("right_half_circle.png")) : - Slic3r::GUI::from_u8(Slic3r::var("up_half_circle.png")), wxBITMAP_TYPE_PNG); - m_thumb_lower = wxBitmap(style == wxSL_HORIZONTAL ? Slic3r::GUI::from_u8(Slic3r::var("left_half_circle.png")) : - Slic3r::GUI::from_u8(Slic3r::var("down_half_circle.png")), wxBITMAP_TYPE_PNG); - m_thumb_size = m_thumb_lower.GetSize(); + m_bmp_thumb_higher = wxBitmap(style == wxSL_HORIZONTAL ? Slic3r::GUI::from_u8(Slic3r::var("right_half_circle.png")) : + Slic3r::GUI::from_u8(Slic3r::var("up_half_circle.png")), wxBITMAP_TYPE_PNG); + m_bmp_thumb_lower = wxBitmap(style == wxSL_HORIZONTAL ? Slic3r::GUI::from_u8(Slic3r::var("left_half_circle.png")) : + Slic3r::GUI::from_u8(Slic3r::var("down_half_circle.png")), wxBITMAP_TYPE_PNG); + m_thumb_size = m_bmp_thumb_lower.GetSize(); - m_add_tick_on = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("colorchange_add_on.png")), wxBITMAP_TYPE_PNG); - m_add_tick_off = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("colorchange_add_off.png")), wxBITMAP_TYPE_PNG); - m_del_tick_on = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("colorchange_delete_on.png")), wxBITMAP_TYPE_PNG); - m_del_tick_off = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("colorchange_delete_off.png")), wxBITMAP_TYPE_PNG); - m_tick_icon_dim = m_add_tick_on.GetSize().x; + m_bmp_add_tick_on = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("colorchange_add_on.png")), wxBITMAP_TYPE_PNG); + m_bmp_add_tick_off = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("colorchange_add_off.png")), wxBITMAP_TYPE_PNG); + m_bmp_del_tick_on = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("colorchange_delete_on.png")), wxBITMAP_TYPE_PNG); + m_bmp_del_tick_off = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("colorchange_delete_off.png")), wxBITMAP_TYPE_PNG); + m_tick_icon_dim = m_bmp_add_tick_on.GetSize().x; + + m_bmp_one_layer_lock_on = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("one_layer_lock_on.png")), wxBITMAP_TYPE_PNG); + m_bmp_one_layer_lock_off = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("one_layer_lock_off.png")), wxBITMAP_TYPE_PNG); + m_bmp_one_layer_unlock_on = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("one_layer_unlock_on.png")), wxBITMAP_TYPE_PNG); + m_bmp_one_layer_unlock_off = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("one_layer_unlock_off.png")), wxBITMAP_TYPE_PNG); + m_lock_icon_dim = m_bmp_one_layer_lock_on.GetSize().x; m_selection = ssUndef; @@ -794,10 +800,12 @@ PrusaDoubleSlider::PrusaDoubleSlider( wxWindow *parent, Bind(wxEVT_ENTER_WINDOW,&PrusaDoubleSlider::OnEnterWin, this); Bind(wxEVT_LEAVE_WINDOW,&PrusaDoubleSlider::OnLeaveWin, this); Bind(wxEVT_KEY_DOWN, &PrusaDoubleSlider::OnKeyDown, this); + Bind(wxEVT_KEY_UP, &PrusaDoubleSlider::OnKeyUp, this); Bind(wxEVT_RIGHT_DOWN, &PrusaDoubleSlider::OnRightDown,this); + Bind(wxEVT_RIGHT_UP, &PrusaDoubleSlider::OnRightUp, this); // control's view variables - SLIDER_MARGIN = 4 + (style == wxSL_HORIZONTAL ? m_thumb_higher.GetWidth() : m_thumb_higher.GetHeight()); + SLIDER_MARGIN = 4 + (style == wxSL_HORIZONTAL ? m_bmp_thumb_higher.GetWidth() : m_bmp_thumb_higher.GetHeight()); DARK_ORANGE_PEN = wxPen(wxColour(253, 84, 2)); ORANGE_PEN = wxPen(wxColour(253, 126, 66)); @@ -841,7 +849,7 @@ void PrusaDoubleSlider::SetHigherValue(const int higher_val) Update(); } -void PrusaDoubleSlider::SetMaxValue(int max_value) +void PrusaDoubleSlider::SetMaxValue(const int max_value) { m_max_value = max_value; Refresh(); @@ -852,7 +860,7 @@ void PrusaDoubleSlider::draw_scroll_line(wxDC& dc, const int lower_pos, const in { int width; int height; - GetSize(&width, &height); + get_size(&width, &height); wxCoord line_beg_x = is_horizontal() ? SLIDER_MARGIN : width*0.5 - 1; wxCoord line_beg_y = is_horizontal() ? height*0.5 - 1 : SLIDER_MARGIN; @@ -879,7 +887,7 @@ void PrusaDoubleSlider::draw_scroll_line(wxDC& dc, const int lower_pos, const in double PrusaDoubleSlider::get_scroll_step() { - const wxSize sz = GetSize(); + const wxSize sz = get_size(); const int& slider_len = m_style == wxSL_HORIZONTAL ? sz.x : sz.y; return double(slider_len - SLIDER_MARGIN * 2) / (m_max_value - m_min_value); } @@ -892,6 +900,19 @@ wxCoord PrusaDoubleSlider::get_position_from_value(const int value) return wxCoord(SLIDER_MARGIN + int(val*step + 0.5)); } +wxSize PrusaDoubleSlider::get_size() +{ + int w, h; + get_size(&w, &h); + return wxSize(w, h); +} + +void PrusaDoubleSlider::get_size(int *w, int *h) +{ + GetSize(w, h); + is_horizontal() ? *w -= m_lock_icon_dim : *h -= m_lock_icon_dim; +} + void PrusaDoubleSlider::get_lower_and_higher_position(int& lower_pos, int& higher_pos) { const double step = get_scroll_step(); @@ -914,7 +935,7 @@ void PrusaDoubleSlider::draw_focus_rect() const wxPen pen = wxPen(wxColour(128, 128, 10), 1, wxPENSTYLE_DOT); dc.SetPen(pen); dc.SetBrush(wxBrush(wxColour(0, 0, 0), wxBRUSHSTYLE_TRANSPARENT)); - dc.DrawRectangle(2, 2, sz.x - 4, sz.y - 4); + dc.DrawRectangle(1, 1, sz.x - 2, sz.y - 2); } void PrusaDoubleSlider::render() @@ -933,22 +954,27 @@ void PrusaDoubleSlider::render() // draw line draw_scroll_line(dc, lower_pos, higher_pos); - //lower slider: - draw_thumb(dc, lower_pos, ssLower); +// //lower slider: +// draw_thumb(dc, lower_pos, ssLower); +// //higher slider: +// draw_thumb(dc, higher_pos, ssHigher); - //higher slider: - draw_thumb(dc, higher_pos, ssHigher); + // draw both sliders + draw_thumbs(dc, lower_pos, higher_pos); //draw color print ticks draw_ticks(dc); + + //draw color print ticks + draw_one_layer_icon(dc); } void PrusaDoubleSlider::draw_action_icon(wxDC& dc, const wxPoint pt_beg, const wxPoint pt_end) { const int tick = m_selection == ssLower ? m_lower_value : m_higher_value; - wxBitmap* icon = m_is_action_icon_focesed ? &m_add_tick_off :&m_add_tick_on; + wxBitmap* icon = m_is_action_icon_focesed ? &m_bmp_add_tick_off : &m_bmp_add_tick_on; if (m_ticks.find(tick) != m_ticks.end()) - icon = m_is_action_icon_focesed ? &m_del_tick_off :&m_del_tick_on; + icon = m_is_action_icon_focesed ? &m_bmp_del_tick_off : &m_bmp_del_tick_on; wxCoord x_draw, y_draw; is_horizontal() ? x_draw = pt_beg.x - 0.5*m_tick_icon_dim : y_draw = pt_beg.y - 0.5*m_tick_icon_dim; @@ -992,7 +1018,8 @@ wxString PrusaDoubleSlider::get_label(const SelectedSlider& selection) const void PrusaDoubleSlider::draw_thumb_text(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection) const { - if (selection == ssUndef) return; + if (m_is_one_layer && selection != m_selection || !selection) + return; wxCoord text_width, text_height; const wxString label = get_label(selection); dc.GetMultiLineTextExtent(label, &text_width, &text_height); @@ -1029,7 +1056,7 @@ void PrusaDoubleSlider::draw_thumb_item(wxDC& dc, const wxPoint& pos, const Sele y_draw = pos.y - m_thumb_size.y; } } - dc.DrawBitmap(selection == ssLower ? m_thumb_lower : m_thumb_higher, x_draw, y_draw); + dc.DrawBitmap(selection == ssLower ? m_bmp_thumb_lower : m_bmp_thumb_higher, x_draw, y_draw); // Update thumb rect update_thumb_rect(x_draw, y_draw, selection); @@ -1039,7 +1066,7 @@ void PrusaDoubleSlider::draw_thumb(wxDC& dc, const wxCoord& pos_coord, const Sel { //calculate thumb position on slider line int width, height; - GetSize(&width, &height); + get_size(&width, &height); const wxPoint pos = is_horizontal() ? wxPoint(pos_coord, height*0.5) : wxPoint(0.5*width, pos_coord); // Draw thumb @@ -1052,11 +1079,35 @@ void PrusaDoubleSlider::draw_thumb(wxDC& dc, const wxCoord& pos_coord, const Sel draw_thumb_text(dc, pos, selection); } +void PrusaDoubleSlider::draw_thumbs(wxDC& dc, const wxCoord& lower_pos, const wxCoord& higher_pos) +{ + //calculate thumb position on slider line + int width, height; + get_size(&width, &height); + const wxPoint pos_l = is_horizontal() ? wxPoint(lower_pos, height*0.5) : wxPoint(0.5*width, lower_pos); + const wxPoint pos_h = is_horizontal() ? wxPoint(higher_pos, height*0.5) : wxPoint(0.5*width, higher_pos); + + // Draw lower thumb + draw_thumb_item(dc, pos_l, ssLower); + // Draw lower info_line + draw_info_line_with_icon(dc, pos_l, ssLower); + + // Draw higher thumb + draw_thumb_item(dc, pos_h, ssHigher); + // Draw higher info_line + draw_info_line_with_icon(dc, pos_h, ssHigher); + // Draw higher thumb text + draw_thumb_text(dc, pos_h, ssHigher); + + // Draw lower thumb text + draw_thumb_text(dc, pos_l, ssLower); +} + void PrusaDoubleSlider::draw_ticks(wxDC& dc) { dc.SetPen(DARK_GREY_PEN); int height, width; - GetSize(&width, &height); + get_size(&width, &height); const wxCoord mid = is_horizontal() ? 0.5*height : 0.5*width; for (auto tick : m_ticks) { @@ -1069,6 +1120,25 @@ void PrusaDoubleSlider::draw_ticks(wxDC& dc) } } +void PrusaDoubleSlider::draw_one_layer_icon(wxDC& dc) +{ + wxBitmap* icon = m_is_one_layer ? + m_is_one_layer_icon_focesed ? &m_bmp_one_layer_lock_off : &m_bmp_one_layer_lock_on : + m_is_one_layer_icon_focesed ? &m_bmp_one_layer_unlock_off : &m_bmp_one_layer_unlock_on; + + int width, height; + get_size(&width, &height); + + wxCoord x_draw, y_draw; + is_horizontal() ? x_draw = width-2 : x_draw = 0.5*width - 0.5*m_lock_icon_dim; + is_horizontal() ? y_draw = 0.5*height - 0.5*m_lock_icon_dim : y_draw = height-2; + + dc.DrawBitmap(*icon, x_draw, y_draw); + + //update rect of the lock/unlock icon + m_rect_one_layer_icon = wxRect(x_draw, y_draw, m_lock_icon_dim, m_lock_icon_dim); +} + void PrusaDoubleSlider::update_thumb_rect(const wxCoord& begin_x, const wxCoord& begin_y, const SelectedSlider& selection) { const wxRect& rect = wxRect(begin_x, begin_y, m_thumb_size.x, m_thumb_size.y); @@ -1078,10 +1148,9 @@ void PrusaDoubleSlider::update_thumb_rect(const wxCoord& begin_x, const wxCoord& m_rect_higher_thumb = rect; } -int PrusaDoubleSlider::position_to_value(wxDC& dc, const wxCoord x, const wxCoord y) +int PrusaDoubleSlider::get_value_from_position(const wxCoord x, const wxCoord y) { - int width, height; - dc.GetSize(&width, &height); + const int height = get_size().y; const double step = get_scroll_step(); if (is_horizontal()) @@ -1119,15 +1188,23 @@ bool PrusaDoubleSlider::is_point_in_rect(const wxPoint& pt, const wxRect& rect) void PrusaDoubleSlider::OnLeftDown(wxMouseEvent& event) { + this->CaptureMouse(); wxClientDC dc(this); wxPoint pos = event.GetLogicalPosition(dc); if (is_point_in_rect(pos, m_rect_tick_action)) { - OnRightDown(event); + action_tick(taOnIcon); return; } m_is_left_down = true; - detect_selected_slider(pos); + if (is_point_in_rect(pos, m_rect_one_layer_icon)){ + m_is_one_layer = !m_is_one_layer; + m_selection == ssLower ? correct_lower_value() : correct_higher_value(); + if (!m_selection) m_selection = ssHigher; + } + else + detect_selected_slider(pos); + Refresh(); Update(); event.Skip(); @@ -1137,38 +1214,39 @@ void PrusaDoubleSlider::correct_lower_value() { if (m_lower_value < m_min_value) m_lower_value = m_min_value; - else if (m_lower_value >= m_higher_value && m_lower_value <= m_max_value) - m_higher_value = m_lower_value; else if (m_lower_value > m_max_value) m_lower_value = m_max_value; + + if (m_lower_value >= m_higher_value && m_lower_value <= m_max_value || m_is_one_layer) + m_higher_value = m_lower_value; } void PrusaDoubleSlider::correct_higher_value() { if (m_higher_value > m_max_value) m_higher_value = m_max_value; - else if (m_higher_value <= m_lower_value && m_higher_value >= m_min_value) - m_lower_value = m_higher_value; else if (m_higher_value < m_min_value) m_higher_value = m_min_value; + + if (m_higher_value <= m_lower_value && m_higher_value >= m_min_value || m_is_one_layer) + m_lower_value = m_higher_value; } void PrusaDoubleSlider::OnMotion(wxMouseEvent& event) { - if (m_selection == ssUndef) - return; - wxClientDC dc(this); - wxPoint pos = event.GetLogicalPosition(dc); - if (!m_is_left_down){ + const wxClientDC dc(this); + const wxPoint pos = event.GetLogicalPosition(dc); + m_is_one_layer_icon_focesed = is_point_in_rect(pos, m_rect_one_layer_icon); + if (!m_is_left_down && !m_is_one_layer){ m_is_action_icon_focesed = is_point_in_rect(pos, m_rect_tick_action); } - else { + else if (m_is_left_down || m_is_right_down){ if (m_selection == ssLower) { - m_lower_value = position_to_value(dc, pos.x, pos.y); + m_lower_value = get_value_from_position(pos.x, pos.y); correct_lower_value(); } else if (m_selection == ssHigher) { - m_higher_value = position_to_value(dc, pos.x, pos.y); + m_higher_value = get_value_from_position(pos.x, pos.y); correct_higher_value(); } } @@ -1179,6 +1257,7 @@ void PrusaDoubleSlider::OnMotion(wxMouseEvent& event) void PrusaDoubleSlider::OnLeftUp(wxMouseEvent& event) { + this->ReleaseMouse(); m_is_left_down = false; Refresh(); Update(); @@ -1189,25 +1268,20 @@ void PrusaDoubleSlider::OnLeftUp(wxMouseEvent& event) ProcessWindowEvent(e); } -void PrusaDoubleSlider::OnEnterWin(wxMouseEvent& event) +void PrusaDoubleSlider::enter_window(wxMouseEvent& event, const bool enter) { - m_is_focused = true; + m_is_focused = enter; Refresh(); Update(); event.Skip(); } -void PrusaDoubleSlider::OnLeaveWin(wxMouseEvent& event) -{ - m_is_focused = false; - OnLeftUp(event); -} - // "condition" have to be true for: // - value increase (if wxSL_VERTICAL) // - value decrease (if wxSL_HORIZONTAL) void PrusaDoubleSlider::move_current_thumb(const bool condition) { + m_is_one_layer = wxGetKeyState(WXK_CONTROL); int delta = condition ? -1 : 1; if (is_horizontal()) delta *= -1; @@ -1235,13 +1309,17 @@ void PrusaDoubleSlider::action_tick(const TicksAction action) const int tick = m_selection == ssLower ? m_lower_value : m_higher_value; - const auto it = m_ticks.find(tick); - if (it == m_ticks.end() && action == taAdd) - m_ticks.insert(tick); - else if (it != m_ticks.end() && action == taDel) + if (action == taOnIcon && !m_ticks.insert(tick).second) m_ticks.erase(tick); - else - return; + else { + const auto it = m_ticks.find(tick); + if (it == m_ticks.end() && action == taAdd) + m_ticks.insert(tick); + else if (it != m_ticks.end() && action == taDel) + m_ticks.erase(tick); + else + return; + } Refresh(); Update(); @@ -1285,17 +1363,43 @@ void PrusaDoubleSlider::OnKeyDown(wxKeyEvent &event) } } -void PrusaDoubleSlider::OnRightDown(wxMouseEvent& event) +void PrusaDoubleSlider::OnKeyUp(wxKeyEvent &event) { - if (m_selection == ssUndef) - return; - - const int new_tick = m_selection == ssLower ? m_lower_value : m_higher_value; - - if (!m_ticks.insert(new_tick).second) - m_ticks.erase(new_tick); + if (event.GetKeyCode() == WXK_CONTROL) + m_is_one_layer = false; Refresh(); Update(); + event.Skip(); +} + +void PrusaDoubleSlider::OnRightDown(wxMouseEvent& event) +{ + this->CaptureMouse(); + const wxClientDC dc(this); + detect_selected_slider(event.GetLogicalPosition(dc)); + if (!m_selection) + return; + + if (m_selection == ssLower) + m_higher_value = m_lower_value; + else + m_lower_value = m_higher_value; + + m_is_right_down = m_is_one_layer = true; + + Refresh(); + Update(); + event.Skip(); +} + +void PrusaDoubleSlider::OnRightUp(wxMouseEvent& event) +{ + this->ReleaseMouse(); + m_is_right_down = m_is_one_layer = false; + + Refresh(); + Update(); + event.Skip(); } // ***************************************************************************** diff --git a/xs/src/slic3r/GUI/wxExtensions.hpp b/xs/src/slic3r/GUI/wxExtensions.hpp index 1887db2b3..064ce1038 100644 --- a/xs/src/slic3r/GUI/wxExtensions.hpp +++ b/xs/src/slic3r/GUI/wxExtensions.hpp @@ -502,6 +502,7 @@ enum SelectedSlider { ssHigher }; enum TicksAction{ + taOnIcon, taAdd, taDel }; @@ -529,9 +530,9 @@ public: } int GetActiveValue() const; wxSize DoGetBestSize() const override; - void SetLowerValue(int lower_val); - void SetHigherValue(int higher_val); - void SetMaxValue(int max_value); + void SetLowerValue(const int lower_val); + void SetHigherValue(const int higher_val); + void SetMaxValue(const int max_value); void SetKoefForLabels(const double koef) { m_label_koef = koef; } @@ -543,11 +544,13 @@ public: void OnLeftDown(wxMouseEvent& event); void OnMotion(wxMouseEvent& event); void OnLeftUp(wxMouseEvent& event); - void OnEnterWin(wxMouseEvent& event); - void OnLeaveWin(wxMouseEvent& event); + void OnEnterWin(wxMouseEvent& event){ enter_window(event, true); } + void OnLeaveWin(wxMouseEvent& event){ enter_window(event, false); } void OnWheel(wxMouseEvent& event); void OnKeyDown(wxKeyEvent &event); + void OnKeyUp(wxKeyEvent &event); void OnRightDown(wxMouseEvent& event); + void OnRightUp(wxMouseEvent& event); protected: @@ -556,7 +559,9 @@ protected: void draw_action_icon(wxDC& dc, const wxPoint pt_beg, const wxPoint pt_end); void draw_scroll_line(wxDC& dc, const int lower_pos, const int higher_pos); void draw_thumb(wxDC& dc, const wxCoord& pos_coord, const SelectedSlider& selection); + void draw_thumbs(wxDC& dc, const wxCoord& lower_pos, const wxCoord& higher_pos); void draw_ticks(wxDC& dc); + void draw_one_layer_icon(wxDC& dc); void draw_thumb_item(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection); void draw_info_line_with_icon(wxDC& dc, const wxPoint& pos, SelectedSlider selection); void draw_thumb_text(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection) const; @@ -567,6 +572,7 @@ protected: void correct_higher_value(); void move_current_thumb(const bool condition); void action_tick(const TicksAction action); + void enter_window(wxMouseEvent& event, const bool enter); bool is_point_in_rect(const wxPoint& pt, const wxRect& rect); bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; } @@ -574,30 +580,41 @@ protected: double get_scroll_step(); wxString get_label(const SelectedSlider& selection) const; void get_lower_and_higher_position(int& lower_pos, int& higher_pos); - int position_to_value(wxDC& dc, const wxCoord x, const wxCoord y); + int get_value_from_position(const wxCoord x, const wxCoord y); wxCoord get_position_from_value(const int value); + wxSize get_size(); + void get_size(int *w, int *h); private: int m_min_value; int m_max_value; int m_lower_value; int m_higher_value; - wxBitmap m_thumb_higher; - wxBitmap m_thumb_lower; - wxBitmap m_add_tick_on; - wxBitmap m_add_tick_off; - wxBitmap m_del_tick_on; - wxBitmap m_del_tick_off; + wxBitmap m_bmp_thumb_higher; + wxBitmap m_bmp_thumb_lower; + wxBitmap m_bmp_add_tick_on; + wxBitmap m_bmp_add_tick_off; + wxBitmap m_bmp_del_tick_on; + wxBitmap m_bmp_del_tick_off; + wxBitmap m_bmp_one_layer_lock_on; + wxBitmap m_bmp_one_layer_lock_off; + wxBitmap m_bmp_one_layer_unlock_on; + wxBitmap m_bmp_one_layer_unlock_off; SelectedSlider m_selection; bool m_is_left_down = false; + bool m_is_right_down = false; + bool m_is_one_layer = false; bool m_is_focused = false; bool m_is_action_icon_focesed = false; + bool m_is_one_layer_icon_focesed = false; wxRect m_rect_lower_thumb; wxRect m_rect_higher_thumb; wxRect m_rect_tick_action; + wxRect m_rect_one_layer_icon; wxSize m_thumb_size; int m_tick_icon_dim; + int m_lock_icon_dim = 16; long m_style; float m_label_koef = 1.0;