From e18b0a1d5f49417206d87c03403358a1410f985b Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Thu, 19 Jun 2008 23:35:53 +0100 Subject: [PATCH] Added scrolling and major timeline-ruler ticks --- src/gui/gtk-lumiera.hpp | 4 +- src/gui/widgets/timeline-widget.cpp | 11 +++++- src/gui/widgets/timeline/timeline-body.cpp | 3 +- src/gui/widgets/timeline/timeline-ruler.cpp | 43 ++++++++++++++------- src/gui/widgets/timeline/timeline-ruler.hpp | 4 +- 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/gui/gtk-lumiera.hpp b/src/gui/gtk-lumiera.hpp index fef358a34..510bf029f 100644 --- a/src/gui/gtk-lumiera.hpp +++ b/src/gui/gtk-lumiera.hpp @@ -31,7 +31,9 @@ #include #include - +extern "C" { +#include +} NOBUG_DECLARE_FLAG(gui); diff --git a/src/gui/widgets/timeline-widget.cpp b/src/gui/widgets/timeline-widget.cpp index d52bff119..48f6baf90 100644 --- a/src/gui/widgets/timeline-widget.cpp +++ b/src/gui/widgets/timeline-widget.cpp @@ -48,8 +48,10 @@ TimelineWidget::TimelineWidget() : headerContainer = new HeaderContainer(this); ASSERT(headerContainer != NULL); - verticalAdjustment.signal_value_changed().connect( + horizontalAdjustment.signal_value_changed().connect( sigc::mem_fun(this, &TimelineWidget::on_scroll) ); + verticalAdjustment.signal_value_changed().connect( + sigc::mem_fun(this, &TimelineWidget::on_scroll) ); attach(*body, 1, 2, 1, 2, FILL|EXPAND, FILL|EXPAND); attach(ruler, 1, 2, 0, 1, FILL|EXPAND, SHRINK); @@ -74,7 +76,8 @@ TimelineWidget::~TimelineWidget() void TimelineWidget::on_scroll() { - + gavl_time_t time = horizontalAdjustment.get_value() * GAVL_TIME_SCALE / 200; + ruler.set_time_offset(time); } void @@ -106,6 +109,10 @@ TimelineWidget::update_scroll() ASSERT(body != NULL); const Allocation body_allocation = body->get_allocation(); + //----- Horizontal Scroll ------// + + horizontalAdjustment.set_upper(1000); + //----- Vertical Scroll -----// // Calculate the vertical length that can be scrolled: diff --git a/src/gui/widgets/timeline/timeline-body.cpp b/src/gui/widgets/timeline/timeline-body.cpp index aaf0b9d26..bb1c7b4d6 100644 --- a/src/gui/widgets/timeline/timeline-body.cpp +++ b/src/gui/widgets/timeline/timeline-body.cpp @@ -82,8 +82,7 @@ TimelineBody::on_expose_event(GdkEventExpose* event) Cairo::RefPtr cairo = window->create_cairo_context(); // Translate the view by the scroll distance - cairo->translate( - -(int)timelineWidget->horizontalAdjustment.get_value(), + cairo->translate(0, -(int)timelineWidget->verticalAdjustment.get_value()); // Interate drawing each track diff --git a/src/gui/widgets/timeline/timeline-ruler.cpp b/src/gui/widgets/timeline/timeline-ruler.cpp index ebecc4805..cc771d62e 100644 --- a/src/gui/widgets/timeline/timeline-ruler.cpp +++ b/src/gui/widgets/timeline/timeline-ruler.cpp @@ -26,7 +26,6 @@ #include "../../window-manager.hpp" extern "C" { -#include #include "../../../lib/time.h" } @@ -52,6 +51,13 @@ TimelineRuler::TimelineRuler() : timeOffset = 0; } +void +TimelineRuler::set_time_offset(gavl_time_t time_offset) +{ + timeOffset = time_offset; + queue_draw(); +} + bool TimelineRuler::on_expose_event(GdkEventExpose* event) { @@ -71,34 +77,45 @@ TimelineRuler::on_expose_event(GdkEventExpose* event) cairo->translate(allocation.get_x(), allocation.get_y()); - // Render the background + // Render the background, and clip inside the area Gdk::Cairo::set_source_color(cairo, style->get_bg(STATE_NORMAL)); cairo->rectangle(0, 0, allocation.get_width(), allocation.get_height()); - cairo->fill(); + cairo->fill_preserve(); + cairo->clip(); // Render ruler annotations + Gdk::Cairo::set_source_color(cairo, style->get_fg(STATE_NORMAL)); + gavl_time_t major_spacing = GAVL_TIME_SCALE; - int64_t time_offset = timeOffset; - while(time_offset / timeScale < allocation.get_width()) + int64_t time_offset = timeOffset - timeOffset % major_spacing; + int x = 0; + const int64_t x_offset = timeOffset / timeScale; + + do { + x = (int)(time_offset / timeScale - x_offset); + + // Draw the major grid-line + cairo->move_to(x + 0.5, 0); + cairo->line_to(x + 0.5, allocation.get_height()); + cairo->set_line_width(1); + cairo->stroke(); + + // Draw the text pango_layout->set_text(lumiera_tmpbuf_print_time(time_offset)); - Pango::Rectangle text_extents = pango_layout->get_logical_extents(); - Gdk::Cairo::set_source_color(cairo, style->get_fg(STATE_NORMAL)); - - const int64_t x = time_offset / timeScale; - cairo->move_to(x, (allocation.get_height() - text_extents.get_height() / Pango::SCALE) / 2); - + Pango::Rectangle text_extents = pango_layout->get_logical_extents(); + cairo->move_to(4 + x, (allocation.get_height() - text_extents.get_height() / Pango::SCALE) / 2); pango_layout->add_to_cairo_context(cairo); - cairo->fill(); time_offset += major_spacing; } + while(x < allocation.get_width()); return true; } - + void TimelineRuler::read_styles() { diff --git a/src/gui/widgets/timeline/timeline-ruler.hpp b/src/gui/widgets/timeline/timeline-ruler.hpp index 9c7fd44c3..76788ce41 100644 --- a/src/gui/widgets/timeline/timeline-ruler.hpp +++ b/src/gui/widgets/timeline/timeline-ruler.hpp @@ -38,6 +38,8 @@ class TimelineRuler : public Gtk::Widget { public: TimelineRuler(); + + void set_time_offset(gavl_time_t time_offset); /* ===== Events ===== */ protected: @@ -47,7 +49,7 @@ class TimelineRuler : public Gtk::Widget private: void read_styles(); - int64_t timeOffset; + gavl_time_t timeOffset; int timeScale; };