| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |
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 |
shumate_inspector_page_dispose (GObject *object) |
| 43 |
{ |
| 44 |
|
| 45 |
shumate_inspector_settings_reset (shumate_inspector_settings_get_default ()); |
| 46 |
|
| 47 |
G_OBJECT_CLASS (shumate_inspector_page_parent_class)->dispose (object); |
| 48 |
} |
| 49 |
|
| 50 |
static void |
| 51 |
shumate_inspector_get_property (GObject *object, |
| 52 |
guint prop_id, |
| 53 |
GValue *value, |
| 54 |
GParamSpec *pspec) |
| 55 |
{ |
| 56 |
ShumateInspectorPage *self = SHUMATE_INSPECTOR_PAGE (object); |
| 57 |
|
| 58 |
switch (prop_id) |
| 59 |
{ |
| 60 |
case PROP_TITLE: |
| 61 |
g_value_set_string (value, _("Shumate")); |
| 62 |
break; |
| 63 |
case PROP_OBJECT: |
| 64 |
g_value_set_object (value, self->object); |
| 65 |
break; |
| 66 |
case PROP_SETTINGS: |
| 67 |
g_value_set_object (value, shumate_inspector_settings_get_default ()); |
| 68 |
break; |
| 69 |
default: |
| 70 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
static void |
| 75 |
shumate_inspector_set_property (GObject *object, |
| 76 |
guint prop_id, |
| 77 |
const GValue *value, |
| 78 |
GParamSpec *pspec) |
| 79 |
{ |
| 80 |
ShumateInspectorPage *self = SHUMATE_INSPECTOR_PAGE (object); |
| 81 |
|
| 82 |
switch (prop_id) |
| 83 |
{ |
| 84 |
case PROP_OBJECT: |
| 85 |
g_set_object (&self->object, g_value_get_object (value)); |
| 86 |
break; |
| 87 |
default: |
| 88 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
static void |
| 93 |
on_show_debug_overlay (ShumateInspectorPage *self, |
| 94 |
GParamSpec *pspec, |
| 95 |
GtkSwitch *widget) |
| 96 |
{ |
| 97 |
ShumateInspectorSettings *settings = shumate_inspector_settings_get_default (); |
| 98 |
shumate_inspector_settings_set_show_debug_overlay (settings, gtk_switch_get_active (widget)); |
| 99 |
} |
| 100 |
|
| 101 |
static void |
| 102 |
on_show_tile_bounds (ShumateInspectorPage *self, |
| 103 |
GParamSpec *pspec, |
| 104 |
GtkSwitch *widget) |
| 105 |
{ |
| 106 |
ShumateInspectorSettings *settings = shumate_inspector_settings_get_default (); |
| 107 |
shumate_inspector_settings_set_show_tile_bounds (settings, gtk_switch_get_active (widget)); |
| 108 |
} |
| 109 |
|
| 110 |
static void |
| 111 |
on_show_collision_boxes (ShumateInspectorPage *self, |
| 112 |
GParamSpec *pspec, |
| 113 |
GtkSwitch *widget) |
| 114 |
{ |
| 115 |
ShumateInspectorSettings *settings = shumate_inspector_settings_get_default (); |
| 116 |
shumate_inspector_settings_set_show_collision_boxes (settings, gtk_switch_get_active (widget)); |
| 117 |
} |
| 118 |
|
| 119 |
static void |
| 120 |
shumate_inspector_page_class_init (ShumateInspectorPageClass *klass) |
| 121 |
{ |
| 122 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 123 |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
| 124 |
|
| 125 |
object_class->dispose = shumate_inspector_page_dispose; |
| 126 |
object_class->get_property = shumate_inspector_get_property; |
| 127 |
object_class->set_property = shumate_inspector_set_property; |
| 128 |
|
| 129 |
props[PROP_TITLE] = |
| 130 |
g_param_spec_string ("title", |
| 131 |
"title", |
| 132 |
"title", |
| 133 |
NULL, |
| 134 |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); |
| 135 |
|
| 136 |
props[PROP_OBJECT] = |
| 137 |
g_param_spec_object ("object", |
| 138 |
"object", |
| 139 |
"object", |
| 140 |
G_TYPE_OBJECT, |
| 141 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
| 142 |
|
| 143 |
props[PROP_SETTINGS] = |
| 144 |
g_param_spec_object ("settings", |
| 145 |
"settings", |
| 146 |
"settings", |
| 147 |
SHUMATE_TYPE_INSPECTOR_SETTINGS, |
| 148 |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); |
| 149 |
|
| 150 |
g_object_class_install_properties (object_class, N_PROPS, props); |
| 151 |
|
| 152 |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/shumate/shumate-inspector-page.ui"); |
| 153 |
gtk_widget_class_bind_template_callback (widget_class, on_show_debug_overlay); |
| 154 |
gtk_widget_class_bind_template_callback (widget_class, on_show_tile_bounds); |
| 155 |
gtk_widget_class_bind_template_callback (widget_class, on_show_collision_boxes); |
| 156 |
} |
| 157 |
|
| 158 |
void |
| 159 |
shumate_inspector_page_init (ShumateInspectorPage *self) |
| 160 |
{ |
| 161 |
gtk_widget_init_template (GTK_WIDGET (self)); |
| 162 |
} |
| 163 |
|
| 164 |
static gboolean registered = FALSE; |
| 165 |
|
| 166 |
void |
| 167 |
shumate_inspector_page_ensure_registered (void) |
| 168 |
{ |
| 169 |
if (registered) |
| 170 |
return; |
| 171 |
|
| 172 |
if (g_io_extension_point_lookup ("gtk-inspector-page")) |
| 173 |
g_io_extension_point_implement ("gtk-inspector-page", |
| 174 |
SHUMATE_TYPE_INSPECTOR_PAGE, |
| 175 |
"libshumate", |
| 176 |
10); |
| 177 |
|
| 178 |
registered = TRUE; |
| 179 |
} |