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