Added SetSliderValues and GetActiveValue functions

This commit is contained in:
YuSanka 2018-08-23 14:37:17 +02:00
parent 2a7059edb3
commit 2ec045a0fb
3 changed files with 31 additions and 6 deletions

View File

@ -1674,6 +1674,7 @@ sub print_info_box_show {
$sizer->Show(1, $show);
$self->Layout;
Wx::GetTopLevelParent($self)->Refresh; # temporary workaround for DoubleSlider on right panel
$panel->Refresh;
}

View File

@ -811,6 +811,13 @@ PrusaDoubleSlider::PrusaDoubleSlider( wxWindow *parent,
segm_pens = { &DARK_ORANGE_PEN, &ORANGE_PEN, &LIGHT_ORANGE_PEN };
}
int PrusaDoubleSlider::GetActiveValue() const
{
return m_selection == ssLower ?
m_lower_value : m_selection == ssHigher ?
m_higher_value : -1;
}
wxSize PrusaDoubleSlider::DoGetBestSize() const
{
const wxSize size = wxControl::DoGetBestSize();
@ -834,6 +841,13 @@ void PrusaDoubleSlider::SetHigherValue(const int higher_val)
Update();
}
void PrusaDoubleSlider::SetMaxValue(int max_value)
{
m_max_value = max_value;
Refresh();
Update();
}
void PrusaDoubleSlider::draw_scroll_line(wxDC& dc, const int lower_pos, const int higher_pos)
{
int width;
@ -967,10 +981,12 @@ wxString PrusaDoubleSlider::get_label(const SelectedSlider& selection) const
{
const int value = selection == ssLower ? m_lower_value : m_higher_value;
if (m_label_koef == 1.0)
if (m_label_koef == 1.0 && m_values.empty())
return wxString::Format("%d", value);
const wxString str = wxNumberFormatter::ToString(m_label_koef*value, 2, wxNumberFormatter::Style_None);
const wxString str = m_values.empty() ?
wxNumberFormatter::ToString(m_label_koef*value, 2, wxNumberFormatter::Style_None) :
wxNumberFormatter::ToString(m_values[value], 2, wxNumberFormatter::Style_None);
return wxString::Format("%s\n(%d)", str, value);
}

View File

@ -521,16 +521,23 @@ public:
const wxValidator& val = wxDefaultValidator,
const wxString& name = wxEmptyString);
int GetLowerValue() {
int GetLowerValue() const {
return m_lower_value;
}
int GetHigherValue() {
int GetHigherValue() const {
return m_higher_value;
}
int GetActiveValue() const;
wxSize DoGetBestSize() const override;
void SetLowerValue(int lower_val);
void SetHigherValue(int higher_val);
void SetKoefForLabels(const double koef){ m_label_koef = koef;}
void SetMaxValue(int max_value);
void SetKoefForLabels(const double koef) {
m_label_koef = koef;
}
void SetSliderValues(const std::vector<double>& values) {
m_values = values;
}
void OnPaint(wxPaintEvent& ){ render();}
void OnLeftDown(wxMouseEvent& event);
@ -545,8 +552,8 @@ public:
protected:
void render();
void draw_action_icon(wxDC& dc, const wxPoint pt_beg, const wxPoint pt_end);
void draw_focus_rect();
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_ticks(wxDC& dc);
@ -608,6 +615,7 @@ private:
std::vector<wxPen*> line_pens;
std::vector<wxPen*> segm_pens;
std::set<int> m_ticks;
std::vector<double> m_values;
};
// ******************************************************************************************