diff options
author | Søren Sandmann Pedersen <sandmann@redhat.com> | 2009-03-31 08:45:10 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <sandmann@redhat.com> | 2009-03-31 08:45:10 -0400 |
commit | 8be9a441d5ca0fe871bc2e936ba1cff0059a557b (patch) | |
tree | b8f0da2ec0c8490a94be439e0046c3cc473a6edd | |
parent | 554ee37c16690bfa38b78eaeeaf78e882391a41a (diff) |
Generate outline
-rw-r--r-- | region_to_path.c | 118 |
1 files changed, 104 insertions, 14 deletions
diff --git a/region_to_path.c b/region_to_path.c index 0b8a1ae..437bd08 100644 --- a/region_to_path.c +++ b/region_to_path.c @@ -3,16 +3,16 @@ #include <cairo.h> static const cairo_rectangle_int_t rects[] = { - { 0, 10, 40, 20 }, - { 50, 0, 40, 20 }, - { 100, 0, 10, 70 }, - { 80, 20, 10, 20 }, - { 20, 30, 10, 10 }, - { 10, 40, 30, 30 }, - { 0, 60, 10, 10 }, - { 40, 50, 20, 20 }, - { 50, 30, 20, 20 }, - { 70, 40, 20, 30 }, + { 0, 100, 400, 200 }, + { 500, 00, 400, 200 }, + { 1000, 00, 100, 700 }, + { 800, 200, 100, 200 }, + { 200, 300, 100, 100 }, + { 100, 400, 300, 300 }, + { 00, 600, 100, 100 }, + { 400, 500, 200, 200 }, + { 500, 300, 200, 200 }, + { 700, 400, 200, 300 }, }; typedef struct hsegment_t hsegment_t; @@ -107,6 +107,72 @@ compare_vsegments (gconstpointer p1, gconstpointer p2) } } +static void add_hsegment (cairo_t *cr, hsegment_t *h, gboolean go_right); + +static void +add_vsegment (cairo_t *cr, vsegment_t *v, gboolean go_down) +{ + hsegment_t *h; + gboolean go_right; + + if (!v->bottom) + return; + + if (go_down) + { + cairo_line_to (cr, v->x, v->y2); + + h = v->bottom; + } + else + { + cairo_line_to (cr, v->x, v->y1); + + h = v->top; + } + + if (h->left == v) + go_right = TRUE; + else + go_right = FALSE; + + v->top = v->bottom = NULL; + + add_hsegment (cr, h, go_right); +} + +static void +add_hsegment (cairo_t *cr, hsegment_t *h, gboolean go_right) +{ + vsegment_t *v; + gboolean go_down; + + if (!h->left) + return; + + if (go_right) + { + cairo_line_to (cr, h->x2, h->y); + + v = h->right; + } + else + { + cairo_line_to (cr, h->x1, h->y); + + v = h->left; + } + + if (v->top == h) + go_down = TRUE; + else + go_down = FALSE; + + h->left = h->right = NULL; + + add_vsegment (cr, v, go_down); +} + static void region_to_path (cairo_t *cr, cairo_region_t *region) { @@ -328,18 +394,31 @@ region_to_path (cairo_t *cr, cairo_region_t *region) if (cr) { + for (i = 0; i < hsegments->len; ++i) + { + hsegment_t *h = &g_array_index (hsegments, hsegment_t, i); + + if (h->left) + { + cairo_move_to (cr, h->x1, h->y); + add_hsegment (cr, h, TRUE); + } + } } + g_array_free (hsegments, TRUE); + g_array_free (vsegments, TRUE); } static gboolean on_expose (GtkWidget *widget, GdkEvent *event, gpointer data) { cairo_t *cr; - + if (GTK_WIDGET_DRAWABLE (widget)) { cairo_region_t *region; + cairo_rectangle_int_t rect; int i; region = cairo_region_create(); @@ -348,6 +427,15 @@ on_expose (GtkWidget *widget, GdkEvent *event, gpointer data) cairo_region_union_rectangle (region, &rects[i]); cr = gdk_cairo_create (widget->window); + +#if 0 + cairo_region_get_extents (region, &rect); + cairo_rectangle (cr, rect.x, rect.y, rect.width + 100, rect.height + 100); + cairo_set_source_rgba (cr, 0, 0, 1, 1); + cairo_fill (cr); +#endif + + cairo_region_translate (region, 50, 50); region_to_path (cr, region); @@ -355,11 +443,13 @@ on_expose (GtkWidget *widget, GdkEvent *event, gpointer data) cairo_fill_preserve (cr); - cairo_set_source_rgba (cr, 0.2, 0.8, 0.2, 1.0); + cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0); cairo_stroke (cr); cairo_destroy (cr); + + cairo_region_destroy (region); } return TRUE; @@ -374,9 +464,9 @@ main (int argc, char **argv) window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), NULL); + gtk_window_set_default_size (window, 1200, 768); - gtk_window_set_default_size (window, 1024, 768); + g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), NULL); gtk_widget_show_all (window); |