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 "shumate-inspector-settings-private.h"
19 : :
20 : : struct _ShumateInspectorSettings {
21 : : GObject parent;
22 : :
23 : : gboolean show_debug_overlay : 1;
24 : : gboolean show_tile_bounds : 1;
25 : : gboolean show_collision_boxes : 1;
26 : : };
27 : :
28 [ + + + - ]: 32 : G_DEFINE_TYPE(ShumateInspectorSettings, shumate_inspector_settings, G_TYPE_OBJECT)
29 : :
30 : : enum {
31 : : PROP_0,
32 : : PROP_SHOW_DEBUG_OVERLAY,
33 : : PROP_SHOW_TILE_BOUNDS,
34 : : PROP_SHOW_COLLISION_BOXES,
35 : : PROP_LAST
36 : : };
37 : :
38 : : static GParamSpec *properties[PROP_LAST];
39 : :
40 : : static ShumateInspectorSettings *default_settings = NULL;
41 : :
42 : : ShumateInspectorSettings *
43 : 22 : shumate_inspector_settings_get_default (void)
44 : : {
45 [ + + ]: 22 : if (G_UNLIKELY (default_settings == NULL))
46 : 4 : default_settings = g_object_new (SHUMATE_TYPE_INSPECTOR_SETTINGS, NULL);
47 : :
48 : 22 : return default_settings;
49 : : }
50 : :
51 : : static void
52 : 0 : shumate_inspector_settings_get_property (GObject *object,
53 : : guint prop_id,
54 : : GValue *value,
55 : : GParamSpec *pspec)
56 : : {
57 : 0 : ShumateInspectorSettings *self = SHUMATE_INSPECTOR_SETTINGS (object);
58 : :
59 [ # # # # ]: 0 : switch (prop_id)
60 : : {
61 : 0 : case PROP_SHOW_DEBUG_OVERLAY:
62 : 0 : g_value_set_boolean (value, self->show_debug_overlay);
63 : 0 : break;
64 : 0 : case PROP_SHOW_TILE_BOUNDS:
65 : 0 : g_value_set_boolean (value, self->show_tile_bounds);
66 : 0 : break;
67 : 0 : case PROP_SHOW_COLLISION_BOXES:
68 : 0 : g_value_set_boolean (value, self->show_collision_boxes);
69 : 0 : break;
70 : 0 : default:
71 : 0 : G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
72 : : }
73 : 0 : }
74 : :
75 : : static void
76 : 0 : shumate_inspector_settings_set_property (GObject *object,
77 : : guint prop_id,
78 : : const GValue *value,
79 : : GParamSpec *pspec)
80 : : {
81 : 0 : ShumateInspectorSettings *self = SHUMATE_INSPECTOR_SETTINGS (object);
82 : :
83 [ # # # # ]: 0 : switch (prop_id)
84 : : {
85 : 0 : case PROP_SHOW_DEBUG_OVERLAY:
86 : 0 : shumate_inspector_settings_set_show_debug_overlay (self, g_value_get_boolean (value));
87 : 0 : break;
88 : 0 : case PROP_SHOW_TILE_BOUNDS:
89 : 0 : shumate_inspector_settings_set_show_tile_bounds (self, g_value_get_boolean (value));
90 : 0 : break;
91 : 0 : case PROP_SHOW_COLLISION_BOXES:
92 : 0 : shumate_inspector_settings_set_show_collision_boxes (self, g_value_get_boolean (value));
93 : 0 : break;
94 : 0 : default:
95 : 0 : G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
96 : : }
97 : 0 : }
98 : :
99 : : static void
100 : 4 : shumate_inspector_settings_class_init (ShumateInspectorSettingsClass *klass)
101 : : {
102 : 4 : GObjectClass *object_class = G_OBJECT_CLASS (klass);
103 : :
104 : 4 : object_class->get_property = shumate_inspector_settings_get_property;
105 : 4 : object_class->set_property = shumate_inspector_settings_set_property;
106 : :
107 : 8 : properties[PROP_SHOW_DEBUG_OVERLAY] =
108 : 4 : g_param_spec_boolean ("show-debug-overlay",
109 : : "show-debug-overlay",
110 : : "show-debug-overlay",
111 : : FALSE,
112 : : G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
113 : :
114 : 8 : properties[PROP_SHOW_TILE_BOUNDS] =
115 : 4 : g_param_spec_boolean ("show-tile-bounds",
116 : : "show-tile-bounds",
117 : : "show-tile-bounds",
118 : : FALSE,
119 : : G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
120 : :
121 : 8 : properties[PROP_SHOW_COLLISION_BOXES] =
122 : 4 : g_param_spec_boolean ("show-collision-boxes",
123 : : "show-collision-boxes",
124 : : "show-collision-boxes",
125 : : FALSE,
126 : : G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
127 : :
128 : 4 : g_object_class_install_properties (object_class, PROP_LAST, properties);
129 : 4 : }
130 : :
131 : : static void
132 : 4 : shumate_inspector_settings_init (ShumateInspectorSettings *self)
133 : : {
134 : 4 : }
135 : :
136 : : void
137 : 0 : shumate_inspector_settings_reset (ShumateInspectorSettings *self)
138 : : {
139 [ # # ]: 0 : g_return_if_fail (SHUMATE_IS_INSPECTOR_SETTINGS (self));
140 : :
141 : 0 : shumate_inspector_settings_set_show_debug_overlay (self, FALSE);
142 : 0 : shumate_inspector_settings_set_show_tile_bounds (self, FALSE);
143 : 0 : shumate_inspector_settings_set_show_collision_boxes (self, FALSE);
144 : : }
145 : :
146 : : gboolean
147 : 20 : shumate_inspector_settings_get_show_debug_overlay (ShumateInspectorSettings *self)
148 : : {
149 [ + - ]: 20 : g_return_val_if_fail (SHUMATE_IS_INSPECTOR_SETTINGS (self), FALSE);
150 : 20 : return self->show_debug_overlay;
151 : : }
152 : :
153 : : void
154 : 0 : shumate_inspector_settings_set_show_debug_overlay (ShumateInspectorSettings *self,
155 : : gboolean show_debug_overlay)
156 : : {
157 [ # # ]: 0 : g_return_if_fail (SHUMATE_IS_INSPECTOR_SETTINGS (self));
158 : :
159 : 0 : show_debug_overlay = !!show_debug_overlay;
160 : :
161 [ # # ]: 0 : if (self->show_debug_overlay != show_debug_overlay)
162 : : {
163 : 0 : self->show_debug_overlay = show_debug_overlay;
164 : 0 : g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_DEBUG_OVERLAY]);
165 : : }
166 : : }
167 : :
168 : : gboolean
169 : 0 : shumate_inspector_settings_get_show_tile_bounds (ShumateInspectorSettings *self)
170 : : {
171 [ # # ]: 0 : g_return_val_if_fail (SHUMATE_IS_INSPECTOR_SETTINGS (self), FALSE);
172 : 0 : return self->show_tile_bounds;
173 : : }
174 : :
175 : : void
176 : 0 : shumate_inspector_settings_set_show_tile_bounds (ShumateInspectorSettings *self,
177 : : gboolean show_tile_bounds)
178 : : {
179 [ # # ]: 0 : g_return_if_fail (SHUMATE_IS_INSPECTOR_SETTINGS (self));
180 : :
181 : 0 : show_tile_bounds = !!show_tile_bounds;
182 : :
183 [ # # ]: 0 : if (self->show_tile_bounds != show_tile_bounds)
184 : : {
185 : 0 : self->show_tile_bounds = show_tile_bounds;
186 : 0 : g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_TILE_BOUNDS]);
187 : : }
188 : : }
189 : :
190 : : gboolean
191 : 0 : shumate_inspector_settings_get_show_collision_boxes (ShumateInspectorSettings *self)
192 : : {
193 [ # # ]: 0 : g_return_val_if_fail (SHUMATE_IS_INSPECTOR_SETTINGS (self), FALSE);
194 : 0 : return self->show_collision_boxes;
195 : : }
196 : :
197 : : void
198 : 0 : shumate_inspector_settings_set_show_collision_boxes (ShumateInspectorSettings *self,
199 : : gboolean show_collision_boxes)
200 : : {
201 [ # # ]: 0 : g_return_if_fail (SHUMATE_IS_INSPECTOR_SETTINGS (self));
202 : :
203 : 0 : show_collision_boxes = !!show_collision_boxes;
204 : :
205 [ # # ]: 0 : if (self->show_collision_boxes != show_collision_boxes)
206 : : {
207 : 0 : self->show_collision_boxes = show_collision_boxes;
208 : 0 : g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_COLLISION_BOXES]);
209 : : }
210 : : }
|