From 039343b3d5d7fd05bfd0b1a530962ba546b1be37 Mon Sep 17 00:00:00 2001 From: Søren Sandmann Date: Sat, 7 Jun 2008 23:32:40 -0400 Subject: TODO; scroll thumbnails: --- TODO | 29 ++++++++++++++++++++++++++--- deck.c | 33 +++++++++++++++++++-------------- deck.h | 4 ++++ main.c | 24 +++++++++++++++++++++++- 4 files changed, 72 insertions(+), 18 deletions(-) diff --git a/TODO b/TODO index 6235c09..c87f19c 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,29 @@ +Bugs + - Infinite recursion - see fixme in "on_changed" + + - The whole "active slide" should be rethought. Probably we + need to deal with an activate *range* of slides, in floating + point. + + Thumbnail scrolling should be done whenever the integer + rounding of that range changes. + + The thing we should keep at a fixed position as much as possible + then is + + - top of first completely visible slide + + - of if that's not possible, top of first slide with a + visible top + + - which reduces to "top of first slide with visible + top" + + This location should survive all resizing. + +-=-=- + + - Think of a better name than oppress - Populist - Demagogue @@ -215,9 +241,6 @@ worthwhile desktop some day). Ie., cut and paste of complex items, built from rectangles/circles/text etc. -- Bugs - - Infinite recursion - see fixme in "on_changed" - - Undo? - Update files in-place? diff --git a/deck.c b/deck.c index be2558a..71cde5b 100644 --- a/deck.c +++ b/deck.c @@ -22,9 +22,9 @@ deck_new (DeckChangeNotify notify, return deck; } -static int -get_slide_height (Deck *deck, - GdkRectangle *viewport) +int +deck_get_slide_height (Deck *deck, + GdkRectangle *viewport) { return (viewport->width - 2 * MARGIN) / RATIO; } @@ -40,20 +40,19 @@ deck_paint (Deck *deck, foo_scroll_area_get_viewport (area, &viewport); - height = get_slide_height (deck, &viewport); - - cairo_move_to (cr, MARGIN, MARGIN); + height = deck_get_slide_height (deck, &viewport); for (i = 0; i < N_SLIDES; ++i) { - cairo_move_to (cr, MARGIN, MARGIN + i * (MARGIN + height)); + double x, y, width; + + x = MARGIN; + y = MARGIN + i * (MARGIN + height); + width = viewport.width - 2 * MARGIN; cairo_set_source_rgba (cr, 1, 1, 1, 1); - cairo_rel_line_to (cr, viewport.width - 2 * MARGIN, 0); - cairo_rel_line_to (cr, 0, height); - cairo_rel_line_to (cr, -(viewport.width - 2 * MARGIN), 0); - cairo_close_path (cr); + cairo_rectangle (cr, x, y, width, height); cairo_fill_preserve (cr); @@ -61,6 +60,12 @@ deck_paint (Deck *deck, cairo_set_line_width (cr, 2); cairo_stroke (cr); + cairo_set_source_rgba (cr, (i + 1.0) / N_SLIDES, 0, + 1 - (i + 1.0) / N_SLIDES, 1); + + cairo_rectangle (cr, x + width/2 - 10, y + height/2 - 10, 20, 20); + + cairo_fill (cr); } } @@ -71,7 +76,7 @@ int deck_get_view_slide (Deck *deck, GdkRectangle *viewport) { - int slide_height = get_slide_height (deck, viewport); + int slide_height = deck_get_slide_height (deck, viewport); /* Compute the y-coordinate of the first visible top edge of a slide */ return (viewport->y - MARGIN) / (MARGIN + slide_height) + 1; @@ -85,7 +90,7 @@ deck_get_slide_location (Deck *deck, GdkRectangle *viewport, int nth_slide) { - int slide_height = get_slide_height (deck, viewport); + int slide_height = deck_get_slide_height (deck, viewport); return nth_slide * (MARGIN + slide_height) + MARGIN; } @@ -93,7 +98,7 @@ deck_get_slide_location (Deck *deck, int deck_get_height (Deck *deck, GdkRectangle *viewport) { - int slide_height = get_slide_height (deck, viewport); + int slide_height = deck_get_slide_height (deck, viewport); return N_SLIDES * slide_height + (N_SLIDES + 1) * MARGIN; } diff --git a/deck.h b/deck.h index 5b01599..22c1ee3 100644 --- a/deck.h +++ b/deck.h @@ -24,4 +24,8 @@ deck_get_slide_location (Deck *deck, GdkRectangle *viewport, int nth_slide); int +deck_get_slide_height (Deck *deck, + GdkRectangle *viewport); + +int deck_get_height (Deck *deck, GdkRectangle *viewport); diff --git a/main.c b/main.c index 80aa2c4..0e93334 100644 --- a/main.c +++ b/main.c @@ -96,6 +96,27 @@ on_main_viewport_size_changed (FooScrollArea *scroll_area, foo_scroll_area_invalidate (scroll_area); } +static void +make_thumbnail_viewable (App *app) +{ + FooScrollArea *area = FOO_SCROLL_AREA (app->thumbnails); + GdkRectangle viewport; + int top, height; + const int margin = 10; + + foo_scroll_area_get_viewport (area, &viewport); + + top = deck_get_slide_location (app->deck, &viewport, app->nth_slide); + height = deck_get_slide_height (app->deck, &viewport); + + if (top - margin < viewport.y) + viewport.y = top - margin; + else if (top + height + margin > viewport.y + viewport.height) + viewport.y = top + height - viewport.height - margin; + + foo_scroll_area_set_viewport_pos (area, viewport.x, viewport.y); +} + static void on_viewport_changed (FooScrollArea *scroll_area, GdkRectangle *viewport, @@ -107,7 +128,8 @@ on_viewport_changed (FooScrollArea *scroll_area, App *app = data; app->nth_slide = deck_get_view_slide (app->deck, viewport); - g_print ("nth: %d\n", app->nth_slide); + + make_thumbnail_viewable (app); } } -- cgit v1.2.3