aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2020-01-14 23:12:18 +0100
committerThomas White <taw@bitwiz.me.uk>2020-01-14 23:12:18 +0100
commit161ff9ecc9be47e9016ef5e347d347f7a336765b (patch)
treea1070f660d8b7f484781f3f4c548069a48826d24
parentcc22260c8e70e01b8944ad1c62e20a65ffe9876f (diff)
Add space for timing ruler
-rw-r--r--libstorycode/gtk/gtknarrativeview.c18
-rw-r--r--libstorycode/gtk/gtknarrativeview.h1
-rw-r--r--libstorycode/gtk/timing_ruler.c66
-rw-r--r--libstorycode/gtk/timing_ruler.h34
-rw-r--r--meson.build1
5 files changed, 116 insertions, 4 deletions
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 <taw@bitwiz.org.uk>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <gtk/gtk.h>
+#include <assert.h>
+#include <math.h>
+#include <libintl.h>
+#define _(x) gettext(x)
+
+#include <narrative.h>
+
+#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; i<start_item; i++ ) {
+ start_item_time += e->n->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 <taw@bitwiz.org.uk>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef TIMING_RULER_H
+#define TIMING_RULER_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#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],