mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-04 10:35:13 +08:00
Added functions for tick adding/deleting
This commit is contained in:
parent
d2282c4bf9
commit
8a9bdc55ee
@ -787,6 +787,7 @@ PrusaDoubleSlider::PrusaDoubleSlider( wxWindow *parent,
|
|||||||
Bind(wxEVT_ENTER_WINDOW,&PrusaDoubleSlider::OnEnterWin, this);
|
Bind(wxEVT_ENTER_WINDOW,&PrusaDoubleSlider::OnEnterWin, this);
|
||||||
Bind(wxEVT_LEAVE_WINDOW,&PrusaDoubleSlider::OnLeaveWin, this);
|
Bind(wxEVT_LEAVE_WINDOW,&PrusaDoubleSlider::OnLeaveWin, this);
|
||||||
Bind(wxEVT_KEY_DOWN, &PrusaDoubleSlider::OnKeyDown, this);
|
Bind(wxEVT_KEY_DOWN, &PrusaDoubleSlider::OnKeyDown, this);
|
||||||
|
Bind(wxEVT_RIGHT_DOWN, &PrusaDoubleSlider::OnRightDown,this);
|
||||||
|
|
||||||
// control's view variables
|
// control's view variables
|
||||||
SLIDER_MARGIN = 2 + (style == wxSL_HORIZONTAL ? m_thumb_higher.GetWidth() : m_thumb_higher.GetHeight());
|
SLIDER_MARGIN = 2 + (style == wxSL_HORIZONTAL ? m_thumb_higher.GetWidth() : m_thumb_higher.GetHeight());
|
||||||
@ -862,6 +863,14 @@ double PrusaDoubleSlider::get_scroll_step()
|
|||||||
return double(slider_len - SLIDER_MARGIN * 2) / (m_max_value - m_min_value);
|
return double(slider_len - SLIDER_MARGIN * 2) / (m_max_value - m_min_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get position on the slider line from entered value
|
||||||
|
wxCoord PrusaDoubleSlider::get_position_from_value(const int value)
|
||||||
|
{
|
||||||
|
const double step = get_scroll_step();
|
||||||
|
const int val = is_horizontal() ? value : m_max_value - value;
|
||||||
|
return wxCoord(SLIDER_MARGIN + int(val*step + 0.5));
|
||||||
|
}
|
||||||
|
|
||||||
void PrusaDoubleSlider::get_lower_and_higher_position(int& lower_pos, int& higher_pos)
|
void PrusaDoubleSlider::get_lower_and_higher_position(int& lower_pos, int& higher_pos)
|
||||||
{
|
{
|
||||||
const double step = get_scroll_step();
|
const double step = get_scroll_step();
|
||||||
@ -896,8 +905,8 @@ void PrusaDoubleSlider::render()
|
|||||||
int width, height;
|
int width, height;
|
||||||
GetSize(&width, &height);
|
GetSize(&width, &height);
|
||||||
|
|
||||||
int lower_pos, higher_pos;
|
const wxCoord lower_pos = get_position_from_value(m_lower_value);
|
||||||
get_lower_and_higher_position(lower_pos, higher_pos);
|
const wxCoord higher_pos = get_position_from_value(m_higher_value);
|
||||||
|
|
||||||
// draw line
|
// draw line
|
||||||
draw_scroll_line(dc, lower_pos, higher_pos);
|
draw_scroll_line(dc, lower_pos, higher_pos);
|
||||||
@ -907,6 +916,9 @@ void PrusaDoubleSlider::render()
|
|||||||
|
|
||||||
//higher slider:
|
//higher slider:
|
||||||
draw_thumb(dc, higher_pos, ssHigher);
|
draw_thumb(dc, higher_pos, ssHigher);
|
||||||
|
|
||||||
|
//draw color print ticks
|
||||||
|
draw_ticks(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrusaDoubleSlider::draw_info_line(wxDC& dc, const wxPoint& pos, const SelectedSlider selection) const
|
void PrusaDoubleSlider::draw_info_line(wxDC& dc, const wxPoint& pos, const SelectedSlider selection) const
|
||||||
@ -988,6 +1000,23 @@ void PrusaDoubleSlider::draw_thumb(wxDC& dc, const wxCoord& pos_coord, const Sel
|
|||||||
draw_thumb_text(dc, pos, selection);
|
draw_thumb_text(dc, pos, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrusaDoubleSlider::draw_ticks(wxDC& dc)
|
||||||
|
{
|
||||||
|
dc.SetPen(DARK_GREY_PEN);
|
||||||
|
int height, width;
|
||||||
|
GetSize(&width, &height);
|
||||||
|
const wxCoord mid = is_horizontal() ? 0.5*height : 0.5*width;
|
||||||
|
for (auto tick : m_ticks)
|
||||||
|
{
|
||||||
|
const wxCoord pos = get_position_from_value(tick);
|
||||||
|
|
||||||
|
is_horizontal() ? dc.DrawLine(pos, mid-14, pos, mid-9) :
|
||||||
|
dc.DrawLine(mid - 14, pos - 1, mid - 9, pos - 1);
|
||||||
|
is_horizontal() ? dc.DrawLine(pos, mid+14, pos, mid+9) :
|
||||||
|
dc.DrawLine(mid + 14, pos - 1, mid + 9, pos - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PrusaDoubleSlider::update_thumb_rect(const wxCoord& begin_x, const wxCoord& begin_y, const SelectedSlider& selection)
|
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);
|
const wxRect& rect = wxRect(begin_x, begin_y, m_thumb_size.x, m_thumb_size.y);
|
||||||
@ -1174,4 +1203,17 @@ void PrusaDoubleSlider::OnKeyDown(wxKeyEvent &event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrusaDoubleSlider::OnRightDown(wxMouseEvent& event)
|
||||||
|
{
|
||||||
|
if (m_selection == ssUndef)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int new_tick = m_selection == ssLower ? m_lower_value : m_higher_value;
|
||||||
|
|
||||||
|
if (!m_ticks.insert(new_tick).second)
|
||||||
|
m_ticks.erase(new_tick);
|
||||||
|
Refresh();
|
||||||
|
Update();
|
||||||
|
}
|
||||||
|
|
||||||
// *****************************************************************************
|
// *****************************************************************************
|
||||||
|
@ -536,6 +536,7 @@ public:
|
|||||||
void OnLeaveWin(wxMouseEvent& event);
|
void OnLeaveWin(wxMouseEvent& event);
|
||||||
void OnWheel(wxMouseEvent& event);
|
void OnWheel(wxMouseEvent& event);
|
||||||
void OnKeyDown(wxKeyEvent &event);
|
void OnKeyDown(wxKeyEvent &event);
|
||||||
|
void OnRightDown(wxMouseEvent& event);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -543,6 +544,7 @@ protected:
|
|||||||
void draw_focus_rect();
|
void draw_focus_rect();
|
||||||
void draw_scroll_line(wxDC& dc, const int lower_pos, const int higher_pos);
|
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_thumb(wxDC& dc, const wxCoord& pos_coord, const SelectedSlider& selection);
|
||||||
|
void draw_ticks(wxDC& dc);
|
||||||
void draw_thumb_item(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection);
|
void draw_thumb_item(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection);
|
||||||
void draw_info_line(wxDC& dc, const wxPoint& pos, SelectedSlider selection) const;
|
void draw_info_line(wxDC& dc, const wxPoint& pos, SelectedSlider selection) const;
|
||||||
void draw_thumb_text(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection) const;
|
void draw_thumb_text(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection) const;
|
||||||
@ -560,6 +562,7 @@ protected:
|
|||||||
wxString get_label(const SelectedSlider& selection) const;
|
wxString get_label(const SelectedSlider& selection) const;
|
||||||
void get_lower_and_higher_position(int& lower_pos, int& higher_pos);
|
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 position_to_value(wxDC& dc, const wxCoord x, const wxCoord y);
|
||||||
|
wxCoord get_position_from_value(const int value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_min_value;
|
int m_min_value;
|
||||||
@ -591,6 +594,7 @@ private:
|
|||||||
|
|
||||||
std::vector<wxPen*> line_pens;
|
std::vector<wxPen*> line_pens;
|
||||||
std::vector<wxPen*> segm_pens;
|
std::vector<wxPen*> segm_pens;
|
||||||
|
std::set<int> m_ticks;
|
||||||
};
|
};
|
||||||
// ******************************************************************************************
|
// ******************************************************************************************
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user