diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2010-10-12 03:46:40 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2010-12-04 15:38:20 +0100 |
commit | 2e8b1cd358207442ea8bf914d9be12ead9510f65 (patch) | |
tree | 5f4194d6f12f26d929c8b974548942e226641a2c | |
parent | a65d0d00c003452f65273c6acc6793f1d815fa51 (diff) | |
download | gtk+-2e8b1cd358207442ea8bf914d9be12ead9510f65.tar.gz |
Gtk9Slice: Fix stretch case.
-rw-r--r-- | gtk/gtk9slice.c | 61 | ||||
-rw-r--r-- | gtk/gtk9slice.h | 4 |
2 files changed, 42 insertions, 23 deletions
diff --git a/gtk/gtk9slice.c b/gtk/gtk9slice.c index 7cd6ad47ab..4b5a0184f6 100644 --- a/gtk/gtk9slice.c +++ b/gtk/gtk9slice.c @@ -54,8 +54,8 @@ gtk_9slice_new (GdkPixbuf *pixbuf, gdouble distance_bottom, gdouble distance_left, gdouble distance_right, - GtkSliceSideModifier vertical_modifier, - GtkSliceSideModifier horizontal_modifier) + GtkSliceSideModifier horizontal_modifier, + GtkSliceSideModifier vertical_modifier) { Gtk9Slice *slice; cairo_surface_t *surface; @@ -185,13 +185,13 @@ gtk_9slice_new (GdkPixbuf *pixbuf, static void render_border (cairo_t *cr, cairo_surface_t *surface, + guint side, gdouble x, gdouble y, gdouble width, gdouble height, GtkSliceSideModifier modifier) { - cairo_pattern_t *pattern; cairo_matrix_t matrix; cairo_save (cr); @@ -199,28 +199,47 @@ render_border (cairo_t *cr, cairo_rectangle (cr, x, y, width, height); cairo_clip (cr); - pattern = cairo_pattern_create_for_surface (surface); + if (modifier == GTK_SLICE_REPEAT) + { + cairo_pattern_t *pattern; - cairo_matrix_init_translate (&matrix, - x, - y); + pattern = cairo_pattern_create_for_surface (surface); - if (modifier == GTK_SLICE_REPEAT) - cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); + cairo_matrix_init_translate (&matrix, - x, - y); + cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); + + cairo_pattern_set_matrix (pattern, &matrix); + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + + cairo_rectangle (cr, x, y, width, height); + } else { - gint w; - - w = cairo_image_surface_get_width (surface); - cairo_matrix_scale (&matrix, width / w, 0); + gint d; + + if (side == SIDE_TOP || side == SIDE_BOTTOM) + { + d = cairo_image_surface_get_width (surface); + + cairo_translate (cr, x + (width / 2), y); + cairo_scale (cr, width / d, 1); + cairo_set_source_surface (cr, surface, - d / 2, 0); + cairo_rectangle (cr, - width / 2, 0, width, height); + } + else + { + d = cairo_image_surface_get_height (surface); + + cairo_translate (cr, x, y + (height / 2)); + cairo_scale (cr, 1, height / d); + cairo_set_source_surface (cr, surface, 0, - d / 2); + cairo_rectangle (cr, 0, - height / 2, width, height); + } } - cairo_pattern_set_matrix (pattern, &matrix); - cairo_set_source (cr, pattern); - - cairo_rectangle (cr, x, y, width, height); cairo_fill (cr); - cairo_pattern_destroy (pattern); - cairo_restore (cr); } @@ -261,7 +280,7 @@ gtk_9slice_render (Gtk9Slice *slice, surface = slice->surfaces[BORDER_MIDDLE][BORDER_TOP]; img_height = cairo_image_surface_get_height (surface); - render_border (cr, surface, + render_border (cr, surface, SIDE_TOP, x + slice->distances[SIDE_LEFT], y, (gdouble) width - slice->distances[SIDE_LEFT] - slice->distances[SIDE_RIGHT], (gdouble) img_height, @@ -271,7 +290,7 @@ gtk_9slice_render (Gtk9Slice *slice, surface = slice->surfaces[BORDER_MIDDLE][BORDER_BOTTOM]; img_height = cairo_image_surface_get_height (surface); - render_border (cr, surface, + render_border (cr, surface, SIDE_BOTTOM, x + slice->distances[SIDE_LEFT], y + height - img_height, (gdouble) width - slice->distances[SIDE_LEFT] - slice->distances[SIDE_RIGHT], (gdouble) img_height, @@ -281,7 +300,7 @@ gtk_9slice_render (Gtk9Slice *slice, surface = slice->surfaces[BORDER_LEFT][BORDER_MIDDLE]; img_width = cairo_image_surface_get_width (surface); - render_border (cr, surface, + render_border (cr, surface, SIDE_LEFT, x, y + slice->distances[SIDE_TOP], (gdouble) img_width, (gdouble) height - slice->distances[SIDE_TOP] - slice->distances[SIDE_BOTTOM], @@ -291,7 +310,7 @@ gtk_9slice_render (Gtk9Slice *slice, surface = slice->surfaces[BORDER_RIGHT][BORDER_MIDDLE]; img_width = cairo_image_surface_get_width (surface); - render_border (cr, surface, + render_border (cr, surface, SIDE_RIGHT, x + width - img_width, y + slice->distances[SIDE_TOP], (gdouble) img_width, height - slice->distances[SIDE_TOP] - slice->distances[SIDE_BOTTOM], slice->modifiers[SIDE_RIGHT]); diff --git a/gtk/gtk9slice.h b/gtk/gtk9slice.h index 28d998b4e3..10e3df079d 100644 --- a/gtk/gtk9slice.h +++ b/gtk/gtk9slice.h @@ -41,8 +41,8 @@ Gtk9Slice * gtk_9slice_new (GdkPixbuf *pixbuf, gdouble distance_bottom, gdouble distance_left, gdouble distance_right, - GtkSliceSideModifier vertical_modifier, - GtkSliceSideModifier horizontal_modifier); + GtkSliceSideModifier horizontal_modifier, + GtkSliceSideModifier vertical_modifier); Gtk9Slice * gtk_9slice_ref (Gtk9Slice *slice); void gtk_9slice_unref (Gtk9Slice *slice); |