diff options
author | Thomas White <taw@bitwiz.org.uk> | 2013-09-18 23:31:55 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2013-09-18 23:31:55 +0200 |
commit | 42d04450f7a56b82bf1edb7b589f0d248aedc917 (patch) | |
tree | af07060666a1cd7e0b8024dbe1670cf95499afde /src | |
parent | b2a80d1efa9bab69bb6f6af5cf822e1b3e73b537 (diff) |
Show thumbnails in slide sorter
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.c | 4 | ||||
-rw-r--r-- | src/presentation.c | 15 | ||||
-rw-r--r-- | src/slide_sorter.c | 71 |
3 files changed, 80 insertions, 10 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c index a3e93c0..69d48c6 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -1922,10 +1922,6 @@ int open_mainwindow(struct presentation *p) vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add(GTK_CONTAINER(window), vbox); - p->edit_slide_width = 1024; - p->proj_slide_width = 2048; - p->thumb_slide_width = 320; /* FIXME: Completely made up */ - p->drawingarea = gtk_drawing_area_new(); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), diff --git a/src/presentation.c b/src/presentation.c index 0847e84..2e6eb03 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -39,6 +39,7 @@ #include "wrap.h" #include "notes.h" #include "inhibit_screensaver.h" +#include "render.h" static int num_presentations = 0; @@ -259,6 +260,10 @@ struct presentation *new_presentation() new->slide_width = 1024.0; new->slide_height = 768.0; + new->edit_slide_width = 1024; + new->proj_slide_width = 2048; + new->thumb_slide_width = 180; + /* Add one blank slide and view it */ new->num_slides = 0; new->slides = NULL; @@ -518,7 +523,7 @@ int load_presentation(struct presentation *p, const char *filename) { FILE *fh; struct ds_node *root; - int r; + int r, i; assert(p->completely_empty); @@ -552,6 +557,14 @@ int load_presentation(struct presentation *p, const char *filename) p->cur_edit_slide = p->slides[0]; + for ( i=0; i<p->num_slides; i++ ) { + struct slide *s = p->slides[i]; + s->rendered_thumb = render_slide(s, p->thumb_slide_width, + p->slide_width, + p->slide_height, + p->is, ISZ_THUMBNAIL); + } + return 0; } diff --git a/src/slide_sorter.c b/src/slide_sorter.c index 1557638..f68e5cb 100644 --- a/src/slide_sorter.c +++ b/src/slide_sorter.c @@ -37,6 +37,9 @@ struct slide_sorter { GtkWidget *window; GtkWidget *da; + + int width; /* Number of slides across */ + struct presentation *p; }; @@ -50,22 +53,70 @@ static gint close_slidesorter_sig(GtkWidget *w, struct presentation *p) static gboolean draw_sig(GtkWidget *da, cairo_t *cr, struct slide_sorter *n) { int width, height; + int tw, th; + int i; + const int bw = 5.0; width = gtk_widget_get_allocated_width(GTK_WIDGET(da)); height = gtk_widget_get_allocated_height(GTK_WIDGET(da)); /* Overall background */ - cairo_rectangle(cr, 00.0, 0.0, width, height); + cairo_rectangle(cr, 0.0, 0.0, width, height); cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_fill(cr); + tw = n->p->thumb_slide_width; + th = (n->p->slide_height/n->p->slide_width) * n->p->thumb_slide_width; + + for ( i=0; i<n->p->num_slides; i++ ) { + + int x = i % n->width; + int y = i / n->width; + + cairo_save(cr); + + cairo_translate(cr, x*(tw+2*bw), y*(th+2*bw)); + cairo_translate(cr, bw, bw); /* Border */ + cairo_rectangle(cr, 0.0, 0.0, tw, th); + cairo_set_source_surface(cr, n->p->slides[i]->rendered_thumb, + 0.0, 0.0); + cairo_fill(cr); + + cairo_rectangle(cr, 0.5, 0.5, tw, th); + cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); + cairo_set_line_width(cr, 1.0); + cairo_stroke(cr); + + cairo_restore(cr); + + } + return FALSE; } +static void size_sig(GtkWidget *da, GdkRectangle *size, struct slide_sorter *n) +{ + int w, h; + int tw, th; + const int bw = 5.0; + + tw = n->p->thumb_slide_width; + th = (n->p->slide_height/n->p->slide_width) * n->p->thumb_slide_width; + + w = size->width; + n->width = w / (tw+2*bw); + + h = (n->p->num_slides / n->width) * (th+2*bw); + + gtk_widget_set_size_request(da, w, h); /* FIXME: Doesn't work */ +} + + void open_slidesorter(struct presentation *p) { struct slide_sorter *n; + GtkWidget *sw; if ( p->slide_sorter != NULL ) return; /* Already open */ @@ -73,18 +124,28 @@ void open_slidesorter(struct presentation *p) if ( n == NULL ) return; p->slide_sorter = n; + n->width = 6; + n->p = p; + n->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(n->window), 500, 500); - gtk_window_set_title(GTK_WINDOW(n->window), "Slide sorter"); - n->da = gtk_drawing_area_new(); - gtk_container_add(GTK_CONTAINER(n->window), n->da); + + sw = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), + GTK_POLICY_NEVER, + GTK_POLICY_ALWAYS); + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), n->da); + gtk_container_add(GTK_CONTAINER(n->window), sw); + + gtk_window_set_title(GTK_WINDOW(n->window), "Slide sorter"); g_signal_connect(G_OBJECT(n->da), "draw", G_CALLBACK(draw_sig), n); + g_signal_connect(G_OBJECT(n->da), "size-allocate", G_CALLBACK(size_sig), + n); g_signal_connect(G_OBJECT(n->window), "destroy", G_CALLBACK(close_slidesorter_sig), p); - gtk_widget_show_all(n->window); } |