50 |
//a balloon with additional info |
//a balloon with additional info |
51 |
struct { |
struct { |
52 |
cairo_surface_t *surface; |
cairo_surface_t *surface; |
53 |
|
int orientation, offset_x, offset_y; |
54 |
|
|
55 |
float lat, lon; |
float lat, lon; |
|
gboolean valid; |
|
56 |
OsmGpsMapRect_t rect; |
OsmGpsMapRect_t rect; |
57 |
|
|
58 |
/* function called to have the user app draw the contents */ |
/* function called to have the user app draw the contents */ |
119 |
#define BALLOON_SHADOW (BALLOON_CORNER_RADIUS/2) |
#define BALLOON_SHADOW (BALLOON_CORNER_RADIUS/2) |
120 |
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
121 |
|
|
122 |
|
#define BALLOON_W (BALLOON_WIDTH + BALLOON_SHADOW) |
123 |
|
#define BALLOON_H (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW) |
124 |
|
|
125 |
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
126 |
|
|
127 |
|
|
161 |
cairo_close_path (cr); |
cairo_close_path (cr); |
162 |
} |
} |
163 |
|
|
|
/* xyz */ |
|
|
|
|
164 |
static void |
static void |
165 |
osd_render_balloon(osm_gps_map_osd_t *osd) { |
osd_render_balloon(osm_gps_map_osd_t *osd) { |
166 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
170 |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
171 |
|
|
172 |
/* ------- convert given coordinate into screen position --------- */ |
/* ------- convert given coordinate into screen position --------- */ |
173 |
gint x0, y0; |
gint xs, ys; |
174 |
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
175 |
priv->balloon.lat, priv->balloon.lon, |
priv->balloon.lat, priv->balloon.lon, |
176 |
&x0, &y0); |
&xs, &ys); |
177 |
|
|
178 |
|
gint x0 = 1, y0 = 1; |
179 |
|
|
180 |
/* check position of this relative to screen center to determine */ |
/* check position of this relative to screen center to determine */ |
181 |
/* pointer direction ... */ |
/* pointer direction ... */ |
182 |
int pointer_x = x0, pointer_x0, pointer_x1; |
int pointer_x, pointer_x0, pointer_x1; |
183 |
int pointer_y = y0; |
int pointer_y; |
184 |
|
|
185 |
/* ... and calculate position */ |
/* ... and calculate position */ |
186 |
if(x0 > osd->widget->allocation.width/2) { |
int orientation = 0; |
187 |
x0 += POINTER_OFFSET; |
if(xs > osd->widget->allocation.width/2) { |
188 |
|
priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET; |
189 |
|
pointer_x = x0 - priv->balloon.offset_x; |
190 |
pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
191 |
pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH; |
pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH; |
192 |
|
orientation |= 1; |
193 |
} else { |
} else { |
194 |
x0 -= POINTER_OFFSET; |
priv->balloon.offset_x = -POINTER_OFFSET; |
195 |
|
pointer_x = x0 - priv->balloon.offset_x; |
196 |
pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
197 |
pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH; |
pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH; |
198 |
} |
} |
199 |
|
|
200 |
gboolean bottom = FALSE; |
gboolean bottom = FALSE; |
201 |
if(y0 > osd->widget->allocation.height/2) { |
if(ys > osd->widget->allocation.height/2) { |
202 |
|
priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT; |
203 |
|
pointer_y = y0 - priv->balloon.offset_y; |
204 |
bottom = TRUE; |
bottom = TRUE; |
205 |
y0 -= BALLOON_HEIGHT + POINTER_HEIGHT; |
orientation |= 2; |
206 |
} else |
} else { |
207 |
|
priv->balloon.offset_y = 0; |
208 |
|
pointer_y = y0 - priv->balloon.offset_y; |
209 |
y0 += POINTER_HEIGHT; |
y0 += POINTER_HEIGHT; |
210 |
|
} |
211 |
|
|
212 |
|
/* if required orientation equals current one, then don't render */ |
213 |
|
/* anything */ |
214 |
|
if(orientation == priv->balloon.orientation) |
215 |
|
return; |
216 |
|
|
217 |
|
priv->balloon.orientation = orientation; |
218 |
|
|
219 |
/* calculate bottom/right of box */ |
/* calculate bottom/right of box */ |
220 |
int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT; |
int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT; |
221 |
|
|
226 |
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
227 |
|
|
228 |
cairo_t *cr = cairo_create(priv->balloon.surface); |
cairo_t *cr = cairo_create(priv->balloon.surface); |
229 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
230 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
231 |
|
cairo_paint(cr); |
232 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
233 |
|
|
234 |
/* --------- draw shadow --------------- */ |
/* --------- draw shadow --------------- */ |
235 |
osm_gps_map_draw_balloon_shape (cr, |
osm_gps_map_draw_balloon_shape (cr, |
254 |
cairo_set_line_width (cr, 1); |
cairo_set_line_width (cr, 1); |
255 |
cairo_stroke (cr); |
cairo_stroke (cr); |
256 |
|
|
|
|
|
|
/* ---------- draw close button --------- */ |
|
|
|
|
|
int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS; |
|
|
int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS; |
|
|
int crad = CLOSE_BUTTON_RADIUS; |
|
|
|
|
|
cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI); |
|
|
cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0); |
|
|
cairo_fill_preserve (cr); |
|
|
cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0); |
|
|
cairo_set_line_width (cr, 2); |
|
|
cairo_stroke(cr); |
|
|
|
|
|
cairo_set_source_rgba (cr, 1, 1, 1, 1.0); |
|
|
cairo_set_line_width (cr, BALLOON_CORNER_RADIUS/3.3); |
|
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
|
|
cairo_move_to (cr, cx - crad/2, cy - crad/2); |
|
|
cairo_line_to (cr, cx + crad/2, cy + crad/2); |
|
|
cairo_stroke (cr); |
|
|
cairo_move_to (cr, cx + crad/2, cy - crad/2); |
|
|
cairo_line_to (cr, cx - crad/2, cy + crad/2); |
|
|
cairo_stroke (cr); |
|
|
|
|
257 |
if (priv->balloon.cb) { |
if (priv->balloon.cb) { |
258 |
/* clip in case application tries to draw in */ |
/* clip in case application tries to draw in */ |
259 |
/* exceed of the balloon */ |
/* exceed of the balloon */ |
265 |
|
|
266 |
priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data); |
priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data); |
267 |
} |
} |
|
|
|
|
cairo_destroy(cr); |
|
|
} |
|
|
|
|
|
#if 0 |
|
|
/* the user clicked into the balloons main area. handle this */ |
|
|
static void |
|
|
osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv = map->priv; |
|
|
|
|
|
if (!priv->balloon.valid) |
|
|
return; |
|
268 |
|
|
269 |
/* check if the close button was clicked */ |
cairo_destroy(cr); |
|
if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) && |
|
|
(x < priv->balloon.rect.w) && |
|
|
(y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) { |
|
|
|
|
|
priv->balloon.valid = FALSE; |
|
|
osm_gps_map_map_redraw_idle(map); |
|
|
} |
|
270 |
} |
} |
271 |
|
|
272 |
/* return true if balloon is being displayed and if */ |
/* return true if balloon is being displayed and if */ |
273 |
/* the given coordinate is within this balloon */ |
/* the given coordinate is within this balloon */ |
274 |
static gboolean |
static gboolean |
275 |
osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y) |
osd_balloon_check(osm_gps_map_osd_t *osd, gint x, gint y) |
276 |
{ |
{ |
277 |
return (priv->balloon.valid && |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
|
(x > priv->balloon.rect.x) && |
|
|
(x < priv->balloon.rect.x + priv->balloon.rect.w) && |
|
|
(y > priv->balloon.rect.y) && |
|
|
(y < priv->balloon.rect.y + priv->balloon.rect.h)); |
|
|
} |
|
278 |
|
|
279 |
#if 0 |
if(!priv->balloon.surface) |
|
/* don't drag if the user clicked within the balloon */ |
|
|
if (osm_gps_map_in_balloon(priv, |
|
|
event->x + EXTRA_BORDER, |
|
|
event->y + EXTRA_BORDER)) |
|
|
{ |
|
|
priv->drag_counter = -1; |
|
280 |
return FALSE; |
return FALSE; |
|
} |
|
|
|
|
|
#ifdef ENABLE_BALLOON |
|
|
/* released inside the balloon? */ |
|
|
if (osm_gps_map_in_balloon(priv, |
|
|
event->x + EXTRA_BORDER, |
|
|
event->y + EXTRA_BORDER)) |
|
|
{ |
|
|
osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget), |
|
|
event->x - priv->balloon.rect.x + EXTRA_BORDER, |
|
|
event->y - priv->balloon.rect.y + EXTRA_BORDER); |
|
|
} |
|
|
#endif |
|
281 |
|
|
282 |
#endif |
gint xs, ys; |
283 |
|
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
284 |
|
priv->balloon.lat, priv->balloon.lon, |
285 |
|
&xs, &ys); |
286 |
|
|
287 |
void |
xs += priv->balloon.rect.x + priv->balloon.offset_x; |
288 |
osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
ys += priv->balloon.rect.y + priv->balloon.offset_y; |
|
OsmGpsMapBalloonCallback cb, gpointer data) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv; |
|
289 |
|
|
290 |
/* remove and previously installed balloon */ |
return (priv->balloon.surface && |
291 |
osm_gps_map_clear_balloon (map); |
(x > xs) && (x < xs + priv->balloon.rect.w) && |
292 |
|
(y > ys) && (y < ys + priv->balloon.rect.h)); |
293 |
|
} |
294 |
|
|
295 |
|
void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) { |
296 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
|
priv = map->priv; |
|
297 |
|
|
298 |
priv->balloon.lat = latitude; |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
299 |
priv->balloon.lon = longitude; |
g_return_if_fail (osd); |
|
priv->balloon.valid = TRUE; |
|
300 |
|
|
301 |
priv->balloon.cb = cb; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
302 |
priv->balloon.data = data; |
g_return_if_fail (priv); |
303 |
|
|
304 |
|
printf("request to clear balloon\n"); |
305 |
|
|
306 |
// this redraws the map |
if(priv->balloon.surface) { |
307 |
osm_gps_map_map_redraw_idle(map); |
cairo_surface_destroy(priv->balloon.surface); |
308 |
|
priv->balloon.surface = NULL; |
309 |
|
priv->balloon.lat = OSM_GPS_MAP_INVALID; |
310 |
|
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
311 |
|
} |
312 |
|
osm_gps_map_redraw(map); |
313 |
} |
} |
314 |
|
|
315 |
void |
void |
316 |
osm_gps_map_clear_balloon (OsmGpsMap *map) |
osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
317 |
{ |
OsmGpsMapBalloonCallback cb, gpointer data) { |
|
OsmGpsMapPrivate *priv; |
|
|
|
|
318 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
|
priv = map->priv; |
|
319 |
|
|
320 |
priv->balloon.valid = FALSE; |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
321 |
|
g_return_if_fail (osd); |
|
osm_gps_map_map_redraw_idle(map); |
|
|
} |
|
|
#endif |
|
322 |
|
|
323 |
void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) { |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
324 |
printf("request to clear balloon\n"); |
g_return_if_fail (priv); |
325 |
} |
|
326 |
|
osm_gps_map_osd_clear_balloon (map); |
327 |
|
|
|
void |
|
|
osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
|
|
OsmGpsMapBalloonCallback cb, gpointer data) |
|
|
{ |
|
328 |
printf("request to draw balloon at %f %f\n", latitude, longitude); |
printf("request to draw balloon at %f %f\n", latitude, longitude); |
329 |
|
|
330 |
|
/* allocate balloon surface */ |
331 |
|
priv->balloon.surface = |
332 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
333 |
|
BALLOON_W+2, BALLOON_H+2); |
334 |
|
|
335 |
|
priv->balloon.lat = latitude; |
336 |
|
priv->balloon.lon = longitude; |
337 |
|
priv->balloon.cb = cb; |
338 |
|
priv->balloon.data = data; |
339 |
|
|
340 |
|
priv->balloon.orientation = -1; |
341 |
|
|
342 |
|
osd_render_balloon(osd); |
343 |
|
|
344 |
|
osm_gps_map_redraw(map); |
345 |
} |
} |
346 |
|
|
347 |
#endif // OSD_BALLOON |
#endif // OSD_BALLOON |
926 |
osd_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
osd_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
927 |
osd_button_t but = OSD_NONE; |
osd_button_t but = OSD_NONE; |
928 |
|
|
929 |
|
#ifdef OSD_BALLOON |
930 |
|
/* check if user clicked into balloon */ |
931 |
|
if(osd_balloon_check(osd, x, y)) |
932 |
|
return OSD_BG; |
933 |
|
#endif |
934 |
|
|
935 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
936 |
/* the source selection area is handles internally */ |
/* the source selection area is handles internally */ |
937 |
but = osd_source_check(osd, x, y); |
but = osd_source_check(osd, x, y); |
1555 |
// now draw this onto the original context |
// now draw this onto the original context |
1556 |
cairo_t *cr = gdk_cairo_create(drawable); |
cairo_t *cr = gdk_cairo_create(drawable); |
1557 |
|
|
1558 |
int x, y; |
gint x, y; |
1559 |
|
|
1560 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1561 |
x = OSD_X; |
x = OSD_X; |
1585 |
cairo_paint(cr); |
cairo_paint(cr); |
1586 |
#endif |
#endif |
1587 |
|
|
1588 |
|
#ifdef OSD_BALLOON |
1589 |
|
if(priv->balloon.surface) { |
1590 |
|
|
1591 |
|
/* convert given lat lon into screen coordinates */ |
1592 |
|
gint x, y; |
1593 |
|
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
1594 |
|
priv->balloon.lat, priv->balloon.lon, |
1595 |
|
&x, &y); |
1596 |
|
|
1597 |
|
/* check if balloon needs to be rerendered */ |
1598 |
|
osd_render_balloon(osd); |
1599 |
|
|
1600 |
|
cairo_set_source_surface(cr, priv->balloon.surface, |
1601 |
|
x + priv->balloon.offset_x, |
1602 |
|
y + priv->balloon.offset_y); |
1603 |
|
cairo_paint(cr); |
1604 |
|
} |
1605 |
|
#endif |
1606 |
|
|
1607 |
x = OSD_X; |
x = OSD_X; |
1608 |
if(x < 0) |
if(x < 0) |
1609 |
x += osd->widget->allocation.width - OSD_W; |
x += osd->widget->allocation.width - OSD_W; |