Diff of /trunk/src/icons.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 174 by harbaum, Tue Nov 10 20:27:30 2009 UTC revision 293 by harbaum, Tue Aug 17 19:00:06 2010 UTC
# Line 24  struct icon_data { Line 24  struct icon_data {
24    GdkPixbuf **data;    GdkPixbuf **data;
25    int count;    int count;
26  } icons[] = {  } icons[] = {
27    { NULL, CACHE_TYPE_MAX+1 },  /* ICON_CACHE_TYPE      */    { NULL, CACHE_TYPE_MAX+5 },             /* ICON_CACHE_TYPE      */
28    { NULL, CACHE_TYPE_MAX+1 },  /* ICON_CACHE_TYPE_SEMI */    { NULL, CACHE_TYPE_MAX+5 },             /* ICON_CACHE_TYPE_SEMI */
29    { NULL, CACHE_TYPE_MAX+1 },  /* ICON_CACHE_TYPE_2X   */    { NULL, CACHE_TYPE_MAX+5 },             /* ICON_CACHE_TYPE_1_5X */
30    { NULL, CACHE_CONT_MAX+1 },  /* ICON_CACHE_SIZE      */    { NULL, CACHE_TYPE_MAX+5 },             /* ICON_CACHE_TYPE_2X   */
31    { NULL, 9 },                 /* ICON_STARS           */    { NULL, CACHE_CONT_MAX+1 },             /* ICON_CACHE_SIZE      */
32    { NULL, LOG_TYPE_MAX+1 },    /* ICON_LOG             */    { NULL, 9 },                            /* ICON_STARS           */
33    { NULL, 9 },                 /* ICON_HEADING         */    { NULL, LOG_TYPE_MAX+1 },               /* ICON_LOG             */
34    { NULL, WPT_SYM_MAX+1 },     /* ICON_WPT             */    { NULL, 9 },                            /* ICON_HEADING         */
35    { NULL, 1 },                 /* ICON_TB              */    { NULL, WPT_SYM_MAX+1 },                /* ICON_WPT             */
36    { NULL, 9 },                 /* ICON_MISC            */    { NULL, 2 },                            /* ICON_TB              */
37    { NULL, 3 },                 /* ICON_FILE            */    { NULL, 8 },                            /* ICON_MISC            */
38      { NULL, WPT_SYM_MAX+CACHE_TYPE_MAX+11 },/* ICON_POS             */
39      { NULL, 3 },                            /* ICON_FILE            */
40      { NULL, 46 },                           /* ICON_ATT             */
41    { NULL, -1 }    { NULL, -1 }
42  };  };
43    
44    /* ICON_ATT */
45    static const char *att_icon_name[] = {
46      "no", "unknown",
47      "dogs", "fee", "rappelling", "boat",                     // 1-4
48      "scuba", "kids", "onehour", "scenic", "hiking",          // 5-9
49      "climbing", "wading", "swimming", "available", "night",  // 10-14
50      "winter", "unknown", "poisonoak", "snakes", "ticks",     // 15-19
51      "mine", "cliff", "hunting", "danger", "wheelchair",      // 20-24
52      "parking", "public", "water", "restrooms", "phone",      // 25-29
53      "picnic", "camping", "bicycles", "motorcycles", "quads", // 30-34
54      "jeeps", "snowmobiles", "horses", "campfires", "thorn",  // 35-39
55      "stealth", "stroller", "firstaid", "cow", "flashlight",  // 40-44
56    
57      NULL
58    };
59    
60  /* ICON_CACHE_TYPE / ICON_CACHE_TYPE_SEMI / ICON_CACHE_TYPE_2X */  /* ICON_CACHE_TYPE / ICON_CACHE_TYPE_SEMI / ICON_CACHE_TYPE_2X */
61  const char *cache_type_icon_name[] = {  const char *cache_type_icon_name[] = {
62    "traditional", "multi",      "mystery", "virtual", "webcam", "event",    "traditional", "multi",      "mystery", "virtual", "webcam", "event",
63    "letterbox",   "earthcache", "wherigo", "megaevent", "cito"    "letterbox",   "earthcache", "wherigo", "megaevent", "cito",
64    
65      /* special overlays */
66      "ovl_override", "ovl_found", "ovl_note", "ovl_mine",
67    
68      NULL
69  };  };
70    
71  /* ICON_CACHE_SIZE */  /* ICON_CACHE_SIZE */
72  const char *cache_size_icon_name[] = {  const char *cache_size_icon_name[] = {
73    "regular", "small",      "micro", "other", "not_chosen", "large",    "regular", "small",      "micro", "other", "not_chosen", "large",
74    "virtual"    "virtual", NULL
75  };  };
76    
77  /* ICON_STARS      */  /* ICON_STARS      */
78  const char *stars_icon_name[] = {  const char *stars_icon_name[] = {
79    "1", "1_5", "2", "2_5", "3", "3_5", "4", "4_5", "5"    "1", "1_5", "2", "2_5", "3", "3_5", "4", "4_5", "5", NULL
80  };  };
81    
82  /* ICON_LOG        */  /* ICON_LOG        */
# Line 62  const char *log_icon_name[] = { Line 86  const char *log_icon_name[] = {
86    "needsmaint", "coord_update",    "needsmaint", "coord_update",
87    "traffic_cone",    "traffic_cone",
88    "traffic_cone", /* LOG_TYPE_NEEDS_ARCHIVED */    "traffic_cone", /* LOG_TYPE_NEEDS_ARCHIVED */
89    "traffic_cone",    "traffic_cone",
90      NULL
91  };  };
92    
93  /* ICON_HEADING    */  /* ICON_HEADING    */
94  const char *heading_icon_name[] = {  const char *heading_icon_name[] = {
95    "n", "ne", "e", "se", "s", "sw", "w", "nw", "none"    "n", "ne", "e", "se", "s", "sw", "w", "nw", "none", NULL
96  };  };
97    
98  /* ICON_WPT        */  /* ICON_WPT        */
99  const char *wpt_sym_icon_name[] = {  const char *wpt_sym_icon_name[] = {
100    "multistage", "parking", "final", "question",    "multistage", "parking", "final", "question",
101    "trailhead", "refpoint",    "trailhead", "refpoint", NULL
102  };  };
103    
104  /* ICON_TB         */  /* ICON_TB         */
105  const char *tb_icon_name[] = {  const char *tb_icon_name[] = {
106    "tb_coin"    "tb", "coin", NULL
107  };  };
108    
109  /* ICON_MISC         */  /* ICON_MISC         */
110  const char *misc_icon_name[] = {  const char *misc_icon_name[] = {
111    "maemo-mapper-out", "override", "locked", "unlocked", "found",    "locked", "unlocked", "delete",
112    "maemo-mapper-in", "note", "delete", "paypal"  #ifdef FREMANTLE
113      "64x64/paypal",
114    #else
115      "32x32/paypal",
116    #endif
117      "32x32/pos_geomath",
118    #ifdef FREMANTLE
119      "64x64/gpxview",
120    #else
121      "32x32/gpxview",
122    #endif
123    #ifndef USE_MAEMO
124      "16x16/speaker", "16x16/speaker_off",
125    #else
126    #ifndef FREMANTLE
127      "24x24/speaker", "24x24/speaker_off",
128    #else
129      "32x32/speaker", "32x32/speaker_off",
130    #endif
131    #endif
132    
133      NULL
134    };
135    
136    /* ICON_POS        */
137    const char *pos_icon_name[] = {
138      "wpt_multistage",         "wpt_parking",           "wpt_final",
139      "wpt_question",           "wpt_trailhead",         "wpt_refpoint",
140    
141      "cache_type_traditional", "cache_type_multi",      "cache_type_mystery",
142      "cache_type_virtual",     "cache_type_webcam",     "cache_type_event",
143      "cache_type_letterbox",   "cache_type_earthcache", "cache_type_wherigo",
144      "cache_type_megaevent",   "cache_type_cito",
145    
146      "pos_wpt", "pos_gps", "pos_geomath", "pos_map", "pos_home",
147    
148      "pos_get", "pos_set", "maemo-mapper", "clipboard",
149    
150      NULL
151  };  };
152    
153  /* ICON_FILE         */  /* ICON_FILE         */
154  const char *file_icon_name[] = {  const char *file_icon_name[] = {
155    "gc", "folder", "zip"    "gc", "folder", "zip", NULL
156  };  };
157    
158  static void icons_load(int type, char *format, const char *names[]) {  static void icons_load(int type, char *format, const char *names[]) {
# Line 103  static void icons_load(int type, char *f Line 166  static void icons_load(int type, char *f
166    icons[type].data = malloc(sizeof(GdkPixbuf *) * icons[type].count);    icons[type].data = malloc(sizeof(GdkPixbuf *) * icons[type].count);
167    
168    for(i=0;i<icons[type].count;i++) {    for(i=0;i<icons[type].count;i++) {
169      if(names[i]) {      g_assert(names[i]);
       GError *error = NULL;  
       char filename[128];  
       strcpy(filename, ICONPATH);  
       snprintf(filename+strlen(filename),  
               sizeof(filename)-strlen(filename), format, names[i], "png");  
       icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error);  
170    
171        GError *error = NULL;
172        char filename[128];
173        strcpy(filename, ICONPATH);
174        snprintf(filename+strlen(filename),
175                 sizeof(filename)-strlen(filename), format, names[i], "png");
176        icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error);
177    
178        if(error) {
179          error = NULL;
180          /* try again in local dir */
181          strcpy(filename, "./data/icons/");
182          snprintf(filename+strlen(filename),
183                   sizeof(filename)-strlen(filename), format, names[i], "png");
184          icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error);
185    
186        if(error) {        if(error) {
187          /* try gif */          icons[type].data[i] = NULL;
188            g_warning("Could not load icon %s: %s\n", names[i], error->message);
189            g_error_free(error);
190          error = NULL;          error = NULL;
191          strcpy(filename, ICONPATH);        }
192          snprintf(filename+strlen(filename),      }
                  sizeof(filename)-strlen(filename), format, names[i], "gif");  
         icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error);  
   
         if(error) {  
           error = NULL;  
           /* try again in local dir */  
           strcpy(filename, "./data/icons/");  
           snprintf(filename+strlen(filename),  
                    sizeof(filename)-strlen(filename), format, names[i], "png");  
           icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error);  
   
           if(error) {  
             error = NULL;  
             /* try gif */  
             strcpy(filename, "./data/icons/");  
             snprintf(filename+strlen(filename),  
                    sizeof(filename)-strlen(filename), format, names[i], "gif");  
             icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error);  
   
   
             if(error) {  
               icons[type].data[i] = NULL;  
               g_warning("Could not load cache type icon %s: %s\n",  
                         names[i], error->message);  
               g_error_free(error);  
               error = NULL;  
             }  
           }  
         }  
       }  
     } else  
       icons[type].data[i] = NULL;  
