From 1b2ae02b2616b4e570492276809e946be6af1960 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 24 Mar 2023 15:30:27 -0400 Subject: [PATCH] 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. --- gtk/gtkmagnifier.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/gtk/gtkmagnifier.c b/gtk/gtkmagnifier.c index 04db746c44..e606ae23e8 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); -- 2.30.2