diff options
author | Thomas White <taw@bitwiz.org.uk> | 2011-05-28 00:04:02 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2011-05-28 00:04:02 +0200 |
commit | c54649108973ba520518bfb0030a8f112698bcfc (patch) | |
tree | db5fed590d48291c378a7255de66e1e97fc4f38b /src/presentation.c | |
parent | ef1fb4982425a8df33850570348cb7d23f62d041 (diff) |
Add slides, switch between slides
Diffstat (limited to 'src/presentation.c')
-rw-r--r-- | src/presentation.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/presentation.c b/src/presentation.c index dc4adbc..4dc9e59 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -34,19 +34,14 @@ #include "objects.h" -struct slide *add_slide(struct presentation *p) +struct slide *add_slide(struct presentation *p, int pos) { struct slide **try; struct slide *new; - - try = realloc(p->slides, (1+p->num_slides)*sizeof(struct slide *)); - if ( try == NULL ) return NULL; - p->slides = try; + int i; new = malloc(sizeof(struct slide)); if ( new == NULL ) return NULL; - /* Doesn't matter that p->slides now has some excess space - - * it'll get corrected the next time a slide is added or deleted. */ /* No objects to start with */ new->num_objects = 0; @@ -60,8 +55,31 @@ struct slide *add_slide(struct presentation *p) new->render_cache = NULL; render_slide(new); /* Render nothing, just to make the surface exist */ - p->slides[p->num_slides++] = new; - printf("Now %i slides\n", p->num_slides); + try = realloc(p->slides, (1+p->num_slides)*sizeof(struct slide *)); + if ( try == NULL ) { + free(new); + return NULL; + } + p->slides = try; + + if ( (p->num_slides>1) && (pos<p->num_slides-1) ) { + + for ( i=p->num_slides; i>pos+1; i-- ) { + p->slides[i] = p->slides[i-1]; + } + p->slides[pos+1] = new; + + } else if ( pos == p->num_slides-1 ) { + + p->slides[pos+1] = new; + + } else { + assert(pos == 0); + p->slides[pos] = new; + } + + p->num_slides++; + return new; } @@ -146,7 +164,7 @@ struct presentation *new_presentation() /* Add one blank slide and view it */ new->num_slides = 0; new->slides = NULL; - new -> view_slide = add_slide(new); + new->view_slide = add_slide(new, 0); new->view_slide_number = 0; new->editing_object = NULL; |