aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am6
-rw-r--r--src/debugger.c178
-rw-r--r--src/debugger.h32
-rw-r--r--src/sc_editor.c13
4 files changed, 222 insertions, 7 deletions
diff --git a/Makefile.am b/Makefile.am
index b7773a3..88141fd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,13 +17,15 @@ src_colloquium_SOURCES = src/colloquium.c src/render.c \
src/imagestore.c src/pr_clock.c \
src/inhibit_screensaver.c \
src/sc_editor.c src/narrative_window.c \
- src/slide_window.c src/testcard.c src/print.c
+ src/slide_window.c src/testcard.c src/print.c \
+ src/debugger.c
EXTRA_DIST += src/presentation.h src/render.h \
src/slideshow.h src/sc_parse.h src/sc_interp.h \
src/imagestore.h src/pr_clock.h \
src/inhibit_screensaver.h src/print.h \
- src/sc_editor.h src/slide_window.h src/narrative_window.h
+ src/sc_editor.h src/slide_window.h src/narrative_window.h \
+ src/print.h src/debugger.h
src/default_stylesheet.o: src/default_stylesheet.sty
ld -r -b binary -o src/default_stylesheet.o src/default_stylesheet.sty
diff --git a/src/debugger.c b/src/debugger.c
new file mode 100644
index 0000000..a1bc0cd
--- /dev/null
+++ b/src/debugger.c
@@ -0,0 +1,178 @@
+/*
+ * print.c
+ *
+ * Copyright © 2017 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 <gtk/gtk.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "presentation.h"
+#include "narrative_window.h"
+#include "render.h"
+#include "frame.h"
+
+
+struct debugwindow
+{
+ GtkWidget *window;
+ GtkWidget *drawingarea;
+ struct frame *fr;
+ guint timeout;
+};
+
+
+static void plot_hr(cairo_t *cr, double *ypos, double width)
+{
+ cairo_move_to(cr, 10.0, *ypos+5.5);
+ cairo_line_to(cr, width-20.0, *ypos+5.5);
+ cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
+ cairo_set_line_width(cr, 1.0);
+ cairo_stroke(cr);
+ *ypos += 10.0;
+}
+
+
+static void plot_text(cairo_t *cr, double *ypos, PangoFontDescription *fontdesc,
+ const char *tmp)
+{
+ PangoLayout *layout;
+ PangoRectangle ext;
+
+ cairo_move_to(cr, 10.0, *ypos);
+
+ layout = pango_cairo_create_layout(cr);
+ pango_layout_set_text(layout, tmp, -1);
+ pango_layout_set_font_description(layout, fontdesc);
+
+ pango_layout_get_extents(layout, NULL, &ext);
+ *ypos += ext.height/PANGO_SCALE;
+
+ cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
+ pango_cairo_show_layout(cr, layout);
+
+ g_object_unref(layout);
+}
+
+
+static const char *str_type(enum para_type t)
+{
+ switch ( t ) {
+ case PARA_TYPE_TEXT : return "text";
+ case PARA_TYPE_CALLBACK : return "callback";
+ default : return "unknown";
+ }
+}
+
+
+static gboolean draw_sig(GtkWidget *da, cairo_t *cr, struct debugwindow *dbgw)
+{
+ int width, height;
+ char tmp[256];
+ PangoFontDescription *fontdesc;
+ int i;
+ double ypos = 10.0;
+
+ /* Background */
+ width = gtk_widget_get_allocated_width(GTK_WIDGET(da));
+ height = gtk_widget_get_allocated_height(GTK_WIDGET(da));
+ cairo_set_source_rgba(cr, 1.0, 0.8, 0.8, 1.0);
+ cairo_rectangle(cr, 0.0, 0.0, width, height);
+ cairo_fill(cr);
+
+ if ( dbgw->fr == NULL ) return FALSE;
+
+ fontdesc = pango_font_description_new();
+ pango_font_description_set_family_static(fontdesc, "Serif");
+ pango_font_description_set_style(fontdesc, PANGO_STYLE_ITALIC);
+ pango_font_description_set_absolute_size(fontdesc, 15*PANGO_SCALE);
+
+ snprintf(tmp, 255, "Frame %p has %i paragraphs", dbgw->fr, dbgw->fr->n_paras);
+ plot_text(cr, &ypos, fontdesc, tmp);
+
+ for ( i=0; i<dbgw->fr->n_paras; i++ ) {
+ enum para_type t = para_type(dbgw->fr->paras[i]);
+ plot_hr(cr, &ypos, width);
+ snprintf(tmp, 255, "Paragraph %i: type %s", i, str_type(t));
+ plot_text(cr, &ypos, fontdesc, tmp);
+
+ }
+
+ pango_font_description_free(fontdesc);
+
+ return FALSE;
+}
+
+
+static gboolean queue_redraw(void *vp)
+{
+ struct debugwindow *dbgw = vp;
+ gint w, h;
+ w = gtk_widget_get_allocated_width(GTK_WIDGET(dbgw->drawingarea));
+ h = gtk_widget_get_allocated_height(GTK_WIDGET(dbgw->drawingarea));
+ gtk_widget_queue_draw_area(GTK_WIDGET(dbgw->drawingarea), 0, 0, w, h);
+ return TRUE;
+}
+
+
+static gboolean close_sig(GtkWidget *widget, GdkEvent *event, struct debugwindow *dbgw)
+{
+ g_source_remove(dbgw->timeout);
+ free(dbgw);
+ return FALSE;
+}
+
+
+void open_debugger(struct frame *fr)
+{
+ struct debugwindow *dbgw;
+ GtkWidget *scroll;
+ dbgw = calloc(1, sizeof(struct debugwindow));
+ if ( dbgw == NULL ) return;
+
+ dbgw->fr = fr;
+
+ dbgw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_role(GTK_WINDOW(dbgw->window), "debugger");
+ gtk_window_set_title(GTK_WINDOW(dbgw->window), "Colloquium debugger");
+
+ scroll = gtk_scrolled_window_new(NULL, NULL);
+ gtk_container_add(GTK_CONTAINER(dbgw->window), scroll);
+
+ dbgw->drawingarea = gtk_drawing_area_new();
+ gtk_container_add(GTK_CONTAINER(scroll), dbgw->drawingarea);
+ gtk_widget_set_size_request(dbgw->drawingarea, 100, 2000);
+
+ g_signal_connect(G_OBJECT(dbgw->drawingarea), "draw",
+ G_CALLBACK(draw_sig), dbgw);
+
+ g_signal_connect(G_OBJECT(dbgw->window), "delete-event",
+ G_CALLBACK(close_sig), dbgw);
+
+ dbgw->timeout = g_timeout_add(1000, queue_redraw, dbgw);
+
+ gtk_widget_show_all(dbgw->window);
+}
diff --git a/src/debugger.h b/src/debugger.h
new file mode 100644
index 0000000..b3fcb46
--- /dev/null
+++ b/src/debugger.h
@@ -0,0 +1,32 @@
+/*
+ * debugger.h
+ *
+ * Copyright © 2017 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 DEBUGGER_H
+#define DEBUGGER_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+extern void open_debugger(struct frame *fr);
+
+#endif /* DEBUGGER_H */
diff --git a/src/sc_editor.c b/src/sc_editor.c
index db0f11d..721626e 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -42,6 +42,7 @@
#include "sc_interp.h"
#include "sc_editor.h"
#include "slideshow.h"
+#include "debugger.h"
static void scroll_interface_init(GtkScrollable *iface)
@@ -1495,11 +1496,13 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
break;
case GDK_KEY_F7 :
- debug_paragraphs(e);
- break;
-
- case GDK_KEY_F8 :
- show_sc_blocks(e->scblocks);
+ if ( event->state == GDK_CONTROL_MASK ) {
+ debug_paragraphs(e);
+ } else if ( event->state == GDK_SHIFT_MASK ) {
+ show_sc_blocks(e->scblocks);
+ } else {
+ open_debugger(e->cursor_frame);
+ }
break;
case GDK_KEY_C :