Parent Directory | Revision Log
Added missing icon
1 | harbaum | 1 | /* |
2 | harbaum | 294 | * Copyright (C) 2008-2010 Till Harbaum <till@harbaum.org>. |
3 | harbaum | 1 | * |
4 | * This file is part of GPXView. | ||
5 | * | ||
6 | * GPXView is free software: you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation, either version 3 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * GPXView is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with GPXView. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | #include "gpxview.h" | ||
21 | harbaum | 53 | #include <math.h> // for isnan() |
22 | harbaum | 1 | |
23 | struct icon_data { | ||
24 | GdkPixbuf **data; | ||
25 | int count; | ||
26 | } icons[] = { | ||
27 | harbaum | 214 | { NULL, CACHE_TYPE_MAX+5 }, /* ICON_CACHE_TYPE */ |
28 | { NULL, CACHE_TYPE_MAX+5 }, /* ICON_CACHE_TYPE_SEMI */ | ||
29 | { NULL, CACHE_TYPE_MAX+5 }, /* ICON_CACHE_TYPE_1_5X */ | ||
30 | { NULL, CACHE_TYPE_MAX+5 }, /* ICON_CACHE_TYPE_2X */ | ||
31 | { NULL, CACHE_CONT_MAX+1 }, /* ICON_CACHE_SIZE */ | ||
32 | { NULL, 9 }, /* ICON_STARS */ | ||
33 | { NULL, LOG_TYPE_MAX+1 }, /* ICON_LOG */ | ||
34 | { NULL, 9 }, /* ICON_HEADING */ | ||
35 | { NULL, WPT_SYM_MAX+1 }, /* ICON_WPT */ | ||
36 | { NULL, 2 }, /* ICON_TB */ | ||
37 | harbaum | 246 | { NULL, 8 }, /* ICON_MISC */ |
38 | harbaum | 249 | { NULL, WPT_SYM_MAX+CACHE_TYPE_MAX+11 },/* ICON_POS */ |
39 | harbaum | 214 | { NULL, 3 }, /* ICON_FILE */ |
40 | harbaum | 294 | { NULL, ATT_MAX+2 }, /* ICON_ATT */ |
41 | harbaum | 1 | { NULL, -1 } |
42 | }; | ||
43 | |||
44 | harbaum | 293 | /* 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 | harbaum | 302 | "landf", "rv", "field_puzzle", "UV", "snowshoes", // 45-49 |
57 | harbaum | 294 | "skiis", "s_tool", "nightcache", "parkngrab", "abandonedbuilding", // 50-54 |
58 | "hike_short", "hike_med", "hike_long", "fuel", "food", // 55-59 | ||
59 | harbaum | 293 | NULL |
60 | }; | ||
61 | |||
62 | harbaum | 174 | /* ICON_CACHE_TYPE / ICON_CACHE_TYPE_SEMI / ICON_CACHE_TYPE_2X */ |
63 | harbaum | 1 | const char *cache_type_icon_name[] = { |
64 | "traditional", "multi", "mystery", "virtual", "webcam", "event", | ||
65 | harbaum | 188 | "letterbox", "earthcache", "wherigo", "megaevent", "cito", |
66 | |||
67 | /* special overlays */ | ||
68 | harbaum | 205 | "ovl_override", "ovl_found", "ovl_note", "ovl_mine", |
69 | harbaum | 189 | |
70 | NULL | ||
71 | harbaum | 1 | }; |
72 | |||
73 | /* ICON_CACHE_SIZE */ | ||
74 | const char *cache_size_icon_name[] = { | ||
75 | "regular", "small", "micro", "other", "not_chosen", "large", | ||
76 | harbaum | 189 | "virtual", NULL |
77 | harbaum | 1 | }; |
78 | |||
79 | /* ICON_STARS */ | ||
80 | const char *stars_icon_name[] = { | ||
81 | harbaum | 189 | "1", "1_5", "2", "2_5", "3", "3_5", "4", "4_5", "5", NULL |
82 | harbaum | 1 | }; |
83 | |||
84 | /* ICON_LOG */ | ||
85 | const char *log_icon_name[] = { | ||
86 | "smile", "sad", "maint", "note", "big_smile", "enabled", | ||
87 | "greenlight", "rsvp", "attended", "camera", "disabled", | ||
88 | "needsmaint", "coord_update", | ||
89 | "traffic_cone", | ||
90 | "traffic_cone", /* LOG_TYPE_NEEDS_ARCHIVED */ | ||
91 | harbaum | 189 | "traffic_cone", |
92 | NULL | ||
93 | harbaum | 1 | }; |
94 | |||
95 | /* ICON_HEADING */ | ||
96 | const char *heading_icon_name[] = { | ||
97 | harbaum | 189 | "n", "ne", "e", "se", "s", "sw", "w", "nw", "none", NULL |
98 | harbaum | 1 | }; |
99 | |||
100 | /* ICON_WPT */ | ||
101 | const char *wpt_sym_icon_name[] = { | ||
102 | "multistage", "parking", "final", "question", | ||
103 | harbaum | 189 | "trailhead", "refpoint", NULL |
104 | harbaum | 1 | }; |
105 | |||
106 | /* ICON_TB */ | ||
107 | const char *tb_icon_name[] = { | ||
108 | harbaum | 189 | "tb", "coin", NULL |
109 | harbaum | 1 | }; |
110 | |||
111 | /* ICON_MISC */ | ||
112 | const char *misc_icon_name[] = { | ||
113 | harbaum | 294 | "32x32/locked", "32x32/unlocked", "32x32/delete", |
114 | harbaum | 229 | #ifdef FREMANTLE |
115 | "64x64/paypal", | ||
116 | #else | ||
117 | "32x32/paypal", | ||
118 | #endif | ||
119 | "32x32/pos_geomath", | ||
120 | #ifdef FREMANTLE | ||
121 | "64x64/gpxview", | ||
122 | #else | ||
123 | "32x32/gpxview", | ||
124 | #endif | ||
125 | harbaum | 246 | #ifndef USE_MAEMO |
126 | "16x16/speaker", "16x16/speaker_off", | ||
127 | #else | ||
128 | #ifndef FREMANTLE | ||
129 | "24x24/speaker", "24x24/speaker_off", | ||
130 | #else | ||
131 | "32x32/speaker", "32x32/speaker_off", | ||
132 | #endif | ||
133 | #endif | ||
134 | |||
135 | harbaum | 213 | NULL |
136 | harbaum | 1 | }; |
137 | |||
138 | harbaum | 213 | /* ICON_POS */ |
139 | const char *pos_icon_name[] = { | ||
140 | harbaum | 214 | "wpt_multistage", "wpt_parking", "wpt_final", |
141 | "wpt_question", "wpt_trailhead", "wpt_refpoint", | ||
142 | harbaum | 213 | |
143 | harbaum | 214 | "cache_type_traditional", "cache_type_multi", "cache_type_mystery", |
144 | "cache_type_virtual", "cache_type_webcam", "cache_type_event", | ||
145 | "cache_type_letterbox", "cache_type_earthcache", "cache_type_wherigo", | ||
146 | "cache_type_megaevent", "cache_type_cito", | ||
147 | |||
148 | harbaum | 231 | "pos_wpt", "pos_gps", "pos_geomath", "pos_map", "pos_home", |
149 | |||
150 | harbaum | 249 | "pos_get", "pos_set", "maemo-mapper", "clipboard", |
151 | harbaum | 231 | |
152 | harbaum | 213 | NULL |
153 | }; | ||
154 | |||
155 | harbaum | 1 | /* ICON_FILE */ |
156 | const char *file_icon_name[] = { | ||
157 | harbaum | 189 | "gc", "folder", "zip", NULL |
158 | harbaum | 1 | }; |
159 | |||
160 | static void icons_load(int type, char *format, const char *names[]) { | ||
161 | int i; | ||
162 | |||
163 | if(!icons[type].count) { | ||
164 | icons[type].data = NULL; | ||
165 | return; | ||
166 | } | ||
167 | |||
168 | icons[type].data = malloc(sizeof(GdkPixbuf *) * icons[type].count); | ||
169 | |||
170 | for(i=0;i<icons[type].count;i++) { | ||
171 | harbaum | 189 | g_assert(names[i]); |
172 | harbaum | 1 | |
173 | harbaum | 189 | GError *error = NULL; |
174 | char filename[128]; | ||
175 | strcpy(filename, ICONPATH); | ||
176 | snprintf(filename+strlen(filename), | ||
177 | sizeof(filename)-strlen(filename), format, names[i], "png"); | ||
178 | icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error); | ||
179 | |||
180 | if(error) { | ||
181 | error = NULL; | ||
182 | /* try again in local dir */ | ||
183 | strcpy(filename, "./data/icons/"); | ||
184 | snprintf(filename+strlen(filename), | ||
185 | sizeof(filename)-strlen(filename), format, names[i], "png"); | ||
186 | icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error); | ||
187 | |||
188 | harbaum | 1 | if(error) { |
189 | harbaum | 189 | icons[type].data[i] = NULL; |
190 | harbaum | 293 | g_warning("Could not load icon %s: %s\n", names[i], error->message); |
191 | harbaum | 189 | g_error_free(error); |
192 | harbaum | 1 | error = NULL; |
193 | harbaum | 189 | } |
194 | } | ||
195 | harbaum | 1 | } |
196 | harbaum | 214 | |
197 | harbaum | 189 | g_assert(!names[i]); |
198 | harbaum | 1 | } |
199 | |||
200 | void icons_init(void) { | ||
201 | |||
202 | /* load cache type icons */ | ||
203 | harbaum | 180 | icons_load(ICON_CACHE_TYPE, "32x32/cache_type_%s.%s", cache_type_icon_name); |
204 | harbaum | 1 | |
205 | harbaum | 174 | /* load semitransparent cache type icons */ |
206 | harbaum | 180 | icons_load(ICON_CACHE_TYPE_SEMI, "32x32/cache_type_%s_semi.%s", cache_type_icon_name); |
207 | harbaum | 151 | |
208 | harbaum | 176 | /* load 150% sized cache type icons */ |
209 | harbaum | 180 | icons_load(ICON_CACHE_TYPE_1_5X, "48x48/cache_type_%s.%s", cache_type_icon_name); |
210 | harbaum | 176 | |
211 | harbaum | 174 | /* load double sized cache type icons */ |
212 | harbaum | 180 | icons_load(ICON_CACHE_TYPE_2X, "64x64/cache_type_%s.%s", cache_type_icon_name); |
213 | harbaum | 174 | |
214 | harbaum | 1 | /* load cache container/size icons */ |
215 | harbaum | 187 | #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
216 | harbaum | 185 | icons_load(ICON_CACHE_SIZE, "45x12/cache_size_%s.%s", cache_size_icon_name); |
217 | harbaum | 187 | #else |
218 | icons_load(ICON_CACHE_SIZE, "90x24/cache_size_%s.%s", cache_size_icon_name); | ||
219 | #endif | ||
220 | harbaum | 1 | |
221 | harbaum | 180 | /* load cache difficulty/terrain/quality icons */ |
222 | harbaum | 187 | #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
223 | icons_load(ICON_STARS, "12x12/stars%s.%s", stars_icon_name); | ||
224 | #else | ||
225 | icons_load(ICON_STARS, "16x16/stars%s.%s", stars_icon_name); | ||
226 | #endif | ||
227 | harbaum | 1 | |
228 | harbaum | 180 | /* load cache log icons */ |
229 | icons_load(ICON_LOG, "32x32/log_icon_%s.%s", log_icon_name); | ||
230 | harbaum | 1 | |
231 | /* load icons to visualize heading */ | ||
232 | harbaum | 187 | #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
233 | icons_load(ICON_HEADING, "32x32/heading_%s.%s", heading_icon_name); | ||
234 | #else | ||
235 | icons_load(ICON_HEADING, "48x48/heading_%s.%s", heading_icon_name); | ||
236 | #endif | ||
237 | harbaum | 1 | |
238 | harbaum | 187 | /* load waypoint icons */ |
239 | harbaum | 184 | icons_load(ICON_WPT, "32x32/wpt_%s.%s", wpt_sym_icon_name); |
240 | harbaum | 1 | |
241 | harbaum | 187 | /* load travelbug/coin icons */ |
242 | harbaum | 180 | icons_load(ICON_TB, "32x32/%s.%s", tb_icon_name); |
243 | harbaum | 1 | |
244 | /* load misc icons */ | ||
245 | icons_load(ICON_MISC, "%s.%s", misc_icon_name); | ||
246 | |||
247 | harbaum | 213 | /* load pos icons */ |
248 | harbaum | 242 | #if !defined(USE_MAEMO) |
249 | harbaum | 213 | icons_load(ICON_POS, "16x16/%s.%s", pos_icon_name); |
250 | harbaum | 214 | #else |
251 | harbaum | 242 | #if (MAEMO_VERSION_MAJOR < 5) |
252 | icons_load(ICON_POS, "24x24/%s.%s", pos_icon_name); | ||
253 | #else | ||
254 | harbaum | 214 | icons_load(ICON_POS, "32x32/%s.%s", pos_icon_name); |
255 | #endif | ||
256 | harbaum | 242 | #endif |
257 | harbaum | 213 | |
258 | harbaum | 1 | /* load file icons */ |
259 | harbaum | 294 | icons_load(ICON_FILE, "32x32/file_%s.%s", file_icon_name); |
260 | harbaum | 293 | |
261 | /* load attribute icons */ | ||
262 | icons_load(ICON_ATT, "32x32/att_%s.%s", att_icon_name); | ||
263 | harbaum | 1 | } |
264 | |||
265 | void icons_free(void) { | ||
266 | int i; | ||
267 | struct icon_data *icon = icons; | ||
268 | |||
269 | while(icon->count >= 0) { | ||
270 | if(icon->count) { | ||
271 | for(i=0;i<icon->count;i++) | ||
272 | if(icon->data[i]) | ||
273 | gdk_pixbuf_unref(icon->data[i]); | ||
274 | |||
275 | free(icon->data); | ||
276 | } | ||
277 | |||
278 | icon++; | ||
279 | } | ||
280 | } | ||
281 | |||
282 | GdkPixbuf *icon_get(int type, int num) { | ||
283 | if(num < 0) return NULL; | ||
284 | if(num >= icons[type].count) return NULL; | ||
285 | |||
286 | return icons[type].data[num]; | ||
287 | } | ||
288 | |||
289 | GtkWidget *icon_get_widget(int type, int num) { | ||
290 | GdkPixbuf *pbuf = icon_get(type, num); | ||
291 | if(!pbuf) return NULL; | ||
292 | |||
293 | return gtk_image_new_from_pixbuf(pbuf); | ||
294 | } | ||
295 | |||
296 | harbaum | 293 | /* routine to overlay two pixbufs */ |
297 | GdkPixbuf *pixbuf_overlay(GdkPixbuf *bot, GdkPixbuf *top) { | ||
298 | GdkPixbuf *pix = gdk_pixbuf_copy(bot); | ||
299 | |||
300 | gdk_pixbuf_composite(top, pix, | ||
301 | 0, 0, gdk_pixbuf_get_width(bot), gdk_pixbuf_get_height(bot), | ||
302 | 0.0, 0.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255); | ||
303 | |||
304 | return pix; | ||
305 | } | ||
306 | |||
307 | GtkWidget *icon_get_widget_ovl(int type, int num, int ovl) { | ||
308 | GdkPixbuf *pbuf0 = icon_get(type, num); | ||
309 | GdkPixbuf *pbuf1 = icon_get(type, ovl); | ||
310 | if(!pbuf0 || !pbuf1) return NULL; | ||
311 | |||
312 | GdkPixbuf *pbuf = pixbuf_overlay(pbuf0, pbuf1); | ||
313 | GtkWidget *widget = gtk_image_new_from_pixbuf(pbuf); | ||
314 | |||
315 | /* widget now holds a reference */ | ||
316 | gdk_pixbuf_unref(pbuf); | ||
317 | |||
318 | return widget; | ||
319 | } | ||
320 | |||
321 | harbaum | 1 | GdkPixbuf *icon_bearing(pos_t from, pos_t to) { |
322 | harbaum | 47 | if(isnan(from.lat) || isnan(from.lon) || |
323 | isnan(to.lat) || isnan(to.lon)) | ||
324 | harbaum | 1 | return icon_get(ICON_HEADING, 8); |
325 | |||
326 | int idx = (gpx_pos_get_bearing(from, to)+22.5)/45.0; | ||
327 | |||
328 | /* make sure we stay in icon bounds */ | ||
329 | if(idx < 0) idx += 8; | ||
330 | if(idx > 7) idx -= 8; | ||
331 | return icon_get(ICON_HEADING, idx); | ||
332 | } | ||
333 |