From e0463da20450ec97e4ee65bca64a09f0783faa33 Mon Sep 17 00:00:00 2001 From: "Michael R. Fisher" Date: Thu, 6 Oct 2011 12:38:10 -0500 Subject: [PATCH] Added TimelineZoomScale widget --- src/gui/panels/timeline-panel.cpp | 16 +++++++++++--- src/gui/panels/timeline-panel.hpp | 4 ++++ src/gui/widgets/timeline-widget.cpp | 10 ++++----- src/gui/widgets/timeline-widget.hpp | 2 +- .../widgets/timeline/timeline-view-window.cpp | 22 +++++++++---------- .../widgets/timeline/timeline-view-window.hpp | 2 +- .../widgets/timeline/timeline-zoom-scale.cpp | 9 ++++++++ 7 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/gui/panels/timeline-panel.cpp b/src/gui/panels/timeline-panel.cpp index 07dce7b1d..a9c967403 100644 --- a/src/gui/panels/timeline-panel.cpp +++ b/src/gui/panels/timeline-panel.cpp @@ -60,6 +60,7 @@ TimelinePanel::TimelinePanel (workspace::PanelManager &panel_manager, , iBeamTool(Gtk::StockID("tool_i_beam")) , zoomIn(Stock::ZOOM_IN) , zoomOut(Stock::ZOOM_OUT) + , zoomScale() , updatingToolbar(false) , currentTool(timeline::Arrow) { @@ -101,9 +102,10 @@ TimelinePanel::TimelinePanel (workspace::PanelManager &panel_manager, toolbar.append(separator2); - toolbar.append(zoomIn, mem_fun(this, &TimelinePanel::on_zoom_in)); - toolbar.append(zoomOut, mem_fun(this, &TimelinePanel::on_zoom_out)); - + toolbar.append(zoomScale); + zoomScale.signal_zoom(). + connect(mem_fun(this,&TimelinePanel::on_zoom)); + toolbar.show_all(); panelBar.pack_start(toolbar, PACK_SHRINK); @@ -183,6 +185,14 @@ TimelinePanel::on_ibeam_tool() set_tool(timeline::IBeam); } +void +TimelinePanel::on_zoom(int64_t zoom_scale) +{ + REQUIRE(timelineWidget); + timelineWidget->zoom_view(zoom_scale); + update_zoom_buttons(); +} + void TimelinePanel::on_zoom_in() { diff --git a/src/gui/panels/timeline-panel.hpp b/src/gui/panels/timeline-panel.hpp index b65469bc9..aac000277 100644 --- a/src/gui/panels/timeline-panel.hpp +++ b/src/gui/panels/timeline-panel.hpp @@ -32,6 +32,8 @@ #include "gui/panels/panel.hpp" #include "gui/widgets/timecode-widget.hpp" #include "gui/widgets/timeline-widget.hpp" +#include "gui/widgets/timeline/timeline-zoom-scale.hpp" + #include "lib/time/timevalue.hpp" #include @@ -87,6 +89,7 @@ private: void on_arrow_tool(); void on_ibeam_tool(); + void on_zoom(int64_t zoom_size); void on_zoom_in(); void on_zoom_out(); @@ -191,6 +194,7 @@ private: MiniButton zoomIn; MiniButton zoomOut; + gui::widgets::timeline::TimelineZoomScale zoomScale; Gtk::SeparatorToolItem separator2; diff --git a/src/gui/widgets/timeline-widget.cpp b/src/gui/widgets/timeline-widget.cpp index a00882b7e..cd1459cd8 100644 --- a/src/gui/widgets/timeline-widget.cpp +++ b/src/gui/widgets/timeline-widget.cpp @@ -129,13 +129,13 @@ TimelineWidget::set_state(shared_ptr new_state) } void -TimelineWidget::zoom_view(int zoom_size) +TimelineWidget::zoom_view(int64_t zoom_scale) { if(state) - { - const int view_width = body->get_allocation().get_width(); - state->get_view_window().zoom_view(view_width / 2, zoom_size); - } + { + const int view_width = body->get_allocation().get_width(); + state->get_view_window().zoom_view(view_width / 2, zoom_scale); + } } ToolType diff --git a/src/gui/widgets/timeline-widget.hpp b/src/gui/widgets/timeline-widget.hpp index ca213c15b..b8371534b 100644 --- a/src/gui/widgets/timeline-widget.hpp +++ b/src/gui/widgets/timeline-widget.hpp @@ -98,7 +98,7 @@ public: * @param zoom_size The number of steps to zoom by. The scale factor * is 1.25^(-zoom_size). */ - void zoom_view(int zoom_size); + void zoom_view(int64_t zoom_scale); /** * Gets the type of the tool currently active. diff --git a/src/gui/widgets/timeline/timeline-view-window.cpp b/src/gui/widgets/timeline/timeline-view-window.cpp index d9b86597b..004022235 100644 --- a/src/gui/widgets/timeline/timeline-view-window.cpp +++ b/src/gui/widgets/timeline/timeline-view-window.cpp @@ -31,8 +31,6 @@ namespace gui { namespace widgets { namespace timeline { - - TimelineViewWindow::TimelineViewWindow (Offset offset, int64_t scale) : timeOffset(offset) , timeScale(scale) @@ -66,21 +64,21 @@ TimelineViewWindow::set_time_scale(int64_t scale) } void -TimelineViewWindow::zoom_view(int point, int zoom_size) -{ - int64_t new_time_scale = (double)timeScale * pow(1.25, -zoom_size); - +TimelineViewWindow::zoom_view(int point, int64_t zoom_scale) +{ + int64_t new_time_scale = zoom_scale; + // Limit zooming in too close if(new_time_scale < 1) new_time_scale = 1; - - // Nudge zoom problems caused by integer rounding + + /* Not sure if this is still needed. MRF + * // Nudge zoom problems caused by integer rounding if(new_time_scale == timeScale && zoom_size < 0) new_time_scale++; - - // Limit zooming out too far - if(new_time_scale > TimelineWidget::MaxScale) - new_time_scale = TimelineWidget::MaxScale; + */ + // Limit to Min and Max scale code moved to timeline-zoom-scale.cpp + // The view must be shifted so that the zoom is centred on the cursor TimeVar newStartPoint = get_time_offset(); newStartPoint += 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 4f1733af8..3bf67ac89 100644 --- a/src/gui/widgets/timeline/timeline-view-window.hpp +++ b/src/gui/widgets/timeline/timeline-view-window.hpp @@ -101,7 +101,7 @@ public: * @param zoom_size The number of steps to zoom by. The scale factor * is 1.25^(-zoom_size). */ - void zoom_view(int point, int zoom_size); + void zoom_view(int point, int64_t zoom_size); /** * Scrolls the view horizontally as a proportion of the view area. diff --git a/src/gui/widgets/timeline/timeline-zoom-scale.cpp b/src/gui/widgets/timeline/timeline-zoom-scale.cpp index c019d83ed..901df2d7f 100644 --- a/src/gui/widgets/timeline/timeline-zoom-scale.cpp +++ b/src/gui/widgets/timeline/timeline-zoom-scale.cpp @@ -32,6 +32,15 @@ class TimelineWidget; namespace timeline { +/** + * TODO: The initial adjustment value needs to + * match what the TimelineViewWindow's actual timeScale + * Value is. TimelineViewWindow::get_time_scale() is + * currently a public method, but will soon be private. + * Maybe TimelineViewWindow can have a zoom_adjustment + * that gets passed to this widget's Constructor? + */ + TimelineZoomScale::TimelineZoomScale() : HBox() , adjustment(0.5, 0.0, 1.0, 0.000001)