Parent Directory | Revision Log
removed unused icons
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+1 }, /* ICON_CACHE_TYPE */ |
28 | { NULL, CACHE_CONT_MAX+1 }, /* ICON_CACHE_SIZE */ |
29 | { NULL, 9 }, /* ICON_STARS */ |
30 | { NULL, LOG_TYPE_MAX+1 }, /* ICON_LOG */ |
31 | { NULL, 9 }, /* ICON_HEADING */ |
32 | { NULL, WPT_SYM_MAX+1 }, /* ICON_WPT */ |
33 | { NULL, 1 }, /* ICON_TB */ |
34 | { NULL, 9 }, /* ICON_MISC */ |
35 | { NULL, 3 }, /* ICON_FILE */ |
36 | { NULL, -1 } |
37 | }; |
38 | |
39 | /* ICON_CACHE_TYPE */ |
40 | const char *cache_type_icon_name[] = { |
41 | "traditional", "multi", "mystery", "virtual", "webcam", "event", |
42 | "letterbox", "earthcache", "wherigo", "megaevent", "cito" |
43 | }; |
44 | |
45 | /* ICON_CACHE_SIZE */ |
46 | const char *cache_size_icon_name[] = { |
47 | "regular", "small", "micro", "other", "not_chosen", "large", |
48 | "virtual" |
49 | }; |
50 | |
51 | /* ICON_STARS */ |
52 | const char *stars_icon_name[] = { |
53 | "1", "1_5", "2", "2_5", "3", "3_5", "4", "4_5", "5" |
54 | }; |
55 | |
56 | /* ICON_LOG */ |
57 | const char *log_icon_name[] = { |
58 | "smile", "sad", "maint", "note", "big_smile", "enabled", |
59 | "greenlight", "rsvp", "attended", "camera", "disabled", |
60 | "needsmaint", "coord_update", |
61 | "traffic_cone", |
62 | "traffic_cone", /* LOG_TYPE_NEEDS_ARCHIVED */ |
63 | "traffic_cone", |
64 | }; |
65 | |
66 | /* ICON_HEADING */ |
67 | const char *heading_icon_name[] = { |
68 | "n", "ne", "e", "se", "s", "sw", "w", "nw", "none" |
69 | }; |
70 | |
71 | /* ICON_WPT */ |
72 | const char *wpt_sym_icon_name[] = { |
73 | "multistage", "parking", "final", "question", |
74 | "trailhead", "refpoint", |
75 | }; |
76 | |
77 | /* ICON_TB */ |
78 | const char *tb_icon_name[] = { |
79 | "tb_coin" |
80 | }; |
81 | |
82 | /* ICON_MISC */ |
83 | const char *misc_icon_name[] = { |
84 | "maemo-mapper-out", "override", "locked", "unlocked", "found", |
85 | "maemo-mapper-in", "note", "delete", "paypal" |
86 | }; |
87 | |
88 | /* ICON_FILE */ |
89 | const char *file_icon_name[] = { |
90 | "gc", "folder", "zip" |
91 | }; |
92 | |
93 | static void icons_load(int type, char *format, const char *names[]) { |
94 | int i; |
95 | |
96 | if(!icons[type].count) { |
97 | icons[type].data = NULL; |
98 | return; |
99 | } |
100 | |
101 | icons[type].data = malloc(sizeof(GdkPixbuf *) * icons[type].count); |
102 | |
103 | for(i=0;i<icons[type].count;i++) { |
104 | if(names[i]) { |
105 | GError *error = NULL; |
106 | char filename[128]; |
107 | strcpy(filename, ICONPATH); |
108 | snprintf(filename+strlen(filename), |
109 | sizeof(filename)-strlen(filename), format, names[i], "png"); |
110 | icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error); |
111 | |
112 | if(error) { |
113 | /* try gif */ |
114 | error = NULL; |
115 | strcpy(filename, ICONPATH); |
116 | snprintf(filename+strlen(filename), |
117 | sizeof(filename)-strlen(filename), format, names[i], "gif"); |
118 | icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error); |
119 | |
120 | if(error) { |
121 | error = NULL; |
122 | /* try again in local dir */ |
123 | strcpy(filename, "./data/icons/"); |
124 | snprintf(filename+strlen(filename), |
125 | sizeof(filename)-strlen(filename), format, names[i], "png"); |
126 | icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error); |
127 | |
128 | if(error) { |
129 | error = NULL; |
130 | /* try gif */ |
131 | strcpy(filename, "./data/icons/"); |
132 | snprintf(filename+strlen(filename), |
133 | sizeof(filename)-strlen(filename), format, names[i], "gif"); |
134 | icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error); |
135 | |
136 | |
137 | if(error) { |
138 | icons[type].data[i] = NULL; |
139 | g_warning("Could not load cache type icon %s: %s\n", |
140 | names[i], error->message); |
141 | g_error_free(error); |
142 | error = NULL; |
143 | } |
144 | } |
145 | } |
146 | } |
147 | } else |
148 | icons[type].data[i] = NULL; |
149 | } |
150 | } |
151 | |
152 | void icons_init(void) { |
153 | |
154 | /* load cache type icons */ |
155 | icons_load(ICON_CACHE_TYPE, "cache_type_%s.%s", cache_type_icon_name); |
156 | |
157 | /* load cache container/size icons */ |
158 | icons_load(ICON_CACHE_SIZE, "cache_size_%s.%s", cache_size_icon_name); |
159 | |
160 | /* load cache difficulty/terrain icons */ |
161 | icons_load(ICON_STARS, "stars%s.%s", stars_icon_name); |
162 | |
163 | /* load cache difficulty/terrain icons */ |
164 | icons_load(ICON_LOG, "log_icon_%s.%s", log_icon_name); |
165 | |
166 | /* load icons to visualize heading */ |
167 | icons_load(ICON_HEADING, "heading_%s.%s", heading_icon_name); |
168 | |
169 | /* load icons to visualize heading */ |
170 | icons_load(ICON_WPT, "wpt_%s.%s", wpt_sym_icon_name); |
171 | |
172 | /* load travelbug icon */ |
173 | icons_load(ICON_TB, "%s.%s", tb_icon_name); |
174 | |
175 | /* load misc icons */ |
176 | icons_load(ICON_MISC, "%s.%s", misc_icon_name); |
177 | |
178 | /* load file icons */ |
179 | icons_load(ICON_FILE, "file_%s.%s", file_icon_name); |
180 | } |
181 | |
182 | void icons_free(void) { |
183 | int i; |
184 | struct icon_data *icon = icons; |
185 | |
186 | while(icon->count >= 0) { |
187 | if(icon->count) { |
188 | for(i=0;i<icon->count;i++) |
189 | if(icon->data[i]) |
190 | gdk_pixbuf_unref(icon->data[i]); |
191 | |
192 | free(icon->data); |
193 | } |
194 | |
195 | icon++; |
196 | } |
197 | } |
198 | |
199 | GdkPixbuf *icon_get(int type, int num) { |
200 | if(num < 0) return NULL; |
201 | if(num >= icons[type].count) return NULL; |
202 | |
203 | return icons[type].data[num]; |
204 | } |
205 | |
206 | GtkWidget *icon_get_widget(int type, int num) { |
207 | GdkPixbuf *pbuf = icon_get(type, num); |
208 | if(!pbuf) return NULL; |
209 | |
210 | return gtk_image_new_from_pixbuf(pbuf); |
211 | } |
212 | |
213 | GdkPixbuf *icon_bearing(pos_t from, pos_t to) { |
214 | if(isnan(from.lat) || isnan(from.lon) || |
215 | isnan(to.lat) || isnan(to.lon)) |
216 | return icon_get(ICON_HEADING, 8); |
217 | |
218 | int idx = (gpx_pos_get_bearing(from, to)+22.5)/45.0; |
219 | |
220 | /* make sure we stay in icon bounds */ |
221 | if(idx < 0) idx += 8; |
222 | if(idx > 7) idx -= 8; |
223 | return icon_get(ICON_HEADING, idx); |
224 | } |
225 |