Compare commits

...

3 Commits

Author SHA1 Message Date
Matthias Clasen
b7f5f1ecee builder-tool: screenshot shadows
This is usually what is wanted.
2022-05-05 16:19:32 -04:00
Matthias Clasen
a6a56f0bc8 magnifier: Capture shadows
This is the expected behavior, we want to see shadows
in the magnifier in the inspector.t
2022-05-05 16:19:32 -04:00
Matthias Clasen
27dab3cc39 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).
2022-05-05 16:19:32 -04:00
4 changed files with 93 additions and 3 deletions

View File

@@ -112,6 +112,7 @@ gtk_magnifier_snapshot (GtkWidget *widget,
width = gtk_widget_get_width (widget);
height = gtk_widget_get_height (widget);
paintable_width = gdk_paintable_get_intrinsic_width (magnifier->paintable);
paintable_height = gdk_paintable_get_intrinsic_height (magnifier->paintable);
if (paintable_width <= 0.0 || paintable_height <= 0.0)
@@ -216,6 +217,8 @@ gtk_magnifier_init (GtkMagnifier *magnifier)
magnifier->magnification = 1;
magnifier->resize = FALSE;
magnifier->paintable = gtk_widget_paintable_new (NULL);
gtk_widget_paintable_set_observed_area (GTK_WIDGET_PAINTABLE (magnifier->paintable),
GTK_WIDGET_PAINTABLE_AREA_RENDERED);
g_signal_connect_swapped (magnifier->paintable, "invalidate-contents", G_CALLBACK (gtk_widget_queue_draw), magnifier);
g_signal_connect_swapped (magnifier->paintable, "invalidate-size", G_CALLBACK (gtk_widget_queue_resize), magnifier);
}

View File

@@ -24,6 +24,7 @@
#include "gtkintl.h"
#include "gtksnapshot.h"
#include "gtkrendernodepaintableprivate.h"
#include "gtktypebuiltins.h"
#include "gtkwidgetprivate.h"
/**
@@ -61,6 +62,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
@@ -71,12 +74,28 @@ struct _GtkWidgetPaintableClass
enum {
PROP_0,
PROP_WIDGET,
PROP_OBSERVED_AREA,
N_PROPS,
};
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 +113,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);
@@ -162,6 +181,10 @@ gtk_widget_paintable_set_property (GObject *object,
gtk_widget_paintable_set_widget (self, g_value_get_object (value));
break;
case PROP_OBSERVED_AREA:
gtk_widget_paintable_set_observed_area (self, g_value_get_enum (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -182,6 +205,10 @@ gtk_widget_paintable_get_property (GObject *object,
g_value_set_object (value, self->widget);
break;
case PROP_OBSERVED_AREA:
g_value_set_enum (value, self->area);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -249,6 +276,14 @@ gtk_widget_paintable_class_init (GtkWidgetPaintableClass *klass)
GTK_TYPE_WIDGET,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
properties[PROP_OBSERVED_AREA] =
g_param_spec_enum ("observed-area",
P_("Area"),
P_("Observed area"),
GTK_TYPE_WIDGET_PAINTABLE_AREA,
GTK_WIDGET_PAINTABLE_AREA_WIDGET,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
@@ -256,6 +291,7 @@ static void
gtk_widget_paintable_init (GtkWidgetPaintable *self)
{
self->current_image = gdk_paintable_new_empty (0, 0);
self->area = GTK_WIDGET_PAINTABLE_AREA_WIDGET;
}
/**
@@ -284,12 +320,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 +440,32 @@ gtk_widget_paintable_pop_snapshot_count (GtkWidgetPaintable *self)
{
self->snapshot_count--;
}
/**
* gtk_widget_paintable_set_observed_area:
* @self: a `GtkWidgetPaintable`
* @area: the area to observe
*
* Sets what area the paintable should observe.
*
* Since: 4.8
*/
void
gtk_widget_paintable_set_observed_area (GtkWidgetPaintable *self,
GtkWidgetPaintableArea area)
{
if (self->area == area)
return;
self->area = area;
g_object_notify (G_OBJECT (self), "observed-area");
gdk_paintable_invalidate_size (GDK_PAINTABLE (self));
gdk_paintable_invalidate_contents (GDK_PAINTABLE (self));
}
GtkWidgetPaintableArea
gtk_widget_paintable_get_observed_area (GtkWidgetPaintable *self)
{
return self->area;
}

View File

@@ -38,6 +38,27 @@ GDK_AVAILABLE_IN_ALL
void gtk_widget_paintable_set_widget (GtkWidgetPaintable *self,
GtkWidget *widget);
/**
* GtkWidgetPaintableArea:
* @GTK_WIDGET_PAINTABLE_AREA_WIDGET: Restrict the paintable to the widget bounds
* @GTK_WIDGET_PAINTABLE_AREA_RENDERED: Include all render nodes produced by the
* widget in the paintable area
*
* Used to indicate what area should be captured by a widget paintable.
*/
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);
GDK_AVAILABLE_IN_4_8
GtkWidgetPaintableArea
gtk_widget_paintable_get_observed_area (GtkWidgetPaintable *self);
G_END_DECLS
#endif /* __GTK_WIDGET_PAINTABLE_H__ */

View File

@@ -100,6 +100,7 @@ snapshot_widget (GtkWidget *widget)
* to delay the snapshot.
*/
paintable = gtk_widget_paintable_new (widget);
gtk_widget_paintable_set_observed_area (GTK_WIDGET_PAINTABLE (paintable), GTK_WIDGET_PAINTABLE_AREA_RENDERED);
g_signal_connect (paintable, "invalidate-contents", G_CALLBACK (draw_paintable), &texture);
g_main_loop_run (loop);