Update...
authorThomas White <taw@bitwiz.org.uk>
Wed, 18 Apr 2012 07:49:09 +0000 (09:49 +0200)
committerThomas White <taw@bitwiz.org.uk>
Wed, 18 Apr 2012 07:49:09 +0000 (09:49 +0200)
12 files changed:
Makefile.am
src/loadsave.c
src/mainwindow.c
src/presentation.c
src/presentation.h
src/slide_render.c [deleted file]
src/slide_render.h [deleted file]
src/slideshow.c
src/storycode.c [new file with mode: 0644]
src/storycode.h [new file with mode: 0644]
src/stylesheet.c
src/stylesheet.h

index 2a6cb28..c7379f5 100644 (file)
@@ -9,17 +9,15 @@ AM_CPPFLAGS = -DDATADIR=\""$(datadir)"\" -I$(top_builddir)/lib -I$(top_srcdir)/l
 LDADD = $(top_builddir)/lib/libgnu.a @IGNORE_UNUSED_LIBRARIES_CFLAGS@
 
 src_colloquium_SOURCES = src/colloquium.c src/presentation.c src/mainwindow.c \
-                         src/slide_render.c src/objects.c src/slideshow.c \
-                         src/stylesheet.c src/loadsave.c src/tool_text.c \
-                         src/tool_select.c src/tool_image.c src/notes.c \
+                         src/storycode.c src/slideshow.c \
+                         src/stylesheet.c src/loadsave.c src/notes.c \
                          src/stylesheet-editor.c
 
 INCLUDES = "-I$(top_srcdir)/data"
 
-EXTRA_DIST += src/presentation.h src/mainwindow.h src/slide_render .h \
-              src/objects.h src/slideshow.h src/stylesheet.h src/loadsave.h \
-              src/tool_text.h src/tool_select.h src/tool_image.h src/notes.h \
-              src/stylesheet-editor.h
+EXTRA_DIST += src/presentation.h src/mainwindow.h src/storycode.h \
+              src/slideshow.h src/stylesheet.h src/loadsave.h \
+              src/notes.h src/stylesheet-editor.h
 
 colloquiumdir = $(datadir)/colloquium
 colloquium_DATA = data/colloquium.ui
index 477cd2d..aac2e4a 100644 (file)
@@ -34,7 +34,6 @@
 #include "presentation.h"
 #include "objects.h"
 #include "stylesheet.h"
-#include "slide_render.h"
 #include "mainwindow.h"
 #include "notes.h"
 
index c0e854f..67d3374 100644 (file)
@@ -34,7 +34,7 @@
 
 #include "presentation.h"
 #include "mainwindow.h"
-#include "slide_render.h"
+#include "storycode.h"
 #include "objects.h"
 #include "slideshow.h"
 #include "stylesheet.h"
@@ -484,7 +484,7 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
        GtkWidget *toolbar;
        GtkWidget *menu;
        GtkWidget *item;
-       int i;
+//     int i;
        GtkActionEntry entries[] = {
 
                { "FileAction", NULL, "_File", NULL, NULL, NULL },
@@ -577,16 +577,16 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
        menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu));
        item = gtk_separator_menu_item_new();
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
-       for ( i=1; i<p->ss->n_frame_classes; i++ )
-       {
-               char *name;
-               name = p->ss->frame_classes[i]->name;
-               item = gtk_menu_item_new_with_label(name);
-               gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
-               g_signal_connect(G_OBJECT(item), "activate",
-                                G_CALLBACK(add_furniture), p);
-
-       }
+//     for ( i=1; i<p->ss->n_frame_classes; i++ )
+//     {
+//             char *name;
+//             name = p->ss->frame_classes[i]->name;
+//             item = gtk_menu_item_new_with_label(name);
+//             gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+//             g_signal_connect(G_OBJECT(item), "activate",
+//                              G_CALLBACK(add_furniture), p);
+//
+//     }
        update_toolbar(p);
 }
 
@@ -601,8 +601,8 @@ static gint close_sig(GtkWidget *window, struct presentation *p)
 static void redraw_frame(struct frame *o)
 {
        if ( o == NULL ) return;
-       gdk_window_invalidate_rect(o->parent->parent->drawingarea->window,
-                                  NULL, FALSE);
+//     gdk_window_invalidate_rect(o->parent->parent->drawingarea->window,
+//                                NULL, FALSE);
 }
 
 
