Branch data Line data Source code
1 : : /*
2 : : * Copyright (C) 2023 James Westman <james@jwestman.net>
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 <https://www.gnu.org/licenses/>.
16 : : */
17 : :
18 : : #include <glib/gi18n.h>
19 : :
20 : : #include "shumate-inspector-page-private.h"
21 : : #include "shumate-inspector-settings-private.h"
22 : :
23 : : struct _ShumateInspectorPage {
24 : : GtkBox parent_instance;
25 : :
26 : : GObject *object;
27 : : };
28 : :
29 [ + - + - ]: 4 : G_DEFINE_FINAL_TYPE(ShumateInspectorPage, shumate_inspector_page, GTK_TYPE_BOX)
30 : :
31 : : enum {
32 : : PROP_0,
33 : : PROP_TITLE,
34 : : PROP_OBJECT,
35 : : PROP_SETTINGS,
36 : : N_PROPS
37 : : };
38 : :
39 : : static GParamSpec *props[N_PROPS];
40 : :
41 : : static void
42 : 0 : shumate_inspector_page_dispose (GObject *object)
43 : : {
44 : : /* When the inspector is closed, reset all the debug settings */
45 : 0 : shumate_inspector_settings_reset (shumate_inspector_settings_get_default ());
46 : :
47 : 0 : G_OBJECT_CLASS (shumate_inspector_page_parent_class)->dispose (object);
48 : 0 : }
49 : :
50 : : static void
51 : 0 : shumate_inspector_get_property (GObject *object,
52 : : guint prop_id,
53 : : GValue *value,
54 : : GParamSpec *pspec)
55 : : {
56 : 0 : ShumateInspectorPage *self = SHUMATE_INSPECTOR_PAGE (object);
57 : :
58 [ # # # # ]: 0 : switch (prop_id)
59 : : {
60 : 0 : case PROP_TITLE:
61 : 0 : g_value_set_string (value, _("Shumate"));
62 : 0 : break;
63 : 0 : case PROP_OBJECT:
64 : 0 : g_value_set_object (value, self->object);
65 : 0 : break;
66 : 0 : case PROP_SETTINGS:
67 : 0 : g_value_set_object (value, shumate_inspector_settings_get_default ());
68 : 0 : break;
69 : 0 : default:
70 : 0 : G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
71 : : }
72 : 0 : }
73 : :
74 : : static void
75 : 0 : shumate_inspector_set_property (GObject *object,
76 : : guint prop_id,
77 : : const GValue *value,
78 : : GParamSpec *pspec)
79 : : {
80 : 0 : ShumateInspectorPage *self = SHUMATE_INSPECTOR_PAGE (object);
81 : :
82 [ # # ]: 0 : switch (prop_id)
83 : : {
84 : 0 : case PROP_OBJECT:
85 : 0 : g_set_object (&self->object, g_value_get_object (value));
86 : 0 : break;
87 : 0 : default:
88 : 0 : G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
89 : : }
90 : 0 : }
91 : :
92 : : static void
93 : 0 : on_show_debug_overlay (ShumateInspectorPage *self,
94 : : GParamSpec *pspec,
95 : : GtkSwitch *widget)
96 : : {
97 : 0 : ShumateInspectorSettings *settings = shumate_inspector_settings_get_default ();
98 : 0 : shumate_inspector_settings_set_show_debug_overlay (settings, gtk_switch_get_active (widget));
99 : 0 : }
100 : :
101 : : static void
102 : 0 : on_show_tile_bounds (ShumateInspectorPage *self,
103 : : GParamSpec *pspec,
104 : : GtkSwitch *widget)
105 : : {
106 : 0 : ShumateInspectorSettings *settings = shumate_inspector_settings_get_default ();
107 : 0 : shumate_inspector_settings_set_show_tile_bounds (settings, gtk_switch_get_active (widget));
108 : 0 : }
109 : :
110 : : static void
111 : 0 : on_show_collision_boxes (ShumateInspectorPage *self,
112 : : GParamSpec *pspec,
113 : : GtkSwitch *widget)
114 : : {
115 : 0 : ShumateInspectorSettings *settings = shumate_inspector_settings_get_default ();
116 : 0 : shumate_inspector_settings_set_show_collision_boxes (settings, gtk_switch_get_active (widget));
117 : 0 : }
118 : :
119 : : static void
120 : 0 : shumate_inspector_page_class_init (ShumateInspectorPageClass *klass)
121 : : {
122 : 0 : GObjectClass *object_class = G_OBJECT_CLASS (klass);
123 : 0 : GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
124 : :
125 : 0 : object_class->dispose = shumate_inspector_page_dispose;
126 : 0 : object_class->get_property = shumate_inspector_get_property;
127 : 0 : object_class->set_property = shumate_inspector_set_property;
128 : :
129 : 0 : props[PROP_TITLE] =
130 : 0 : g_param_spec_string ("title",
131 : : "title",
132 : : "title",
133 : : NULL,
134 : : G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
135 : :
136 : 0 : props[PROP_OBJECT] =
137 : 0 : g_param_spec_object ("object",
138 : : "object",
139 : : "object",
140 : : G_TYPE_OBJECT,
141 : : G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
142 : :
143 : 0 : props[PROP_SETTINGS] =
144 : 0 : g_param_spec_object ("settings",
145 : : "settings",
146 : : "settings",
147 : : SHUMATE_TYPE_INSPECTOR_SETTINGS,
148 : : G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
149 : :
150 : 0 : g_object_class_install_properties (object_class, N_PROPS, props);
151 : :
152 : 0 : gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/shumate/shumate-inspector-page.ui");
153 : 0 : gtk_widget_class_bind_template_callback (widget_class, on_show_debug_overlay);
154 : 0 : gtk_widget_class_bind_template_callback (widget_class, on_show_tile_bounds);
155 : 0 : gtk_widget_class_bind_template_callback (widget_class, on_show_collision_boxes);
156 : 0 : }
157 : :
158 : : void
159 : 0 : shumate_inspector_page_init (ShumateInspectorPage *self)
160 : : {
161 : 0 : gtk_widget_init_template (GTK_WIDGET (self));
162 : 0 : }
163 : :
164 : : static gboolean registered = FALSE;
165 : :
166 : : void
167 : 3 : shumate_inspector_page_ensure_registered (void)
168 : : {
169 [ + - ]: 3 : if (registered)
170 : : return;
171 : :
172 [ + + ]: 3 : if (g_io_extension_point_lookup ("gtk-inspector-page"))
173 : 2 : g_io_extension_point_implement ("gtk-inspector-page",
174 : : SHUMATE_TYPE_INSPECTOR_PAGE,
175 : : "libshumate",
176 : : 10);
177 : :
178 : 3 : registered = TRUE;
179 : : }
|