Parent Directory | Revision Log
New about dialog
1 | /* |
2 | * Copyright (C) 2008 Till Harbaum <till@harbaum.org>. |
3 | * |
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 | #include <math.h> // for isnan() |
22 | |
23 | struct icon_data { |
24 | GdkPixbuf **data; |
25 | int count; |
26 | } icons[] = { |
27 | { 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 | { NULL, 8 }, /* ICON_MISC */ |
38 | { NULL, WPT_SYM_MAX+CACHE_TYPE_MAX+7 }, /* ICON_POS */ |
39 | { NULL, 3 }, /* ICON_FILE */ |
40 | { NULL, -1 } |
41 | }; |
42 | |
43 | /* ICON_CACHE_TYPE / ICON_CACHE_TYPE_SEMI / ICON_CACHE_TYPE_2X */ |
44 | const char *cache_type_icon_name[] = { |
45 | "traditional", "multi", "mystery", "virtual", "webcam", "event", |
46 | "letterbox", "earthcache", "wherigo", "megaevent", "cito", |
47 | |
48 | /* special overlays */ |
49 | "ovl_override", "ovl_found", "ovl_note", "ovl_mine", |
50 | |
51 | NULL |
52 | }; |
53 | |
54 | /* ICON_CACHE_SIZE */ |
55 | const char *cache_size_icon_name[] = { |
56 | "regular", "small", "micro", "other", "not_chosen", "large", |
57 | "virtual", NULL |
58 | }; |
59 | |
60 | /* ICON_STARS */ |
61 | const char *stars_icon_name[] = { |
62 | "1", "1_5", "2", "2_5", "3", "3_5", "4", "4_5", "5", NULL |
63 | }; |
64 | |
65 | /* ICON_LOG */ |
66 | const char *log_icon_name[] = { |
67 | "smile", "sad", "maint", "note", "big_smile", "enabled", |
68 | "greenlight", "rsvp", "attended", "camera", "disabled", |
69 | "needsmaint", "coord_update", |
70 | "traffic_cone", |
71 | "traffic_cone", /* LOG_TYPE_NEEDS_ARCHIVED */ |
72 | "traffic_cone", |
73 | NULL |
74 | }; |
75 | |
76 | /* ICON_HEADING */ |
77 | const char *heading_icon_name[] = { |
78 | "n", "ne", "e", "se", "s", "sw", "w", "nw", "none", NULL |
79 | }; |
80 | |
81 | /* ICON_WPT */ |
82 | const char *wpt_sym_icon_name[] = { |
83 | "multistage", "parking", "final", "question", |
84 | "trailhead", "refpoint", NULL |
85 | }; |
86 | |
87 | /* ICON_TB */ |
88 | const char *tb_icon_name[] = { |
89 | "tb", "coin", NULL |
90 | }; |
91 | |
92 | /* ICON_MISC */ |
93 | const char *misc_icon_name[] = { |
94 | "maemo-mapper-out", "locked", "unlocked", |
95 | "maemo-mapper-in", "delete", |
96 | #ifdef FREMANTLE |
97 | "64x64/paypal", |
98 | #else |
99 | "32x32/paypal", |
100 | #endif |
101 | "32x32/pos_geomath", |
102 | #ifdef FREMANTLE |
103 | "64x64/gpxview", |
104 | #else |
105 | "32x32/gpxview", |
106 | #endif |
107 | NULL |
108 | }; |
109 | |
110 | /* ICON_POS */ |
111 | const char *pos_icon_name[] = { |
112 | "wpt_multistage", "wpt_parking", "wpt_final", |
113 | "wpt_question", "wpt_trailhead", "wpt_refpoint", |
114 | |
115 | "cache_type_traditional", "cache_type_multi", "cache_type_mystery", |
116 | "cache_type_virtual", "cache_type_webcam", "cache_type_event", |
117 | "cache_type_letterbox", "cache_type_earthcache", "cache_type_wherigo", |
118 | "cache_type_megaevent", "cache_type_cito", |
119 | |
120 | "pos_btn", "pos_gps", "pos_geomath", "pos_map", "pos_home", |
121 | NULL |
122 | }; |
123 | |
124 | /* ICON_FILE */ |
125 | const char *file_icon_name[] = { |
126 | "gc", "folder", "zip", NULL |
127 | }; |
128 | |
129 | static void icons_load(int type, char *format, const char *names[]) { |
130 | int i; |
131 | |
132 | if(!icons[type].count) { |
133 | icons[type].data = NULL; |
134 | return; |
135 | } |
136 | |
137 | icons[type].data = malloc(sizeof(GdkPixbuf *) * icons[type].count); |
138 | |
139 | for(i=0;i<icons[type].count;i++) { |
140 | g_assert(names[i]); |
141 | |
142 | GError *error = NULL; |
143 | char filename[128]; |
144 | strcpy(filename, ICONPATH); |
145 | snprintf(filename+strlen(filename), |
146 | sizeof(filename)-strlen(filename), format, names[i], "png"); |
147 | icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error); |
148 | |
149 | if(error) { |
150 | error = NULL; |
151 | /* try again in local dir */ |
152 | strcpy(filename, "./data/icons/"); |
153 | snprintf(filename+strlen(filename), |
154 | sizeof(filename)-strlen(filename), format, names[i], "png"); |
155 | icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error); |
156 | |
157 | if(error) { |
158 | icons[type].data[i] = NULL; |
159 | g_warning("Could not load cache type icon %s: %s\n", |
160 | names[i], error->message); |
161 | g_error_free(error); |
162 | error = NULL; |
163 | } |
164 | } |
165 | } |
166 | |
167 | g_assert(!names[i]); |
168 | } |
169 | |
170 | void icons_init(void) { |
171 | |
172 | /* load cache type icons */ |
173 | icons_load(ICON_CACHE_TYPE, "32x32/cache_type_%s.%s", cache_type_icon_name); |
174 | |
175 | /* load semitransparent cache type icons */ |
176 | icons_load(ICON_CACHE_TYPE_SEMI, "32x32/cache_type_%s_semi.%s", cache_type_icon_name); |
177 | |
178 | /* load 150% sized cache type icons */ |
179 | icons_load(ICON_CACHE_TYPE_1_5X, "48x48/cache_type_%s.%s", cache_type_icon_name); |
180 | |
181 | /* load double sized cache type icons */ |
182 | icons_load(ICON_CACHE_TYPE_2X, "64x64/cache_type_%s.%s", cache_type_icon_name); |
183 | |
184 | /* load cache container/size icons */ |
185 | #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
186 | icons_load(ICON_CACHE_SIZE, "45x12/cache_size_%s.%s", cache_size_icon_name); |
187 | #else |
188 | icons_load(ICON_CACHE_SIZE, "90x24/cache_size_%s.%s", cache_size_icon_name); |
189 | #endif |
190 | |
191 | /* load cache difficulty/terrain/quality icons */ |
192 | #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
193 | icons_load(ICON_STARS, "12x12/stars%s.%s", stars_icon_name); |
194 | #else |
195 | icons_load(ICON_STARS, "16x16/stars%s.%s", stars_icon_name); |
196 | #endif |
197 | |
198 | /* load cache log icons */ |
199 | icons_load(ICON_LOG, "32x32/log_icon_%s.%s", log_icon_name); |
200 | |
201 | /* load icons to visualize heading */ |
202 | #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
203 | icons_load(ICON_HEADING, "32x32/heading_%s.%s", heading_icon_name); |
204 | #else |
205 | icons_load(ICON_HEADING, "48x48/heading_%s.%s", heading_icon_name); |
206 | #endif |
207 | |
208 | /* load waypoint icons */ |
209 | icons_load(ICON_WPT, "32x32/wpt_%s.%s", wpt_sym_icon_name); |
210 | |
211 | /* load travelbug/coin icons */ |
212 | icons_load(ICON_TB, "32x32/%s.%s", tb_icon_name); |
213 | |
214 | /* load misc icons */ |
215 | icons_load(ICON_MISC, "%s.%s", misc_icon_name); |
216 | |
217 | /* load pos icons */ |
218 | #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
219 | icons_load(ICON_POS, "16x16/%s.%s", pos_icon_name); |
220 | #else |
221 | icons_load(ICON_POS, "32x32/%s.%s", pos_icon_name); |
222 | #endif |
223 | |
224 | /* load file icons */ |
225 | icons_load(ICON_FILE, "file_%s.%s", file_icon_name); |
226 | } |
227 | |
228 | void icons_free(void) { |
229 | int i; |
230 | struct icon_data *icon = icons; |
231 | |
232 | while(icon->count >= 0) { |
233 | if(icon->count) { |
234 | for(i=0;i<icon->count;i++) |
235 | if(icon->data[i]) |
236 | gdk_pixbuf_unref(icon->data[i]); |
237 | |
238 | free(icon->data); |
239 | } |
240 | |
241 | icon++; |
242 | } |
243 | } |
244 | |
245 | GdkPixbuf *icon_get(int type, int num) { |
246 | if(num < 0) return NULL; |
247 | if(num >= icons[type].count) return NULL; |
248 | |
249 | return icons[type].data[num]; |
250 | } |
251 | |
252 | GtkWidget *icon_get_widget(int type, int num) { |
253 | GdkPixbuf *pbuf = icon_get(type, num); |
254 | if(!pbuf) return NULL; |
255 | |
256 | return gtk_image_new_from_pixbuf(pbuf); |
257 | } |
258 | |
259 | GdkPixbuf *icon_bearing(pos_t from, pos_t to) { |
260 | if(isnan(from.lat) || isnan(from.lon) || |
261 | isnan(to.lat) || isnan(to.lon)) |
262 | return icon_get(ICON_HEADING, 8); |
263 | |
264 | int idx = (gpx_pos_get_bearing(from, to)+22.5)/45.0; |
265 | |
266 | /* make sure we stay in icon bounds */ |
267 | if(idx < 0) idx += 8; |
268 | if(idx > 7) idx -= 8; |
269 | return icon_get(ICON_HEADING, idx); |
270 | } |
271 |