From: dooglus Date: Wed, 6 Feb 2008 17:43:35 +0000 (+0000) Subject: Improve the range of different scales used on the timeslider. Previously 3 fps anima... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=aaed0cdf5160358d08681ab1c420480a748bf6fa;p=synfig.git Improve the range of different scales used on the timeslider. Previously 3 fps animations were having the timeslider labelled "0.75f, 1.5f, ..." rather than "1f, 2f, ...". git-svn-id: http://svn.voria.com/code@1609 1f10aa63-cdf2-0310-b900-c93c546f37ac --- diff --git a/synfig-studio/trunk/src/gtkmm/widget_timeslider.cpp b/synfig-studio/trunk/src/gtkmm/widget_timeslider.cpp index 651cbe0..9f299c9 100644 --- a/synfig-studio/trunk/src/gtkmm/widget_timeslider.cpp +++ b/synfig-studio/trunk/src/gtkmm/widget_timeslider.cpp @@ -458,40 +458,58 @@ bool Widget_Timeslider::redraw(bool /*doublebuffer*/) //draw these lines... (always 5 between) maybe 6? const int subdiv = 4; - //1h 45 30 20 10 5 - //..., 3m, 2m, 1m30s, 1m, 30s, 20s, 10s, 5s, 3s, 2s, 1s, 0.5s - //frames... (how???) - double ranges[] = - { 1.0/fps,subdiv/fps,0.25,0.5, 1, 2, 3, 5, 10, 20, 30, 60, 90, 120, 180, 300, 600, 1200, 1800, 2700, 3600 }; - //{ 3600, 2700, 1800, 1200, 600, 300, 180, 120, 90, 60, 30, 20, 10, 5, 3, 2, 1, 0.5 }; - const int ranges_size = sizeof(ranges)/sizeof(double); - - double lowerrange = dtdp*75, upperrange = dtdp*150; - double midrange = (lowerrange + upperrange)/2; + int ifps = round_to_int(fps); + if (ifps < 1) ifps = 1; - //find most ideal scale - double scale = ranges[0]; - { - double *val = binary_find(ranges, ranges+ranges_size, midrange); - double *after = val+1; + std::vector ranges; - if(val >= ranges+ranges_size) - { - val = ranges+ranges_size-1; - } + unsigned int pos = 0; - if(after >= ranges+ranges_size) + // build a list of all the factors of the frame rate + for (int i = 1; i*i <= ifps; i++) + if ((ifps%i) == 0) { - after = ranges+ranges_size-1; + ranges.insert(ranges.begin()+pos, i/fps); + if (i*i != ifps) + ranges.insert(ranges.begin()+pos+1, ifps/i/fps); + pos++; } - scale = *val; - - double diff = abs(scale - midrange), diff2 = abs(*after - midrange); - if(diff2 < diff) - scale = *after; + // fill in any gaps where one factor is more than 2 times the previous + std::vector::iterator iter, next; + pos = 0; + for (pos = 0; pos < ranges.size()-1; pos++) + { + iter = ranges.begin()+pos; + next = iter+1; + if (*iter*2 < *next) + ranges.insert(next, *iter*2); } + double more_ranges[] = { + 2, 3, 5, 10, 20, 30, 60, 90, 120, 180, + 300, 600, 1200, 1800, 2700, 3600, 3600*2, + 3600*4, 3600*8, 3600*16, 3600*32, 3600*64, + 3600*128, 3600*256, 3600*512, 3600*1024 }; + + ranges.insert(ranges.end(), more_ranges, more_ranges + sizeof(more_ranges)/sizeof(double)); + + double lowerrange = dtdp*140, upperrange = dtdp*280; + double midrange = (lowerrange + upperrange)/2; + + //find most ideal scale + double scale; + next = binary_find(ranges.begin(), ranges.end(), midrange); + iter = next++; + + if (iter == ranges.end()) iter--; + if (next == ranges.end()) next--; + + if (abs(*next - midrange) < abs(*iter - midrange)) + scale = *next; + else + scale = *iter; + //synfig::info("Range found: (l %.2lf,u %.2lf - m %.2lf) -> %.2lf",lowerrange,upperrange,midrange,scale); //search around this area to get the right one