]> err.no Git - mapper/commitdiff
MapWidget: Path handling changes.
authorKaj-Michael Lang <milang@tal.org>
Fri, 1 Aug 2008 12:36:14 +0000 (15:36 +0300)
committerKaj-Michael Lang <milang@tal.org>
Fri, 1 Aug 2008 12:36:14 +0000 (15:36 +0300)
- Add gtk_map_toggle_current_track()
- Add gtk_map_toggle_current_route()
- Add boolean argument to path add to set a current track

libs/libgtkmap/gtkmap.c
libs/libgtkmap/gtkmap.h

index 4e8253ed07c6a94305c9259c5962f3a797a124c5..c7318a5606768254a59e3f3773b100f9d634c707 100644 (file)
@@ -1191,11 +1191,12 @@ for (iter=priv->paths; iter!=NULL; iter=iter->next) {
 /**
  * gtk_map_add_path:
  * @path: A path object to add to the map
+ * @current: Is this the current track ?
  *
  * Adds a new path to the map.
  */
 gboolean
-gtk_map_add_path(GtkWidget *widget, Path *path)
+gtk_map_add_path(GtkWidget *widget, Path *path, gboolean current)
 {
 GtkMap *map;
 GtkMapPriv *priv;
@@ -1207,10 +1208,67 @@ map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
 
 /* Don't allow duplicates */
-if (g_slist_find(priv->paths, path)!=NULL)
+if (g_slist_find(priv->paths, path)!=NULL) {
+       g_debug("Tried to add duplicate path!");
        return FALSE;
+}
 g_object_ref(path);
 priv->paths=g_slist_append(priv->paths, path);
+if (current==TRUE)
+       priv->current_track=path;
+gtk_map_refresh(widget);
+return TRUE;
+}
+
+/**
+ * gtk_map_set_current_track:
+ * @path:
+ *
+ * Toggle if given path is current track
+ */
+gboolean
+gtk_map_toggle_current_track(GtkWidget *widget, Path *path, gboolean current)
+{
+GtkMap *map;
+GtkMapPriv *priv;
+
+g_return_val_if_fail(GTK_IS_MAP(widget), FALSE);
+g_return_val_if_fail(path, FALSE);
+
+map=GTK_MAP(widget);
+priv=GTK_MAP_GET_PRIVATE(map);
+
+if (g_slist_find(priv->paths, path)==NULL)
+       return FALSE;
+
+priv->current_track=current==TRUE ? path : NULL;
+
+return TRUE;
+}
+
+/**
+ * gtk_map_set_current_route:
+ * @path:
+ *
+ * Toggle if given path is current route
+ */
+gboolean
+gtk_map_toggle_current_route(GtkWidget *widget, Path *path, gboolean current)
+{
+GtkMap *map;
+GtkMapPriv *priv;
+
+g_return_val_if_fail(GTK_IS_MAP(widget), FALSE);
+g_return_val_if_fail(path, FALSE);
+
+map=GTK_MAP(widget);
+priv=GTK_MAP_GET_PRIVATE(map);
+
+if (g_slist_find(priv->paths, path)==NULL)
+       return FALSE;
+
+priv->current_route=current==TRUE ? path : NULL;
+
 return TRUE;
 }
 
@@ -1232,10 +1290,21 @@ g_return_val_if_fail(path, FALSE);
 map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
 
-if (g_slist_find(priv->paths, path)==NULL)
+if (g_slist_find(priv->paths, path)==NULL) {
+       g_debug("Path is not on map");
        return FALSE;
+}
+
 priv->paths=g_slist_remove(priv->paths, path);
+
+if (priv->current_track==path)
+       priv->current_track=NULL;
+
+if (priv->current_route==path)
+       priv->current_route=NULL;
+
 g_object_unref(path);
+gtk_map_refresh(widget);
 return TRUE;
 }
 
@@ -1892,7 +1961,7 @@ priv=GTK_MAP_GET_PRIVATE(map);
 omode=priv->center_mode;
 
 /* If we have a track, then we can center on it */
-if (priv->current_track) {
+if (priv->current_track && mode!=CENTER_MANUAL) {
        priv->center_mode=mode;
        if (omode!=mode)
                g_signal_emit(widget, gtk_map_signals[MAP_CENTER_MODE_CHANGED], 0, NULL);
index 5ac2f39c1e6498a3bc40a07a50d79c5560a46f72..999e5c989f610758ba82e143799d18edd0c2a0d3 100644 (file)
@@ -130,9 +130,9 @@ gboolean gtk_map_markers_add(GtkWidget *map, GtkMapMarkerType type, GtkListStore
 gboolean gtk_map_markers_remove(GtkWidget *map, GtkMapMarkerType type, GtkListStore *store);
 
 /* Paths */
-gboolean gtk_map_add_path(GtkWidget *map, Path *path);
+gboolean gtk_map_add_path(GtkWidget *map, Path *path, gboolean current);
 gboolean gtk_map_remove_path(GtkWidget *map, Path *path);
-gboolean gtk_map_remove_path_by_id(GtkWidget *map, gint path_id);
+gboolean gtk_map_toggle_current_track(GtkWidget *widget, Path *path, gboolean current);
 void gtk_map_set_path_display(GtkWidget *widget, gint path_mask);
 
 /* Get copy of map back buffer */