1/*
2 * Copyright © 2018 Benjamin Otte
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Benjamin Otte <otte@gnome.org>
18 */
19
20#include "config.h"
21
22#include "highlightoverlay.h"
23
24#include "gtkintl.h"
25#include "gtkwidget.h"
26
27struct _GtkHighlightOverlay
28{
29 GtkInspectorOverlay parent_instance;
30
31 GtkWidget *widget;
32 GdkRGBA color;
33};
34
35struct _GtkHighlightOverlayClass
36{
37 GtkInspectorOverlayClass parent_class;
38};
39
40G_DEFINE_TYPE (GtkHighlightOverlay, gtk_highlight_overlay, GTK_TYPE_INSPECTOR_OVERLAY)
41
42static void
43gtk_highlight_overlay_snapshot (GtkInspectorOverlay *overlay,
44 GtkSnapshot *snapshot,
45 GskRenderNode *node,
46 GtkWidget *widget)
47{
48 GtkHighlightOverlay *self = GTK_HIGHLIGHT_OVERLAY (ptr: overlay);
49 graphene_rect_t bounds;
50
51 if (!gtk_widget_compute_bounds (widget: self->widget, target: widget, out_bounds: &bounds))
52 return;
53
54 gtk_snapshot_append_color (snapshot,
55 color: &self->color,
56 bounds: &bounds);
57}
58
59static void
60gtk_highlight_overlay_queue_draw (GtkInspectorOverlay *overlay)
61{
62 GtkHighlightOverlay *self = GTK_HIGHLIGHT_OVERLAY (ptr: overlay);
63
64 gtk_widget_queue_draw (widget: self->widget);
65}
66
67static void
68gtk_highlight_overlay_dispose (GObject *object)
69{
70 GtkHighlightOverlay *self = GTK_HIGHLIGHT_OVERLAY (ptr: object);
71
72 g_clear_object (&self->widget);
73
74 G_OBJECT_CLASS (gtk_highlight_overlay_parent_class)->dispose (object);
75}
76
77static void
78gtk_highlight_overlay_class_init (GtkHighlightOverlayClass *klass)
79{
80 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
81 GtkInspectorOverlayClass *overlay_class = GTK_INSPECTOR_OVERLAY_CLASS (ptr: klass);
82
83 overlay_class->snapshot = gtk_highlight_overlay_snapshot;
84 overlay_class->queue_draw = gtk_highlight_overlay_queue_draw;
85
86 gobject_class->dispose = gtk_highlight_overlay_dispose;
87}
88
89static void
90gtk_highlight_overlay_init (GtkHighlightOverlay *self)
91{
92 self->color = (GdkRGBA) { 0.0, 0.0, 1.0, 0.2 };
93}
94
95GtkInspectorOverlay *
96gtk_highlight_overlay_new (GtkWidget *widget)
97{
98 GtkHighlightOverlay *self;
99
100 self = g_object_new (GTK_TYPE_HIGHLIGHT_OVERLAY, NULL);
101
102 self->widget = g_object_ref (widget);
103
104 return GTK_INSPECTOR_OVERLAY (ptr: self);
105}
106
107GtkWidget *
108gtk_highlight_overlay_get_widget (GtkHighlightOverlay *self)
109{
110 return self->widget;
111}
112
113void
114gtk_highlight_overlay_set_color (GtkHighlightOverlay *self,
115 const GdkRGBA *color)
116{
117 if (gdk_rgba_equal (p1: &self->color, p2: color))
118 return;
119
120 self->color = *color;
121 gtk_inspector_overlay_queue_draw (self: GTK_INSPECTOR_OVERLAY (ptr: self));
122}
123

source code of gtk/gtk/inspector/highlightoverlay.c