summaryrefslogtreecommitdiff
path: root/gtk/gtkiconhelper.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-03-15 18:10:01 +0100
committerBenjamin Otte <otte@redhat.com>2018-03-16 06:04:45 +0100
commitc6541853ab6cd593733ab310119fbd95056b32fe (patch)
treefea61c173419b1f2526a66afa733cd3bd6b56ed0 /gtk/gtkiconhelper.c
parent0a08c0388587500930a684d3bcf7d26d7dc7bd52 (diff)
downloadgtk+-c6541853ab6cd593733ab310119fbd95056b32fe.tar.gz
image: Add gtk_image_set_keep_aspect_ratio()
If set, the image will draw its contents while keeping their aspect ratio. That means empty areas show up on the top/bottom or left/right. Also move the special-case snapshotting code for icons to GtkIconHelper. That's where it belongs.
Diffstat (limited to 'gtk/gtkiconhelper.c')
-rw-r--r--gtk/gtkiconhelper.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c
index 5a38f2aea2..c9aff693b6 100644
--- a/gtk/gtkiconhelper.c
+++ b/gtk/gtkiconhelper.c
@@ -249,11 +249,41 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable,
if (self->paintable == NULL)
return;
- gtk_css_style_snapshot_icon_paintable (style,
- snapshot,
- self->paintable,
- width, height,
- self->texture_is_symbolic);
+ switch (gtk_image_definition_get_storage_type (self->def))
+ {
+ case GTK_IMAGE_ICON_NAME:
+ case GTK_IMAGE_GICON:
+ {
+ double x, y, w, h;
+
+ /* Never scale up icons. */
+ w = gdk_paintable_get_intrinsic_width (self->paintable);
+ h = gdk_paintable_get_intrinsic_height (self->paintable);
+ w = MIN (w, width);
+ h = MIN (h, height);
+ x = (width - w) / 2;
+ y = (height - h) / 2;
+ gtk_snapshot_offset (snapshot, x, y);
+ gtk_css_style_snapshot_icon_paintable (style,
+ snapshot,
+ self->paintable,
+ w, h,
+ self->texture_is_symbolic);
+ gtk_snapshot_offset (snapshot, -x, -y);
+ }
+ break;
+
+ case GTK_IMAGE_TEXTURE:
+ case GTK_IMAGE_PAINTABLE:
+ case GTK_IMAGE_EMPTY:
+ default:
+ gtk_css_style_snapshot_icon_paintable (style,
+ snapshot,
+ self->paintable,
+ width, height,
+ self->texture_is_symbolic);
+ break;
+ }
}
static GdkPaintable *