18 |
*/ |
*/ |
19 |
|
|
20 |
#include "gpxview.h" |
#include "gpxview.h" |
21 |
|
#include <math.h> // for isnan() |
22 |
|
|
23 |
struct icon_data { |
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_CONT_MAX+1 }, /* ICON_CACHE_SIZE */ |
{ NULL, CACHE_TYPE_MAX+5 }, /* ICON_CACHE_TYPE_SEMI */ |
29 |
{ NULL, 9 }, /* ICON_STARS */ |
{ NULL, CACHE_TYPE_MAX+5 }, /* ICON_CACHE_TYPE_1_5X */ |
30 |
{ NULL, LOG_TYPE_MAX+1 }, /* ICON_LOG */ |
{ NULL, CACHE_TYPE_MAX+5 }, /* ICON_CACHE_TYPE_2X */ |
31 |
{ NULL, 9 }, /* ICON_HEADING */ |
{ NULL, CACHE_CONT_MAX+1 }, /* ICON_CACHE_SIZE */ |
32 |
{ NULL, WPT_SYM_MAX+1 }, /* ICON_WPT */ |
{ NULL, 9 }, /* ICON_STARS */ |
33 |
{ NULL, 1 }, /* ICON_TB */ |
{ NULL, LOG_TYPE_MAX+1 }, /* ICON_LOG */ |
34 |
{ NULL, 8 }, /* ICON_MISC */ |
{ NULL, 9 }, /* ICON_HEADING */ |
35 |
{ NULL, 3 }, /* ICON_FILE */ |
{ NULL, WPT_SYM_MAX+1 }, /* ICON_WPT */ |
36 |
|
{ NULL, 2 }, /* ICON_TB */ |
37 |
|
{ NULL, 6 }, /* ICON_MISC */ |
38 |
|
{ NULL, WPT_SYM_MAX+3 }, /* ICON_POS */ |
39 |
|
{ NULL, 3 }, /* ICON_FILE */ |
40 |
{ NULL, -1 } |
{ NULL, -1 } |
41 |
}; |
}; |
42 |
|
|
43 |
/* ICON_CACHE_TYPE */ |
/* ICON_CACHE_TYPE / ICON_CACHE_TYPE_SEMI / ICON_CACHE_TYPE_2X */ |
44 |
const char *cache_type_icon_name[] = { |
const char *cache_type_icon_name[] = { |
45 |
"traditional", "multi", "mystery", "virtual", "webcam", "event", |
"traditional", "multi", "mystery", "virtual", "webcam", "event", |
46 |
"letterbox", "earthcache", "wherigo", "megaevent", "cito" |
"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 */ |
/* ICON_CACHE_SIZE */ |
55 |
const char *cache_size_icon_name[] = { |
const char *cache_size_icon_name[] = { |
56 |
"regular", "small", "micro", "other", "not_chosen", "large", |
"regular", "small", "micro", "other", "not_chosen", "large", |
57 |
"virtual" |
"virtual", NULL |
58 |
}; |
}; |
59 |
|
|
60 |
/* ICON_STARS */ |
/* ICON_STARS */ |
61 |
const char *stars_icon_name[] = { |
const char *stars_icon_name[] = { |
62 |
"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 |
63 |
}; |
}; |
64 |
|
|
65 |
/* ICON_LOG */ |
/* ICON_LOG */ |
69 |
"needsmaint", "coord_update", |
"needsmaint", "coord_update", |
70 |
"traffic_cone", |
"traffic_cone", |
71 |
"traffic_cone", /* LOG_TYPE_NEEDS_ARCHIVED */ |
"traffic_cone", /* LOG_TYPE_NEEDS_ARCHIVED */ |
72 |
"traffic_cone", |
"traffic_cone", |
73 |
|
NULL |
74 |
}; |
}; |
75 |
|
|
76 |
/* ICON_HEADING */ |
/* ICON_HEADING */ |
77 |
const char *heading_icon_name[] = { |
const char *heading_icon_name[] = { |
78 |
"n", "ne", "e", "se", "s", "sw", "w", "nw", "none" |
"n", "ne", "e", "se", "s", "sw", "w", "nw", "none", NULL |
79 |
}; |
}; |
80 |
|
|
81 |
/* ICON_WPT */ |
/* ICON_WPT */ |
82 |
const char *wpt_sym_icon_name[] = { |
const char *wpt_sym_icon_name[] = { |
83 |
"multistage", "parking", "final", "question", |
"multistage", "parking", "final", "question", |
84 |
"trailhead", "refpoint", |
"trailhead", "refpoint", NULL |
85 |
}; |
}; |
86 |
|
|
87 |
/* ICON_TB */ |
/* ICON_TB */ |
88 |
const char *tb_icon_name[] = { |
const char *tb_icon_name[] = { |
89 |
"tb_coin" |
"tb", "coin", NULL |
90 |
}; |
}; |
91 |
|
|
92 |
/* ICON_MISC */ |
/* ICON_MISC */ |
93 |
const char *misc_icon_name[] = { |
const char *misc_icon_name[] = { |
94 |
"maemo-mapper-out", "override", "locked", "unlocked", "found", |
"maemo-mapper-out", "locked", "unlocked", |
95 |
"maemo-mapper-in", "note", "delete" |
"maemo-mapper-in", "delete", "paypal", |
96 |
|
NULL |
97 |
|
}; |
98 |
|
|
99 |
|
/* ICON_POS */ |
100 |
|
const char *pos_icon_name[] = { |
101 |
|
"wpt_multistage", "wpt_parking", "wpt_final", "wpt_question", |
102 |
|
"wpt_trailhead", "wpt_refpoint", |
103 |
|
|
104 |
|
"pos_btn", "pos_gps", |
105 |
|
NULL |
106 |
}; |
}; |
107 |
|
|
108 |
/* ICON_FILE */ |
/* ICON_FILE */ |
109 |
const char *file_icon_name[] = { |
const char *file_icon_name[] = { |
110 |
"gc", "folder", "zip" |
"gc", "folder", "zip", NULL |
111 |
}; |
}; |
112 |
|
|
113 |
static void icons_load(int type, char *format, const char *names[]) { |
static void icons_load(int type, char *format, const char *names[]) { |
121 |
icons[type].data = malloc(sizeof(GdkPixbuf *) * icons[type].count); |
icons[type].data = malloc(sizeof(GdkPixbuf *) * icons[type].count); |
122 |
|
|
123 |
for(i=0;i<icons[type].count;i++) { |
for(i=0;i<icons[type].count;i++) { |
124 |
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); |
|
125 |
|
|
126 |
|
GError *error = NULL; |
127 |
|
char filename[128]; |
128 |
|
strcpy(filename, ICONPATH); |
129 |
|
snprintf(filename+strlen(filename), |
130 |
|
sizeof(filename)-strlen(filename), format, names[i], "png"); |
131 |
|
icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error); |
132 |
|
|
133 |
|
if(error) { |
134 |
|
error = NULL; |
135 |
|
/* try again in local dir */ |
136 |
|
strcpy(filename, "./data/icons/"); |
137 |
|
snprintf(filename+strlen(filename), |
138 |
|
sizeof(filename)-strlen(filename), format, names[i], "png"); |
139 |
|
icons[type].data[i] = gdk_pixbuf_new_from_file(filename, &error); |
140 |
|
|
141 |
if(error) { |
if(error) { |
142 |
/* try gif */ |
icons[type].data[i] = NULL; |
143 |
|
g_warning("Could not load cache type icon %s: %s\n", |
144 |
|
names[i], error->message); |
145 |
|
g_error_free(error); |
146 |
error = NULL; |
error = NULL; |
147 |
strcpy(filename, ICONPATH); |
} |
148 |
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; |
|
149 |
} |
} |
150 |
|
|
151 |
|
g_assert(!names[i]); |
152 |
} |
} |
153 |
|
|
154 |
void icons_init(void) { |
void icons_init(void) { |
155 |
|
|
156 |
/* load cache type icons */ |
/* load cache type icons */ |
157 |
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); |
158 |
|
|
159 |
/* load cache container/size icons */ |
/* load semitransparent cache type icons */ |
160 |
icons_load(ICON_CACHE_SIZE, "cache_size_%s.%s", cache_size_icon_name); |
icons_load(ICON_CACHE_TYPE_SEMI, "32x32/cache_type_%s_semi.%s", cache_type_icon_name); |
161 |
|
|
162 |
/* load cache difficulty/terrain icons */ |
/* load 150% sized cache type icons */ |
163 |
icons_load(ICON_STARS, "stars%s.%s", stars_icon_name); |
icons_load(ICON_CACHE_TYPE_1_5X, "48x48/cache_type_%s.%s", cache_type_icon_name); |
164 |
|
|
165 |
/* load cache difficulty/terrain icons */ |
/* load double sized cache type icons */ |
166 |
icons_load(ICON_LOG, "log_icon_%s.%s", log_icon_name); |
icons_load(ICON_CACHE_TYPE_2X, "64x64/cache_type_%s.%s", cache_type_icon_name); |
167 |
|
|
168 |
/* load icons to visualize heading */ |
/* load cache container/size icons */ |
169 |
icons_load(ICON_HEADING, "heading_%s.%s", heading_icon_name); |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
170 |
|
icons_load(ICON_CACHE_SIZE, "45x12/cache_size_%s.%s", cache_size_icon_name); |
171 |
|
#else |
172 |
|
icons_load(ICON_CACHE_SIZE, "90x24/cache_size_%s.%s", cache_size_icon_name); |
173 |
|
#endif |
174 |
|
|
175 |
|
/* load cache difficulty/terrain/quality icons */ |
176 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
177 |
|
icons_load(ICON_STARS, "12x12/stars%s.%s", stars_icon_name); |
178 |
|
#else |
179 |
|
icons_load(ICON_STARS, "16x16/stars%s.%s", stars_icon_name); |
180 |
|
#endif |
181 |
|
|
182 |
|
/* load cache log icons */ |
183 |
|
icons_load(ICON_LOG, "32x32/log_icon_%s.%s", log_icon_name); |
184 |
|
|
185 |
/* load icons to visualize heading */ |
/* load icons to visualize heading */ |
186 |
icons_load(ICON_WPT, "wpt_%s.%s", wpt_sym_icon_name); |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
187 |
|
icons_load(ICON_HEADING, "32x32/heading_%s.%s", heading_icon_name); |
188 |
|
#else |
189 |
|
icons_load(ICON_HEADING, "48x48/heading_%s.%s", heading_icon_name); |
190 |
|
#endif |
191 |
|
|
192 |
/* load travelbug icon */ |
/* load waypoint icons */ |
193 |
icons_load(ICON_TB, "%s.%s", tb_icon_name); |
icons_load(ICON_WPT, "32x32/wpt_%s.%s", wpt_sym_icon_name); |
194 |
|
|
195 |
|
/* load travelbug/coin icons */ |
196 |
|
icons_load(ICON_TB, "32x32/%s.%s", tb_icon_name); |
197 |
|
|
198 |
/* load misc icons */ |
/* load misc icons */ |
199 |
icons_load(ICON_MISC, "%s.%s", misc_icon_name); |
icons_load(ICON_MISC, "%s.%s", misc_icon_name); |
200 |
|
|
201 |
|
/* load pos icons */ |
202 |
|
icons_load(ICON_POS, "16x16/%s.%s", pos_icon_name); |
203 |
|
|
204 |
/* load file icons */ |
/* load file icons */ |
205 |
icons_load(ICON_FILE, "file_%s.%s", file_icon_name); |
icons_load(ICON_FILE, "file_%s.%s", file_icon_name); |
206 |
} |
} |
237 |
} |
} |
238 |
|
|
239 |
GdkPixbuf *icon_bearing(pos_t from, pos_t to) { |
GdkPixbuf *icon_bearing(pos_t from, pos_t to) { |
240 |
if(!from.lat && !from.lon) |
if(isnan(from.lat) || isnan(from.lon) || |
241 |
|
isnan(to.lat) || isnan(to.lon)) |
242 |
return icon_get(ICON_HEADING, 8); |
return icon_get(ICON_HEADING, 8); |
243 |
|
|
244 |
int idx = (gpx_pos_get_bearing(from, to)+22.5)/45.0; |
int idx = (gpx_pos_get_bearing(from, to)+22.5)/45.0; |