shumate/shumate-simple-map.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (C) 2021 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-simple-map.h" | ||
| 19 | #include "shumate-map.h" | ||
| 20 | #include "shumate-map-layer.h" | ||
| 21 | #include "shumate-symbol-event.h" | ||
| 22 | |||
| 23 | /** | ||
| 24 | * ShumateSimpleMap: | ||
| 25 | * | ||
| 26 | * A ready-to-use map [class@Gtk.Widget].If you want to use your own implementation, | ||
| 27 | * you can look at the [class@Shumate.Map] widget. | ||
| 28 | * | ||
| 29 | * The simple map contains a zoom widget, a [class@Shumate.License] at the bottom, | ||
| 30 | * a [class@Shumate.Scale] and a [class@Shumate.Compass]. | ||
| 31 | */ | ||
| 32 | |||
| 33 | struct _ShumateSimpleMap | ||
| 34 | { | ||
| 35 | GtkWidget parent_instance; | ||
| 36 | |||
| 37 | ShumateMapSource *map_source; | ||
| 38 | GList *overlay_layers; | ||
| 39 | |||
| 40 | ShumateMap *map; | ||
| 41 | ShumateMapLayer *map_layer; | ||
| 42 | |||
| 43 | ShumateLicense *license; | ||
| 44 | ShumateScale *scale; | ||
| 45 | ShumateCompass *compass; | ||
| 46 | |||
| 47 | GtkBox *buttons; | ||
| 48 | GtkBox *zoom_buttons; | ||
| 49 | }; | ||
| 50 | |||
| 51 | static void buildable_interface_init (GtkBuildableIface *iface); | ||
| 52 | |||
| 53 |
3/6shumate_simple_map_class_intern_init:
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1 time.
shumate_simple_map_get_type:
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 7 not taken.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 7 not taken.
|
3 | G_DEFINE_TYPE_WITH_CODE (ShumateSimpleMap, shumate_simple_map, GTK_TYPE_WIDGET, |
| 54 | G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_interface_init)) | ||
| 55 | |||
| 56 | enum { | ||
| 57 | PROP_0, | ||
| 58 | PROP_MAP_SOURCE, | ||
| 59 | PROP_VIEWPORT, | ||
| 60 | PROP_COMPASS, | ||
| 61 | PROP_LICENSE, | ||
| 62 | PROP_SCALE, | ||
| 63 | PROP_SHOW_ZOOM_BUTTONS, | ||
| 64 | PROP_MAP, | ||
| 65 | PROP_BASE_MAP_LAYER, | ||
| 66 | N_PROPS | ||
| 67 | }; | ||
| 68 | |||
| 69 | static GParamSpec *properties [N_PROPS]; | ||
| 70 | |||
| 71 | enum { | ||
| 72 | SYMBOL_CLICKED, | ||
| 73 | LAST_SIGNAL | ||
| 74 | }; | ||
| 75 | |||
| 76 | static guint signals[LAST_SIGNAL] = { 0, }; | ||
| 77 | |||
| 78 | ShumateSimpleMap * | ||
| 79 | ✗ | shumate_simple_map_new (void) | |
| 80 | { | ||
| 81 | ✗ | return g_object_new (SHUMATE_TYPE_SIMPLE_MAP, NULL); | |
| 82 | } | ||
| 83 | |||
| 84 | |||
| 85 | static void | ||
| 86 | ✗ | shumate_simple_map_finalize (GObject *object) | |
| 87 | { | ||
| 88 | ✗ | ShumateSimpleMap *self = (ShumateSimpleMap *)object; | |
| 89 | |||
| 90 | ✗ | g_clear_object (&self->map_source); | |
| 91 | ✗ | g_clear_list (&self->overlay_layers, NULL); | |
| 92 | |||
| 93 | ✗ | G_OBJECT_CLASS (shumate_simple_map_parent_class)->finalize (object); | |
| 94 | ✗ | } | |
| 95 | |||
| 96 | |||
| 97 | static void | ||
| 98 | ✗ | shumate_simple_map_get_property (GObject *object, | |
| 99 | guint prop_id, | ||
| 100 | GValue *value, | ||
| 101 | GParamSpec *pspec) | ||
| 102 | { | ||
| 103 | ✗ | ShumateSimpleMap *self = SHUMATE_SIMPLE_MAP (object); | |
| 104 | |||
| 105 | ✗ | switch (prop_id) | |
| 106 | { | ||
| 107 | ✗ | case PROP_MAP_SOURCE: | |
| 108 | ✗ | g_value_set_object (value, shumate_simple_map_get_map_source (self)); | |
| 109 | ✗ | break; | |
| 110 | |||
| 111 | ✗ | case PROP_VIEWPORT: | |
| 112 | ✗ | g_value_set_object (value, shumate_simple_map_get_viewport (self)); | |
| 113 | ✗ | break; | |
| 114 | |||
| 115 | ✗ | case PROP_COMPASS: | |
| 116 | ✗ | g_value_set_object (value, shumate_simple_map_get_compass (self)); | |
| 117 | ✗ | break; | |
| 118 | |||
| 119 | ✗ | case PROP_SCALE: | |
| 120 | ✗ | g_value_set_object (value, shumate_simple_map_get_scale (self)); | |
| 121 | ✗ | break; | |
| 122 | |||
| 123 | ✗ | case PROP_LICENSE: | |
| 124 | ✗ | g_value_set_object (value, shumate_simple_map_get_license (self)); | |
| 125 | ✗ | break; | |
| 126 | |||
| 127 | ✗ | case PROP_SHOW_ZOOM_BUTTONS: | |
| 128 | ✗ | g_value_set_boolean (value, shumate_simple_map_get_show_zoom_buttons (self)); | |
| 129 | ✗ | break; | |
| 130 | |||
| 131 | ✗ | case PROP_MAP: | |
| 132 | ✗ | g_value_set_object (value, shumate_simple_map_get_map (self)); | |
| 133 | ✗ | break; | |
| 134 | |||
| 135 | ✗ | case PROP_BASE_MAP_LAYER: | |
| 136 | ✗ | g_value_set_object (value, shumate_simple_map_get_base_map_layer (self)); | |
| 137 | ✗ | break; | |
| 138 | |||
| 139 | ✗ | default: | |
| 140 | ✗ | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
| 141 | } | ||
| 142 | ✗ | } | |
| 143 | |||
| 144 | |||
| 145 | static void | ||
| 146 | ✗ | shumate_simple_map_set_property (GObject *object, | |
| 147 | guint prop_id, | ||
| 148 | const GValue *value, | ||
| 149 | GParamSpec *pspec) | ||
| 150 | { | ||
| 151 | ✗ | ShumateSimpleMap *self = SHUMATE_SIMPLE_MAP (object); | |
| 152 | |||
| 153 | ✗ | switch (prop_id) | |
| 154 | { | ||
| 155 | ✗ | case PROP_MAP_SOURCE: | |
| 156 | ✗ | shumate_simple_map_set_map_source (self, g_value_get_object (value)); | |
| 157 | ✗ | break; | |
| 158 | |||
| 159 | ✗ | case PROP_SHOW_ZOOM_BUTTONS: | |
| 160 | ✗ | shumate_simple_map_set_show_zoom_buttons (self, g_value_get_boolean (value)); | |
| 161 | ✗ | break; | |
| 162 | |||
| 163 | ✗ | default: | |
| 164 | ✗ | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
| 165 | } | ||
| 166 | ✗ | } | |
| 167 | |||
| 168 | |||
| 169 | static void | ||
| 170 | ✗ | shumate_simple_map_dispose (GObject *object) | |
| 171 | { | ||
| 172 | ✗ | GtkWidget *child; | |
| 173 | |||
| 174 | ✗ | while ((child = gtk_widget_get_first_child (GTK_WIDGET (object)))) | |
| 175 | ✗ | gtk_widget_unparent (child); | |
| 176 | |||
| 177 | ✗ | G_OBJECT_CLASS (shumate_simple_map_parent_class)->dispose (object); | |
| 178 | ✗ | } | |
| 179 | |||
| 180 | |||
| 181 | static void | ||
| 182 | ✗ | on_zoom_in_clicked (ShumateSimpleMap *self, | |
| 183 | GtkButton *button) | ||
| 184 | { | ||
| 185 | ✗ | shumate_map_zoom_in (self->map); | |
| 186 | ✗ | } | |
| 187 | |||
| 188 | |||
| 189 | static void | ||
| 190 | ✗ | on_zoom_out_clicked (ShumateSimpleMap *self, | |
| 191 | GtkButton *button) | ||
| 192 | { | ||
| 193 | ✗ | shumate_map_zoom_out (self->map); | |
| 194 | ✗ | } | |
| 195 | |||
| 196 | |||
| 197 | static void | ||
| 198 | ✗ | on_symbol_clicked (ShumateSimpleMap *self, | |
| 199 | ShumateSymbolEvent *event, | ||
| 200 | ShumateMapLayer *map_layer) | ||
| 201 | { | ||
| 202 | ✗ | g_signal_emit (self, signals[SYMBOL_CLICKED], 0, event); | |
| 203 | ✗ | } | |
| 204 | |||
| 205 | |||
| 206 | static GObject * | ||
| 207 | ✗ | shumate_simple_map_get_internal_child (GtkBuildable *buildable, | |
| 208 | GtkBuilder *builder, | ||
| 209 | const char *childname) | ||
| 210 | { | ||
| 211 | ✗ | ShumateSimpleMap *self = SHUMATE_SIMPLE_MAP (buildable); | |
| 212 | |||
| 213 | ✗ | if (!g_strcmp0 (childname, "compass")) | |
| 214 | ✗ | return G_OBJECT (self->compass); | |
| 215 | ✗ | else if (!g_strcmp0 (childname, "license")) | |
| 216 | ✗ | return G_OBJECT (self->license); | |
| 217 | ✗ | else if (!g_strcmp0 (childname, "scale")) | |
| 218 | ✗ | return G_OBJECT (self->scale); | |
| 219 | ✗ | else if (!g_strcmp0 (childname, "map")) | |
| 220 | ✗ | return G_OBJECT (self->map); | |
| 221 | else | ||
| 222 | return NULL; | ||
| 223 | } | ||
| 224 | |||
| 225 | |||
| 226 | static void | ||
| 227 | 1 | shumate_simple_map_class_init (ShumateSimpleMapClass *klass) | |
| 228 | { | ||
| 229 | 1 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
| 230 | 1 | GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); | |
| 231 | |||
| 232 | 1 | object_class->dispose = shumate_simple_map_dispose; | |
| 233 | 1 | object_class->finalize = shumate_simple_map_finalize; | |
| 234 | 1 | object_class->get_property = shumate_simple_map_get_property; | |
| 235 | 1 | object_class->set_property = shumate_simple_map_set_property; | |
| 236 | |||
| 237 | /** | ||
| 238 | * ShumateSimpleMap:viewport: | ||
| 239 | * | ||
| 240 | * The viewport to use. | ||
| 241 | */ | ||
| 242 | 2 | properties[PROP_VIEWPORT] = | |
| 243 | 1 | g_param_spec_object ("viewport", NULL, NULL, | |
| 244 | SHUMATE_TYPE_VIEWPORT, | ||
| 245 | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); | ||
| 246 | |||
| 247 | /** | ||
| 248 | * ShumateSimpleMap:map-source: | ||
| 249 | * | ||
| 250 | * The source of the tiles this simple map displays. | ||
| 251 | */ | ||
| 252 | 2 | properties[PROP_MAP_SOURCE] = | |
| 253 | 1 | g_param_spec_object ("map-source", NULL, NULL, | |
| 254 | SHUMATE_TYPE_MAP_SOURCE, | ||
| 255 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); | ||
| 256 | |||
| 257 | /** | ||
| 258 | * ShumateSimpleMap:compass: | ||
| 259 | * | ||
| 260 | * The compass widget. | ||
| 261 | */ | ||
| 262 | 2 | properties[PROP_COMPASS] = | |
| 263 | 1 | g_param_spec_object ("compass", NULL, NULL, | |
| 264 | SHUMATE_TYPE_COMPASS, | ||
| 265 | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); | ||
| 266 | |||
| 267 | /** | ||
| 268 | * ShumateSimpleMap:license: | ||
| 269 | * | ||
| 270 | * The license widget. | ||
| 271 | */ | ||
| 272 | 2 | properties[PROP_LICENSE] = | |
| 273 | 1 | g_param_spec_object ("license", NULL, NULL, | |
| 274 | SHUMATE_TYPE_LICENSE, | ||
| 275 | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); | ||
| 276 | |||
| 277 | /** | ||
| 278 | * ShumateSimpleMap:scale: | ||
| 279 | * | ||
| 280 | * The scale widget. | ||
| 281 | */ | ||
| 282 | 2 | properties[PROP_SCALE] = | |
| 283 | 1 | g_param_spec_object ("scale", NULL, NULL, | |
| 284 | SHUMATE_TYPE_SCALE, | ||
| 285 | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); | ||
| 286 | |||
| 287 | /** | ||
| 288 | * ShumateSimpleMap:map: | ||
| 289 | * | ||
| 290 | * The map widget. | ||
| 291 | */ | ||
| 292 | 2 | properties[PROP_MAP] = | |
| 293 | 1 | g_param_spec_object ("map", NULL, NULL, | |
| 294 | SHUMATE_TYPE_MAP, | ||
| 295 | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); | ||
| 296 | |||
| 297 | /** | ||
| 298 | * ShumateSimpleMap:show-zoom-buttons: | ||
| 299 | * | ||
| 300 | * Whether zoom buttons are shown. | ||
| 301 | */ | ||
| 302 | 2 | properties[PROP_SHOW_ZOOM_BUTTONS] = | |
| 303 | 1 | g_param_spec_boolean ("show-zoom-buttons", NULL, NULL, | |
| 304 | TRUE, | ||
| 305 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); | ||
| 306 | |||
| 307 | /** | ||
| 308 | * ShumateSimpleMap:base-map-layer: | ||
| 309 | * | ||
| 310 | * The [class@MapLayer] that displays the map source. | ||
| 311 | * | ||
| 312 | * This is a read-only property. To change the basemap, set the | ||
| 313 | * [property@SimpleMap:map-source] property. | ||
| 314 | * | ||
| 315 | * Since: 1.4 | ||
| 316 | */ | ||
| 317 | 2 | properties[PROP_BASE_MAP_LAYER] = | |
| 318 | 1 | g_param_spec_object ("base-map-layer", NULL, NULL, | |
| 319 | SHUMATE_TYPE_MAP_LAYER, | ||
| 320 | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); | ||
| 321 | |||
| 322 | 1 | g_object_class_install_properties (object_class, N_PROPS, properties); | |
| 323 | |||
| 324 | /** | ||
| 325 | * ShumateSimpleMap::symbol-clicked: | ||
| 326 | * @self: the [class@SimpleMap] emitting the signal | ||
| 327 | * @event: a [class@SymbolEvent] with details about the clicked symbol. | ||
| 328 | * | ||
| 329 | * Emitted when a symbol in the base map layer (not in overlay layers) is | ||
| 330 | * clicked. | ||
| 331 | * | ||
| 332 | * Since: 1.1 | ||
| 333 | */ | ||
| 334 | 2 | signals[SYMBOL_CLICKED] = | |
| 335 | 1 | g_signal_new ("symbol-clicked", | |
| 336 | G_OBJECT_CLASS_TYPE (object_class), | ||
| 337 | G_SIGNAL_RUN_LAST, | ||
| 338 | 0, NULL, NULL, | ||
| 339 | g_cclosure_marshal_VOID__OBJECT, | ||
| 340 | G_TYPE_NONE, | ||
| 341 | 1, | ||
| 342 | SHUMATE_TYPE_SYMBOL_EVENT); | ||
| 343 | |||
| 344 | 1 | gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/shumate/shumate-simple-map.ui"); | |
| 345 | 1 | gtk_widget_class_bind_template_child (widget_class, ShumateSimpleMap, map); | |
| 346 | 1 | gtk_widget_class_bind_template_child (widget_class, ShumateSimpleMap, license); | |
| 347 | 1 | gtk_widget_class_bind_template_child (widget_class, ShumateSimpleMap, scale); | |
| 348 | 1 | gtk_widget_class_bind_template_child (widget_class, ShumateSimpleMap, compass); | |
| 349 | 1 | gtk_widget_class_bind_template_child (widget_class, ShumateSimpleMap, zoom_buttons); | |
| 350 | 1 | gtk_widget_class_bind_template_callback (widget_class, on_zoom_in_clicked); | |
| 351 | 1 | gtk_widget_class_bind_template_callback (widget_class, on_zoom_out_clicked); | |
| 352 | 1 | gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); | |
| 353 | 1 | } | |
| 354 | |||
| 355 | static void | ||
| 356 | 1 | buildable_interface_init (GtkBuildableIface *iface) | |
| 357 | { | ||
| 358 | 1 | iface->get_internal_child = shumate_simple_map_get_internal_child; | |
| 359 | 1 | } | |
| 360 | |||
| 361 | static void | ||
| 362 | ✗ | shumate_simple_map_init (ShumateSimpleMap *self) | |
| 363 | { | ||
| 364 | ✗ | ShumateViewport *viewport; | |
| 365 | |||
| 366 | ✗ | gtk_widget_init_template (GTK_WIDGET (self)); | |
| 367 | |||
| 368 | ✗ | viewport = shumate_simple_map_get_viewport (self); | |
| 369 | |||
| 370 | ✗ | self->map_layer = shumate_map_layer_new (NULL, viewport); | |
| 371 | ✗ | shumate_map_add_layer (self->map, SHUMATE_LAYER (self->map_layer)); | |
| 372 | ✗ | g_signal_connect_object (self->map_layer, "symbol-clicked", (GCallback)on_symbol_clicked, self, G_CONNECT_SWAPPED); | |
| 373 | ✗ | } | |
| 374 | |||
| 375 | |||
| 376 | /** | ||
| 377 | * shumate_simple_map_get_viewport: | ||
| 378 | * @self: a [class@Map] | ||
| 379 | * | ||
| 380 | * Gets the map's viewport, needed for constructing map layers that will be added | ||
| 381 | * to it. | ||
| 382 | * | ||
| 383 | * Returns: (transfer none): a [class@Viewport] | ||
| 384 | */ | ||
| 385 | ShumateViewport * | ||
| 386 | ✗ | shumate_simple_map_get_viewport (ShumateSimpleMap *self) | |
| 387 | { | ||
| 388 | ✗ | g_return_val_if_fail (SHUMATE_IS_SIMPLE_MAP (self), NULL); | |
| 389 | ✗ | return shumate_map_get_viewport (self->map); | |
| 390 | } | ||
| 391 | |||
| 392 | |||
| 393 | /** | ||
| 394 | * shumate_simple_map_get_map_source: | ||
| 395 | * @self: a [class@SimpleMap] | ||
| 396 | * | ||
| 397 | * Gets the map source for the current base layer. | ||
| 398 | * | ||
| 399 | * Returns: (transfer none): a [class@MapSource] | ||
| 400 | */ | ||
| 401 | ShumateMapSource * | ||
| 402 | ✗ | shumate_simple_map_get_map_source (ShumateSimpleMap *self) | |
| 403 | { | ||
| 404 | ✗ | g_return_val_if_fail (SHUMATE_IS_SIMPLE_MAP (self), NULL); | |
| 405 | ✗ | return self->map_source; | |
| 406 | } | ||
| 407 | |||
| 408 | |||
| 409 | /** | ||
| 410 | * shumate_simple_map_set_map_source: | ||
| 411 | * @self: a [class@SimpleMap] | ||
| 412 | * @map_source: (nullable): a [class@MapSource] | ||
| 413 | * | ||
| 414 | * Sets the source for the base map. | ||
| 415 | */ | ||
| 416 | void | ||
| 417 | ✗ | shumate_simple_map_set_map_source (ShumateSimpleMap *self, | |
| 418 | ShumateMapSource *map_source) | ||
| 419 | { | ||
| 420 | ✗ | ShumateViewport *viewport; | |
| 421 | |||
| 422 | ✗ | g_return_if_fail (SHUMATE_IS_SIMPLE_MAP (self)); | |
| 423 | ✗ | g_return_if_fail (map_source == NULL || SHUMATE_IS_MAP_SOURCE (map_source)); | |
| 424 | |||
| 425 | ✗ | viewport = shumate_map_get_viewport (self->map); | |
| 426 | |||
| 427 | ✗ | if (self->map_source == map_source) | |
| 428 | return; | ||
| 429 | |||
| 430 | ✗ | if (self->map_source) { | |
| 431 | ✗ | shumate_license_remove_map_source (self->license, self->map_source); | |
| 432 | } | ||
| 433 | |||
| 434 | ✗ | g_set_object (&self->map_source, map_source); | |
| 435 | |||
| 436 | ✗ | shumate_viewport_set_reference_map_source (viewport, map_source); | |
| 437 | ✗ | shumate_map_set_map_source (self->map, map_source); | |
| 438 | ✗ | shumate_map_layer_set_map_source (self->map_layer, map_source); | |
| 439 | ✗ | shumate_license_append_map_source (self->license, map_source); | |
| 440 | |||
| 441 | ✗ | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MAP_SOURCE]); | |
| 442 | ✗ | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_BASE_MAP_LAYER]); | |
| 443 | } | ||
| 444 | |||
| 445 | |||
| 446 | /** | ||
| 447 | * shumate_simple_map_add_overlay_layer: | ||
| 448 | * @self: a [class@SimpleMap] | ||
| 449 | * @layer: a [class@Layer] to add | ||
| 450 | * | ||
| 451 | * Adds a map layer as an overlay on top of the base map. | ||
| 452 | */ | ||
| 453 | void | ||
| 454 | ✗ | shumate_simple_map_add_overlay_layer (ShumateSimpleMap *self, | |
| 455 | ShumateLayer *layer) | ||
| 456 | { | ||
| 457 | ✗ | g_return_if_fail (SHUMATE_IS_SIMPLE_MAP (self)); | |
| 458 | ✗ | g_return_if_fail (SHUMATE_IS_LAYER (layer)); | |
| 459 | |||
| 460 | ✗ | self->overlay_layers = g_list_append (self->overlay_layers, layer); | |
| 461 | ✗ | shumate_map_add_layer (self->map, layer); | |
| 462 | } | ||
| 463 | |||
| 464 | |||
| 465 | /** | ||
| 466 | * shumate_simple_map_insert_overlay_layer_above: | ||
| 467 | * @self: a [class@SimpleMap] | ||
| 468 | * @layer: a [class@Layer] to insert | ||
| 469 | * | ||
| 470 | * Inserts a map layer as an overlay on top of the base map. The layer will | ||
| 471 | * appear above @sibling, or at the bottom (but still above the base map) | ||
| 472 | * if @sibling is %NULL. | ||
| 473 | * | ||
| 474 | * Since: 1.5 | ||
| 475 | */ | ||
| 476 | void | ||
| 477 | ✗ | shumate_simple_map_insert_overlay_layer_above (ShumateSimpleMap *self, | |
| 478 | ShumateLayer *layer, | ||
| 479 | ShumateLayer *sibling) | ||
| 480 | { | ||
| 481 | ✗ | gint idx; | |
| 482 | |||
| 483 | ✗ | g_return_if_fail (SHUMATE_IS_SIMPLE_MAP (self)); | |
| 484 | ✗ | g_return_if_fail (SHUMATE_IS_LAYER (layer)); | |
| 485 | ✗ | g_return_if_fail (sibling == NULL || SHUMATE_IS_LAYER (sibling)); | |
| 486 | |||
| 487 | ✗ | if (sibling == NULL) | |
| 488 | idx = 0; | ||
| 489 | else | ||
| 490 | ✗ | idx = g_list_index (self->overlay_layers, sibling) + 1; | |
| 491 | |||
| 492 | ✗ | self->overlay_layers = g_list_insert (self->overlay_layers, layer, idx); | |
| 493 | ✗ | shumate_map_insert_layer_above (self->map, layer, sibling); | |
| 494 | } | ||
| 495 | |||
| 496 | |||
| 497 | /** | ||
| 498 | * shumate_simple_map_insert_overlay_layer_behind: | ||
| 499 | * @self: a [class@SimpleMap] | ||
| 500 | * @layer: a [class@Layer] to insert | ||
| 501 | * | ||
| 502 | * Inserts a map layer as an overlay on top of the base map. The layer will | ||
| 503 | * appear just below @sibling, or above everything else if @sibling is %NULL. | ||
| 504 | * | ||
| 505 | * Since: 1.5 | ||
| 506 | */ | ||
| 507 | void | ||
| 508 | ✗ | shumate_simple_map_insert_overlay_layer_behind (ShumateSimpleMap *self, | |
| 509 | ShumateLayer *layer, | ||
| 510 | ShumateLayer *sibling) | ||
| 511 | { | ||
| 512 | ✗ | GList *sibling_link; | |
| 513 | |||
| 514 | ✗ | g_return_if_fail (SHUMATE_IS_SIMPLE_MAP (self)); | |
| 515 | ✗ | g_return_if_fail (SHUMATE_IS_LAYER (layer)); | |
| 516 | ✗ | g_return_if_fail (sibling == NULL || SHUMATE_IS_LAYER (sibling)); | |
| 517 | |||
| 518 | ✗ | sibling_link = g_list_find (self->overlay_layers, sibling); | |
| 519 | ✗ | self->overlay_layers = g_list_insert_before (self->overlay_layers, sibling_link, layer); | |
| 520 | ✗ | shumate_map_insert_layer_behind (self->map, layer, sibling); | |
| 521 | } | ||
| 522 | |||
| 523 | |||
| 524 | /** | ||
| 525 | * shumate_simple_map_remove_overlay_layer: | ||
| 526 | * @self: a [class@SimpleMap] | ||
| 527 | * @layer: a [class@Layer] that was added to the map previously | ||
| 528 | * | ||
| 529 | * Removes a layer from the map. | ||
| 530 | */ | ||
| 531 | void | ||
| 532 | ✗ | shumate_simple_map_remove_overlay_layer (ShumateSimpleMap *self, | |
| 533 | ShumateLayer *layer) | ||
| 534 | { | ||
| 535 | ✗ | g_return_if_fail (SHUMATE_IS_SIMPLE_MAP (self)); | |
| 536 | ✗ | g_return_if_fail (SHUMATE_IS_LAYER (layer)); | |
| 537 | |||
| 538 | ✗ | self->overlay_layers = g_list_remove (self->overlay_layers, layer); | |
| 539 | ✗ | shumate_map_remove_layer (self->map, layer); | |
| 540 | } | ||
| 541 | |||
| 542 | |||
| 543 | /** | ||
| 544 | * shumate_simple_map_get_compass: | ||
| 545 | * @self: a [class@SimpleMap] | ||
| 546 | * | ||
| 547 | * Gets the compass widget for the map. | ||
| 548 | * | ||
| 549 | * Returns: (transfer none): a [class@Compass] | ||
| 550 | */ | ||
| 551 | ShumateCompass * | ||
| 552 | ✗ | shumate_simple_map_get_compass (ShumateSimpleMap *self) | |
| 553 | { | ||
| 554 | ✗ | g_return_val_if_fail (SHUMATE_IS_SIMPLE_MAP (self), NULL); | |
| 555 | |||
| 556 | ✗ | return self->compass; | |
| 557 | } | ||
| 558 | |||
| 559 | |||
| 560 | /** | ||
| 561 | * shumate_simple_map_get_license: | ||
| 562 | * @self: a [class@SimpleMap] | ||
| 563 | * | ||
| 564 | * Gets the license widget for the map. | ||
| 565 | * | ||
| 566 | * Returns: (transfer none): a [class@License] | ||
| 567 | */ | ||
| 568 | ShumateLicense * | ||
| 569 | ✗ | shumate_simple_map_get_license (ShumateSimpleMap *self) | |
| 570 | { | ||
| 571 | ✗ | g_return_val_if_fail (SHUMATE_IS_SIMPLE_MAP (self), NULL); | |
| 572 | |||
| 573 | ✗ | return self->license; | |
| 574 | } | ||
| 575 | |||
| 576 | |||
| 577 | /** | ||
| 578 | * shumate_simple_map_get_scale: | ||
| 579 | * @self: a [class@SimpleMap] | ||
| 580 | * | ||
| 581 | * Gets the scale widget for the map. | ||
| 582 | * | ||
| 583 | * Returns: (transfer none): a [class@Scale] | ||
| 584 | */ | ||
| 585 | ShumateScale * | ||
| 586 | ✗ | shumate_simple_map_get_scale (ShumateSimpleMap *self) | |
| 587 | { | ||
| 588 | ✗ | g_return_val_if_fail (SHUMATE_IS_SIMPLE_MAP (self), NULL); | |
| 589 | ✗ | return self->scale; | |
| 590 | } | ||
| 591 | |||
| 592 | |||
| 593 | /** | ||
| 594 | * shumate_simple_map_get_show_zoom_buttons: | ||
| 595 | * @self: a [class@SimpleMap] | ||
| 596 | * | ||
| 597 | * Gets whether or not the zoom buttons are shown. | ||
| 598 | * | ||
| 599 | * Returns: %TRUE if the zoom buttons are visible, otherwise %FALSE | ||
| 600 | */ | ||
| 601 | gboolean | ||
| 602 | ✗ | shumate_simple_map_get_show_zoom_buttons (ShumateSimpleMap *self) | |
| 603 | { | ||
| 604 | ✗ | g_return_val_if_fail (SHUMATE_IS_SIMPLE_MAP (self), FALSE); | |
| 605 | ✗ | return gtk_widget_is_visible (GTK_WIDGET (self->zoom_buttons)); | |
| 606 | } | ||
| 607 | |||
| 608 | |||
| 609 | /** | ||
| 610 | * shumate_simple_map_set_show_zoom_buttons: | ||
| 611 | * @self: a [class@SimpleMap] | ||
| 612 | * @show_zoom_buttons: %TRUE to show the zoom buttons, %FALSE to hide them | ||
| 613 | * | ||
| 614 | * Sets whether or not the zoom buttons are shown. | ||
| 615 | */ | ||
| 616 | void | ||
| 617 | ✗ | shumate_simple_map_set_show_zoom_buttons (ShumateSimpleMap *self, | |
| 618 | gboolean show_zoom_buttons) | ||
| 619 | { | ||
| 620 | ✗ | g_return_if_fail (SHUMATE_IS_SIMPLE_MAP (self)); | |
| 621 | ✗ | gtk_widget_set_visible (GTK_WIDGET (self->zoom_buttons), show_zoom_buttons); | |
| 622 | ✗ | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_ZOOM_BUTTONS]); | |
| 623 | } | ||
| 624 | |||
| 625 | |||
| 626 | /** | ||
| 627 | * shumate_simple_map_get_map: | ||
| 628 | * @self: a [class@SimpleMap] | ||
| 629 | * | ||
| 630 | * Gets the [class@SimpleMap]'s underlying [class@Map]. | ||
| 631 | * | ||
| 632 | * Returns: (transfer none): a [class@Map] | ||
| 633 | */ | ||
| 634 | ShumateMap * | ||
| 635 | ✗ | shumate_simple_map_get_map (ShumateSimpleMap *self) | |
| 636 | { | ||
| 637 | ✗ | g_return_val_if_fail (SHUMATE_IS_SIMPLE_MAP (self), NULL); | |
| 638 | |||
| 639 | ✗ | return self->map; | |
| 640 | } | ||
| 641 | |||
| 642 | |||
| 643 | /** | ||
| 644 | * shumate_simple_map_get_base_map_layer: | ||
| 645 | * @self: a [class@SimpleMap] | ||
| 646 | * | ||
| 647 | * Gets the [class@MapLayer] that displays the base map. | ||
| 648 | * | ||
| 649 | * Returns: (transfer none): the base map layer | ||
| 650 | * | ||
| 651 | * Since: 1.4 | ||
| 652 | */ | ||
| 653 | ShumateMapLayer * | ||
| 654 | ✗ | shumate_simple_map_get_base_map_layer (ShumateSimpleMap *self) | |
| 655 | { | ||
| 656 | ✗ | g_return_val_if_fail (SHUMATE_IS_SIMPLE_MAP (self), NULL); | |
| 657 | |||
| 658 | ✗ | return self->map_layer; | |
| 659 | } | ||
| 660 |