From: Matthias Clasen Date: Mon, 13 Mar 2023 07:11:29 +0000 (+0100) Subject: gtk4-demo: Fix rotation handling in image scaling X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~5^2~7^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=88d9244b988146281fc041202f5efcfb2302e86f;p=gtk4.git gtk4-demo: Fix rotation handling in image scaling We weren't sizing the widget correctly in rotated cases. --- diff --git a/demos/gtk-demo/demo3widget.c b/demos/gtk-demo/demo3widget.c index 756cb7565d..6fc935cffd 100644 --- a/demos/gtk-demo/demo3widget.c +++ b/demos/gtk-demo/demo3widget.c @@ -67,15 +67,13 @@ demo3_widget_snapshot (GtkWidget *widget, if (G_APPROX_VALUE (self->angle, 90.f, FLT_EPSILON) || G_APPROX_VALUE (self->angle, 270.f, FLT_EPSILON)) { - double s; - - s = w2; + double s = w2; w2 = h2; h2 = s; } - x = MAX (0, (width - ceil (w2)) / 2); - y = MAX (0, (height - ceil (h2)) / 2); + x = (width - ceil (w2)) / 2; + y = (height - ceil (h2)) / 2; gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height)); gtk_snapshot_save (snapshot); @@ -102,14 +100,26 @@ demo3_widget_measure (GtkWidget *widget, int *natural_baseline) { Demo3Widget *self = DEMO3_WIDGET (widget); + int width, height; int size; + width = gdk_texture_get_width (self->texture); + height = gdk_texture_get_height (self->texture); + + if (G_APPROX_VALUE (self->angle, 90.f, FLT_EPSILON) || + G_APPROX_VALUE (self->angle, 270.f, FLT_EPSILON)) + { + int s = width; + width = height; + height = s; + } + if (orientation == GTK_ORIENTATION_HORIZONTAL) - size = gdk_texture_get_width (self->texture); + size = width; else - size = gdk_texture_get_height (self->texture); + size = height; - *minimum = *natural = self->scale * size; + *minimum = *natural = (int) ceil (self->scale * size); } static void