#include "deck.h" #define MARGIN 18 #define RATIO 1.414 #define N_SLIDES 30 struct Deck { DeckChangeNotify notify; /* Called on slide add/delete/reorder */ gpointer data; int view_width; int thumb_width; }; Deck * deck_new (DeckChangeNotify notify, gpointer data) { Deck *deck = g_new0 (Deck, 1); deck->notify = notify; deck->data = data; return deck; } void deck_set_main_width (Deck *deck, int view_width) { deck->view_width = view_width; } static int get_slide_height (int view_width) { return (view_width - 2 * MARGIN) / RATIO; } int deck_get_main_slide_height (Deck *deck) { return get_slide_height (deck->view_width); } int deck_get_thumb_slide_height (Deck *deck) { return get_slide_height (deck->thumb_width); } static void deck_paint (Deck *deck, cairo_t *cr, int orig_x, int orig_y, int width, gboolean is_thumbnail) { int height; int i; height = get_slide_height (width); width -= 2 * MARGIN; for (i = 0; i < N_SLIDES; ++i) { double x, y; x = orig_x + MARGIN; y = orig_y + MARGIN + i * (MARGIN + height); cairo_save (cr); cairo_set_source_rgba (cr, 0, 0, 0, 0.6); cairo_translate (cr, 2, 2); cairo_rectangle (cr, x, y, width, height); cairo_fill (cr); cairo_restore (cr); cairo_set_source_rgba (cr, 1, 1, 1, 1); cairo_rectangle (cr, x, y, width, height); cairo_fill (cr); cairo_rectangle (cr, x + 0.5, y + 0.5, width - 1, height - 1); cairo_set_source_rgba (cr, 0, 0, 0, 1); cairo_set_line_width (cr, 1); cairo_stroke (cr); cairo_set_source_rgba (cr, (i + 1.0) / N_SLIDES, 0, 1 - (i + 1.0) / N_SLIDES, 1); if (is_thumbnail) { cairo_rectangle (cr, x + width/2 - 4, y + height/2 - 4, 8, 8); } else { cairo_rectangle (cr, x + width/2 - 10, y + height/2 - 10, 20, 20); } cairo_fill (cr); } } void deck_paint_main (Deck *deck, cairo_t *cr, int orig_x, int orig_y) { deck_paint (deck, cr, orig_x, orig_y, deck->view_width, FALSE); } void deck_paint_thumbs (Deck *deck, cairo_t *cr, int x, int y) { deck_paint (deck, cr, x, y, deck->thumb_width, TRUE); } /* Returns the slide the user is likely looking * at, given the viewport. */ int deck_get_view_slide (Deck *deck, GdkRectangle *viewport) { int slide_height = deck_get_main_slide_height (deck); /* Compute the y-coordinate of the first visible top edge of a slide */ return (viewport->y - MARGIN) / (MARGIN + slide_height) + 1; } /* Returns the y coordinate of the nth slide given * the viewport */ int deck_get_main_slide_location (Deck *deck, int nth_slide) { int slide_height = deck_get_main_slide_height (deck); return nth_slide * (MARGIN + slide_height) + MARGIN; } int deck_get_thumb_slide_location (Deck *deck, int nth_slide) { int slide_height = deck_get_thumb_slide_height (deck); return nth_slide * (MARGIN + slide_height) + MARGIN; } int deck_get_main_height (Deck *deck) { int slide_height = deck_get_main_slide_height (deck); return N_SLIDES * slide_height + (N_SLIDES + 1) * MARGIN; } void deck_set_thumb_width (Deck *deck, int thumb_width) { deck->thumb_width = thumb_width; } int deck_get_thumb_height (Deck *deck) { int thumb_height = deck_get_thumb_slide_height (deck); return N_SLIDES * thumb_height + (N_SLIDES + 1) * MARGIN; }