From 708aea87bdcda84a8dac7346c2b95f367f3d2fcb Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Tue, 2 Sep 2008 22:39:53 +0100 Subject: [PATCH] Fixed a bug with body redrawing and added some documentation --- src/gui/widgets/timeline-widget.cpp | 13 ++++++++++--- src/gui/widgets/timeline-widget.hpp | 9 +++++++++ src/gui/widgets/timeline/timeline-body.cpp | 18 ++++++++---------- src/gui/widgets/timeline/timeline-body.hpp | 10 ++++++++-- src/gui/widgets/timeline/timeline-ruler.cpp | 10 +++++++--- src/gui/widgets/timeline/timeline-ruler.hpp | 14 +++++++------- 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/gui/widgets/timeline-widget.cpp b/src/gui/widgets/timeline-widget.cpp index 9345efe59..c7463768b 100644 --- a/src/gui/widgets/timeline-widget.cpp +++ b/src/gui/widgets/timeline-widget.cpp @@ -110,7 +110,8 @@ TimelineWidget::set_time_offset(gavl_time_t time_offset) timeOffset = time_offset; horizontalAdjustment.set_value(time_offset); - ruler->update_view(); + + viewChangedSignal.emit(); } int64_t @@ -129,7 +130,7 @@ TimelineWidget::set_time_scale(int64_t time_scale) const int view_width = body->get_allocation().get_width(); horizontalAdjustment.set_page_size(timeScale * view_width); - ruler->update_view(); + viewChangedSignal.emit(); } void @@ -261,6 +262,12 @@ TimelineWidget::set_tool(ToolType tool_type) body->set_tool(tool_type); } +sigc::signal +TimelineWidget::view_changed_signal() const +{ + return viewChangedSignal; +} + sigc::signal TimelineWidget::mouse_hover_signal() const { @@ -271,7 +278,7 @@ void TimelineWidget::on_scroll() { timeOffset = horizontalAdjustment.get_value(); - ruler->update_view(); + viewChangedSignal.emit(); } void diff --git a/src/gui/widgets/timeline-widget.hpp b/src/gui/widgets/timeline-widget.hpp index 004a01ca6..ef13ef556 100644 --- a/src/gui/widgets/timeline-widget.hpp +++ b/src/gui/widgets/timeline-widget.hpp @@ -157,6 +157,8 @@ public: public: /* ===== Signals ===== */ + sigc::signal view_changed_signal() const; + sigc::signal mouse_hover_signal() const; /* ===== Events ===== */ @@ -208,10 +210,17 @@ protected: Gtk::HScrollbar horizontalScroll; Gtk::VScrollbar verticalScroll; + // Signals + sigc::signal viewChangedSignal; sigc::signal mouseHoverSignal; /* ===== Constants ===== */ public: + /** + * The maximum scale for timeline display. + * @remarks At MaxScale, every pixel on the timeline is equivalent + * to 30000000 gavl_time_t increments. + */ static const int64_t MaxScale; protected: diff --git a/src/gui/widgets/timeline/timeline-body.cpp b/src/gui/widgets/timeline/timeline-body.cpp index 795bc249d..8cf36af2c 100644 --- a/src/gui/widgets/timeline/timeline-body.cpp +++ b/src/gui/widgets/timeline/timeline-body.cpp @@ -55,10 +55,8 @@ TimelineBody::TimelineBody(lumiera::gui::widgets::TimelineWidget REQUIRE(timelineWidget != NULL); // Connect up some events - timelineWidget->horizontalAdjustment.signal_value_changed().connect( - sigc::mem_fun(this, &TimelineBody::on_scroll) ); - timelineWidget->verticalAdjustment.signal_value_changed().connect( - sigc::mem_fun(this, &TimelineBody::on_scroll) ); + timelineWidget->view_changed_signal().connect(sigc::mem_fun( + this, &TimelineBody::on_update_view) ); // Install style properties register_styles(); @@ -109,6 +107,12 @@ TimelineBody::set_tool(timeline::ToolType tool_type) tool->apply_cursor(); } +void +TimelineBody::on_update_view() +{ + queue_draw(); +} + void TimelineBody::on_realize() { @@ -217,12 +221,6 @@ TimelineBody::on_expose_event(GdkEventExpose* event) return true; } - -void -TimelineBody::on_scroll() -{ - queue_draw(); -} bool TimelineBody::on_scroll_event (GdkEventScroll* event) diff --git a/src/gui/widgets/timeline/timeline-body.hpp b/src/gui/widgets/timeline/timeline-body.hpp index 2fc7314f9..9fcf15885 100644 --- a/src/gui/widgets/timeline/timeline-body.hpp +++ b/src/gui/widgets/timeline/timeline-body.hpp @@ -52,6 +52,9 @@ public: */ TimelineBody(lumiera::gui::widgets::TimelineWidget *timeline_widget); + /** + * Destructor + */ ~TimelineBody(); /** @@ -68,6 +71,11 @@ public: /* ===== Events ===== */ protected: + /** + * An event handler for when the view window of the timeline changes. + */ + void on_update_view(); + /** * An event handler for when the widget is realized. */ @@ -77,8 +85,6 @@ protected: * An event handler for when the window must be redrawn. */ bool on_expose_event(GdkEventExpose* event); - - void on_scroll(); bool on_scroll_event(GdkEventScroll* event); diff --git a/src/gui/widgets/timeline/timeline-ruler.cpp b/src/gui/widgets/timeline/timeline-ruler.cpp index 17a9a1445..08eee617c 100644 --- a/src/gui/widgets/timeline/timeline-ruler.cpp +++ b/src/gui/widgets/timeline/timeline-ruler.cpp @@ -63,6 +63,10 @@ TimelineRuler::TimelineRuler( { REQUIRE(timelineWidget != NULL); + // Connect event handlers + timelineWidget->view_changed_signal().connect(sigc::mem_fun( + this, &TimelineRuler::on_update_view) ); + // Install style properties register_styles(); } @@ -75,7 +79,7 @@ TimelineRuler::set_mouse_chevron_offset(int offset) } void -TimelineRuler::update_view() +TimelineRuler::on_update_view() { rulerImage.clear(); queue_draw(); @@ -222,8 +226,8 @@ TimelineRuler::draw_ruler(Cairo::RefPtr cr, REQUIRE(ruler_rect.get_height() > 0); REQUIRE(timelineWidget != NULL); - const gavl_time_t left_offset = timelineWidget->timeOffset; - const int64_t time_scale = timelineWidget->timeScale; + const gavl_time_t left_offset = timelineWidget->get_time_offset(); + const int64_t time_scale = timelineWidget->get_time_scale(); // Preparation steps const int height = ruler_rect.get_height(); diff --git a/src/gui/widgets/timeline/timeline-ruler.hpp b/src/gui/widgets/timeline/timeline-ruler.hpp index 73fe08a79..affda5adf 100644 --- a/src/gui/widgets/timeline/timeline-ruler.hpp +++ b/src/gui/widgets/timeline/timeline-ruler.hpp @@ -59,14 +59,14 @@ public: */ void set_mouse_chevron_offset(int offset); - /** - * Causes the ruler to be redrawn from scratch. The cached ruler - * backdrop is destroyed and redrawn. - */ - void update_view(); - /* ===== Events ===== */ -protected: +private: + /** + * An event handler for when the view window of the timeline changes. + * @remarks Causes the ruler to be redrawn from scratch. The cached + * ruler backdrop is destroyed and redrawn. + */ + void on_update_view(); /** * An event handler for when the widget is realized.