aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2012-10-12 00:53:34 +0200
committerThomas White <taw@bitwiz.org.uk>2012-10-12 00:53:34 +0200
commit350c51a006edba2a46e7f17bf05098b398a4cb80 (patch)
treeb6a996032b7131eb72c5b070325c78a005087ed0
parenteea7bf93ada2a57fad1dac3e5233f703d1af02ff (diff)
Move "frame" to new module
-rw-r--r--Makefile.am9
-rw-r--r--src/frame.c84
-rw-r--r--src/frame.h62
-rw-r--r--src/layout.c1
-rw-r--r--src/layout.h3
-rw-r--r--src/mainwindow.c5
-rw-r--r--src/presentation.c1
-rw-r--r--src/presentation.h28
-rw-r--r--src/render.c1
-rw-r--r--src/storycode.c54
-rw-r--r--tests/render_test.c1
-rw-r--r--tests/render_test_sc1.c1
12 files changed, 166 insertions, 84 deletions
diff --git a/Makefile.am b/Makefile.am
index 2111532..b655539 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,7 +11,7 @@ LDADD = $(top_builddir)/lib/libgnu.a @IGNORE_UNUSED_LIBRARIES_CFLAGS@
src_colloquium_SOURCES = src/colloquium.c src/storycode.c src/render.c \
src/layout.c src/mainwindow.c src/presentation.c \
- src/stylesheet.c src/loadsave.c
+ src/stylesheet.c src/loadsave.c src/frame.c
INCLUDES = "-I$(top_srcdir)/data"
@@ -30,10 +30,11 @@ EXTRA_DIST += $(colloquium_DATA)
noinst_PROGRAMS = tests/storycode_test tests/render_test tests/render_test_sc1
TESTS = tests/storycode_test tests/render_test tests/render_test_sc1
-tests_storycode_test_SOURCES = tests/storycode_test.c src/storycode.c
+tests_storycode_test_SOURCES = tests/storycode_test.c src/storycode.c \
+ src/frame.c
tests_render_test_SOURCES = tests/render_test.c src/storycode.c src/render.c \
- src/layout.c
+ src/layout.c src/frame.c
tests_render_test_sc1_SOURCES = tests/render_test_sc1.c src/storycode.c \
- src/render.c src/layout.c
+ src/render.c src/layout.c src/frame.c
diff --git a/src/frame.c b/src/frame.c
new file mode 100644
index 0000000..637fff1
--- /dev/null
+++ b/src/frame.c
@@ -0,0 +1,84 @@
+/*
+ * frame.c
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2012 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 <assert.h>
+#include <stdlib.h>
+
+#include "frame.h"
+
+
+static int alloc_ro(struct frame *fr)
+{
+ struct frame **new_ro;
+
+ new_ro = realloc(fr->rendering_order,
+ fr->max_ro*sizeof(struct frame *));
+ if ( new_ro == NULL ) return 1;
+
+ fr->rendering_order = new_ro;
+
+ return 0;
+}
+
+
+struct frame *frame_new()
+{
+ struct frame *n;
+
+ n = calloc(1, sizeof(struct frame));
+ if ( n == NULL ) return NULL;
+
+ n->rendering_order = NULL;
+ n->max_ro = 32;
+ alloc_ro(n);
+
+ n->num_ro = 1;
+ n->rendering_order[0] = n;
+
+ n->pl = NULL;
+
+ return n;
+}
+
+
+struct frame *add_subframe(struct frame *fr)
+{
+ struct frame *n;
+
+ n = frame_new();
+ if ( n == NULL ) return NULL;
+
+ if ( fr->num_ro == fr->max_ro ) {
+ fr->max_ro += 32;
+ if ( alloc_ro(fr) ) return NULL;
+ }
+
+ fr->rendering_order[fr->num_ro++] = n;
+
+ return n;
+}
+
diff --git a/src/frame.h b/src/frame.h
new file mode 100644
index 0000000..7f56889
--- /dev/null
+++ b/src/frame.h
@@ -0,0 +1,62 @@
+/*
+ * frame.h
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2012 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 FRAME_H
+#define FRAME_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pango/pango.h>
+
+#include "layout.h"
+
+
+struct frame
+{
+ struct frame **rendering_order;
+ int num_ro;
+ int max_ro;
+
+ char *sc; /* Storycode */
+
+ struct layout_parameters lop;
+ struct style *style; /* Non-NULL if 'lop' came from SS */
+
+ /* Location relative to parent, calculated from layout parameters */
+ double offs_x;
+ double offs_y;
+ double w;
+ double h;
+
+ PangoLayout *pl;
+
+ /* True if this frame should be deleted on the next mouse click */
+ int empty;
+};
+
+
+extern struct frame *frame_new(void);
+extern struct frame *add_subframe(struct frame *fr);
+
+#endif /* FRAME_H */
diff --git a/src/layout.c b/src/layout.c
index cef270d..10cb686 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -32,6 +32,7 @@
#include "presentation.h"
#include "layout.h"
#include "stylesheet.h"
+#include "frame.h"
static void copy_lop_from_style(struct frame *fr, struct style *style)
diff --git a/src/layout.h b/src/layout.h
index b35a532..8d7dd49 100644
--- a/src/layout.h
+++ b/src/layout.h
@@ -28,6 +28,9 @@
#endif
+struct frame;
+
+
typedef enum
{
DIR_NONE,
diff --git a/src/mainwindow.c b/src/mainwindow.c
index a4221a6..1a5f7d9 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -35,6 +35,7 @@
#include "presentation.h"
#include "mainwindow.h"
#include "render.h"
+#include "frame.h"
static void redraw_slide(struct slide *s)
@@ -517,13 +518,15 @@ static gint add_furniture(GtkWidget *widget, struct presentation *p)
{
gchar *name;
struct style *sty;
+ struct frame *fr;
g_object_get(G_OBJECT(widget), "label", &name, NULL);
sty = find_style(p->ss, name);
g_free(name);
if ( sty == NULL ) return 0;
- /* FIXME: Create it */
+ fr = add_subframe(p->cur_edit_slide->top);
+ fr->style = sty;
return 0;
}
diff --git a/src/presentation.c b/src/presentation.c
index ec918a6..1b3e00c 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -34,6 +34,7 @@
#include "stylesheet.h"
#include "loadsave.h"
#include "mainwindow.h"
+#include "frame.h"
static int num_presentations = 0;
diff --git a/src/presentation.h b/src/presentation.h
index daa016b..c237aac 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -28,7 +28,6 @@
#endif
#include <cairo.h>
-#include <pango/pango.h>
#include <gtk/gtk.h>
struct frame;
@@ -47,36 +46,12 @@ struct slide
/* This should always be present (and up to date). */
cairo_surface_t *rendered_thumb;
- struct frame *top;
+ struct frame *top;
char *notes;
};
-struct frame
-{
- struct frame **rendering_order;
- int num_ro;
- int max_ro;
-
- char *sc; /* Storycode */
-
- struct layout_parameters lop;
- struct style *style; /* Non-NULL if 'lop' came from SS */
-
- /* Location relative to parent, calculated from layout parameters */
- double offs_x;
- double offs_y;
- double w;
- double h;
-
- PangoLayout *pl;
-
- /* True if this frame should be deleted on the next mouse click */
- int empty;
-};
-
-
struct presentation
{
char *titlebar;
@@ -141,6 +116,7 @@ extern int slide_number(struct presentation *p, struct slide *s);
extern int load_presentation(struct presentation *p, const char *filename);
extern int save_presentation(struct presentation *p, const char *filename);
+
#define UNUSED __attribute__((unused))
diff --git a/src/render.c b/src/render.c
index ba0ae69..8738b4b 100644
--- a/src/render.c
+++ b/src/render.c
@@ -35,6 +35,7 @@
#include "storycode.h"
#include "stylesheet.h"
#include "presentation.h"
+#include "frame.h"
/* Render Level 1 Storycode */
diff --git a/src/storycode.c b/src/storycode.c
index 3432090..1ef01d7 100644
--- a/src/storycode.c
+++ b/src/storycode.c
@@ -31,7 +31,7 @@
#include <ctype.h>
#include "storycode.h"
-#include "presentation.h"
+#include "frame.h"
struct _scblocklist
@@ -393,58 +393,6 @@ static char *remove_blocks(const char *in, const char *blockname)
}
-static int alloc_ro(struct frame *fr)
-{
- struct frame **new_ro;
-
- new_ro = realloc(fr->rendering_order,
- fr->max_ro*sizeof(struct frame *));
- if ( new_ro == NULL ) return 1;
-
- fr->rendering_order = new_ro;
-
- return 0;
-}
-
-
-static struct frame *frame_new()
-{
- struct frame *n;
-
- n = calloc(1, sizeof(struct frame));
- if ( n == NULL ) return NULL;
-
- n->rendering_order = NULL;
- n->max_ro = 32;
- alloc_ro(n);
-
- n->num_ro = 1;
- n->rendering_order[0] = n;
-
- n->pl = NULL;
-
- return n;
-}
-
-
-static struct frame *add_subframe(struct frame *fr)
-{
- struct frame *n;
-
- n = frame_new();
- if ( n == NULL ) return NULL;
-
- if ( fr->num_ro == fr->max_ro ) {
- fr->max_ro += 32;
- if ( alloc_ro(fr) ) return NULL;
- }
-
- fr->rendering_order[fr->num_ro++] = n;
-
- return n;
-}
-
-
static void recursive_unpack(struct frame *fr, const char *sc)
{
SCBlockList *bl;
diff --git a/tests/render_test.c b/tests/render_test.c
index fc4784e..027847a 100644
--- a/tests/render_test.c
+++ b/tests/render_test.c
@@ -34,6 +34,7 @@
#include "../src/render.h"
#include "../src/layout.h"
#include "../src/stylesheet.h"
+#include "../src/frame.h"
static gint mw_destroy(GtkWidget *w, void *p)
diff --git a/tests/render_test_sc1.c b/tests/render_test_sc1.c
index 03a8ec5..3b0d6a9 100644
--- a/tests/render_test_sc1.c
+++ b/tests/render_test_sc1.c
@@ -35,6 +35,7 @@
#include "../src/render.h"
#include "../src/layout.h"
#include "../src/stylesheet.h"
+#include "../src/frame.h"
static gint mw_destroy(GtkWidget *w, void *p)