@@ -615,7 +615,7 @@ void redraw_overlay(struct presentation *p)
 static gboolean im_commit_sig(GtkIMContext *im, gchar *str,
                               struct presentation *p)
 {
-       if ( p->editing_object == NULL ) {
+       if ( p->cur_frame == NULL ) {
                if ( str[0] == 'b' ) {
                        check_toggle_blank(p);
                } else {
@@ -638,7 +638,7 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
                                           event);
        if ( r ) return FALSE;  /* IM ate it */
 
-       p->cur_tool->key_pressed(p->editing_object, event->keyval, p->cur_tool);
+//     p->cur_tool->key_pressed(p->editing_object, event->keyval, p->cur_tool);
 
        switch ( event->keyval ) {
 
@@ -652,12 +652,12 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
 
                case GDK_KEY_Escape :
                if ( p->slideshow != NULL ) end_slideshow(p);
-               redraw_object(p->editing_object);
-               p->editing_object = NULL;
+               redraw_frame(p->cur_frame);
+               p->cur_frame = NULL;
                break;
 
                case GDK_KEY_Return :
-               p->cur_tool->im_commit(p->editing_object, "\n", p->cur_tool);
+               //p->cur_tool->im_commit(p->cur_frame, "\n", p->cur_tool);
                break;
 
                case GDK_KEY_B :
@@ -682,27 +682,27 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
 
 static void draw_overlay(cairo_t *cr, struct presentation *p)
 {
-       struct object *o = p->editing_object;
+       struct frame *fr = p->cur_frame;
 
-       if ( o != NULL ) {
+       if ( fr != NULL ) {
                /* Draw margins */
-               cairo_move_to(cr, o->style->margin_left, -p->border_offs_y);
-               cairo_line_to(cr, o->style->margin_left,
+               cairo_move_to(cr, fr->cl->margin_left, -p->border_offs_y);
+               cairo_line_to(cr, fr->cl->margin_left,
                                  p->slide_height+p->border_offs_y);
 
-               cairo_move_to(cr, p->slide_width-o->style->margin_right,
+               cairo_move_to(cr, p->slide_width-fr->cl->margin_right,
                                  -p->border_offs_y);
-               cairo_line_to(cr, p->slide_width-o->style->margin_right,
+               cairo_line_to(cr, p->slide_width-fr->cl->margin_right,
                                  p->slide_height+p->border_offs_y);
 
-               cairo_move_to(cr, -p->border_offs_x, o->style->margin_top);
+               cairo_move_to(cr, -p->border_offs_x, fr->cl->margin_top);
                cairo_line_to(cr, p->slide_width+p->border_offs_x,
-                                 o->style->margin_top);
+                                 fr->cl->margin_top);
 
                cairo_move_to(cr, -p->border_offs_x,
-                                 p->slide_height-o->style->margin_bottom);
+                                 p->slide_height-fr->cl->margin_bottom);
                cairo_line_to(cr, p->slide_width+p->border_offs_x,
-                                 p->slide_height-o->style->margin_bottom);
+                                 p->slide_height-fr->cl->margin_bottom);
 
                cairo_set_source_rgb(cr, 0.2, 0.2, 0.2);
                cairo_set_line_width(cr, 1.0);
@@ -775,7 +775,7 @@ int open_mainwindow(struct presentation *p)
        GtkWidget *window;
        GtkWidget *vbox;
        GtkWidget *sw;
-       GtkTargetEntry targets[1];
+//     GtkTargetEntry targets[1];
 
        if ( p->window != NULL ) {
                fprintf(stderr, "Presentation window is already open!\n");
@@ -814,16 +814,16 @@ int open_mainwindow(struct presentation *p)
                               | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
                               | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
 
-       g_signal_connect(G_OBJECT(p->drawingarea), "button-press-event",
-                        G_CALLBACK(button_press_sig), p);
-       g_signal_connect(G_OBJECT(p->drawingarea), "button-release-event",
-                        G_CALLBACK(button_release_sig), p);
+//     g_signal_connect(G_OBJECT(p->drawingarea), "button-press-event",
+//                      G_CALLBACK(button_press_sig), p);
+//     g_signal_connect(G_OBJECT(p->drawingarea), "button-release-event",
+//                      G_CALLBACK(button_release_sig), p);
        g_signal_connect(G_OBJECT(p->drawingarea), "key-press-event",
                         G_CALLBACK(key_press_sig), p);
        g_signal_connect(G_OBJECT(p->drawingarea), "expose-event",
                         G_CALLBACK(expose_sig), p);
-       g_signal_connect(G_OBJECT(p->drawingarea), "motion-notify-event",
-                        G_CALLBACK(motion_sig), p);
+//     g_signal_connect(G_OBJECT(p->drawingarea), "motion-notify-event",
+//                      G_CALLBACK(motion_sig), p);
 
        /* Input method */
        p->im_context = gtk_im_multicontext_new();
index 702ac7a..2ca1cd6 100644 (file)
@@ -31,7 +31,6 @@
 #include <gtk/gtk.h>
 
 #include "presentation.h"
-#include "slide_render.h"
 #include "objects.h"
 #include "stylesheet.h"
 #include "tool_select.h"
index c28dfe2..ddd8b4e 100644 (file)
@@ -35,6 +35,7 @@
 struct slide
 {
        struct presentation *parent;
+       struct slide_template *st;
 
        /* Any of these may be NULL */
        cairo_surface_t *rendered_proj;
diff --git a/src/slide_render.c b/src/slide_render.c
deleted file mode 100644 (file)
index 7f83ec8..0000000
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * slide_render.c
- *
- * Colloquium - A tiny presentation program
- *
- * Copyright (c) 2011 Thomas White <taw@bitwiz.org.uk>
- *
- * This program 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 <cairo.h>
-#include <cairo-pdf.h>
-#include <pango/pangocairo.h>
-#include <assert.h>
-
-#include "slide_render.h"
-#include "presentation.h"
-#include "objects.h"
-#include "stylesheet.h"
-
-
-static void render_bgblock(cairo_t *cr, struct bgblock *b)
-{
-       GdkColor col1;
-       GdkColor col2;
-       cairo_pattern_t *patt = NULL;
-       double cx, cy, r, r1, r2;
-
-       cairo_rectangle(cr, b->min_x, b->min_y,
-                           b->max_x - b->min_x,
-                           b->max_y - b->min_y);
-
-       switch ( b->type ) {
-
-               case BGBLOCK_SOLID :
-               gdk_color_parse(b->colour1, &col1);
-               gdk_cairo_set_source_color(cr, &col1);
-               /* FIXME: Honour alpha as well */
-               cairo_fill(cr);
-               break;
-
-               case BGBLOCK_GRADIENT_CIRCULAR :
-               cx = b->min_x + (b->max_x-b->min_x)/2.0;
-               cy = b->min_y + (b->max_y-b->min_y)/2.0;
-               r1 = (b->max_x-b->min_x)/2.0;
-               r2 = (b->max_y-b->min_y)/2.0;
-               r = r1 > r2 ? r1 : r2;
-               patt = cairo_pattern_create_radial(cx, cy, r, cx, cy, 0.0);
-               /* Fall-through */
-
-               case BGBLOCK_GRADIENT_X :
-               if ( patt == NULL ) {
-                       patt = cairo_pattern_create_linear(b->min_x, 0.0,
-                                                          b->max_y, 0.0);
-               }
-               /* Fall-through */
-
-               case BGBLOCK_GRADIENT_Y :
-               if ( patt == NULL ) {
-                       patt = cairo_pattern_create_linear(0.0, b->min_y,
-                                                          0.0, b->max_y);
-               }
-
-               gdk_color_parse(b->colour1, &col1);
-               gdk_color_parse(b->colour2, &col2);
-               cairo_pattern_add_color_stop_rgba(patt, 0.0, col1.red/65535.0,
-                                                            col1.green/65535.0,
-                                                            col1.blue/65535.0,
-                                                            b->alpha1);
-               cairo_pattern_add_color_stop_rgba(patt, 1.0, col2.red/65535.0,
-                                                            col2.green/65535.0,
-                                                            col2.blue/65535.0,
-                                                            b->alpha2);
-               cairo_set_source(cr, patt);
-               cairo_fill(cr);
-               cairo_pattern_destroy(patt);
-               break;
-
-               case BGBLOCK_IMAGE :
-               cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
-               cairo_fill(cr);
-
-       }
-}
-
-
-static void render_slide_bits(struct slide *s, cairo_t *cr)
-{
-       int i;
-       cairo_font_options_t *fopts;
-
-       fopts = cairo_font_options_create();
-       cairo_font_options_set_hint_style(fopts, CAIRO_HINT_STYLE_NONE);
-       cairo_font_options_set_hint_metrics(fopts, CAIRO_HINT_METRICS_OFF);
-       cairo_font_options_set_antialias(fopts, CAIRO_ANTIALIAS_SUBPIXEL);
-       cairo_set_font_options(cr, fopts);
-
-       for ( i=0; i<s->parent->ss->n_bgblocks; i++ ) {
-               render_bgblock(cr, &s->parent->ss->bgblocks[i]);
-       }
-
-       for ( i=0; i<s->num_objects; i++ ) {
-
-               struct object *o = s->objects[i];
-
-               o->render_object(cr, o);
-
-       }
-
-       cairo_font_options_destroy(fopts);
-}
-
-static cairo_surface_t *render_slide(struct slide *s, int w, int h)
-{
-       cairo_surface_t *surf;
-       cairo_t *cr;
-
-       surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
-
-       cr = cairo_create(surf);
-       cairo_scale(cr, w/s->parent->slide_width, h/s->parent->slide_height);
-
-       render_slide_bits(s, cr);
-
-       cairo_destroy(cr);
-
-       return surf;
-}
-
-
-void redraw_slide(struct slide *s)
-{
-       int w, h;
-
-       if ( s->rendered_thumb != NULL ) {
-               cairo_surface_destroy(s->rendered_thumb);
-       }
-
-       w = s->parent->thumb_slide_width;
-       h = (s->parent->slide_height/s->parent->slide_width) * w;
-       s->rendered_thumb = render_slide(s, w, h);
-       /* FIXME: Request redraw for slide sorter if open */
-
-       /* Is this slide currently open in the editor? */
-       if ( s == s->parent->cur_edit_slide ) {
-
-               GtkWidget *da;
-
-               if ( s->rendered_edit != NULL ) {
-                       cairo_surface_destroy(s->rendered_edit);
-               }
-
-               w = s->parent->edit_slide_width;
-               h = (s->parent->slide_height/s->parent->slide_width) * w;
-               s->rendered_edit = render_slide(s, w, h);
-
-               da = s->parent->drawingarea;
-               if ( da != NULL ) {
-                       gdk_window_invalidate_rect(da->window, NULL, FALSE);
-               }
-
-       }
-
-       /* Is this slide currently being displayed on the projector? */
-       if ( s == s->parent->cur_proj_slide ) {
-
-               GtkWidget *da;
-
-               if ( s->rendered_proj != NULL ) {
-                       cairo_surface_destroy(s->rendered_proj);
-               }
-
-               w = s->parent->proj_slide_width;
-               h = (s->parent->slide_height/s->parent->slide_width) * w;
-               s->rendered_proj = render_slide(s, w, h);
-
-               da = s->parent->ss_drawingarea;
-               if ( da != NULL ) {
-                       gdk_window_invalidate_rect(da->window, NULL, FALSE);
-               }
-
-       }
-}
-
-
-void draw_rubberband_box(cairo_t *cr, double x, double y,
-                         double width, double height)
-{
-       cairo_new_path(cr);
-       cairo_rectangle(cr, x, y, width, height);
-       cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
-       cairo_set_line_width(cr, 0.5);
-       cairo_stroke(cr);
-}
-
-
-void draw_resize_handle(cairo_t *cr, double x, double y)
-{
-       cairo_new_path(cr);
-       cairo_rectangle(cr, x, y, 20.0, 20.0);
-       cairo_set_source_rgba(cr, 0.9, 0.9, 0.9, 0.5);
-       cairo_fill(cr);
-}
-
-
-void draw_editing_box(cairo_t *cr, double xmin, double ymin,
-                      double width, double height)
-{
-       const double dash[] = {2.0, 2.0};
-
-       cairo_new_path(cr);
-       cairo_rectangle(cr, xmin-5.0, ymin-5.0, width+10.0, height+10.0);
-       cairo_set_source_rgb(cr, 0.0, 0.69, 1.0);
-       cairo_set_line_width(cr, 0.5);
-       cairo_stroke(cr);
-
-       cairo_new_path(cr);
-       cairo_rectangle(cr, xmin, ymin, width, height);
-       cairo_set_dash(cr, dash, 2, 0.0);
-       cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
-       cairo_set_line_width(cr, 0.1);
-       cairo_stroke(cr);
-
-       cairo_set_dash(cr, NULL, 0, 0.0);
-}
-
-
-int export_pdf(struct presentation *p, const char *filename)
-{
-       int i;
-       cairo_surface_t *surf;
-       cairo_t *cr;
-
-       surf = cairo_pdf_surface_create(filename, p->slide_width,
-                                                 p->slide_height);
-
-       if ( cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS ) {
-               fprintf(stderr, "Couldn't create Cairo surface\n");
-               return 1;
-       }
-
-       cr = cairo_create(surf);
-
-       for ( i=0; i<p->num_slides; i++ ) {
-               render_slide_bits(p->slides[i], cr);
-               cairo_surface_show_page(surf);
-       }
-
-       cairo_surface_finish(surf);
-       cairo_destroy(cr);
-
-       return 0;
-}
diff --git a/src/slide_render.h b/src/slide_render.h
deleted file mode 100644 (file)
index 34f4d85..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * slide_render.h
- *
- * Colloquium - A tiny presentation program
- *
- * Copyright (c) 2011 Thomas White <taw@bitwiz.org.uk>
- *
- * This program 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 SLIDE_RENDER_H
-#define SLIDE_RENDER_H
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-
-#include "presentation.h"
-
-extern void redraw_slide(struct slide *s);
-
-extern void draw_rubberband_box(cairo_t *cr, double xmin, double ymin,
-                                double width, double height);
-
-extern void draw_resize_handle(cairo_t *cr, double x, double y);
-
-extern void draw_editing_box(cairo_t *cr, double xmin, double ymin,
-                             double width, double height);
-
-extern int export_pdf(struct presentation *p, const char *filename);
-
-#endif /* SLIDE_RENDER_H */
index 0f1c5cd..bcbf528 100644 (file)
@@ -32,7 +32,7 @@
 #include <gdk/gdkkeysyms.h>
 
 #include "presentation.h"
-#include "slide_render.h"
+#include "storycode.h"
 #include "mainwindow.h"
 #include "notes.h"
 
diff --git a/src/storycode.c b/src/storycode.c
new file mode 100644 (file)
index 0000000..a0a6da9
--- /dev/null
@@ -0,0 +1,270 @@
+/*
+ * slide_render.c
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2011 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This program 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 <cairo.h>
+#include <cairo-pdf.h>
+#include <pango/pangocairo.h>
+#include <assert.h>
+
+#include "storycode.h"
+#include "presentation.h"
+#include "objects.h"
+#include "stylesheet.h"
+
+
+static void render_bgblock(cairo_t *cr, struct bgblock *b)
+{
+       GdkColor col1;
+       GdkColor col2;
+       cairo_pattern_t *patt = NULL;
+       double cx, cy, r, r1, r2;
+
+       cairo_rectangle(cr, b->min_x, b->min_y,
+                           b->max_x - b->min_x,
+                           b->max_y - b->min_y);
+
+       switch ( b->type ) {
+
+               case BGBLOCK_SOLID :
+               gdk_color_parse(b->colour1, &col1);
+               gdk_cairo_set_source_color(cr, &col1);
+               /* FIXME: Honour alpha as well */
+               cairo_fill(cr);
+               break;
+
+               case BGBLOCK_GRADIENT_CIRCULAR :
+               cx = b->min_x + (b->max_x-b->min_x)/2.0;
+               cy = b->min_y + (b->max_y-b->min_y)/2.0;
+               r1 = (b->max_x-b->min_x)/2.0;
+               r2 = (b->max_y-b->min_y)/2.0;
+               r = r1 > r2 ? r1 : r2;
+               patt = cairo_pattern_create_radial(cx, cy, r, cx, cy, 0.0);
+               /* Fall-through */
+
+               case BGBLOCK_GRADIENT_X :
+               if ( patt == NULL ) {
+                       patt = cairo_pattern_create_linear(b->min_x, 0.0,
+                                                          b->max_y, 0.0);
+               }
+               /* Fall-through */
+
+               case BGBLOCK_GRADIENT_Y :
+               if ( patt == NULL ) {
+                       patt = cairo_pattern_create_linear(0.0, b->min_y,
+                                                          0.0, b->max_y);
+               }
+
+               gdk_color_parse(b->colour1, &col1);
+               gdk_color_parse(b->colour2, &col2);
+               cairo_pattern_add_color_stop_rgba(patt, 0.0, col1.red/65535.0,
+                                                            col1.green/65535.0,
+                                                            col1.blue/65535.0,
+                                                            b->alpha1);
+               cairo_pattern_add_color_stop_rgba(patt, 1.0, col2.red/65535.0,
+                                                            col2.green/65535.0,
+                                                            col2.blue/65535.0,
+                                                            b->alpha2);
+               cairo_set_source(cr, patt);
+               cairo_fill(cr);
+               cairo_pattern_destroy(patt);
+               break;
+
+               case BGBLOCK_IMAGE :
+               cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
+               cairo_fill(cr);
+
+       }
+}
+
+
+static void render_slide_bits(struct slide *s, cairo_t *cr)
+{
+       int i;
+       cairo_font_options_t *fopts;
+
+       fopts = cairo_font_options_create();
+       cairo_font_options_set_hint_style(fopts, CAIRO_HINT_STYLE_NONE);
+       cairo_font_options_set_hint_metrics(fopts, CAIRO_HINT_METRICS_OFF);
+       cairo_font_options_set_antialias(fopts, CAIRO_ANTIALIAS_SUBPIXEL);
+       cairo_set_font_options(cr, fopts);
+
+       for ( i=0; i<s->st->n_bgblocks; i++ ) {
+               render_bgblock(cr, s->st->bgblocks[i]);
+       }
+
+       for ( i=0; i<s->num_objects; i++ ) {
+
+               struct object *o = s->objects[i];
+
+               o->render_object(cr, o);
+
+       }
+
+       cairo_font_options_destroy(fopts);
+}
+
+static cairo_surface_t *render_slide(struct slide *s, int w, int h)
+{
+       cairo_surface_t *surf;
+       cairo_t *cr;
+
+       surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
+
+       cr = cairo_create(surf);
+       cairo_scale(cr, w/s->parent->slide_width, h/s->parent->slide_height);
+
+       render_slide_bits(s, cr);
+
+       cairo_destroy(cr);
+
+       return surf;
+}
+
+
+void redraw_slide(struct slide *s)
+{
+       int w, h;
+
+       if ( s->rendered_thumb != NULL ) {
+               cairo_surface_destroy(s->rendered_thumb);
+       }
+
+       w = s->parent->thumb_slide_width;
+       h = (s->parent->slide_height/s->parent->slide_width) * w;
+       s->rendered_thumb = render_slide(s, w, h);
+       /* FIXME: Request redraw for slide sorter if open */
+
+       /* Is this slide currently open in the editor? */
+       if ( s == s->parent->cur_edit_slide ) {
+
+               GtkWidget *da;
+
+               if ( s->rendered_edit != NULL ) {
+                       cairo_surface_destroy(s->rendered_edit);
+               }
+
+               w = s->parent->edit_slide_width;
+               h = (s->parent->slide_height/s->parent->slide_width) * w;
+               s->rendered_edit = render_slide(s, w, h);
+
+               da = s->parent->drawingarea;
+               if ( da != NULL ) {
+                       gdk_window_invalidate_rect(da->window, NULL, FALSE);
+               }
+
+       }
+
+       /* Is this slide currently being displayed on the projector? */
+       if ( s == s->parent->cur_proj_slide ) {
+
+               GtkWidget *da;
+
+               if ( s->rendered_proj != NULL ) {
+                       cairo_surface_destroy(s->rendered_proj);
+               }
+
+               w = s->parent->proj_slide_width;
+               h = (s->parent->slide_height/s->parent->slide_width) * w;
+               s->rendered_proj = render_slide(s, w, h);
+
+               da = s->parent->ss_drawingarea;
+               if ( da != NULL ) {
+                       gdk_window_invalidate_rect(da->window, NULL, FALSE);
+               }
+
+       }
+}
+
+
+void draw_rubberband_box(cairo_t *cr, double x, double y,
+                         double width, double height)
+{
+       cairo_new_path(cr);
+       cairo_rectangle(cr, x, y, width, height);
+       cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
+       cairo_set_line_width(cr, 0.5);
+       cairo_stroke(cr);
+}
+
+
+void draw_resize_handle(cairo_t *cr, double x, double y)
+{
+       cairo_new_path(cr);
+       cairo_rectangle(cr, x, y, 20.0, 20.0);
+       cairo_set_source_rgba(cr, 0.9, 0.9, 0.9, 0.5);
+       cairo_fill(cr);
+}
+
+
+void draw_editing_box(cairo_t *cr, double xmin, double ymin,
+                      double width, double height)
+{
+       const double dash[] = {2.0, 2.0};
+
+       cairo_new_path(cr);
+       cairo_rectangle(cr, xmin-5.0, ymin-5.0, width+10.0, height+10.0);
+       cairo_set_source_rgb(cr, 0.0, 0.69, 1.0);
+       cairo_set_line_width(cr, 0.5);
+       cairo_stroke(cr);
+
+       cairo_new_path(cr);
+       cairo_rectangle(cr, xmin, ymin, width, height);
+       cairo_set_dash(cr, dash, 2, 0.0);
+       cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
+       cairo_set_line_width(cr, 0.1);
+       cairo_stroke(cr);
+
+       cairo_set_dash(cr, NULL, 0, 0.0);
+}
+
+
+int export_pdf(struct presentation *p, const char *filename)
+{
+       int i;
+       cairo_surface_t *surf;
+       cairo_t *cr;
+
+       surf = cairo_pdf_surface_create(filename, p->slide_width,
+                                                 p->slide_height);
+
+       if ( cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS ) {
+               fprintf(stderr, "Couldn't create Cairo surface\n");
+               return 1;
+       }
+
+       cr = cairo_create(surf);
+
+       for ( i=0; i<p->num_slides; i++ ) {
+               render_slide_bits(p->slides[i], cr);
+               cairo_surface_show_page(surf);
+       }
+
+       cairo_surface_finish(surf);
+       cairo_destroy(cr);
+
+       return 0;
+}
diff --git a/src/storycode.h b/src/storycode.h
new file mode 100644 (file)
index 0000000..34f4d85
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * slide_render.h
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2011 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This program 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 SLIDE_RENDER_H
+#define SLIDE_RENDER_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include "presentation.h"
+
+extern void redraw_slide(struct slide *s);
+
+extern void draw_rubberband_box(cairo_t *cr, double xmin, double ymin,
+                                double width, double height);
+
+extern void draw_resize_handle(cairo_t *cr, double x, double y);
+
+extern void draw_editing_box(cairo_t *cr, double xmin, double ymin,
+                             double width, double height);
+
+extern int export_pdf(struct presentation *p, const char *filename);
+
+#endif /* SLIDE_RENDER_H */
index 6de86bc..a4b3543 100644 (file)
@@ -37,8 +37,8 @@
 
 struct _stylesheet
 {
-       struct slide_template **templates;
-       int                     n_templates;
+       struct slide_template **slide_templates;
+       int                     n_slide_templates;
 };
 
 
@@ -67,7 +67,7 @@ struct slide_template *new_slide_template(StyleSheet *ss, const char *name)
                return NULL;
        }
        ss->slide_templates = slide_templates_new;
-       ss->slide_templates[n] = ss;
+       ss->slide_templates[n] = st;
        ss->n_slide_templates = n+1;
 
        return st;
@@ -93,7 +93,7 @@ struct frame_class *new_frame_class(struct slide_template *st, const char *name)
                free(fc);
                return NULL;
        }
-       st->frame_classe = frame_classes_new;
+       st->frame_classes = frame_classes_new;
        st->frame_classes[n] = fc;
        st->n_frame_classes = n+1;
 
@@ -125,7 +125,7 @@ static void free_slide_template(struct slide_template *st)
        free(st->frame_classes);
 
        for ( i=0; i<st->n_bgblocks; i++ ) {
-               free_frame_class(st->bgblocks[i]);
+               free_bgblock(st->bgblocks[i]);
        }
        free(st->bgblocks);
 
@@ -158,21 +158,31 @@ void default_stylesheet(StyleSheet *ss)
        fc->margin_right = 20.0;
        fc->margin_top = 20.0;
        fc->margin_bottom = 20.0;
-       fc->sc_prologue = strdup("\FF'Sans 50';\FC'#000000000000';");
+       fc->sc_prologue = strdup("\\FF'Sans 50';\\FC'#000000000000';");
 
        fc = new_frame_class(st, "Author(s)");
        fc->margin_left = 20.0;
        fc->margin_right = 20.0;
        fc->margin_top = 20.0;
        fc->margin_bottom = 20.0;
-       fc->sc_prologue = strdup("\FF'Sans 30';\FC'#000000000000';");
+       fc->sc_prologue = strdup("\\FF'Sans 30';\\FC'#000000000000';");
 
        fc = new_frame_class(st, "Date");
        fc->margin_left = 20.0;
        fc->margin_right = 20.0;
        fc->margin_top = 20.0;
        fc->margin_bottom = 20.0;
-       fc->sc_prologue = strdup("\FF'Sans 30';\FC'#000000000000';");
+       fc->sc_prologue = strdup("\\FF'Sans 30';\\FC'#000000000000';");
+
+       st->bgblocks = malloc(sizeof(struct bgblock));
+       st->n_bgblocks = 1;
+       st->bgblocks[0]->type = BGBLOCK_SOLID;
+       st->bgblocks[0]->min_x = 0.0;
+       st->bgblocks[0]->max_x = 1024.0;
+       st->bgblocks[0]->min_y = 0.0;
+       st->bgblocks[0]->max_y = 768.0;
+       st->bgblocks[0]->colour1 = strdup("#eeeeeeeeeeee");
+       st->bgblocks[0]->alpha1 = 1.0;
 
        st = new_slide_template(ss, "Slide");
 
@@ -181,28 +191,28 @@ void default_stylesheet(StyleSheet *ss)
        fc->margin_right = 20.0;
        fc->margin_top = 20.0;
        fc->margin_bottom = 20.0;
-       fc->sc_prologue = strdup("\FF'Sans 18';\FC'#000000000000';");
+       fc->sc_prologue = strdup("\\FF'Sans 18';\\FC'#000000000000';");
 
        fc = new_frame_class(st, "Title");
        fc->margin_left = 20.0;
        fc->margin_right = 20.0;
        fc->margin_top = 20.0;
        fc->margin_bottom = 20.0;
-       fc->sc_prologue = strdup("\FF'Sans 40';\FC'#000000000000';");
+       fc->sc_prologue = strdup("\\FF'Sans 40';\\FC'#000000000000';");
 
        fc = new_frame_class(st, "Credit");
        fc->margin_left = 20.0;
        fc->margin_right = 20.0;
        fc->margin_top = 20.0;
        fc->margin_bottom = 35.0;
-       fc->sc_prologue = strdup("\FF'Sans 14';\FC'#000000000000';");
+       fc->sc_prologue = strdup("\\FF'Sans 14';\\FC'#000000000000';");
 
        fc = new_frame_class(st, "Date");
        fc->margin_left = 600.0;
        fc->margin_right = 100.0;
        fc->margin_top = 745.0;
        fc->margin_bottom = 5.0;
-       fc->sc_prologue = strdup("\FF'Sans 12';\FC'#999999999999';");
+       fc->sc_prologue = strdup("\\FF'Sans 12';\\FC'#999999999999';");
 
        fc = new_frame_class(st, "Slide number");
        fc->margin_left = 600.0;
@@ -218,15 +228,15 @@ void default_stylesheet(StyleSheet *ss)
        fc->margin_bottom = 5.0;
        fc->sc_prologue = strdup("\\FF'Sans 12';\\FC'#999999999999';\\JC\\VC");
 
-       ss->bgblocks = malloc(sizeof(struct bgblock));
-       ss->n_bgblocks = 1;
-       ss->bgblocks[0].type = BGBLOCK_SOLID;
-       ss->bgblocks[0].min_x = 0.0;
-       ss->bgblocks[0].max_x = 1024.0;
-       ss->bgblocks[0].min_y = 0.0;
-       ss->bgblocks[0].max_y = 768.0;
-       ss->bgblocks[0].colour1 = strdup("#ffffffffffff");
-       ss->bgblocks[0].alpha1 = 1.0;
+       st->bgblocks = malloc(sizeof(struct bgblock));
+       st->n_bgblocks = 1;
+       st->bgblocks[0]->type = BGBLOCK_SOLID;
+       st->bgblocks[0]->min_x = 0.0;
+       st->bgblocks[0]->max_x = 1024.0;
+       st->bgblocks[0]->min_y = 0.0;
+       st->bgblocks[0]->max_y = 768.0;
+       st->bgblocks[0]->colour1 = strdup("#ffffffffffff");
+       st->bgblocks[0]->alpha1 = 1.0;
 }
 
 
@@ -257,7 +267,7 @@ static enum bgblocktype str_to_bgtype(char *t)
 }
 
 
-static int read_frame_class(struct frame_class *fs, struct ds_node *root)
+static int read_frame_class(struct frame_class *fc, struct ds_node *root)
 {
        get_field_f(root, "margin_left",   &fc->margin_left);
        get_field_f(root, "margin_right",  &fc->margin_right);
@@ -311,12 +321,14 @@ struct slide_template *tree_to_slide_template(StyleSheet *ss,
 {
        struct slide_template *st;
        int i;
+       char *v;
+       struct ds_node *node;
 
        get_field_s(root, "name", &v);
        if ( v == NULL ) {
                fprintf(stderr, "No name for slide template '%s'\n",
-                       node->children[i]->key);
-               continue;
+                       root->children[i]->key);
+               return NULL;
        }
 
        st = new_slide_template(ss, v);
@@ -342,7 +354,7 @@ struct slide_template *tree_to_slide_template(StyleSheet *ss,
 
                struct frame_class *fc;
 
-               fc = &st->frame_classes[i];
+               fc = st->frame_classes[i];
 
                if ( read_frame_class(fc, node->children[i]) ) {
                        fprintf(stderr, "Couldn't read frame class %i\n", i);
@@ -370,7 +382,7 @@ struct slide_template *tree_to_slide_template(StyleSheet *ss,
 
                struct bgblock *b;
 
-               b = &st->bgblocks[i];
+               b = st->bgblocks[i];
 
                if ( read_bgblock(b, node->children[i]) ) {
                        fprintf(stderr, "Couldn't read bgblock %i\n", i);
@@ -418,8 +430,8 @@ StyleSheet *new_stylesheet()
        ss = calloc(1, sizeof(struct _stylesheet));
        if ( ss == NULL ) return NULL;
 
-       ss->n_styles = 0;
-       ss->styles = NULL;
+       ss->n_slide_templates = 0;
+       ss->slide_templates = NULL;
 
        return ss;
 }
@@ -467,17 +479,17 @@ void write_stylesheet(StyleSheet *ss, struct serializer *ser)
        int i;
 
        serialize_start(ser, "templates");
-       for ( i=0; i<ss->n_templates; i++ ) {
+       for ( i=0; i<ss->n_slide_templates; i++ ) {
 
                int j;
                struct slide_template *st;
 
-               st = ss->templates[i];
+               st = ss->slide_templates[i];
 
                serialize_start(ser, "bgblocks");
                for ( j=0; j<st->n_bgblocks; j++ ) {
 
-                       struct bgblock *b = &st->bgblocks[j];
+                       struct bgblock *b = st->bgblocks[j];
                        char id[32];
 
                        snprintf(id, 31, "%i", j);
@@ -516,7 +528,7 @@ void write_stylesheet(StyleSheet *ss, struct serializer *ser)
                serialize_end(ser);
 
                serialize_start(ser, "frame_classes");
-               for ( j=0; j<st->n_styles; j++ ) {
+               for ( j=0; j<st->n_frame_classes; j++ ) {
 
                        struct frame_class *fc = st->frame_classes[j];
                        char id[32];
@@ -555,12 +567,12 @@ struct frame_class *find_frame_class(struct slide_template *st,
 }
 
 
-struct frame_class *find_slide_template(StyleSheet *ss, const char *name)
+struct slide_template *find_slide_template(StyleSheet *ss, const char *name)
 {
        int i;
-       for ( i=0; i<ss->n_templates; i++ ) {
-               if ( strcmp(ss->templates[i]->name, name) == 0 ) {
-                       return ss->templates[i];
+       for ( i=0; i<ss->n_slide_templates; i++ ) {
+               if ( strcmp(ss->slide_templates[i]->name, name) == 0 ) {
+                       return ss->slide_templates[i];
                }
        }
 
index 73c4e2c..558c7c5 100644 (file)
@@ -32,6 +32,8 @@
 
 struct frame_class
 {
+       char *name;
+
        /* Margins of this frame from the parent */
        double   margin_left;
        double   margin_right;
@@ -97,8 +99,8 @@ extern void default_stylesheet(StyleSheet *ss);
 extern int save_stylesheet(StyleSheet *ss, const char *filename);
 
 /* Used during deserialization */
-extern struct frame_class *find_slide_template(StyleSheet *ss,
-                                               const char *name);
+extern struct slide_template *find_slide_template(StyleSheet *ss,
+                                                  const char *name);
 
 extern struct frame_class *find_frame_class(struct slide_template *st,
                                             const char *name);