diff options
author | Owen Taylor <owt1@cornell.edu> | 1998-01-30 03:58:47 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 1998-01-30 03:58:47 +0000 |
commit | 7922f34318d4f5f3262a4c22336aa6bd5eb8d143 (patch) | |
tree | fa02934fe8f7009869bcbaaec179a9ee4906fb22 /gtk/gtkstyle.c | |
parent | ac492cfab6574f65e07ff257018186e29e2f7ee6 (diff) | |
download | gdk-pixbuf-7922f34318d4f5f3262a4c22336aa6bd5eb8d143.tar.gz |
Close the polygon if it isn't already. (To match gtk_draw_polygon)
Thu Jan 29 22:57:39 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtkstyle.c (gtk_default_draw_polygon): Close
the polygon if it isn't already. (To match gtk_draw_polygon)
Simplified logic. (Appearance could probably be
improved for objects with gradual curves by adding in
some intermediate edge coloration)
Diffstat (limited to 'gtk/gtkstyle.c')
-rw-r--r-- | gtk/gtkstyle.c | 56 |
1 files changed, 20 insertions, 36 deletions
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c index db9ee483d..12652f652 100644 --- a/gtk/gtkstyle.c +++ b/gtk/gtkstyle.c @@ -1186,28 +1186,32 @@ gtk_default_draw_polygon (GtkStyle *style, if (fill) gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints); - npoints -= 1; + /* Check if polygon is closed */ + + if ((points[0].x == points[npoints-1].x) && + (points[0].y == points[npoints-1].y)) + npoints--; + for (i = 0; i < npoints; i++) { - if ((points[i].x == points[i+1].x) && - (points[i].y == points[i+1].y)) + GdkPoint *next; + + next = (i == npoints-1) ? &points[0] : &points[i+1]; + + if ((points[i].x == next->x) && + (points[i].y == next->y)) { angle = 0; } else { - angle = atan2 (points[i+1].y - points[i].y, - points[i+1].x - points[i].x); + angle = atan2 (next->y - points[i].y, + next->x - points[i].x); } if ((angle > -pi_3_over_4) && (angle < pi_over_4)) { - while (angle < 0) - angle += M_PI; - while (angle > M_PI) - angle -= M_PI; - - if ((angle > pi_3_over_4) || (angle < pi_over_4)) + if (angle > -pi_over_4) { xadjust = 0; yadjust = 1; @@ -1220,34 +1224,14 @@ gtk_default_draw_polygon (GtkStyle *style, gdk_draw_line (window, gc1, points[i].x-xadjust, points[i].y-yadjust, - points[i+1].x-xadjust, points[i+1].y-yadjust); + next->x-xadjust, next->y-yadjust); gdk_draw_line (window, gc3, points[i].x, points[i].y, - points[i+1].x, points[i+1].y); - } - } - - for (i = 0; i < npoints; i++) - { - if ((points[i].x == points[i+1].x) && - (points[i].y == points[i+1].y)) - { - angle = 0; + next->x, next->y); } else { - angle = atan2 (points[i+1].y - points[i].y, - points[i+1].x - points[i].x); - } - - if ((angle <= -pi_3_over_4) || (angle >= pi_over_4)) - { - while (angle < 0) - angle += M_PI; - while (angle > M_PI) - angle -= M_PI; - - if ((angle > pi_3_over_4) || (angle < pi_over_4)) + if ((angle < -pi_3_over_4) || (angle > pi_3_over_4)) { xadjust = 0; yadjust = 1; @@ -1260,10 +1244,10 @@ gtk_default_draw_polygon (GtkStyle *style, gdk_draw_line (window, gc4, points[i].x+xadjust, points[i].y+yadjust, - points[i+1].x+xadjust, points[i+1].y+yadjust); + next->x+xadjust, next->y+yadjust); gdk_draw_line (window, gc2, points[i].x, points[i].y, - points[i+1].x, points[i+1].y); + next->x, next->y); } } } |