1 | |
2 | #include "config.h" |
3 | #include "baselineoverlay.h" |
4 | #include "gtkwidgetprivate.h" |
5 | #include "gtkcssstyleprivate.h" |
6 | #include "gtkcssnodeprivate.h" |
7 | #include "gtkcssnumbervalueprivate.h" |
8 | #include "gtkcssboxesprivate.h" |
9 | |
10 | struct _GtkBaselineOverlay |
11 | { |
12 | GtkInspectorOverlay parent_instance; |
13 | }; |
14 | |
15 | struct _GtkBaselineOverlayClass |
16 | { |
17 | GtkInspectorOverlayClass parent_class; |
18 | }; |
19 | |
20 | G_DEFINE_TYPE (GtkBaselineOverlay, gtk_baseline_overlay, GTK_TYPE_INSPECTOR_OVERLAY) |
21 | |
22 | static void |
23 | recurse_child_widgets (GtkWidget *widget, |
24 | GtkSnapshot *snapshot) |
25 | { |
26 | int baseline; |
27 | GtkWidget *child; |
28 | GtkCssBoxes boxes; |
29 | |
30 | if (!gtk_widget_get_mapped (widget)) |
31 | return; |
32 | |
33 | if (gtk_widget_get_overflow (widget) == GTK_OVERFLOW_HIDDEN) |
34 | { |
35 | gtk_css_boxes_init (boxes: &boxes, widget); |
36 | gtk_snapshot_push_rounded_clip (snapshot, bounds: gtk_css_boxes_get_padding_box (boxes: &boxes)); |
37 | } |
38 | |
39 | baseline = gtk_widget_get_allocated_baseline (widget); |
40 | |
41 | if (baseline != -1) |
42 | { |
43 | GdkRGBA red = {1, 0, 0, 1}; |
44 | graphene_rect_t bounds; |
45 | int width; |
46 | |
47 | width = gtk_widget_get_width (widget); |
48 | |
49 | /* Now do all the stuff */ |
50 | gtk_snapshot_push_debug (snapshot, message: "Widget baseline debugging" ); |
51 | |
52 | graphene_rect_init (r: &bounds, |
53 | x: 0, y: baseline, |
54 | width, height: 1); |
55 | gtk_snapshot_append_color (snapshot, color: &red, bounds: &bounds); |
56 | |
57 | gtk_snapshot_pop (snapshot); |
58 | } |
59 | |
60 | /* Recurse into child widgets */ |
61 | for (child = gtk_widget_get_first_child (widget); |
62 | child != NULL; |
63 | child = gtk_widget_get_next_sibling (widget: child)) |
64 | { |
65 | graphene_matrix_t matrix; |
66 | |
67 | if (gtk_widget_compute_transform (widget: child, target: widget, out_transform: &matrix)) |
68 | { |
69 | gtk_snapshot_save (snapshot); |
70 | gtk_snapshot_transform_matrix (snapshot, matrix: &matrix); |
71 | recurse_child_widgets (widget: child, snapshot); |
72 | gtk_snapshot_restore (snapshot); |
73 | } |
74 | } |
75 | |
76 | if (gtk_widget_get_overflow (widget) == GTK_OVERFLOW_HIDDEN) |
77 | gtk_snapshot_pop (snapshot); |
78 | } |
79 | |
80 | static void |
81 | gtk_baseline_overlay_snapshot (GtkInspectorOverlay *overlay, |
82 | GtkSnapshot *snapshot, |
83 | GskRenderNode *node, |
84 | GtkWidget *widget) |
85 | { |
86 | recurse_child_widgets (widget, snapshot); |
87 | } |
88 | |
89 | static void |
90 | gtk_baseline_overlay_init (GtkBaselineOverlay *self) |
91 | { |
92 | } |
93 | |
94 | static void |
95 | gtk_baseline_overlay_class_init (GtkBaselineOverlayClass *klass) |
96 | { |
97 | GtkInspectorOverlayClass *overlay_class = (GtkInspectorOverlayClass *)klass; |
98 | |
99 | overlay_class->snapshot = gtk_baseline_overlay_snapshot; |
100 | } |
101 | |
102 | GtkInspectorOverlay * |
103 | gtk_baseline_overlay_new (void) |
104 | { |
105 | return g_object_new (GTK_TYPE_BASELINE_OVERLAY, NULL); |
106 | } |
107 | |