summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@l3000.localdomain>2010-11-07 07:28:48 -0500
committerSøren Sandmann Pedersen <ssp@l3000.localdomain>2010-11-07 07:28:48 -0500
commitc38c861d3f8f4e0e1076368bb350131c6cd0e4aa (patch)
treeeec5ee3c55cfd4fdf08e1a3ee7cfd317d8dc7032
parent06410b056fd9ba73f1a179662aa31bcd8da9be47 (diff)
Add demo; fix bug
-rw-r--r--demo.c126
-rw-r--r--region-iter.c30
2 files changed, 149 insertions, 7 deletions
diff --git a/demo.c b/demo.c
new file mode 100644
index 0000000..712d12e
--- /dev/null
+++ b/demo.c
@@ -0,0 +1,126 @@
+#include <gtk/gtk.h>
+#include <glib.h>
+#include <cairo.h>
+
+#define NO_MAIN
+#include "region-iter.c"
+
+static const pixman_rectangle32_t rects[] = {
+ { 0, 50, 200, 100 },
+ { 250, 0, 200, 100 },
+ { 500, 0, 50, 350 },
+ { 400, 100, 50, 100 },
+ { 100, 150, 50, 50 },
+ { 50, 200, 150, 150 },
+ { 0, 300, 50, 50 },
+ { 200, 250, 100, 100 },
+ { 250, 150, 100, 100 },
+ { 350, 200, 100, 150 },
+ { 250, 350, 150, 50 },
+ { 450, 350, 50, 50 },
+ { 50, 450, 400, 50 },
+ { 25, 135, 600, 25 }
+};
+
+static corner_t *
+make_path (int *n_corners)
+{
+ corner_t *corners;
+ pixman_region32_t region;
+ int i;
+
+ pixman_region32_init (&region);
+
+ for (i = 0; i < sizeof (rects) / sizeof (rects[0]); ++i)
+ {
+ pixman_region32_union_rect (&region, &region,
+ rects[i].x, rects[i].y,
+ rects[i].width, rects[i].height);
+ }
+
+ corners = region_path (&region, n_corners);
+
+ pixman_region32_fini (&region);
+
+ return corners;
+}
+
+static gboolean
+on_expose (GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ cairo_t *cr;
+ int i;
+
+ if (GTK_WIDGET_DRAWABLE (widget))
+ {
+ corner_t *corners;
+ int n_corners;
+ int new = 0;
+
+ cr = gdk_cairo_create (widget->window);
+
+ for (i = 0; i < sizeof (rects) / sizeof (rects[0]); ++i)
+ {
+ cairo_rectangle (cr,
+ rects[i].x, rects[i].y,
+ rects[i].width, rects[i].height);
+
+ cairo_set_source_rgba (cr, 0, 0, 0.7, 0.7);
+ cairo_fill (cr);
+ }
+
+ corners = make_path (&n_corners);
+
+ for (i = 0; i < n_corners; ++i)
+ {
+ corner_t *corner = &(corners[i]);
+
+ cairo_move_to (cr, corner->x, corner->y);
+
+ while (corner->next != -1)
+ {
+ corner_t *next = &(corners[corner->next]);
+
+ cairo_line_to (cr, next->x, next->y);
+
+ corner->next = -1;
+ corner = next;
+ }
+ }
+
+ cairo_set_source_rgba (cr, 0.2, 0.8, 0.2, 0.6);
+
+ cairo_fill_preserve (cr);
+
+ cairo_set_source_rgba (cr, 0.0, 0.3, 0.0, 0.8);
+
+ cairo_stroke (cr);
+
+ free (corners);
+
+ cairo_destroy (cr);
+ }
+
+ return TRUE;
+}
+
+int
+main (int argc, char **argv)
+{
+ GtkWindow *window;
+
+ gtk_init (&argc, &argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ gtk_window_set_default_size (window, 1200, 768);
+
+ g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), NULL);
+
+ gtk_widget_show_all (window);
+
+ gtk_main ();
+
+ return 0;
+
+}
diff --git a/region-iter.c b/region-iter.c
index 37e9222..9820200 100644
--- a/region-iter.c
+++ b/region-iter.c
@@ -4,8 +4,12 @@
#include <limits.h>
#include <assert.h>
+#ifndef TRUE
#define TRUE 1
+#endif
+#ifndef FALSE
#define FALSE 0
+#endif
static const pixman_box32_t sentinel =
{
@@ -75,6 +79,7 @@ region_iter_init (region_iter_t *iter, pixman_region32_t *region)
{
iter->y = INT_MIN;
iter->first_row = TRUE;
+ iter->final_row = FALSE;
if (!region->data)
{
@@ -109,7 +114,7 @@ region_iter_get_row (region_iter_t *iter, row_t *row)
iter->final_row = FALSE;
iter->first = NULL;
-
+
return TRUE;
}
else if (iter->first_row || iter->y < iter->first->y1)
@@ -472,7 +477,7 @@ region_path (pixman_region32_t *region, int *n)
int *old_active;
int old_n_active;
int current;
-
+
old_active = active;
old_n_active = n_active;
@@ -493,7 +498,7 @@ region_path (pixman_region32_t *region, int *n)
corners[old_active[current]].x <= x2)
{
int c = old_active[current];
-
+
if (corners[c].x == x1)
p1 = c;
else if (corners[c].x == x2)
@@ -509,7 +514,7 @@ region_path (pixman_region32_t *region, int *n)
corners[c1].y = row1.y2;
corners[c2].x = x2;
corners[c2].y = row1.y2;
-
+
if (p1 != -1)
{
if (type == ROW1)
@@ -543,14 +548,20 @@ region_path (pixman_region32_t *region, int *n)
while (current < old_n_active)
active = add_active (active, &n_active, old_active[current++]);
-
- free (old_active);
+#if 0
+ int i;
+ printf ("active:\n");
+ for (i = 0; i < n_active; ++i)
+ printf (" %d %d, ", corners[active[i]].x, corners[active[i]].y);
+ printf ("\n");
+#endif
+
+ free (old_active);
row1 = row2;
}
*n = n_corners;
-
return corners;
}
@@ -578,6 +589,8 @@ dump_corners (corner_t *corners, int n_corners)
}
+#ifndef NO_MAIN
+
int
main ()
{
@@ -705,3 +718,6 @@ main ()
return 0;
}
+
+#endif
+