aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2012-05-14 09:28:37 +0200
committerThomas White <taw@bitwiz.org.uk>2012-05-14 09:28:37 +0200
commit940337bb4e46463b794fd9779cc3e07e7e175cee (patch)
treebe47cbc8b911b301fff29d778a40ceca854904b0 /src
parent7046f1d355dac1c3ac1d83677390d89ab0514ead (diff)
Storycode - more work
Diffstat (limited to 'src')
-rw-r--r--src/loadsave.c150
-rw-r--r--src/presentation.c65
-rw-r--r--src/presentation.h14
-rw-r--r--src/storycode.c9
-rw-r--r--src/storycode.h11
-rw-r--r--src/stylesheet-editor.c105
-rw-r--r--src/stylesheet.c2
7 files changed, 135 insertions, 221 deletions
diff --git a/src/loadsave.c b/src/loadsave.c
index aac2e4a..4388953 100644
--- a/src/loadsave.c
+++ b/src/loadsave.c
@@ -553,52 +553,9 @@ int get_field_s(struct ds_node *root, const char *key, char **val)
}
-static enum objtype text_to_type(const char *t)
+static struct frame *tree_to_frame(struct ds_node *root)
{
- if ( strcmp(t, "text") == 0 ) return OBJ_TEXT;
- if ( strcmp(t, "image") == 0 ) return OBJ_IMAGE;
-
- return OBJ_UNKNOWN;
-}
-
-
-static const char *type_text(enum objtype t)
-{
- switch ( t )
- {
- case OBJ_TEXT : return "text";
- case OBJ_IMAGE : return "image";
- default : return "unknown";
- }
-}
-
-
-
-static struct object *tree_to_object(struct presentation *p,
- struct ds_node *root)
-{
- struct object *o = NULL;
- char *v;
-
- if ( get_field_s(root, "type", &v) ) return NULL;
-
- switch ( text_to_type(v) ) {
-
- case OBJ_TEXT :
- o = p->text_tool->deserialize(p, root, p->text_tool);
- break;
-
- case OBJ_IMAGE :
- o = p->image_tool->deserialize(p, root, p->image_tool);
- break;
-
- default :
- fprintf(stderr, "Unrecognised object type '%s'\n", v);
- break;
-
- }
-
- return o;
+ return NULL;
}
@@ -615,94 +572,19 @@ static struct slide *tree_to_slide(struct presentation *p, struct ds_node *root)
/* Loop over objects */
for ( i=0; i<root->n_children; i++ ) {
- struct object *o;
+ struct frame *fr;
- o = tree_to_object(p, root->children[i]);
- if ( o != NULL ) {
- add_object_to_slide(s, o);
- if ( o->type != OBJ_TEXT) o->update_object(o);
+ fr = tree_to_frame(root->children[i]);
+ if ( fr != NULL ) {
+ add_frame_to_slide(s, fr);
}
}
- redraw_slide(s);
-
return s;
}
-static void try_last(struct slide *s, struct slide *ls, enum object_role r)
-{
- if ( s->roles[r] == NULL ) {
- s->roles[r] = ls->roles[r];
- }
-}
-
-
-static void try_update(struct object *o)
-{
- if ( o == NULL ) return;
- o->update_object(o);
-}
-
-
-/* Go through all the slides and make sure the roles are tidied up */
-static void fix_up_roles(struct presentation *p)
-{
- int i;
- struct slide *last_slide = NULL;
-
- for ( i=0; i<p->num_slides; i++ ) {
-
- int j;
- struct slide *s;
-
- s = p->slides[i];
-
- for ( j=0; j<NUM_S_ROLES; j++ ) {
- s->roles[j] = NULL;
- }
-
- for ( j=0; j<s->num_objects; j++ ) {
-
- struct object *o;
- enum object_role r;
-
- o = s->objects[j];
- r = o->style->role;
-
- if ( r == S_ROLE_NONE ) continue;
-
- if ( s->roles[r] != NULL ) {
- fprintf(stderr, "Warning, two objects in slide"
- " with role %i.\n", r);
- continue;
- }
-
- s->roles[r] = o;
-
- }
-
- if ( last_slide != NULL ) {
-
- /* Set off-slide references for this slide */
- try_last(s, last_slide, S_ROLE_PTITLE_REF);
- try_last(s, last_slide, S_ROLE_PAUTHOR_REF);
- try_last(s, last_slide, S_ROLE_PDATE_REF);
-
- }
-
- try_update(s->roles[S_ROLE_PTITLE]);
- try_update(s->roles[S_ROLE_PAUTHOR]);
- try_update(s->roles[S_ROLE_PDATE]);
- try_update(s->roles[S_ROLE_SLIDENUMBER]);
-
- last_slide = s;
-
- }
-}
-
-
static int tree_to_slides(struct ds_node *root, struct presentation *p)
{
int i;
@@ -714,13 +596,10 @@ static int tree_to_slides(struct ds_node *root, struct presentation *p)
s = tree_to_slide(p, root->children[i]);
if ( s != NULL ) {
insert_slide(p, s, p->num_slides-1);
- redraw_slide(s);
}
}
- fix_up_roles(p);
-
return 0;
}
@@ -776,7 +655,7 @@ int tree_to_presentation(struct ds_node *root, struct presentation *p)
}
p->cur_edit_slide = p->slides[0];
- redraw_slide(p->cur_edit_slide);
+// redraw_slide(p->cur_edit_slide);
return 0;
}
@@ -943,17 +822,16 @@ int save_presentation(struct presentation *p, const char *filename)
snprintf(s_id, 31, "%i", i);
serialize_start(&ser, s_id);
- for ( j=0; j<s->num_objects; j++ ) {
+ for ( j=0; j<s->num_frames; j++ ) {
- struct object *o = s->objects[j];
- char o_id[32];
+ struct frame *fr = s->frames[j];
+ char fr_id[32];
- if ( o->empty ) continue;
- snprintf(o_id, 31, "%i", j);
+ if ( fr->empty ) continue;
+ snprintf(fr_id, 31, "%i", j);
- serialize_start(&ser, o_id);
- serialize_s(&ser, "type", type_text(o->type));
- o->serialize(o, &ser);
+ serialize_start(&ser, fr_id);
+ fr->serialize(fr, &ser);
serialize_end(&ser);
}
diff --git a/src/presentation.c b/src/presentation.c
index 2ca1cd6..36e2abe 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -117,9 +117,9 @@ struct slide *new_slide()
new = calloc(1, sizeof(struct slide));
if ( new == NULL ) return NULL;
- /* No objects to start with */
- new->num_objects = 0;
- new->objects = NULL;
+ /* No frames to start with */
+ new->num_frames = 0;
+ new->frames = NULL;
new->rendered_edit = NULL;
new->rendered_proj = NULL;
@@ -131,12 +131,26 @@ struct slide *new_slide()
}
+static void free_frame(struct frame *fr)
+{
+ int i;
+
+ for ( i=0; i<fr->num_children; i++ ) {
+ free_frame(fr->children[i]);
+ }
+
+ free(fr->sc);
+
+ free(fr);
+}
+
+
void free_slide(struct slide *s)
{
int i;
- for ( i=0; i<s->num_objects; i++ ) {
- delete_object(s->objects[i]);
+ for ( i=0; i<s->num_frames; i++ ) {
+ free_frame(s->frames[i]);
}
free(s);
@@ -192,16 +206,15 @@ struct slide *add_slide(struct presentation *p, int pos)
}
-int add_object_to_slide(struct slide *s, struct object *o)
+int add_frame_to_slide(struct slide *s, struct frame *fr)
{
- struct object **try;
+ struct frame **try;
- try = realloc(s->objects, (1+s->num_objects)*sizeof(struct object *));
+ try = realloc(s->frames, (1+s->num_frames)*sizeof(struct frame *));
if ( try == NULL ) return 1;
- s->objects = try;
+ s->frames = try;
- s->objects[s->num_objects++] = o;
- o->parent = s;
+ s->frames[s->num_frames++] = fr;
s->parent->completely_empty = 0;
@@ -209,49 +222,49 @@ int add_object_to_slide(struct slide *s, struct object *o)
}
-void remove_object_from_slide(struct slide *s, struct object *o)
+void remove_frame_from_slide(struct slide *s, struct frame *fr)
{
int i;
int found = 0;
- for ( i=0; i<s->num_objects; i++ ) {
+ for ( i=0; i<s->num_frames; i++ ) {
- if ( s->objects[i] == o ) {
+ if ( s->frames[i] == fr ) {
assert(!found);
found = 1;
}
if ( found ) {
- if ( i == s->num_objects-1 ) {
- s->objects[i] = NULL;
+ if ( i == s->num_frames-1 ) {
+ s->frames[i] = NULL;
} else {
- s->objects[i] = s->objects[i+1];
+ s->frames[i] = s->frames[i+1];
}
}
}
- s->num_objects--;
+ s->num_frames--;
}
-struct object *find_object_at_position(struct slide *s, double x, double y)
+struct frame *find_frame_at_position(struct slide *s, double x, double y)
{
int i;
- struct object *o = NULL;
+ struct frame *fr = NULL;
- for ( i=0; i<s->num_objects; i++ ) {
+ for ( i=0; i<s->num_frames; i++ ) {
- if ( (x>s->objects[i]->x) && (y>s->objects[i]->y)
- && (x<s->objects[i]->x+s->objects[i]->bb_width)
- && (y<s->objects[i]->y+s->objects[i]->bb_height) )
+ if ( /* FIXME: implement */ 1 )
{
- o = s->objects[i];
+ fr = s->frames[i];
}
}
- return o;
+ /* FIXME: Recurse */
+
+ return fr;
}
diff --git a/src/presentation.h b/src/presentation.h
index ddd8b4e..1e0e787 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -44,8 +44,8 @@ struct slide
/* This should always be present (and up to date). */
cairo_surface_t *rendered_thumb;
- int num_objects;
- struct object **objects;
+ int num_frames;
+ struct frame **frames;
char *notes;
};
@@ -156,9 +156,15 @@ struct frame
struct frame_class *cl;
struct frame **children;
- int n_children;
+ int num_children;
+
+ int (*render_frame)(struct frame *this, cairo_t *cr);
+ int (*serialize)(struct frame *this,
+ struct serializer *ser);
char *sc; /* Storycode */
+
+ int empty;
};
@@ -170,6 +176,8 @@ extern struct slide *add_slide(struct presentation *p, int pos);
extern int insert_slide(struct presentation *p, struct slide *s, int pos);
extern void free_slide(struct slide *s);
+extern int add_frame_to_slide(struct slide *s, struct frame *fr);
+
extern void get_titlebar_string(struct presentation *p);
extern struct frame *find_frame_at_position(struct slide *s,
diff --git a/src/storycode.c b/src/storycode.c
index a0a6da9..d394f02 100644
--- a/src/storycode.c
+++ b/src/storycode.c
@@ -1,5 +1,5 @@
/*
- * slide_render.c
+ * storycode.c
*
* Colloquium - A tiny presentation program
*
@@ -116,17 +116,18 @@ static void render_slide_bits(struct slide *s, cairo_t *cr)
render_bgblock(cr, s->st->bgblocks[i]);
}
- for ( i=0; i<s->num_objects; i++ ) {
+ for ( i=0; i<s->num_frames; i++ ) {
- struct object *o = s->objects[i];
+ struct frame *fr = s->frames[i];
- o->render_object(cr, o);
+ fr->render_frame(fr, cr);
}
cairo_font_options_destroy(fopts);
}
+
static cairo_surface_t *render_slide(struct slide *s, int w, int h)
{
cairo_surface_t *surf;
diff --git a/src/storycode.h b/src/storycode.h
index 34f4d85..bd33638 100644
--- a/src/storycode.h
+++ b/src/storycode.h
@@ -1,5 +1,5 @@
/*
- * slide_render.h
+ * storycode.h
*
* Colloquium - A tiny presentation program
*
@@ -20,8 +20,8 @@
*
*/
-#ifndef SLIDE_RENDER_H
-#define SLIDE_RENDER_H
+#ifndef STORYCODE_H
+#define STORYCODE_H
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -42,4 +42,7 @@ extern void draw_editing_box(cairo_t *cr, double xmin, double ymin,
extern int export_pdf(struct presentation *p, const char *filename);
-#endif /* SLIDE_RENDER_H */
+extern char *sc_get_final_font(const char *sc);
+extern char *sc_get_final_text_colour(const char *sc);
+
+#endif /* STORYCODE_H */
diff --git a/src/stylesheet-editor.c b/src/stylesheet-editor.c
index cd6abc7..c08271c 100644
--- a/src/stylesheet-editor.c
+++ b/src/stylesheet-editor.c
@@ -34,24 +34,30 @@
#include "stylesheet.h"
#include "objects.h"
#include "loadsave.h"
+#include "storycode.h"
struct _stylesheetwindow
{
- struct presentation *p; /* Presentation to update when user alters
- * something in this window */
- GtkWidget *window;
- StyleSheet *ss; /* Style sheet this window corresponds to */
+ struct presentation *p; /* Presentation to update when user alters
+ * something in this window */
+ GtkWidget *window;
+ StyleSheet *ss; /* Style sheet this window corresponds to */
- GtkWidget *margin_left;
- GtkWidget *margin_right;
- GtkWidget *margin_top;
- GtkWidget *margin_bottom;
+ GtkWidget *margin_left;
+ GtkWidget *margin_right;
+ GtkWidget *margin_top;
+ GtkWidget *margin_bottom;
- GtkWidget *text_font;
- GtkWidget *text_colour;
+ GtkWidget *text_font;
+ GtkWidget *text_colour;
- struct style *cur_style;
+ char *font;
+ char *colour;
+ double alpha;
+
+ struct slide_template *cur_slide_template;
+ struct frame_class *cur_frame_class;
};
@@ -61,10 +67,10 @@ static void text_font_set_sig(GtkFontButton *widget,
const gchar *font;
font = gtk_font_button_get_font_name(widget);
- free(s->cur_style->font);
- s->cur_style->font = strdup(font);
+ free(s->font);
+ s->font = strdup(font);
- notify_style_update(s->p, s->cur_style);
+// notify_style_update(s->p, s->cur_frame_class);
}
@@ -75,76 +81,86 @@ static void text_colour_set_sig(GtkColorButton *widget,
guint16 al;
gtk_color_button_get_color(widget, &col);
- free(s->cur_style->colour);
- s->cur_style->colour = gdk_color_to_string(&col);
+ free(s->colour);
+ s->colour = gdk_color_to_string(&col);
al = gtk_color_button_get_alpha(widget);
- s->cur_style->alpha = (double)al / 65535.0;
+ s->alpha = (double)al / 65535.0;
- notify_style_update(s->p, s->cur_style);
+// notify_style_update(s->p, s->cur_frame_class);
}
static void margin_left_changed_sig(GtkSpinButton *spin,
struct _stylesheetwindow *s)
{
- s->cur_style->margin_left = gtk_spin_button_get_value(spin);
- notify_style_update(s->p, s->cur_style);
+ s->cur_frame_class->margin_left = gtk_spin_button_get_value(spin);
+// notify_style_update(s->p, s->cur_frame_class);
}
static void margin_right_changed_sig(GtkSpinButton *spin,
struct _stylesheetwindow *s)
{
- s->cur_style->margin_right = gtk_spin_button_get_value(spin);
- notify_style_update(s->p, s->cur_style);
+ s->cur_frame_class->margin_right = gtk_spin_button_get_value(spin);
+// notify_style_update(s->p, s->cur_frame_class);
}
static void margin_top_changed_sig(GtkSpinButton *spin,
struct _stylesheetwindow *s)
{
- s->cur_style->margin_top = gtk_spin_button_get_value(spin);
- notify_style_update(s->p, s->cur_style);
+ s->cur_frame_class->margin_top = gtk_spin_button_get_value(spin);
+// notify_style_update(s->p, s->cur_frame_class);
}
static void margin_bottom_changed_sig(GtkSpinButton *spin,
struct _stylesheetwindow *s)
{
- s->cur_style->margin_bottom = gtk_spin_button_get_value(spin);
- notify_style_update(s->p, s->cur_style);
+ s->cur_frame_class->margin_bottom = gtk_spin_button_get_value(spin);
+// notify_style_update(s->p, s->cur_frame_class);
}
-static void style_changed_sig(GtkComboBox *combo,
- struct _stylesheetwindow *s)
+static void frame_class_changed_sig(GtkComboBox *combo,
+ struct _stylesheetwindow *s)
{
int n;
GdkColor col;
+ char *font;
n = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
- s->cur_style = s->ss->styles[n];
+ s->cur_frame_class = s->cur_slide_template->frame_classes[n];
gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_left),
- s->cur_style->margin_left);
+ s->cur_frame_class->margin_left);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_right),
- s->cur_style->margin_right);
+ s->cur_frame_class->margin_right);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_bottom),
- s->cur_style->margin_bottom);
+ s->cur_frame_class->margin_bottom);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_top),
- s->cur_style->margin_top);
+ s->cur_frame_class->margin_top);
- n = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
- s->cur_style = s->ss->styles[n];
+ font = sc_get_final_font(s->cur_frame_class->sc_prologue);
+ gtk_font_button_set_font_name(GTK_FONT_BUTTON(s->text_font), font);
- gtk_font_button_set_font_name(GTK_FONT_BUTTON(s->text_font),
- s->cur_style->font);
-
- gdk_color_parse(s->cur_style->colour, &col);
+ s->colour = sc_get_final_text_colour(s->cur_frame_class->sc_prologue);
+ gdk_color_parse(s->colour, &col);
gtk_color_button_set_color(GTK_COLOR_BUTTON(s->text_colour), &col);
}
+static void slide_template_changed_sig(GtkComboBox *combo,
+ struct _stylesheetwindow *s)
+{
+ for ( i=0; i<s->ss->n_styles; i++ ) {
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combo),
+ s->ss->styles[i]->name);
+ }
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
+}
+
+
static void do_layout(struct _stylesheetwindow *s, GtkWidget *b)
{
GtkWidget *table;
@@ -161,11 +177,6 @@ static void do_layout(struct _stylesheetwindow *s, GtkWidget *b)
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
combo = gtk_combo_box_new_text();
- for ( i=0; i<s->ss->n_styles; i++ ) {
- gtk_combo_box_append_text(GTK_COMBO_BOX(combo),
- s->ss->styles[i]->name);
- }
- gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
g_signal_connect(G_OBJECT(combo), "changed",
G_CALLBACK(style_changed_sig), s);
gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0);
@@ -236,7 +247,7 @@ static void do_layout(struct _stylesheetwindow *s, GtkWidget *b)
G_CALLBACK(text_colour_set_sig), s);
/* Force first update */
- style_changed_sig(GTK_COMBO_BOX(combo), s);
+ frame_class_changed_sig(GTK_COMBO_BOX(combo), s);
}
@@ -264,8 +275,8 @@ StylesheetWindow *open_stylesheet(struct presentation *p)
s->p = p;
s->ss = p->ss;
- s->cur_style = NULL;
- s->cur_style = NULL;
+ s->cur_slide_template = NULL;
+ s->cur_frame_class = NULL;
s->window = gtk_dialog_new_with_buttons("Stylesheet",
GTK_WINDOW(p->window), 0,
diff --git a/src/stylesheet.c b/src/stylesheet.c
index a4b3543..eb959c1 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -327,7 +327,7 @@ struct slide_template *tree_to_slide_template(StyleSheet *ss,
get_field_s(root, "name", &v);
if ( v == NULL ) {
fprintf(stderr, "No name for slide template '%s'\n",
- root->children[i]->key);
+ root->key);
return NULL;
}