From d6fa67f2b8f9073737cd3c305ace3664395eb1d0 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 27 Nov 2011 01:28:48 +0100 Subject: [PATCH] refactor zoom smothing into TimelineViewWindow --- src/gui/widgets/timeline-widget.cpp | 4 +-- src/gui/widgets/timeline-widget.hpp | 10 ------- .../widgets/timeline/timeline-view-window.cpp | 27 +++++++++++++++---- .../widgets/timeline/timeline-view-window.hpp | 14 ++++++++++ .../widgets/timeline/timeline-zoom-scale.cpp | 13 +-------- 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/gui/widgets/timeline-widget.cpp b/src/gui/widgets/timeline-widget.cpp index 81d93e5ba..fac09a6f5 100644 --- a/src/gui/widgets/timeline-widget.cpp +++ b/src/gui/widgets/timeline-widget.cpp @@ -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 source_state) : Table(2, 2) diff --git a/src/gui/widgets/timeline-widget.hpp b/src/gui/widgets/timeline-widget.hpp index b5d57c667..ffff15dda 100644 --- a/src/gui/widgets/timeline-widget.hpp +++ b/src/gui/widgets/timeline-widget.hpp @@ -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; diff --git a/src/gui/widgets/timeline/timeline-view-window.cpp b/src/gui/widgets/timeline/timeline-view-window.cpp index c53722e89..357e4db97 100644 --- a/src/gui/widgets/timeline/timeline-view-window.cpp +++ b/src/gui/widgets/timeline/timeline-view-window.cpp @@ -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)); diff --git a/src/gui/widgets/timeline/timeline-view-window.hpp b/src/gui/widgets/timeline/timeline-view-window.hpp index d52f84406..f4c6fa558 100644 --- a/src/gui/widgets/timeline/timeline-view-window.hpp +++ b/src/gui/widgets/timeline/timeline-view-window.hpp @@ -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. diff --git a/src/gui/widgets/timeline/timeline-zoom-scale.cpp b/src/gui/widgets/timeline/timeline-zoom-scale.cpp index 02169dfdd..99299608a 100644 --- a/src/gui/widgets/timeline/timeline-zoom-scale.cpp +++ b/src/gui/widgets/timeline/timeline-zoom-scale.cpp @@ -102,21 +102,10 @@ TimelineZoomScale::wireTimelineState (shared_ptr currentState, void TimelineZoomScale::on_timeline_state_changed (shared_ptr 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