Made the selection marquee stylable
This commit is contained in:
parent
7e556d08e1
commit
1b89b61370
5 changed files with 123 additions and 75 deletions
|
|
@ -124,6 +124,8 @@ class "GtkProgressBar" style:highest "lumiera_progressbars"
|
|||
style "timeline_body"
|
||||
{
|
||||
gtkmm__CustomObject_TimelineBody::background = "#7E838B"
|
||||
gtkmm__CustomObject_TimelineBody::selection = "#2D2D90"
|
||||
gtkmm__CustomObject_TimelineBody::selection_alpha = 0.5
|
||||
}
|
||||
|
||||
style "timeline_ruler" = "default_base"
|
||||
|
|
@ -137,6 +139,7 @@ style "timeline_ruler" = "default_base"
|
|||
gtkmm__CustomObject_TimelineRuler::annotation_vert_margin = 0
|
||||
gtkmm__CustomObject_TimelineRuler::min_division_width = 100
|
||||
gtkmm__CustomObject_TimelineRuler::mouse_chevron_size = 5
|
||||
gtkmm__CustomObject_TimelineRuler::selection_chevron_size = 5
|
||||
}
|
||||
|
||||
style "timeline_header_base" = "default_base"
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ TimelineBody::TimelineBody(lumiera::gui::widgets::TimelineWidget
|
|||
mouseDownX(0),
|
||||
mouseDownY(0),
|
||||
beginShiftTimeOffset(0),
|
||||
selectionAlpha(0.5),
|
||||
timelineWidget(timeline_widget)
|
||||
{
|
||||
REQUIRE(timelineWidget != NULL);
|
||||
|
|
@ -60,12 +61,7 @@ TimelineBody::TimelineBody(lumiera::gui::widgets::TimelineWidget
|
|||
sigc::mem_fun(this, &TimelineBody::on_scroll) );
|
||||
|
||||
// Install style properties
|
||||
gtk_widget_class_install_style_property(
|
||||
GTK_WIDGET_CLASS(G_OBJECT_GET_CLASS(gobj())),
|
||||
g_param_spec_boxed("background",
|
||||
"Track Background",
|
||||
"The background colour of timeline tracks",
|
||||
GDK_TYPE_COLOR, G_PARAM_READABLE));
|
||||
register_styles();
|
||||
}
|
||||
|
||||
TimelineBody::~TimelineBody()
|
||||
|
|
@ -254,14 +250,14 @@ TimelineBody::on_expose_event(GdkEventExpose* event)
|
|||
// Prepare to render via cairo
|
||||
Glib::RefPtr<Style> style = get_style();
|
||||
const Allocation allocation = get_allocation();
|
||||
Cairo::RefPtr<Cairo::Context> cairo = window->create_cairo_context();
|
||||
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
|
||||
|
||||
REQUIRE(style);
|
||||
REQUIRE(cairo);
|
||||
REQUIRE(cr);
|
||||
|
||||
// Translate the view by the scroll distance
|
||||
cairo->translate(0, -get_vertical_offset());
|
||||
cairo->get_matrix(view_matrix);
|
||||
cr->translate(0, -get_vertical_offset());
|
||||
cr->get_matrix(view_matrix);
|
||||
|
||||
// Interate drawing each track
|
||||
BOOST_FOREACH( Track* track, timelineWidget->tracks )
|
||||
|
|
@ -272,17 +268,17 @@ TimelineBody::on_expose_event(GdkEventExpose* event)
|
|||
ASSERT(height >= 0);
|
||||
|
||||
// Draw the track background
|
||||
cairo->rectangle(0, 0, allocation.get_width(), height);
|
||||
gdk_cairo_set_source_color(cairo->cobj(), &background);
|
||||
cairo->fill();
|
||||
cr->rectangle(0, 0, allocation.get_width(), height);
|
||||
gdk_cairo_set_source_color(cr->cobj(), &backgroundColour);
|
||||
cr->fill();
|
||||
|
||||
// Render the track
|
||||
cairo->save();
|
||||
track->draw_track(cairo);
|
||||
cairo->restore();
|
||||
cr->save();
|
||||
track->draw_track(cr);
|
||||
cr->restore();
|
||||
|
||||
// Shift for the next track
|
||||
cairo->translate(0, height + TimelineWidget::TrackPadding);
|
||||
cr->translate(0, height + TimelineWidget::TrackPadding);
|
||||
}
|
||||
|
||||
//----- Draw the selection -----//
|
||||
|
|
@ -291,34 +287,38 @@ TimelineBody::on_expose_event(GdkEventExpose* event)
|
|||
const int end_x = timelineWidget->time_to_x(
|
||||
timelineWidget->get_selection_end());
|
||||
|
||||
cairo->set_matrix(view_matrix);
|
||||
cr->set_matrix(view_matrix);
|
||||
|
||||
// Draw the cover
|
||||
if(end_x > 0 && start_x < allocation.get_width())
|
||||
{
|
||||
cairo->set_source_rgba(1.0, 0, 0, 0.5);
|
||||
cairo->rectangle(start_x + 0.5, 0,
|
||||
cr->set_source_rgba(
|
||||
(float)selectionColour.red / 0xFFFF,
|
||||
(float)selectionColour.green / 0xFFFF,
|
||||
(float)selectionColour.blue / 0xFFFF,
|
||||
selectionAlpha);
|
||||
cr->rectangle(start_x + 0.5, 0,
|
||||
end_x - start_x, allocation.get_height());
|
||||
cairo->fill();
|
||||
cr->fill();
|
||||
}
|
||||
|
||||
cairo->set_source_rgb(1.0, 0, 0);
|
||||
cairo->set_line_width(1);
|
||||
gdk_cairo_set_source_color(cr->cobj(), &selectionColour);
|
||||
cr->set_line_width(1);
|
||||
|
||||
// Draw the start
|
||||
if(start_x >= 0 && start_x < allocation.get_width())
|
||||
{
|
||||
cairo->move_to(start_x + 0.5, 0);
|
||||
cairo->line_to(start_x + 0.5, allocation.get_height());
|
||||
cairo->stroke_preserve();
|
||||
cr->move_to(start_x + 0.5, 0);
|
||||
cr->line_to(start_x + 0.5, allocation.get_height());
|
||||
cr->stroke_preserve();
|
||||
}
|
||||
|
||||
// Draw the end
|
||||
if(end_x >= 0 && end_x < allocation.get_width())
|
||||
{
|
||||
cairo->move_to(end_x + 0.5, 0);
|
||||
cairo->line_to(end_x + 0.5, allocation.get_height());
|
||||
cairo->stroke_preserve();
|
||||
cr->move_to(end_x + 0.5, 0);
|
||||
cr->line_to(end_x + 0.5, allocation.get_height());
|
||||
cr->stroke_preserve();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -343,12 +343,42 @@ TimelineBody::set_vertical_offset(int offset)
|
|||
{
|
||||
timelineWidget->verticalAdjustment.set_value(offset);
|
||||
}
|
||||
|
||||
void
|
||||
TimelineBody::register_styles() const
|
||||
{
|
||||
GtkWidgetClass *klass = GTK_WIDGET_CLASS(G_OBJECT_GET_CLASS(gobj()));
|
||||
|
||||
gtk_widget_class_install_style_property(
|
||||
GTK_WIDGET_CLASS(G_OBJECT_GET_CLASS(gobj())),
|
||||
g_param_spec_boxed("background",
|
||||
"Track Background",
|
||||
"The background colour of timeline tracks",
|
||||
GDK_TYPE_COLOR, G_PARAM_READABLE));
|
||||
|
||||
gtk_widget_class_install_style_property(
|
||||
GTK_WIDGET_CLASS(G_OBJECT_GET_CLASS(gobj())),
|
||||
g_param_spec_boxed("selection",
|
||||
"End lines of a selection",
|
||||
"The colour of selection limit lines",
|
||||
GDK_TYPE_COLOR, G_PARAM_READABLE));
|
||||
|
||||
gtk_widget_class_install_style_property(klass,
|
||||
g_param_spec_float("selection_alpha",
|
||||
"Selection Alpha",
|
||||
"The transparency of the selection marque.",
|
||||
0, 1.0, 0.5, G_PARAM_READABLE));
|
||||
}
|
||||
|
||||
void
|
||||
TimelineBody::read_styles()
|
||||
{
|
||||
background = WindowManager::read_style_colour_property(
|
||||
backgroundColour = WindowManager::read_style_colour_property(
|
||||
*this, "background", 0, 0, 0);
|
||||
selectionColour = WindowManager::read_style_colour_property(
|
||||
*this, "selection", 0, 0, 0);
|
||||
|
||||
get_style_property("selection_alpha", selectionAlpha);
|
||||
}
|
||||
|
||||
} // namespace timeline
|
||||
|
|
|
|||
|
|
@ -71,6 +71,8 @@ private:
|
|||
int get_vertical_offset() const;
|
||||
|
||||
void set_vertical_offset(int offset);
|
||||
|
||||
void register_styles() const;
|
||||
|
||||
void read_styles();
|
||||
|
||||
|
|
@ -91,7 +93,10 @@ private:
|
|||
gavl_time_t beginShiftTimeOffset;
|
||||
int beginShiftVerticalOffset;
|
||||
|
||||
GdkColor background;
|
||||
// Style properties
|
||||
GdkColor backgroundColour;
|
||||
GdkColor selectionColour;
|
||||
float selectionAlpha;
|
||||
|
||||
lumiera::gui::widgets::TimelineWidget *timelineWidget;
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ TimelineRuler::TimelineRuler(
|
|||
minorLongTickHeight(0),
|
||||
minorShortTickHeight(0),
|
||||
minDivisionWidth(100),
|
||||
mouseChevronSize(5),
|
||||
selectionChevronSize(5),
|
||||
timelineWidget(timeline_widget)
|
||||
{
|
||||
REQUIRE(timelineWidget != NULL);
|
||||
|
|
@ -99,8 +101,8 @@ TimelineRuler::on_expose_event(GdkEventExpose* event)
|
|||
// Prepare to render via cairo
|
||||
const Allocation allocation = get_allocation();
|
||||
|
||||
Cairo::RefPtr<Context> cairo = window->create_cairo_context();
|
||||
REQUIRE(cairo);
|
||||
Cairo::RefPtr<Context> cr = window->create_cairo_context();
|
||||
REQUIRE(cr);
|
||||
|
||||
// Draw the ruler
|
||||
if(!rulerImage)
|
||||
|
|
@ -122,12 +124,12 @@ TimelineRuler::on_expose_event(GdkEventExpose* event)
|
|||
}
|
||||
|
||||
// Draw the cached ruler image
|
||||
cairo->set_source(rulerImage, 0, 0);
|
||||
cairo->paint();
|
||||
cr->set_source(rulerImage, 0, 0);
|
||||
cr->paint();
|
||||
|
||||
// Draw the overlays
|
||||
draw_mouse_chevron(cairo, allocation);
|
||||
draw_selection(cairo, allocation);
|
||||
draw_mouse_chevron(cr, allocation);
|
||||
draw_selection(cr, allocation);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -161,10 +163,10 @@ TimelineRuler::on_size_allocate(Gtk::Allocation& allocation)
|
|||
}
|
||||
|
||||
void
|
||||
TimelineRuler::draw_ruler(Cairo::RefPtr<Cairo::Context> cairo,
|
||||
TimelineRuler::draw_ruler(Cairo::RefPtr<Cairo::Context> cr,
|
||||
const Gdk::Rectangle ruler_rect)
|
||||
{
|
||||
REQUIRE(cairo);
|
||||
REQUIRE(cr);
|
||||
REQUIRE(ruler_rect.get_width() > 0);
|
||||
REQUIRE(ruler_rect.get_height() > 0);
|
||||
REQUIRE(timelineWidget != NULL);
|
||||
|
|
@ -178,18 +180,18 @@ TimelineRuler::draw_ruler(Cairo::RefPtr<Cairo::Context> cairo,
|
|||
Glib::RefPtr<Style> style = get_style();
|
||||
|
||||
// Render the background, and clip inside the area
|
||||
Gdk::Cairo::set_source_color(cairo, style->get_bg(STATE_NORMAL));
|
||||
cairo->rectangle(0, 0,
|
||||
Gdk::Cairo::set_source_color(cr, style->get_bg(STATE_NORMAL));
|
||||
cr->rectangle(0, 0,
|
||||
ruler_rect.get_width(), ruler_rect.get_height());
|
||||
cairo->fill_preserve();
|
||||
cairo->clip();
|
||||
cr->fill_preserve();
|
||||
cr->clip();
|
||||
|
||||
// Make sure we don't have impossible zoom
|
||||
if(time_scale <= 0)
|
||||
return;
|
||||
|
||||
// Render ruler annotations
|
||||
Gdk::Cairo::set_source_color(cairo, style->get_fg(STATE_NORMAL));
|
||||
Gdk::Cairo::set_source_color(cr, style->get_fg(STATE_NORMAL));
|
||||
|
||||
const gavl_time_t major_spacing = calculate_major_spacing();
|
||||
const gavl_time_t minor_spacing = major_spacing / 10;
|
||||
|
|
@ -205,31 +207,31 @@ TimelineRuler::draw_ruler(Cairo::RefPtr<Cairo::Context> cairo,
|
|||
{
|
||||
x = (int)(time_offset / time_scale - x_offset);
|
||||
|
||||
cairo->set_line_width(1);
|
||||
cr->set_line_width(1);
|
||||
|
||||
if(time_offset % major_spacing == 0)
|
||||
{
|
||||
// Draw the major grid-line
|
||||
cairo->move_to(x + 0.5, height - majorTickHeight);
|
||||
cairo->line_to(x + 0.5, height);
|
||||
cairo->stroke();
|
||||
cr->move_to(x + 0.5, height - majorTickHeight);
|
||||
cr->line_to(x + 0.5, height);
|
||||
cr->stroke();
|
||||
|
||||
// Draw the text
|
||||
pango_layout->set_text(lumiera_tmpbuf_print_time(time_offset));
|
||||
cairo->move_to(annotationHorzMargin + x, annotationVertMargin);
|
||||
pango_layout->add_to_cairo_context(cairo);
|
||||
cairo->fill();
|
||||
cr->move_to(annotationHorzMargin + x, annotationVertMargin);
|
||||
pango_layout->add_to_cairo_context(cr);
|
||||
cr->fill();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw the long or short minor grid-line
|
||||
if(time_offset % (minor_spacing * 2) == 0)
|
||||
cairo->move_to(x + 0.5, height - minorLongTickHeight);
|
||||
cr->move_to(x + 0.5, height - minorLongTickHeight);
|
||||
else
|
||||
cairo->move_to(x + 0.5, height - minorShortTickHeight);
|
||||
cr->move_to(x + 0.5, height - minorShortTickHeight);
|
||||
|
||||
cairo->line_to(x + 0.5, height);
|
||||
cairo->stroke();
|
||||
cr->line_to(x + 0.5, height);
|
||||
cr->stroke();
|
||||
}
|
||||
|
||||
time_offset += minor_spacing;
|
||||
|
|
@ -238,10 +240,10 @@ TimelineRuler::draw_ruler(Cairo::RefPtr<Cairo::Context> cairo,
|
|||
}
|
||||
|
||||
void
|
||||
TimelineRuler::draw_mouse_chevron(Cairo::RefPtr<Cairo::Context> cairo,
|
||||
TimelineRuler::draw_mouse_chevron(Cairo::RefPtr<Cairo::Context> cr,
|
||||
const Gdk::Rectangle ruler_rect)
|
||||
{
|
||||
REQUIRE(cairo);
|
||||
REQUIRE(cr);
|
||||
REQUIRE(ruler_rect.get_width() > 0);
|
||||
REQUIRE(ruler_rect.get_height() > 0);
|
||||
|
||||
|
|
@ -252,37 +254,37 @@ TimelineRuler::draw_mouse_chevron(Cairo::RefPtr<Cairo::Context> cairo,
|
|||
|
||||
// Set the source colour
|
||||
Glib::RefPtr<Style> style = get_style();
|
||||
Gdk::Cairo::set_source_color(cairo, style->get_fg(STATE_NORMAL));
|
||||
Gdk::Cairo::set_source_color(cr, style->get_fg(STATE_NORMAL));
|
||||
|
||||
cairo->move_to(mouseChevronOffset + 0.5,
|
||||
cr->move_to(mouseChevronOffset + 0.5,
|
||||
ruler_rect.get_height());
|
||||
cairo->rel_line_to(-mouseChevronSize, -mouseChevronSize);
|
||||
cairo->rel_line_to(2 * mouseChevronSize, 0);
|
||||
cr->rel_line_to(-mouseChevronSize, -mouseChevronSize);
|
||||
cr->rel_line_to(2 * mouseChevronSize, 0);
|
||||
|
||||
cairo->fill();
|
||||
cr->fill();
|
||||
}
|
||||
|
||||
void
|
||||
TimelineRuler::draw_selection(Cairo::RefPtr<Cairo::Context> cairo,
|
||||
TimelineRuler::draw_selection(Cairo::RefPtr<Cairo::Context> cr,
|
||||
const Gdk::Rectangle ruler_rect)
|
||||
{
|
||||
REQUIRE(cairo);
|
||||
REQUIRE(cr);
|
||||
REQUIRE(ruler_rect.get_width() > 0);
|
||||
REQUIRE(ruler_rect.get_height() > 0);
|
||||
REQUIRE(timelineWidget != NULL);
|
||||
|
||||
Glib::RefPtr<Style> style = get_style();
|
||||
Gdk::Cairo::set_source_color(cairo, style->get_fg(STATE_NORMAL));
|
||||
Gdk::Cairo::set_source_color(cr, style->get_fg(STATE_NORMAL));
|
||||
|
||||
// Draw the selection start chevron
|
||||
const int a = timelineWidget->time_to_x(
|
||||
timelineWidget->selectionStart) + 1;
|
||||
if(a >= 0 && a < ruler_rect.get_width())
|
||||
{
|
||||
cairo->move_to(a, ruler_rect.get_height());
|
||||
cairo->rel_line_to(0, -mouseChevronSize);
|
||||
cairo->rel_line_to(-mouseChevronSize, 0);
|
||||
cairo->fill();
|
||||
cr->move_to(a, ruler_rect.get_height());
|
||||
cr->rel_line_to(0, -selectionChevronSize);
|
||||
cr->rel_line_to(-selectionChevronSize, 0);
|
||||
cr->fill();
|
||||
}
|
||||
|
||||
// Draw the selection end chevron
|
||||
|
|
@ -290,10 +292,10 @@ TimelineRuler::draw_selection(Cairo::RefPtr<Cairo::Context> cairo,
|
|||
timelineWidget->selectionEnd);
|
||||
if(b >= 0 && b < ruler_rect.get_width())
|
||||
{
|
||||
cairo->move_to(b, ruler_rect.get_height());
|
||||
cairo->rel_line_to(0, -mouseChevronSize);
|
||||
cairo->rel_line_to(mouseChevronSize, 0);
|
||||
cairo->fill();
|
||||
cr->move_to(b, ruler_rect.get_height());
|
||||
cr->rel_line_to(0, -selectionChevronSize);
|
||||
cr->rel_line_to(selectionChevronSize, 0);
|
||||
cr->fill();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -394,6 +396,12 @@ TimelineRuler::register_styles() const
|
|||
"Mouse Chevron Size",
|
||||
"The height of the mouse chevron in pixels.",
|
||||
0, G_MAXINT, 5, G_PARAM_READABLE));
|
||||
|
||||
gtk_widget_class_install_style_property(klass,
|
||||
g_param_spec_int("selection_chevron_size",
|
||||
"Selection Chevron Size",
|
||||
"The height of the selection chevrons in pixels.",
|
||||
0, G_MAXINT, 5, G_PARAM_READABLE));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -406,6 +414,7 @@ TimelineRuler::read_styles()
|
|||
get_style_property("minor_short_tick_height", minorShortTickHeight);
|
||||
get_style_property("min_division_width", minDivisionWidth);
|
||||
get_style_property("mouse_chevron_size", mouseChevronSize);
|
||||
get_style_property("selection_chevron_size", selectionChevronSize);
|
||||
}
|
||||
|
||||
} // namespace timeline
|
||||
|
|
|
|||
|
|
@ -70,10 +70,10 @@ private:
|
|||
void draw_ruler(Cairo::RefPtr<Cairo::Context> cairo,
|
||||
const Gdk::Rectangle ruler_rect);
|
||||
|
||||
void draw_mouse_chevron(Cairo::RefPtr<Cairo::Context> cairo,
|
||||
void draw_mouse_chevron(Cairo::RefPtr<Cairo::Context> cr,
|
||||
const Gdk::Rectangle ruler_rect);
|
||||
|
||||
void draw_selection(Cairo::RefPtr<Cairo::Context> cairo,
|
||||
void draw_selection(Cairo::RefPtr<Cairo::Context> cr,
|
||||
const Gdk::Rectangle ruler_rect);
|
||||
|
||||
gavl_time_t calculate_major_spacing() const;
|
||||
|
|
@ -95,6 +95,7 @@ private:
|
|||
int minorShortTickHeight;
|
||||
int minDivisionWidth;
|
||||
int mouseChevronSize;
|
||||
int selectionChevronSize;
|
||||
|
||||
// Owner
|
||||
lumiera::gui::widgets::TimelineWidget *timelineWidget;
|
||||
|
|
|
|||
Loading…
Reference in a new issue