From a7aff05dd3449b17d01ab62bb34bc861971772da Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Mon, 23 Jun 2008 17:07:57 +0100 Subject: [PATCH] Styled timeline text --- src/gui/lumiera_ui.rc | 3 +- src/gui/widgets/timeline-widget.cpp | 8 +++-- src/gui/widgets/timeline-widget.hpp | 1 + src/gui/widgets/timeline/timeline-ruler.cpp | 40 +++++++++++++++++---- src/gui/widgets/timeline/timeline-ruler.hpp | 7 ++++ 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/gui/lumiera_ui.rc b/src/gui/lumiera_ui.rc index 59a021ac5..34dbf31a6 100644 --- a/src/gui/lumiera_ui.rc +++ b/src/gui/lumiera_ui.rc @@ -120,7 +120,8 @@ style "timeline_body" style "timeline_ruler" = "default_base" { -# gtkmm__CustomObject_TimelineRuler::background = "#0000FF" + font_name = "sans 8" + gtkmm__CustomObject_TimelineRuler::annotation_margin = 4 # gtkmm__CustomObject_TimelineRuler::annotations = "#00FF00" } diff --git a/src/gui/widgets/timeline-widget.cpp b/src/gui/widgets/timeline-widget.cpp index 2b6cc96e5..151b50183 100644 --- a/src/gui/widgets/timeline-widget.cpp +++ b/src/gui/widgets/timeline-widget.cpp @@ -39,6 +39,7 @@ const int64_t TimelineWidget::MaxScale = 30000000; TimelineWidget::TimelineWidget() : Table(2, 2), + timeOffset(0), timeScale(1), totalHeight(0), horizontalAdjustment(0, 0, 0), @@ -81,12 +82,13 @@ TimelineWidget::~TimelineWidget() gavl_time_t TimelineWidget::get_time_offset() const { - return (gavl_time_t)horizontalAdjustment.get_value(); + return timeOffset; } void TimelineWidget::set_time_offset(gavl_time_t time_offset) { + timeOffset = time_offset; horizontalAdjustment.set_value(time_offset); ruler.set_time_offset(time_offset); } @@ -107,8 +109,8 @@ TimelineWidget::set_time_scale(int64_t time_scale) void TimelineWidget::on_scroll() { - gavl_time_t time = horizontalAdjustment.get_value(); - ruler.set_time_offset(time); + timeOffset = horizontalAdjustment.get_value(); + ruler.set_time_offset(timeOffset); } void diff --git a/src/gui/widgets/timeline-widget.hpp b/src/gui/widgets/timeline-widget.hpp index e415fe62f..35c11aa3d 100644 --- a/src/gui/widgets/timeline-widget.hpp +++ b/src/gui/widgets/timeline-widget.hpp @@ -98,6 +98,7 @@ protected: void zoom_view(int point, int zoom_size); protected: + gavl_time_t timeOffset; int64_t timeScale; int totalHeight; diff --git a/src/gui/widgets/timeline/timeline-ruler.cpp b/src/gui/widgets/timeline/timeline-ruler.cpp index 71d6c3632..b88feccb4 100644 --- a/src/gui/widgets/timeline/timeline-ruler.cpp +++ b/src/gui/widgets/timeline/timeline-ruler.cpp @@ -43,10 +43,29 @@ namespace timeline { TimelineRuler::TimelineRuler() : Glib::ObjectBase("TimelineRuler"), timeOffset(0), - timeScale(1) + timeScale(1), + annotationHorzMargin(0), + annotationVertMargin(0) { set_flags(Gtk::NO_WINDOW); // This widget will not have a window set_size_request(-1, 20); + + // Install style properties + gtk_widget_class_install_style_property( + GTK_WIDGET_CLASS(G_OBJECT_GET_CLASS(gobj())), + g_param_spec_int("annotation_horz_margin", + "Horizontal margin around annotation text", + "The horiztontal margin around the annotation text in pixels.", + G_MININT, G_MAXINT, 4, + G_PARAM_READABLE)); + + gtk_widget_class_install_style_property( + GTK_WIDGET_CLASS(G_OBJECT_GET_CLASS(gobj())), + g_param_spec_int("annotation_vert_margin", + "Vertical margin around annotation text", + "The vertical margin around the annotation text in pixels.", + G_MININT, G_MAXINT, 4, + G_PARAM_READABLE)); } void @@ -71,6 +90,9 @@ TimelineRuler::on_expose_event(GdkEventExpose* event) Glib::RefPtr window = get_window(); if(!window) return false; + + // Load styles + read_styles(); // Prepare to render via cairo Allocation allocation = get_allocation(); @@ -112,10 +134,9 @@ TimelineRuler::on_expose_event(GdkEventExpose* event) // Draw the text pango_layout->set_text(lumiera_tmpbuf_print_time(time_offset)); - Pango::Rectangle text_extents = pango_layout->get_logical_extents(); - const int text_height = text_extents.get_height() / Pango::SCALE; - cairo->move_to(4 + x, - (allocation.get_height() - text_height) / 2); + //Pango::Rectangle text_extents = pango_layout->get_logical_extents(); + //const int text_height = text_extents.get_height() / Pango::SCALE; + cairo->move_to(annotationHorzMargin + x, annotationVertMargin); pango_layout->add_to_cairo_context(cairo); cairo->fill(); @@ -132,8 +153,6 @@ TimelineRuler::calculate_major_spacing() const int i = 0; const int min_division_width = 100; - g_message("timeScale = %d", timeScale); - const gavl_time_t major_spacings[] = { GAVL_TIME_SCALE / 1000, GAVL_TIME_SCALE / 400, @@ -169,6 +188,13 @@ TimelineRuler::calculate_major_spacing() const return major_spacings[i]; } + +void +TimelineRuler::read_styles() +{ + get_style_property("annotation_horz_margin", annotationHorzMargin); + get_style_property("annotation_vert_margin", annotationVertMargin); +} } // namespace timeline } // namespace widgets diff --git a/src/gui/widgets/timeline/timeline-ruler.hpp b/src/gui/widgets/timeline/timeline-ruler.hpp index 1e5b51d8f..931c6ef3a 100644 --- a/src/gui/widgets/timeline/timeline-ruler.hpp +++ b/src/gui/widgets/timeline/timeline-ruler.hpp @@ -61,9 +61,16 @@ protected: private: gavl_time_t calculate_major_spacing() const; + void read_styles(); + private: + // View values gavl_time_t timeOffset; int64_t timeScale; + + // Style values + int annotationHorzMargin; + int annotationVertMargin; }; } // namespace timeline