From 004105227d4dab3853d8b670193bde7734283010 Mon Sep 17 00:00:00 2001 From: dooglus Date: Sun, 10 Feb 2008 13:58:11 +0000 Subject: [PATCH] Improve the algorithm for determining the number of tick marks to put between pairs of labels in the timeslider widgets. It's better to divide 5 minutes into 5 tics of 1 minute each than 6 ticks of 50 seconds each, for example. git-svn-id: http://svn.voria.com/code@1653 1f10aa63-cdf2-0310-b900-c93c546f37ac --- .../trunk/src/gtkmm/widget_timeslider.cpp | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/synfig-studio/trunk/src/gtkmm/widget_timeslider.cpp b/synfig-studio/trunk/src/gtkmm/widget_timeslider.cpp index e15e2e7..f46b0c8 100644 --- a/synfig-studio/trunk/src/gtkmm/widget_timeslider.cpp +++ b/synfig-studio/trunk/src/gtkmm/widget_timeslider.cpp @@ -505,12 +505,29 @@ bool Widget_Timeslider::redraw(bool /*doublebuffer*/) iter = next; scale = *iter; - if (iter != ranges.begin()) iter--; - if (iter != ranges.begin()) iter--; - if (iter != ranges.begin()) iter--; // subdivide into this many tick marks (8 or less) - const int subdiv = round_to_int(scale / *iter); + int subdiv = round_to_int(scale * ifps); + + if (subdiv > 8) + { + const int ideal = subdiv; + + // find a number of tick marks that nicely divides the scale + // (5 minutes divided by 6 is 50s, but that's not 'nice' - + // 5 ticks of 1m each is much simpler than 6 ticks of 50s) + for (subdiv = 8; subdiv > 0; subdiv--) + if ((ideal <= ifps*2 && (ideal % (subdiv )) == 0) || + (ideal <= ifps*2*60 && (ideal % (subdiv*ifps )) == 0) || + (ideal <= ifps*2*60*60 && (ideal % (subdiv*ifps*60 )) == 0) || + (true && (ideal % (subdiv*ifps*60*60)) == 0)) + break; + + // if we didn't find anything, use 4 ticks + if (!subdiv) + subdiv = 4; + } + time_per_tickmark = scale / subdiv; //get first valid line and its position in pixel space -- 2.7.4