]> git.street.me.uk Git - andy/viking.git/blobdiff - src/garminsymbols.c
Fix CPU usage going to 100% when statusbar items update is called.
[andy/viking.git] / src / garminsymbols.c
index d44e4407a3d771c465cb96db4330656e5aa03645..b0b2cdbbe42a59e145c853080c30ee0b9f404540 100644 (file)
@@ -2,6 +2,8 @@
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ * Copyright (C) 2005, Alex Foobarian <foobarian@gmail.com>
+ * Copyright (C) 2008, Quy Tonthat <qtonthat@gmail.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
@@ -330,12 +332,24 @@ static void init_icons() {
 }
 
 static GdkPixbuf *get_wp_sym_from_index ( gint i ) {
-  if ( !garmin_syms[i].icon && 
-      ((vik_use_small_wp_icons && garmin_syms[i].data) ||
-       (!vik_use_small_wp_icons && garmin_syms[i].data_large))) {
-    garmin_syms[i].icon = gdk_pixbuf_from_pixdata (
-       vik_use_small_wp_icons ? garmin_syms[i].data : garmin_syms[i].data_large,
-       FALSE, NULL );
+  // Ensure data exists to either directly load icon or scale from the other set
+  if ( !garmin_syms[i].icon && ( garmin_syms[i].data || garmin_syms[i].data_large) ) {
+    if ( a_vik_get_use_large_waypoint_icons() ) {
+      if ( garmin_syms[i].data_large )
+       // Directly load icon
+       garmin_syms[i].icon = gdk_pixbuf_from_pixdata ( garmin_syms[i].data_large, FALSE, NULL );
+      else
+       // Up sample from small image
+       garmin_syms[i].icon = gdk_pixbuf_scale_simple ( gdk_pixbuf_from_pixdata ( garmin_syms[i].data, FALSE, NULL ), 30, 30, GDK_INTERP_BILINEAR );
+    }
+    else {
+      if ( garmin_syms[i].data )
+       // Directly use small symbol
+       garmin_syms[i].icon = gdk_pixbuf_from_pixdata ( garmin_syms[i].data, FALSE, NULL );
+      else
+       // Down size large image
+       garmin_syms[i].icon = gdk_pixbuf_scale_simple ( gdk_pixbuf_from_pixdata ( garmin_syms[i].data_large, FALSE, NULL ), 18, 18, GDK_INTERP_BILINEAR );
+    }
   }
   return garmin_syms[i].icon;
 }
@@ -361,8 +375,8 @@ GdkPixbuf *a_get_wp_sym ( const gchar *sym ) {
 void a_populate_sym_list ( GtkListStore *list ) {
   gint i;
   for (i=0; i<G_N_ELEMENTS(garmin_syms); i++) {
-    if ((vik_use_small_wp_icons && garmin_syms[i].data) ||
-        (!vik_use_small_wp_icons && garmin_syms[i].data_large)) {
+    // Ensure at least one symbol available - the other can be auto generated
+    if ( garmin_syms[i].data || garmin_syms[i].data_large ) {
       GtkTreeIter iter;
       gtk_list_store_append(list, &iter);
       gtk_list_store_set(list, &iter, 0, garmin_syms[i].sym, 1, get_wp_sym_from_index(i), -1);
@@ -371,3 +385,14 @@ void a_populate_sym_list ( GtkListStore *list ) {
 }
 
 
+/* Use when preferences have changed to reset icons*/
+void clear_garmin_icon_syms () {
+  g_debug("garminsymbols: clear_garmin_icon_syms");
+  gint i;
+  for (i=0; i<G_N_ELEMENTS(garmin_syms); i++) {
+    if (garmin_syms[i].icon) {
+      g_object_unref (garmin_syms[i].icon);
+      garmin_syms[i].icon = NULL;
+    }
+  }
+}