diff options
author | Thomas White <taw@bitwiz.me.uk> | 2019-02-20 22:51:31 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.me.uk> | 2019-02-20 22:51:31 +0100 |
commit | 2244ab129bf25893cae4d68313222ef810bd0631 (patch) | |
tree | bafc8f43f481f5ae380d084cccfa4fdbc87f5bad /libstorycode/slide.c | |
parent | 24c20239779d0ec616adde651c594c7bf08d58c7 (diff) |
Add creation of most slide items
Diffstat (limited to 'libstorycode/slide.c')
-rw-r--r-- | libstorycode/slide.c | 82 |
1 files changed, 79 insertions, 3 deletions
diff --git a/libstorycode/slide.c b/libstorycode/slide.c index 6ff5691..3f65ca8 100644 --- a/libstorycode/slide.c +++ b/libstorycode/slide.c @@ -45,9 +45,18 @@ struct slide_item { enum slide_item_type type; - /* For SLIDE_ITEM_TEXT */ + /* For TEXT */ char **paragraphs; int n_paras; + + /* For IMAGE */ + char *filename; + + /* For SLIDETITLE */ + char *text; + + /* For TEXT and IMAGE */ + struct frame_geom geom; }; @@ -75,14 +84,39 @@ void slide_free(Slide *s) } +static struct slide_item *add_item(Slide *s) +{ + struct slide_item *new_items; + new_items = realloc(s->items, (s->n_items+1)*sizeof(struct slide_item)); + if ( new_items == NULL ) return NULL; + s->items = new_items; + return &s->items[s->n_items++]; +} + + int slide_add_prestitle(Slide *s, char *prestitle) { + struct slide_item *item; + + item = add_item(s); + if ( item == NULL ) return 1; + + item->type = SLIDE_ITEM_PRESTITLE; return 0; } int slide_add_image(Slide *s, char *filename, struct frame_geom geom) { + struct slide_item *item; + + item = add_item(s); + if ( item == NULL ) return 1; + + item->type = SLIDE_ITEM_IMAGE; + item->geom = geom; + item->filename = filename; + return 0; } @@ -90,21 +124,63 @@ int slide_add_image(Slide *s, char *filename, struct frame_geom geom) int slide_add_text(Slide *s, char **text, int n_text, struct frame_geom geom) { int i; - printf("got text:\n"); + struct slide_item *item; + + item = add_item(s); + if ( item == NULL ) return 1; + + item->type = SLIDE_ITEM_TEXT; + item->paragraphs = malloc(n_text*sizeof(char *)); + if ( item->paragraphs == NULL ) { + s->n_items--; + return 1; + } + for ( i=0; i<n_text; i++ ) { - printf("%3i: '%s'\n", i, text[i]); + item->n_paras = n_text; + item->paragraphs[i] = text[i]; } + item->n_paras = n_text; + + item->geom = geom; + return 0; } int slide_add_footer(Slide *s) { + struct slide_item *item; + + item = add_item(s); + if ( item == NULL ) return 1; + + item->type = SLIDE_ITEM_FOOTER; + return 0; } int slide_add_slidetitle(Slide *s, char *slidetitle) { + struct slide_item *item; + + item = add_item(s); + if ( item == NULL ) return 1; + + item->type = SLIDE_ITEM_SLIDETITLE; + item->text = slidetitle; + return 0; } + + +void describe_slide(Slide *s) +{ + int i; + + printf(" %i items\n", s->n_items); + for ( i=0; i<s->n_items; i++ ) { + printf("item %i: %i\n", i, s->items[i].type); + } +} |