Added scrolling and major timeline-ruler ticks

This commit is contained in:
Joel Holdsworth 2008-06-19 23:35:53 +01:00
parent 25f28ee586
commit e18b0a1d5f
5 changed files with 46 additions and 19 deletions

View file

@ -31,7 +31,9 @@
#include <gtkmm.h>
#include <nobug.h>
extern "C" {
#include <gavl/gavltime.h>
}
NOBUG_DECLARE_FLAG(gui);

View file

@ -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:

View file

@ -82,8 +82,7 @@ TimelineBody::on_expose_event(GdkEventExpose* event)
Cairo::RefPtr<Cairo::Context> 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

View file

@ -26,7 +26,6 @@
#include "../../window-manager.hpp"
extern "C" {
#include <gavl/gavltime.h>
#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()
{

View file

@ -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;
};