]> git.street.me.uk Git - andy/viking.git/blobdiff - src/viklayer.c
Github #15: Relicense files marked GPL2 only to GPL2+.
[andy/viking.git] / src / viklayer.c
index 5959cd6a927991b998e2d8ad4d641b6bd6c24c39..1f30ca2a8b4e8de0813bf807216ddbc4012ce68e 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2005, Alex Foobarian <foobarian@gmail.com>
  * Copyright (C) 2003-2007, Evan Battaglia <gtoevan@gmx.net>
+ * Copyright (C) 2013, Rob Norris <rw_norris@hotmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -41,6 +42,9 @@ extern VikLayerInterface vik_coord_layer_interface;
 extern VikLayerInterface vik_georef_layer_interface;
 extern VikLayerInterface vik_gps_layer_interface;
 extern VikLayerInterface vik_dem_layer_interface;
+#ifdef HAVE_LIBMAPNIK
+extern VikLayerInterface vik_mapnik_layer_interface;
+#endif
 
 enum {
   VL_UPDATE_SIGNAL,
@@ -92,10 +96,15 @@ static gboolean idle_draw ( VikLayer *vl )
 void vik_layer_emit_update ( VikLayer *vl )
 {
   if ( vl->visible && vl->realized ) {
+    GThread *thread = vik_window_get_thread ( VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl)) );
+    if ( !thread )
+      // Do nothing
+      return;
+
     vik_window_set_redraw_trigger(vl);
 
     // Only ever draw when there is time to do so
-    if ( g_thread_self() != vik_window_get_thread (VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl))) )
+    if ( g_thread_self() != thread )
       // Drawing requested from another (background) thread, so handle via the gdk thread method
       gdk_threads_add_idle ( (GSourceFunc) idle_draw, vl );
     else
@@ -130,6 +139,9 @@ static VikLayerInterface *vik_layer_interfaces[VIK_LAYER_NUM_TYPES] = {
   &vik_gps_layer_interface,
   &vik_maps_layer_interface,
   &vik_dem_layer_interface,
+#ifdef HAVE_LIBMAPNIK
+  &vik_mapnik_layer_interface,
+#endif
 };
 
 VikLayerInterface *vik_layer_get_interface ( VikLayerTypeEnum type )
@@ -202,7 +214,14 @@ const gchar *vik_layer_get_name ( VikLayer *l )
   return l->name;
 }
 
-VikLayer *vik_layer_create ( VikLayerTypeEnum type, VikViewport *vp, GtkWindow *w, gboolean interactive )
+time_t vik_layer_get_timestamp ( VikLayer *vl )
+{
+  if ( vik_layer_interfaces[vl->type]->get_timestamp )
+    return vik_layer_interfaces[vl->type]->get_timestamp ( vl );
+  return 0;
+}
+
+VikLayer *vik_layer_create ( VikLayerTypeEnum type, VikViewport *vp, gboolean interactive )
 {
   VikLayer *new_layer = NULL;
   g_assert ( type < VIK_LAYER_NUM_TYPES );
@@ -284,8 +303,11 @@ void vik_layer_marshall_params ( VikLayer *vl, guint8 **data, gint *datalen )
   g_byte_array_append ( b, (guint8 *)&len, sizeof(len) );      \
   g_byte_array_append ( b, (guint8 *)(obj), len );
 
+  // Store the internal properties first
+  vlm_append(&vl->visible, sizeof(vl->visible));
   vlm_append(vl->name, strlen(vl->name));
 
+  // Now the actual parameters
   if ( params && get_param )
   {
     VikLayerParamData d;
@@ -348,13 +370,13 @@ void vik_layer_unmarshall_params ( VikLayer *vl, guint8 *data, gint datalen, Vik
 #define vlm_read(obj)                          \
   memcpy((obj), b+sizeof(gint), vlm_size);     \
   b += sizeof(gint) + vlm_size;
-  
+
+  vlm_read(&vl->visible);
+
   s = g_malloc(vlm_size + 1);
   s[vlm_size]=0;
   vlm_read(s);
-  
   vik_layer_rename(vl, s);
-  
   g_free(s);
 
   if ( params && set_param )
@@ -631,6 +653,8 @@ VikLayerTypedParamData *vik_layer_data_typed_param_copy_from_string ( VikLayerPa
  */
 void vik_layer_set_defaults ( VikLayer *vl, VikViewport *vvp )
 {
+  // Sneaky initialize of the viewport value here
+  vl->vvp = vvp;
   VikLayerInterface *vli = vik_layer_get_interface ( vl->type );
   const gchar *layer_name = vli->fixed_layer_name;
   VikLayerParamData data;