Styled timeline text
This commit is contained in:
parent
8e940b879d
commit
a7aff05dd3
5 changed files with 48 additions and 11 deletions
|
|
@ -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"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ protected:
|
|||
void zoom_view(int point, int zoom_size);
|
||||
|
||||
protected:
|
||||
gavl_time_t timeOffset;
|
||||
int64_t timeScale;
|
||||
|
||||
int totalHeight;
|
||||
|
|
|
|||
|
|
@ -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<Gdk::Window> 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue