diff options
author | Søren Sandmann <sandmann@redhat.com> | 2008-06-05 18:16:52 -0400 |
---|---|---|
committer | Søren Sandmann <sandmann@redhat.com> | 2008-06-05 18:16:52 -0400 |
commit | e9eaa5b1ec9eb280589f7f692ca8191dddca9ee7 (patch) | |
tree | 9dd36848a8dda44df1b17801682313eed9439105 /main.c | |
parent | 44ffeb68a9914aba719767ce4c318abceaa87b6a (diff) |
TODO; draw some slides
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 82 |
1 files changed, 71 insertions, 11 deletions
@@ -35,6 +35,13 @@ on_thumbs_paint (FooScrollArea *scroll_area, } +#define MARGIN 20 +#define RATIO 1.414 +#define N_SLIDES 10 + +int slide_width; +int slide_height; + static void on_main_paint (FooScrollArea *scroll_area, cairo_t *cr, @@ -42,10 +49,74 @@ on_main_paint (FooScrollArea *scroll_area, GdkRegion *region, gpointer data) { + int i; + + cairo_move_to (cr, MARGIN, MARGIN); + + for (i = 0; i < N_SLIDES; ++i) + { + cairo_move_to (cr, MARGIN, MARGIN + i * (MARGIN + slide_height)); + + cairo_set_source_rgba (cr, 1, 1, 1, 1); + + cairo_rel_line_to (cr, slide_width, 0); + cairo_rel_line_to (cr, 0, slide_height); + cairo_rel_line_to (cr, -slide_width, 0); + cairo_close_path (cr); + + cairo_fill_preserve (cr); + + cairo_set_source_rgba (cr, 0, 0, 0, 0.5); + cairo_set_line_width (cr, 2); + cairo_stroke (cr); + + } + g_print ("paint %d %d %d %d\n", extents->x, extents->y, extents->width, extents->height); } static void +on_viewport_changed (FooScrollArea *scroll_area, + GdkRectangle *viewport, + GdkRectangle *old_viewport) +{ + int th; + double ratio; + + if (old_viewport) + { + slide_width = viewport->width - 2 * MARGIN; + slide_height = slide_width / RATIO; + + th = N_SLIDES * slide_height + (N_SLIDES + 1) * MARGIN; + + g_print ("new slide height: %d, new y: %d\n", slide_height, viewport->y); + + /* FIXME: We can recurse infinitely here when the area gets + * narrow enough that the scrollbar disappears causing the area + * to widen a little causing the scrollbar to appear causing + * the arrow to narrow causing ... + * + * For now we work around by have POLICY_ALWAYS on the scrollbar, + * it needs to be thought through and fixed in the scroll area + */ + + ratio = (double)viewport->width / old_viewport->width; + + g_print ("ratio: %f (%d %d)\n", ratio, old_viewport->y, (int)(old_viewport->y * ratio)); + + foo_scroll_area_set_size_fixed_y (scroll_area, viewport->width, th, + old_viewport->y + 100, + (old_viewport->y + 100) * ratio + 0.5); + } + +#if 0 + foo_scroll_area_set_size (scroll_area, viewport->width, th); +#endif + foo_scroll_area_invalidate (scroll_area); +} + +static void set_size (GtkWindow *window) { GdkScreen *screen; @@ -65,14 +136,6 @@ set_size (GtkWindow *window) gtk_window_resize (window, width, height); } -static void -on_viewport_changed (FooScrollArea *scroll_area, - GdkRectangle *viewport, - GdkRectangle *old_viewport) -{ - foo_scroll_area_set_size (scroll_area, 800, 30); -} - int main (int argc, char **argv) { @@ -94,15 +157,12 @@ main (int argc, char **argv) GTK_CONTAINER (get_widget (app, "thumbnails_scrolled_window")), app->thumbnails); - foo_scroll_area_set_size (app->main_area, 80, 30); foo_scroll_area_set_min_size (app->thumbnails, 200, -1); g_signal_connect (app->main_area, "paint", G_CALLBACK (on_main_paint), app); -#if 0 g_signal_connect (app->main_area, "viewport_changed", G_CALLBACK (on_viewport_changed), app); -#endif g_signal_connect (app->thumbnails, "paint", G_CALLBACK (on_thumbs_paint), app); |