193    }    }
194    
195      g_assert(!names[i]);
196  }  }
197    
198  void icons_init(void) {  void icons_init(void) {
199    
200    /* load cache type icons */    /* load cache type icons */
201    icons_load(ICON_CACHE_TYPE, "cache_type_%s.%s", cache_type_icon_name);    icons_load(ICON_CACHE_TYPE, "32x32/cache_type_%s.%s", cache_type_icon_name);
202    
203    /* load semitransparent cache type icons */    /* load semitransparent cache type icons */
204    icons_load(ICON_CACHE_TYPE_SEMI, "cache_type_%s_semi.%s", cache_type_icon_name);    icons_load(ICON_CACHE_TYPE_SEMI, "32x32/cache_type_%s_semi.%s", cache_type_icon_name);
205    
206      /* load 150% sized cache type icons */
207      icons_load(ICON_CACHE_TYPE_1_5X, "48x48/cache_type_%s.%s", cache_type_icon_name);
208    
209    /* load double sized cache type icons */    /* load double sized cache type icons */
210    icons_load(ICON_CACHE_TYPE_2X, "cache_type_%s_2x.%s", cache_type_icon_name);    icons_load(ICON_CACHE_TYPE_2X, "64x64/cache_type_%s.%s", cache_type_icon_name);
211    
212    /* load cache container/size icons */    /* load cache container/size icons */
213    icons_load(ICON_CACHE_SIZE, "cache_size_%s.%s", cache_size_icon_name);  #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
214      icons_load(ICON_CACHE_SIZE, "45x12/cache_size_%s.%s", cache_size_icon_name);
215    /* load cache difficulty/terrain icons */  #else
216    icons_load(ICON_STARS, "stars%s.%s", stars_icon_name);    icons_load(ICON_CACHE_SIZE, "90x24/cache_size_%s.%s", cache_size_icon_name);
217    #endif
218    
219      /* load cache difficulty/terrain/quality icons */
220    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
221      icons_load(ICON_STARS, "12x12/stars%s.%s", stars_icon_name);
222    #else
223      icons_load(ICON_STARS, "16x16/stars%s.%s", stars_icon_name);
224    #endif
225    
226    /* load cache difficulty/terrain icons */    /* load cache log icons */
227    icons_load(ICON_LOG, "log_icon_%s.%s", log_icon_name);    icons_load(ICON_LOG, "32x32/log_icon_%s.%s", log_icon_name);
228    
229    /* load icons to visualize heading */    /* load icons to visualize heading */
230    icons_load(ICON_HEADING, "heading_%s.%s", heading_icon_name);  #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
231      icons_load(ICON_HEADING, "32x32/heading_%s.%s", heading_icon_name);
232    #else
233      icons_load(ICON_HEADING, "48x48/heading_%s.%s", heading_icon_name);
234    #endif
235    
236    /* load icons to visualize heading */    /* load waypoint icons */
237    icons_load(ICON_WPT, "wpt_%s.%s", wpt_sym_icon_name);    icons_load(ICON_WPT, "32x32/wpt_%s.%s", wpt_sym_icon_name);
238    
239    /* load travelbug icon */    /* load travelbug/coin icons */
240    icons_load(ICON_TB, "%s.%s", tb_icon_name);    icons_load(ICON_TB, "32x32/%s.%s", tb_icon_name);
241    
242    /* load misc icons */    /* load misc icons */
243    icons_load(ICON_MISC, "%s.%s", misc_icon_name);    icons_load(ICON_MISC, "%s.%s", misc_icon_name);
244    
245      /* load pos icons */
246    #if !defined(USE_MAEMO)
247      icons_load(ICON_POS, "16x16/%s.%s", pos_icon_name);
248    #else
249    #if (MAEMO_VERSION_MAJOR < 5)
250      icons_load(ICON_POS, "24x24/%s.%s", pos_icon_name);
251    #else
252      icons_load(ICON_POS, "32x32/%s.%s", pos_icon_name);
253    #endif
254    #endif
255    
256    /* load file icons */    /* load file icons */
257    icons_load(ICON_FILE, "file_%s.%s", file_icon_name);    icons_load(ICON_FILE, "file_%s.%s", file_icon_name);
258    
259      /* load attribute icons */
260      icons_load(ICON_ATT, "32x32/att_%s.%s", att_icon_name);
261  }  }
262    
263  void icons_free(void) {  void icons_free(void) {
# Line 218  GtkWidget *icon_get_widget(int type, int Line 291  GtkWidget *icon_get_widget(int type, int
291    return gtk_image_new_from_pixbuf(pbuf);    return gtk_image_new_from_pixbuf(pbuf);
292  }  }
293    
294    /* routine to overlay two pixbufs */
295    GdkPixbuf *pixbuf_overlay(GdkPixbuf *bot, GdkPixbuf *top) {
296      GdkPixbuf *pix = gdk_pixbuf_copy(bot);
297    
298      gdk_pixbuf_composite(top, pix,
299           0, 0, gdk_pixbuf_get_width(bot), gdk_pixbuf_get_height(bot),
300           0.0, 0.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
301    
302      return pix;
303    }
304    
305    GtkWidget *icon_get_widget_ovl(int type, int num, int ovl) {
306      GdkPixbuf *pbuf0 = icon_get(type, num);
307      GdkPixbuf *pbuf1 = icon_get(type, ovl);
308      if(!pbuf0 || !pbuf1) return NULL;
309    
310      GdkPixbuf *pbuf = pixbuf_overlay(pbuf0, pbuf1);
311      GtkWidget *widget = gtk_image_new_from_pixbuf(pbuf);
312    
313      /* widget now holds a reference */
314      gdk_pixbuf_unref(pbuf);
315    
316      return widget;
317    }
318    
319  GdkPixbuf *icon_bearing(pos_t from, pos_t to) {  GdkPixbuf *icon_bearing(pos_t from, pos_t to) {
320    if(isnan(from.lat) || isnan(from.lon) ||    if(isnan(from.lat) || isnan(from.lon) ||
321       isnan(to.lat) || isnan(to.lon))       isnan(to.lat) || isnan(to.lon))

Legend:
Removed from v.174  
changed lines
  Added in v.293