[gtk/magnifier-shadow: 1/2] widgetpaintable: Add an observed area enum




commit c9c880dbc4c92ff6f4520576c3eb7d8b4add8b1c
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu May 5 15:20:25 2022 -0400

    widgetpaintable: Add an observed area enum
    
    This can be used to capture just the widget area, or
    all of the rendered area (including shadows, etc).

 gtk/gtkwidgetpaintable.c | 30 +++++++++++++++++++++++++++---
 gtk/gtkwidgetpaintable.h |  9 +++++++++
 2 files changed, 36 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkwidgetpaintable.c b/gtk/gtkwidgetpaintable.c
index 50ea1582fb..6bb90988ef 100644
--- a/gtk/gtkwidgetpaintable.c
+++ b/gtk/gtkwidgetpaintable.c
@@ -61,6 +61,8 @@ struct _GtkWidgetPaintable
 
   GdkPaintable *current_image;          /* the image that we are presenting */
   GdkPaintable *pending_image;          /* the image that we should be presenting */
+
+  GtkWidgetPaintableArea area;
 };
 
 struct _GtkWidgetPaintableClass
@@ -77,6 +79,21 @@ enum {
 
 static GParamSpec *properties[N_PROPS] = { NULL, };
 
+static gboolean
+gtk_widget_paintable_compute_bounds (GtkWidgetPaintable *self,
+                                     graphene_rect_t    *bounds)
+{
+  if (self->area == GTK_WIDGET_PAINTABLE_AREA_WIDGET)
+    return gtk_widget_compute_bounds (self->widget, self->widget, bounds);
+  else if (self->widget->priv->render_node)
+    {
+      gsk_render_node_get_bounds (self->widget->priv->render_node, bounds);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 gtk_widget_paintable_paintable_snapshot (GdkPaintable *paintable,
                                          GdkSnapshot  *snapshot,
@@ -94,7 +111,7 @@ gtk_widget_paintable_paintable_snapshot (GdkPaintable *paintable,
       gtk_snapshot_push_clip (snapshot,
                               &GRAPHENE_RECT_INIT(0, 0, width, height));
 
-      if (gtk_widget_compute_bounds (self->widget, self->widget, &bounds))
+      if (gtk_widget_paintable_compute_bounds (self, &bounds))
         {
           gtk_snapshot_scale (snapshot, width / bounds.size.width, height / bounds.size.height);
           gtk_snapshot_translate (snapshot, &bounds.origin);
@@ -284,12 +301,12 @@ gtk_widget_paintable_snapshot_widget (GtkWidgetPaintable *self)
   if (self->widget == NULL)
     return gdk_paintable_new_empty (0, 0);
 
-  if (!gtk_widget_compute_bounds (self->widget, self->widget, &bounds))
+  if (!gtk_widget_paintable_compute_bounds (self, &bounds))
     return gdk_paintable_new_empty (0, 0);
 
   if (self->widget->priv->render_node == NULL)
     return gdk_paintable_new_empty (bounds.size.width, bounds.size.height);
-  
+
   return gtk_render_node_paintable_new (self->widget->priv->render_node, &bounds);
 }
 
@@ -404,3 +421,10 @@ gtk_widget_paintable_pop_snapshot_count (GtkWidgetPaintable *self)
 {
   self->snapshot_count--;
 }
+
+void
+gtk_widget_paintable_set_observed_area (GtkWidgetPaintable     *self,
+                                        GtkWidgetPaintableArea  area)
+{
+  self->area = area;
+}
diff --git a/gtk/gtkwidgetpaintable.h b/gtk/gtkwidgetpaintable.h
index 3af7ddf137..adf1411a4b 100644
--- a/gtk/gtkwidgetpaintable.h
+++ b/gtk/gtkwidgetpaintable.h
@@ -38,6 +38,15 @@ GDK_AVAILABLE_IN_ALL
 void            gtk_widget_paintable_set_widget         (GtkWidgetPaintable     *self,
                                                          GtkWidget              *widget);
 
+typedef enum {
+  GTK_WIDGET_PAINTABLE_AREA_WIDGET,
+  GTK_WIDGET_PAINTABLE_AREA_RENDERED
+} GtkWidgetPaintableArea;
+
+GDK_AVAILABLE_IN_4_8
+void            gtk_widget_paintable_set_observed_area  (GtkWidgetPaintable     *self,
+                                                         GtkWidgetPaintableArea  area);
+
 G_END_DECLS
 
 #endif /* __GTK_WIDGET_PAINTABLE_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]