summaryrefslogtreecommitdiff
path: root/gtk/gtkmagnifier.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2023-03-24 15:30:27 -0400
committerMatthias Clasen <mclasen@redhat.com>2023-03-24 16:05:32 -0400
commitd2693ba66e6f560f350f4afebafc75366e9a5b14 (patch)
tree3569b49189b16a3abb28762eeac1dfefd6c3a96f /gtk/gtkmagnifier.c
parent9db08c7a86be691ccca80f5b0d18787552c0dff4 (diff)
downloadgtk+-d2693ba66e6f560f350f4afebafc75366e9a5b14.tar.gz
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.
Diffstat (limited to 'gtk/gtkmagnifier.c')
-rw-r--r--gtk/gtkmagnifier.c22
1 files changed, 18 insertions, 4 deletions
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);