From e9747b360cd626ace1f04f357215411a90fdec14 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 31 May 2008 18:21:05 +0100 Subject: [PATCH] Track backgrounds are now painted from the style --- src/gui/lumiera_ui.rc | 2 +- src/gui/widgets/timeline-widget.cpp | 6 ++- src/gui/widgets/timeline-widget.hpp | 4 ++ src/gui/widgets/timeline/timeline-body.cpp | 52 ++++++++++++---------- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/gui/lumiera_ui.rc b/src/gui/lumiera_ui.rc index f0c1163e5..f37b4c12b 100644 --- a/src/gui/lumiera_ui.rc +++ b/src/gui/lumiera_ui.rc @@ -112,7 +112,7 @@ class "GtkProgressBar" style:highest "lumiera_progressbars" style "timeline_body" { - gtkmm__CustomObject_TimelineBody::track_background = "#FF7F00" + gtkmm__CustomObject_TimelineBody::track_background = "#7E838B" } class "gtkmm__CustomObject_TimelineBody" style:highest "timeline_body" diff --git a/src/gui/widgets/timeline-widget.cpp b/src/gui/widgets/timeline-widget.cpp index 163ea60c1..e448f62f2 100644 --- a/src/gui/widgets/timeline-widget.cpp +++ b/src/gui/widgets/timeline-widget.cpp @@ -30,6 +30,8 @@ namespace lumiera { namespace gui { namespace widgets { +const int TimelineWidget::TrackPadding = 1; + TimelineWidget::TimelineWidget() : Table(2, 2), totalHeight(0), @@ -39,7 +41,7 @@ TimelineWidget::TimelineWidget() : verticalScroll(verticalAdjustment), ruler("ruler") { - rowHeaderLayout.set_size_request(100, 100); + rowHeaderLayout.set_size_request(100, 0); body = new TimelineBody(this); @@ -97,7 +99,7 @@ TimelineWidget::move_headers() const int height = track->get_track_height(); rowHeaderLayout.move(track->get_header_widget(), 0, offset - y_scroll_offset); - offset += height; + offset += height + TrackPadding; } totalHeight = offset; verticalAdjustment.set_upper(totalHeight); diff --git a/src/gui/widgets/timeline-widget.hpp b/src/gui/widgets/timeline-widget.hpp index 7ceb3f125..fb87f321b 100644 --- a/src/gui/widgets/timeline-widget.hpp +++ b/src/gui/widgets/timeline-widget.hpp @@ -69,6 +69,10 @@ class TimelineWidget : public Gtk::Table Gtk::Adjustment horizontalAdjustment, verticalAdjustment; Gtk::HScrollbar horizontalScroll; Gtk::VScrollbar verticalScroll; + + /* ===== Constants ===== */ + protected: + static const int TrackPadding; friend class timeline::TimelineBody; }; diff --git a/src/gui/widgets/timeline/timeline-body.cpp b/src/gui/widgets/timeline/timeline-body.cpp index f7e747f55..e7c9e0b78 100644 --- a/src/gui/widgets/timeline/timeline-body.cpp +++ b/src/gui/widgets/timeline/timeline-body.cpp @@ -27,6 +27,7 @@ using namespace Gtk; using namespace std; +using namespace lumiera::gui::widgets; using namespace lumiera::gui::widgets::timeline; namespace lumiera { @@ -69,41 +70,44 @@ TimelineBody::on_expose_event(GdkEventExpose* event) Glib::RefPtr window = get_window(); if(!window) return false; - - read_styles(); - - - Gtk::Allocation allocation = get_allocation(); - const int width = allocation.get_width(); - const int height = allocation.get_height(); - - Cairo::RefPtr cairo = window->create_cairo_context(); - cairo->set_line_width(10.0); - cairo->rectangle(50, 50, 100, 100); - gdk_cairo_set_source_color(cairo->cobj(), &track_background); - - cairo->fill_preserve(); - + // Makes sure the widget styles have been loaded + read_styles(); + + // Prepare to render via cairo + Gtk::Allocation allocation = get_allocation(); + Cairo::RefPtr cairo = window->create_cairo_context(); + // Translate the view by the scroll distance cairo->translate( - -timelineWidget->horizontalAdjustment.get_value(), - -timelineWidget->verticalAdjustment.get_value()); - cairo->save(); - + -(int)timelineWidget->horizontalAdjustment.get_value(), + -(int)timelineWidget->verticalAdjustment.get_value()); + + // Interate drawing each track vector::iterator i; for(i = timelineWidget->tracks.begin(); i != timelineWidget->tracks.end(); i++) { timeline::Track *track = *i; - g_assert(track != NULL); - track->draw_track(cairo); - } + g_assert(track != NULL); - cairo->restore(); + const int track_height = track->get_track_height(); + + // Draw the track background + cairo->rectangle(0, 0, allocation.get_width(), track_height); + gdk_cairo_set_source_color(cairo->cobj(), &track_background); + cairo->fill(); + + // Render the track + cairo->save(); + track->draw_track(cairo); + cairo->restore(); + + // Shift for the next track + cairo->translate(0, track_height + TimelineWidget::TrackPadding); + } return true; - } void