Track backgrounds are now painted from the style

This commit is contained in:
Joel Holdsworth 2008-05-31 18:21:05 +01:00
parent 71b45acf54
commit e9747b360c
4 changed files with 37 additions and 27 deletions

View file

@ -112,7 +112,7 @@ class "GtkProgressBar" style:highest "lumiera_progressbars"
style "timeline_body" style "timeline_body"
{ {
gtkmm__CustomObject_TimelineBody::track_background = "#FF7F00" gtkmm__CustomObject_TimelineBody::track_background = "#7E838B"
} }
class "gtkmm__CustomObject_TimelineBody" style:highest "timeline_body" class "gtkmm__CustomObject_TimelineBody" style:highest "timeline_body"

View file

@ -30,6 +30,8 @@ namespace lumiera {
namespace gui { namespace gui {
namespace widgets { namespace widgets {
const int TimelineWidget::TrackPadding = 1;
TimelineWidget::TimelineWidget() : TimelineWidget::TimelineWidget() :
Table(2, 2), Table(2, 2),
totalHeight(0), totalHeight(0),
@ -39,7 +41,7 @@ TimelineWidget::TimelineWidget() :
verticalScroll(verticalAdjustment), verticalScroll(verticalAdjustment),
ruler("ruler") ruler("ruler")
{ {
rowHeaderLayout.set_size_request(100, 100); rowHeaderLayout.set_size_request(100, 0);
body = new TimelineBody(this); body = new TimelineBody(this);
@ -97,7 +99,7 @@ TimelineWidget::move_headers()
const int height = track->get_track_height(); const int height = track->get_track_height();
rowHeaderLayout.move(track->get_header_widget(), 0, offset - y_scroll_offset); rowHeaderLayout.move(track->get_header_widget(), 0, offset - y_scroll_offset);
offset += height; offset += height + TrackPadding;
} }
totalHeight = offset; totalHeight = offset;
verticalAdjustment.set_upper(totalHeight); verticalAdjustment.set_upper(totalHeight);

View file

@ -70,6 +70,10 @@ class TimelineWidget : public Gtk::Table
Gtk::HScrollbar horizontalScroll; Gtk::HScrollbar horizontalScroll;
Gtk::VScrollbar verticalScroll; Gtk::VScrollbar verticalScroll;
/* ===== Constants ===== */
protected:
static const int TrackPadding;
friend class timeline::TimelineBody; friend class timeline::TimelineBody;
}; };

View file

@ -27,6 +27,7 @@
using namespace Gtk; using namespace Gtk;
using namespace std; using namespace std;
using namespace lumiera::gui::widgets;
using namespace lumiera::gui::widgets::timeline; using namespace lumiera::gui::widgets::timeline;
namespace lumiera { namespace lumiera {
@ -70,40 +71,43 @@ TimelineBody::on_expose_event(GdkEventExpose* event)
if(!window) if(!window)
return false; return false;
// Makes sure the widget styles have been loaded
read_styles(); read_styles();
// Prepare to render via cairo
Gtk::Allocation allocation = get_allocation(); Gtk::Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
Cairo::RefPtr<Cairo::Context> cairo = window->create_cairo_context(); Cairo::RefPtr<Cairo::Context> 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();
// Translate the view by the scroll distance
cairo->translate( cairo->translate(
-timelineWidget->horizontalAdjustment.get_value(), -(int)timelineWidget->horizontalAdjustment.get_value(),
-timelineWidget->verticalAdjustment.get_value()); -(int)timelineWidget->verticalAdjustment.get_value());
cairo->save();
// Interate drawing each track
vector<timeline::Track*>::iterator i; vector<timeline::Track*>::iterator i;
for(i = timelineWidget->tracks.begin(); for(i = timelineWidget->tracks.begin();
i != timelineWidget->tracks.end(); i++) i != timelineWidget->tracks.end(); i++)
{ {
timeline::Track *track = *i; timeline::Track *track = *i;
g_assert(track != NULL); g_assert(track != NULL);
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); track->draw_track(cairo);
cairo->restore();
// Shift for the next track
cairo->translate(0, track_height + TimelineWidget::TrackPadding);
} }
cairo->restore();
return true; return true;
} }
void void