refactor zoom smothing into TimelineViewWindow
This commit is contained in:
parent
a6392f5d14
commit
d6fa67f2b8
5 changed files with 38 additions and 30 deletions
|
|
@ -41,9 +41,7 @@ namespace widgets {
|
|||
const int TimelineWidget::TrackPadding = 1;
|
||||
const int TimelineWidget::HeaderWidth = 150;
|
||||
const int TimelineWidget::HeaderIndentWidth = 10;
|
||||
const double TimelineWidget::ZoomIncrement = 1.25; // Not currently used
|
||||
const double TimelineWidget::ZoomSmoothing = 9.0;
|
||||
const int64_t TimelineWidget::MaxScale = 30000000; // 30 Million
|
||||
|
||||
|
||||
TimelineWidget::TimelineWidget(shared_ptr<timeline::TimelineState> source_state)
|
||||
: Table(2, 2)
|
||||
|
|
|
|||
|
|
@ -278,20 +278,10 @@ protected:
|
|||
bool update_tracks_frozen;
|
||||
|
||||
/* ===== Constants ===== */
|
||||
public:
|
||||
/**
|
||||
* The maximum scale for timeline display.
|
||||
* @remarks At MaxScale, every pixel on the timeline is equivalent
|
||||
* to 30000000 lumiera::Time increments.
|
||||
*/
|
||||
static const int64_t MaxScale;
|
||||
static const double ZoomSmoothing;
|
||||
|
||||
protected:
|
||||
static const int TrackPadding;
|
||||
static const int HeaderWidth;
|
||||
static const int HeaderIndentWidth;
|
||||
static const double ZoomIncrement;
|
||||
|
||||
friend class timeline::TimelineBody;
|
||||
friend class timeline::TimelineHeaderContainer;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,14 @@ namespace gui {
|
|||
namespace widgets {
|
||||
namespace timeline {
|
||||
|
||||
/* == public constants == */
|
||||
|
||||
const int64_t TimelineViewWindow::MaxScale = 30000000; // 30 Million
|
||||
const double TimelineViewWindow::ZoomIncrement = 1.25; // Not currently used
|
||||
const double TimelineViewWindow::ZoomSmoothing = 9.0;
|
||||
|
||||
|
||||
|
||||
TimelineViewWindow::TimelineViewWindow (Offset offset, int64_t scale)
|
||||
: timeOffset(offset)
|
||||
, timeScale(scale)
|
||||
|
|
@ -67,7 +75,7 @@ TimelineViewWindow::set_time_scale(int64_t scale)
|
|||
void
|
||||
TimelineViewWindow::set_time_scale(double ratio)
|
||||
{
|
||||
int64_t max = TimelineWidget::MaxScale;
|
||||
int64_t max = MaxScale;
|
||||
int64_t min = 1;
|
||||
|
||||
if(ratio <= 0.0)
|
||||
|
|
@ -84,19 +92,28 @@ TimelineViewWindow::set_time_scale(double ratio)
|
|||
set_time_scale((int64_t)(ratio * max));
|
||||
}
|
||||
|
||||
double
|
||||
TimelineViewWindow::get_smoothed_time_scale() const
|
||||
{
|
||||
double linear_scale ( 1.0 / MaxScale * timeScale);
|
||||
|
||||
// reverse the effect of zoom scale smoothing
|
||||
return pow (linear_scale, (1.0 / ZoomSmoothing));
|
||||
}
|
||||
|
||||
void
|
||||
TimelineViewWindow::zoom_view(int point, double time_scale_ratio)
|
||||
{
|
||||
// Apply the smoothing factor
|
||||
int64_t new_time_scale(pow (time_scale_ratio, TimelineWidget::ZoomSmoothing)
|
||||
* double(TimelineWidget::MaxScale));
|
||||
int64_t new_time_scale(pow (time_scale_ratio, ZoomSmoothing)
|
||||
* double(MaxScale));
|
||||
|
||||
/* Prevent Zooming in To Close and Far */
|
||||
if(new_time_scale < 1)
|
||||
new_time_scale = 1;
|
||||
|
||||
if(new_time_scale > TimelineWidget::MaxScale)
|
||||
new_time_scale = TimelineWidget::MaxScale;
|
||||
if(new_time_scale > MaxScale)
|
||||
new_time_scale = MaxScale;
|
||||
|
||||
// The view must be shifted so that the zoom is centred on the cursor
|
||||
TimeVar newStartPoint = timeOffset + TimeValue(point * (timeScale - new_time_scale));
|
||||
|
|
|
|||
|
|
@ -54,6 +54,16 @@ using lib::time::Offset;
|
|||
class TimelineViewWindow
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* The maximum scale for timeline display.
|
||||
* @remarks At MaxScale, every pixel on the timeline is equivalent
|
||||
* to 30000000 lumiera::Time increments.
|
||||
*/
|
||||
static const int64_t MaxScale;
|
||||
static const double ZoomSmoothing;
|
||||
static const double ZoomIncrement;
|
||||
|
||||
|
||||
/**
|
||||
* @param offset The initial view offset.
|
||||
|
|
@ -95,6 +105,10 @@ public:
|
|||
*/
|
||||
void set_time_scale(int64_t time_scale);
|
||||
void set_time_scale(double ratio);
|
||||
|
||||
/** get the current time scale with zoom smoothing applied */
|
||||
double get_smoothed_time_scale() const;
|
||||
|
||||
/**
|
||||
* Zooms the view in or out as by a number of steps while keeping a
|
||||
* given point on the timeline still.
|
||||
|
|
|
|||
|
|
@ -102,21 +102,10 @@ TimelineZoomScale::wireTimelineState (shared_ptr<TimelineState> currentState,
|
|||
void
|
||||
TimelineZoomScale::on_timeline_state_changed (shared_ptr<TimelineState> newState)
|
||||
{
|
||||
/////////////////////////////TICKET #861 : part of that could be a library routine!
|
||||
REQUIRE (newState);
|
||||
timelineState = newState;
|
||||
|
||||
int64_t current_scale =
|
||||
getViewWindow().get_time_scale();
|
||||
|
||||
double linear_scale =
|
||||
(double) current_scale / (double) TimelineWidget::MaxScale;
|
||||
|
||||
/* We have to Revese the Smoothing */
|
||||
double new_relative_scale =
|
||||
pow(linear_scale,(1.0 / TimelineWidget::ZoomSmoothing));
|
||||
|
||||
adjustment.set_value(new_relative_scale);
|
||||
adjustment.set_value (getViewWindow().get_smoothed_time_scale());
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Reference in a new issue