From: Matthias Clasen Date: Fri, 24 Mar 2023 19:30:27 +0000 (-0400) Subject: magnifier: Correct position of area X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~1^2~505^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d2693ba66e6f560f350f4afebafc75366e9a5b14;p=gtk4.git magnifier: Correct position of area The widget paintable uses the widgets bounds as intrinsic size, so we need to offset from that to the allocation, which is what the coordinates are relative to. --- diff --git a/gtk/gtkmagnifier.c b/gtk/gtkmagnifier.c index a70bdf1c90..bca4db6b8a 100644 --- a/gtk/gtkmagnifier.c +++ b/gtk/gtkmagnifier.c @@ -20,6 +20,7 @@ #include "gtkmagnifierprivate.h" #include "gtkwidgetprivate.h" #include "gtksnapshot.h" +#include "gtkcssboxesprivate.h" enum { PROP_INSPECTED = 1, @@ -105,10 +106,23 @@ gtk_magnifier_snapshot (GtkWidget *widget, { GtkMagnifier *magnifier = GTK_MAGNIFIER (widget); double width, height, paintable_width, paintable_height; - - if (gtk_widget_paintable_get_widget (GTK_WIDGET_PAINTABLE (magnifier->paintable)) == NULL) + GtkWidget *inspected; + GtkCssBoxes boxes; + const graphene_rect_t *content_rect; + const graphene_rect_t *border_rect; + graphene_point_t offset; + + inspected = gtk_widget_paintable_get_widget (GTK_WIDGET_PAINTABLE (magnifier->paintable)); + if (inspected == NULL) return; + gtk_css_boxes_init (&boxes, inspected); + content_rect = gtk_css_boxes_get_content_rect (&boxes); + border_rect = gtk_css_boxes_get_border_rect (&boxes); + + offset.x = content_rect->origin.x - border_rect->origin.x; + offset.y = content_rect->origin.y - border_rect->origin.y; + width = gtk_widget_get_width (widget); height = gtk_widget_get_height (widget); paintable_width = gdk_paintable_get_intrinsic_width (magnifier->paintable); @@ -121,8 +135,8 @@ gtk_magnifier_snapshot (GtkWidget *widget, gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (width / 2, height / 2)); gtk_snapshot_scale (snapshot, magnifier->magnification, magnifier->magnification); gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT ( - - CLAMP (magnifier->x, 0, paintable_width), - - CLAMP (magnifier->y, 0, paintable_height))); + - CLAMP (magnifier->x + offset.x, 0, paintable_width), + - CLAMP (magnifier->y + offset.y, 0, paintable_height))); gdk_paintable_snapshot (magnifier->paintable, snapshot, paintable_width, paintable_height); gtk_snapshot_restore (snapshot);