[gtk/baselineoverlay: 3008/3010] inspector: Draw baselines as an overlay
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/baselineoverlay: 3008/3010] inspector: Draw baselines as an overlay
- Date: Mon, 10 Feb 2020 05:12:18 +0000 (UTC)
commit 4a978dc8c464cbf2ae400ec4b582d5a7e9a4fe90
Author: Matthias Clasen <mclasen redhat com>
Date: Mon May 13 17:36:46 2019 +0000
inspector: Draw baselines as an overlay
gtk/inspector/baselineoverlay.c | 106 ++++++++++++++++++++++++++++++++++++++++
gtk/inspector/baselineoverlay.h | 17 +++++++
gtk/inspector/meson.build | 1 +
gtk/inspector/visual.c | 35 ++++++++++---
4 files changed, 152 insertions(+), 7 deletions(-)
---
diff --git a/gtk/inspector/baselineoverlay.c b/gtk/inspector/baselineoverlay.c
new file mode 100644
index 0000000000..276a4cc82e
--- /dev/null
+++ b/gtk/inspector/baselineoverlay.c
@@ -0,0 +1,106 @@
+
+#include "config.h"
+#include "baselineoverlay.h"
+#include "gtkwidgetprivate.h"
+#include "gtkcssstyleprivate.h"
+#include "gtkcssnodeprivate.h"
+#include "gtkcssnumbervalueprivate.h"
+#include "gtkcssboxesprivate.h"
+
+struct _GtkBaselineOverlay
+{
+ GtkInspectorOverlay parent_instance;
+};
+
+struct _GtkBaselineOverlayClass
+{
+ GtkInspectorOverlayClass parent_class;
+};
+
+G_DEFINE_TYPE (GtkBaselineOverlay, gtk_baseline_overlay, GTK_TYPE_INSPECTOR_OVERLAY)
+
+static void
+recurse_child_widgets (GtkWidget *widget,
+ GtkSnapshot *snapshot)
+{
+ int baseline;
+ GtkWidget *child;
+ GtkCssBoxes boxes;
+
+ if (!gtk_widget_get_mapped (widget))
+ return;
+
+ if (gtk_widget_get_overflow (widget) == GTK_OVERFLOW_HIDDEN)
+ {
+ gtk_css_boxes_init (&boxes, widget);
+ gtk_snapshot_push_rounded_clip (snapshot, gtk_css_boxes_get_padding_box (&boxes));
+ }
+
+ baseline = gtk_widget_get_allocated_baseline (widget);
+
+ if (baseline != -1)
+ {
+ GdkRGBA red = {1, 0, 0, 1};
+ graphene_rect_t bounds;
+ int width;
+
+ width = gtk_widget_get_width (widget);
+
+ /* Now do all the stuff */
+ gtk_snapshot_push_debug (snapshot, "Widget baseline debugging");
+
+ graphene_rect_init (&bounds,
+ 0, baseline,
+ width, 1);
+ gtk_snapshot_append_color (snapshot, &red, &bounds);
+
+ gtk_snapshot_pop (snapshot);
+ }
+
+ /* Recurse into child widgets */
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ graphene_matrix_t matrix;
+
+ if (gtk_widget_compute_transform (child, widget, &matrix))
+ {
+ gtk_snapshot_save (snapshot);
+ gtk_snapshot_transform_matrix (snapshot, &matrix);
+ recurse_child_widgets (child, snapshot);
+ gtk_snapshot_restore (snapshot);
+ }
+ }
+
+ if (gtk_widget_get_overflow (widget) == GTK_OVERFLOW_HIDDEN)
+ gtk_snapshot_pop (snapshot);
+}
+
+static void
+gtk_baseline_overlay_snapshot (GtkInspectorOverlay *overlay,
+ GtkSnapshot *snapshot,
+ GskRenderNode *node,
+ GtkWidget *widget)
+{
+ recurse_child_widgets (widget, snapshot);
+}
+
+static void
+gtk_baseline_overlay_init (GtkBaselineOverlay *self)
+{
+}
+
+static void
+gtk_baseline_overlay_class_init (GtkBaselineOverlayClass *klass)
+{
+ GtkInspectorOverlayClass *overlay_class = (GtkInspectorOverlayClass *)klass;
+
+ overlay_class->snapshot = gtk_baseline_overlay_snapshot;
+}
+
+GtkInspectorOverlay *
+gtk_baseline_overlay_new (void)
+{
+ return g_object_new (GTK_TYPE_BASELINE_OVERLAY, NULL);
+}
diff --git a/gtk/inspector/baselineoverlay.h b/gtk/inspector/baselineoverlay.h
new file mode 100644
index 0000000000..5901940101
--- /dev/null
+++ b/gtk/inspector/baselineoverlay.h
@@ -0,0 +1,17 @@
+#ifndef __GTK_BASELINE_OVERLAY_H__
+#define __GTK_BASELINE_OVERLAY_H__
+
+#include "inspectoroverlay.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_BASELINE_OVERLAY (gtk_baseline_overlay_get_type ())
+G_DECLARE_FINAL_TYPE (GtkBaselineOverlay, gtk_baseline_overlay, GTK, BASELINE_OVERLAY, GtkInspectorOverlay)
+
+GtkInspectorOverlay * gtk_baseline_overlay_new (void);
+
+G_END_DECLS
+
+
+
+#endif
diff --git a/gtk/inspector/meson.build b/gtk/inspector/meson.build
index dbcea03bb0..c945386d2d 100644
--- a/gtk/inspector/meson.build
+++ b/gtk/inspector/meson.build
@@ -1,6 +1,7 @@
inspector_sources = files(
'action-editor.c',
'actions.c',
+ 'baselineoverlay.c',
'cellrenderergraph.c',
'controllers.c',
'css-editor.c',
diff --git a/gtk/inspector/visual.c b/gtk/inspector/visual.c
index ef78b33a07..7fcf969905 100644
--- a/gtk/inspector/visual.c
+++ b/gtk/inspector/visual.c
@@ -24,6 +24,7 @@
#include "updatesoverlay.h"
#include "layoutoverlay.h"
#include "focusoverlay.h"
+#include "baselineoverlay.h"
#include "window.h"
#include "gtkadjustment.h"
@@ -94,6 +95,7 @@ struct _GtkInspectorVisualPrivate
GtkInspectorOverlay *updates_overlay;
GtkInspectorOverlay *layout_overlay;
GtkInspectorOverlay *focus_overlay;
+ GtkInspectorOverlay *baseline_overlay;
GdkDisplay *display;
};
@@ -354,18 +356,37 @@ fallback_activate (GtkSwitch *sw,
}
static void
-baselines_activate (GtkSwitch *sw)
+baselines_activate (GtkSwitch *sw,
+ GParamSpec *pspec,
+ GtkInspectorVisual *vis)
{
- guint flags;
+ GtkInspectorVisualPrivate *priv = vis->priv;
+ GtkInspectorWindow *iw;
+ gboolean baselines;
- flags = gtk_get_debug_flags ();
+ baselines = gtk_switch_get_active (sw);
+ iw = GTK_INSPECTOR_WINDOW (gtk_widget_get_root (GTK_WIDGET (vis)));
+ if (iw == NULL)
+ return;
- if (gtk_switch_get_active (sw))
- flags |= GTK_DEBUG_BASELINES;
+ if (baselines)
+ {
+ if (priv->baseline_overlay == NULL)
+ {
+ priv->baseline_overlay = gtk_baseline_overlay_new ();
+ gtk_inspector_window_add_overlay (iw, priv->baseline_overlay);
+ g_object_unref (priv->baseline_overlay);
+ }
+ }
else
- flags &= ~GTK_DEBUG_BASELINES;
+ {
+ if (priv->baseline_overlay != NULL)
+ {
+ gtk_inspector_window_remove_overlay (iw, priv->baseline_overlay);
+ priv->baseline_overlay = NULL;
+ }
+ }
- gtk_set_debug_flags (flags);
redraw_everything ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]