DoubleSlider: Fixed ruler for the short objects
This commit is contained in:
parent
250bd689f2
commit
10c41290fd
1 changed files with 73 additions and 62 deletions
|
@ -569,7 +569,7 @@ void Control::draw_tick_on_mouse_position(wxDC& dc)
|
||||||
|
|
||||||
if (m_extra_style & wxSL_VALUE_LABEL) {
|
if (m_extra_style & wxSL_VALUE_LABEL) {
|
||||||
wxColour old_clr = dc.GetTextForeground();
|
wxColour old_clr = dc.GetTextForeground();
|
||||||
dc.SetTextForeground(LIGHT_GREY_PEN.GetColour());
|
dc.SetTextForeground(GREY_PEN.GetColour());
|
||||||
draw_tick_text(dc, pos, tick, ltEstimatedTime, false);
|
draw_tick_text(dc, pos, tick, ltEstimatedTime, false);
|
||||||
dc.SetTextForeground(old_clr);
|
dc.SetTextForeground(old_clr);
|
||||||
}
|
}
|
||||||
|
@ -893,6 +893,11 @@ void Control::Ruler::update(wxWindow* win, const std::vector<double>& values, do
|
||||||
int DPI = GUI::get_dpi_for_window(win);
|
int DPI = GUI::get_dpi_for_window(win);
|
||||||
int pixels_per_sm = lround((double)(DPI) * 5.0/25.4);
|
int pixels_per_sm = lround((double)(DPI) * 5.0/25.4);
|
||||||
|
|
||||||
|
if (lround(scroll_step) > pixels_per_sm) {
|
||||||
|
long_step = -1.0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int pow = -2;
|
int pow = -2;
|
||||||
int step = 0;
|
int step = 0;
|
||||||
auto end_it = count == 1 ? values.end() : values.begin() + lround(values.size() / count);
|
auto end_it = count == 1 ? values.end() : values.begin() + lround(values.size() / count);
|
||||||
|
@ -907,15 +912,15 @@ void Control::Ruler::update(wxWindow* win, const std::vector<double>& values, do
|
||||||
break;
|
break;
|
||||||
int tick = val_it - values.begin();
|
int tick = val_it - values.begin();
|
||||||
|
|
||||||
if (lround(tick * scroll_step) > pixels_per_sm) {
|
// find next tick with istep
|
||||||
step = istep;
|
val *= 2;
|
||||||
|
val_it = std::lower_bound(values.begin(), end_it, val - epsilon());
|
||||||
|
// count of short ticks between ticks
|
||||||
|
int short_ticks_cnt = val_it == values.end() ? tick : val_it - values.begin() - tick;
|
||||||
|
|
||||||
// find next tick with istep
|
if (lround(short_ticks_cnt * scroll_step) > pixels_per_sm) {
|
||||||
val *= 2;
|
step = istep;
|
||||||
val_it = std::lower_bound(values.begin(), end_it, val - epsilon());
|
// there couldn't be more then 10 short ticks between ticks
|
||||||
// count of short ticks between ticks
|
|
||||||
int short_ticks_cnt = val_it == values.end() ? tick : val_it - values.begin() - tick;
|
|
||||||
// there couldn't be more then 10 short ticks between thicks
|
|
||||||
short_step = 0.1 * short_ticks_cnt;
|
short_step = 0.1 * short_ticks_cnt;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -931,71 +936,77 @@ void Control::Ruler::update(wxWindow* win, const std::vector<double>& values, do
|
||||||
void Control::draw_ruler(wxDC& dc)
|
void Control::draw_ruler(wxDC& dc)
|
||||||
{
|
{
|
||||||
m_ruler.update(this->GetParent(), m_values, get_scroll_step());
|
m_ruler.update(this->GetParent(), m_values, get_scroll_step());
|
||||||
if (!m_ruler.is_ok())
|
|
||||||
return;
|
|
||||||
|
|
||||||
int height, width;
|
int height, width;
|
||||||
get_size(&width, &height);
|
get_size(&width, &height);
|
||||||
const wxCoord mid = is_horizontal() ? 0.5 * height : 0.5 * width;
|
const wxCoord mid = is_horizontal() ? 0.5 * height : 0.5 * width;
|
||||||
|
|
||||||
auto draw_short_ticks = [this, mid](wxDC& dc, double& current_tick, int max_tick) {
|
dc.SetPen(GREY_PEN);
|
||||||
while (current_tick < max_tick) {
|
|
||||||
wxCoord pos = get_position_from_value(lround(current_tick));
|
|
||||||
draw_ticks_pair(dc, pos, mid, 2);
|
|
||||||
current_tick += m_ruler.short_step;
|
|
||||||
if (current_tick > m_max_value)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
dc.SetPen(LIGHT_GREY_PEN);
|
|
||||||
wxColour old_clr = dc.GetTextForeground();
|
wxColour old_clr = dc.GetTextForeground();
|
||||||
dc.SetTextForeground(LIGHT_GREY_PEN.GetColour());
|
dc.SetTextForeground(GREY_PEN.GetColour());
|
||||||
|
|
||||||
double short_tick;
|
if (m_ruler.long_step < 0)
|
||||||
int tick = 0;
|
for (int tick = 1; tick < m_values.size(); tick++) {
|
||||||
double value = 0.0;
|
wxCoord pos = get_position_from_value(tick);
|
||||||
int sequence = 0;
|
draw_ticks_pair(dc, pos, mid, 5);
|
||||||
|
draw_tick_text(dc, wxPoint(mid, pos), tick);
|
||||||
while (tick <= m_max_value) {
|
|
||||||
value += m_ruler.long_step;
|
|
||||||
if (value > m_values.back() && sequence < m_ruler.count) {
|
|
||||||
value = m_ruler.long_step;
|
|
||||||
for (tick; tick < m_values.size(); tick++)
|
|
||||||
if (m_values[tick] < value)
|
|
||||||
break;
|
|
||||||
// short ticks from the last tick to the end of current sequence
|
|
||||||
draw_short_ticks(dc, short_tick, tick);
|
|
||||||
sequence++;
|
|
||||||
}
|
}
|
||||||
short_tick = tick;
|
else {
|
||||||
|
auto draw_short_ticks = [this, mid](wxDC& dc, double& current_tick, int max_tick) {
|
||||||
|
while (current_tick < max_tick) {
|
||||||
|
wxCoord pos = get_position_from_value(lround(current_tick));
|
||||||
|
draw_ticks_pair(dc, pos, mid, 2);
|
||||||
|
current_tick += m_ruler.short_step;
|
||||||
|
if (current_tick > m_max_value)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
for (tick; tick < m_values.size(); tick++) {
|
double short_tick;
|
||||||
if (m_values[tick] == value)
|
int tick = 0;
|
||||||
break;
|
double value = 0.0;
|
||||||
if (m_values[tick] > value) {
|
int sequence = 0;
|
||||||
if (tick > 0)
|
|
||||||
tick--;
|
while (tick <= m_max_value) {
|
||||||
|
value += m_ruler.long_step;
|
||||||
|
if (value > m_values.back() && sequence < m_ruler.count) {
|
||||||
|
value = m_ruler.long_step;
|
||||||
|
for (tick; tick < m_values.size(); tick++)
|
||||||
|
if (m_values[tick] < value)
|
||||||
|
break;
|
||||||
|
// short ticks from the last tick to the end of current sequence
|
||||||
|
draw_short_ticks(dc, short_tick, tick);
|
||||||
|
sequence++;
|
||||||
|
}
|
||||||
|
short_tick = tick;
|
||||||
|
|
||||||
|
for (tick; tick < m_values.size(); tick++) {
|
||||||
|
if (m_values[tick] == value)
|
||||||
|
break;
|
||||||
|
if (m_values[tick] > value) {
|
||||||
|
if (tick > 0)
|
||||||
|
tick--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tick > m_max_value)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
wxCoord pos = get_position_from_value(tick);
|
||||||
|
draw_ticks_pair(dc, pos, mid, 5);
|
||||||
|
draw_tick_text(dc, wxPoint(mid, pos), tick);
|
||||||
|
|
||||||
|
draw_short_ticks(dc, short_tick, tick);
|
||||||
|
|
||||||
|
if (value == m_values.back() && sequence < m_ruler.count) {
|
||||||
|
value = 0.0;
|
||||||
|
sequence++;
|
||||||
|
tick++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tick > m_max_value)
|
// short ticks from the last tick to the end
|
||||||
break;
|
draw_short_ticks(dc, short_tick, m_max_value);
|
||||||
|
|
||||||
wxCoord pos = get_position_from_value(tick);
|
|
||||||
draw_ticks_pair(dc, pos, mid, 5);
|
|
||||||
draw_tick_text(dc, wxPoint(mid, pos), tick);
|
|
||||||
|
|
||||||
draw_short_ticks(dc, short_tick, tick);
|
|
||||||
|
|
||||||
if (value == m_values.back() && sequence < m_ruler.count) {
|
|
||||||
value = 0.0;
|
|
||||||
sequence++;
|
|
||||||
tick++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// short ticks from the last tick to the end
|
|
||||||
draw_short_ticks(dc, short_tick, m_max_value);
|
|
||||||
|
|
||||||
dc.SetTextForeground(old_clr);
|
dc.SetTextForeground(old_clr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue