From 161ff9ecc9be47e9016ef5e347d347f7a336765b Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 14 Jan 2020 23:12:18 +0100 Subject: Add space for timing ruler --- libstorycode/gtk/gtknarrativeview.c | 18 +++++++--- libstorycode/gtk/gtknarrativeview.h | 1 + libstorycode/gtk/timing_ruler.c | 66 +++++++++++++++++++++++++++++++++++++ libstorycode/gtk/timing_ruler.h | 34 +++++++++++++++++++ meson.build | 1 + 5 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 libstorycode/gtk/timing_ruler.c create mode 100644 libstorycode/gtk/timing_ruler.h diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c index dbb5514..1787eac 100644 --- a/libstorycode/gtk/gtknarrativeview.c +++ b/libstorycode/gtk/gtknarrativeview.c @@ -40,6 +40,7 @@ #include "gtknarrativeview.h" #include "narrative_priv.h" +#include "timing_ruler.h" static void scroll_interface_init(GtkScrollable *iface) @@ -145,7 +146,7 @@ static void rewrap_range(GtkNarrativeView *e, int min, int max) static void update_size(GtkNarrativeView *e) { - e->w = e->visible_width; + e->w = e->visible_width - e->ruler_width; e->h = narrative_get_height(e->n); set_vertical_params(e); @@ -158,7 +159,7 @@ static gboolean gtknv_resize_sig(GtkWidget *widget, GdkEventConfigure *event, { e->visible_height = event->height; e->visible_width = event->width; - e->w = e->visible_width; + e->w = e->visible_width - e->ruler_width; rewrap_range(e, 0, e->n->n_items-1); @@ -518,6 +519,10 @@ static gboolean gtknv_draw_sig(GtkWidget *da, cairo_t *cr, GtkNarrativeView *e) cairo_translate(cr, -e->h_scroll_pos, -e->scroll_pos); + /* Space for ruler */ + cairo_save(cr); + cairo_translate(cr, e->ruler_width, 0.0); + /* Rendering background */ cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); cairo_rectangle(cr, 0.0, 0.0, e->w, e->h); @@ -532,6 +537,10 @@ static gboolean gtknv_draw_sig(GtkWidget *da, cairo_t *cr, GtkNarrativeView *e) cairo_translate(cr, e->n->space_l, e->n->space_t); gtknv_draw_overlay(cr, e); + /* Timing ruler */ + cairo_restore(cr); + draw_ruler(cr, e); + return FALSE; } @@ -899,7 +908,7 @@ static gboolean gtknv_button_press_sig(GtkWidget *da, GdkEventButton *event, { gdouble x, y; - x = event->x; + x = event->x - e->ruler_width; y = event->y + e->scroll_pos; /* Clicked an existing frame, no immediate dragging */ @@ -941,7 +950,7 @@ static gboolean gtknv_motion_sig(GtkWidget *da, GdkEventMotion *event, struct edit_pos old_sel_end; int minp, maxp; - x = event->x; + x = event->x - e->ruler_width; y = event->y + e->scroll_pos; if ( e->drag_status == NARRATIVE_DRAG_STATUS_COULD_DRAG ) { @@ -1210,6 +1219,7 @@ GtkWidget *gtk_narrative_view_new(Narrative *n) nview->n = n; nview->rewrap_needed = 0; nview->para_highlight = 0; + nview->ruler_width = 100.0; gtk_widget_set_size_request(GTK_WIDGET(nview), nview->w, nview->h); diff --git a/libstorycode/gtk/gtknarrativeview.h b/libstorycode/gtk/gtknarrativeview.h index 02045fd..2a2b0e9 100644 --- a/libstorycode/gtk/gtknarrativeview.h +++ b/libstorycode/gtk/gtknarrativeview.h @@ -82,6 +82,7 @@ struct _gtknarrativeview int visible_height; int visible_width; int rewrap_needed; + double ruler_width; /* Location of the cursor */ struct edit_pos cpos; diff --git a/libstorycode/gtk/timing_ruler.c b/libstorycode/gtk/timing_ruler.c new file mode 100644 index 0000000..66b925e --- /dev/null +++ b/libstorycode/gtk/timing_ruler.c @@ -0,0 +1,66 @@ +/* + * gtknarrativeview.c + * + * Copyright © 2013-2019 Thomas White + * + * This file is part of Colloquium. + * + * Colloquium is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#define _(x) gettext(x) + +#include + +#include "narrative_priv.h" +#include "gtknarrativeview.h" + + +void draw_ruler(cairo_t *cr, GtkNarrativeView *e) +{ + int start_item, end_item; + int i; + double start_item_time = 0.0; + double t; + + /* Background */ + cairo_set_source_rgba(cr, 0.9, 0.9, 0.9, 1.0); + cairo_rectangle(cr, 0.0, 0.0, e->ruler_width, e->h); + cairo_fill(cr); + + /* Which items are visible? */ + narrative_get_item_range(e->n, e->scroll_pos, e->scroll_pos+e->visible_height, + &start_item, &end_item); + + for ( i=0; in->items[i].estd_duration; + } + t = start_item_time; + for ( i=start_item; i<=end_item; i++ ) { + //printf("%4i: %.2f mins\n", i, t); + t += e->n->items[i].estd_duration; + } +} diff --git a/libstorycode/gtk/timing_ruler.h b/libstorycode/gtk/timing_ruler.h new file mode 100644 index 0000000..bd6c398 --- /dev/null +++ b/libstorycode/gtk/timing_ruler.h @@ -0,0 +1,34 @@ +/* + * timing_ruler.h + * + * Copyright © 2014-2019 Thomas White + * + * This file is part of Colloquium. + * + * Colloquium is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef TIMING_RULER_H +#define TIMING_RULER_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "gtknarrativeview.h" + +extern void draw_ruler(cairo_t *cr, GtkNarrativeView *e); + +#endif /* TIMING_RULER_H */ diff --git a/meson.build b/meson.build index 139c818..c325c67 100644 --- a/meson.build +++ b/meson.build @@ -88,6 +88,7 @@ libgtkstorycode_includes = include_directories('libstorycode/gtk') libgtkstorycode = library('gtkstorycode', ['libstorycode/gtk/gtknarrativeview.c', + 'libstorycode/gtk/timing_ruler.c', 'libstorycode/gtk/gtkslideview.c'], include_directories : libgtkstorycode_includes, dependencies : [gtk_dep, libstorycode_dep, mdep], -- cgit v1.2.3