2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 //##############################################################################################################
25 //# Authors: Martin Schaller (04/2008)
27 //##############################################################################################################
36 #include "draw_info.h"
39 #include "projection.h"
43 #include "transform.h"
55 //##############################################################################################################
58 //# Authors: Martin Schaller (04/2008)
59 //##############################################################################################################
62 struct graphics_priv *priv;
63 struct graphics_methods meth;
66 struct graphics_font **font;
67 struct graphics_gc *gc[3];
69 struct callback_list *cbl;
71 int gamma,brightness,contrast;
76 struct display_context
80 struct graphics_gc *gc;
81 struct graphics_image *img;
84 struct transformation *trans;
94 struct layout *layout;
95 struct display_context dc;
98 struct mapset_handle *msh;
101 struct map_selection *sel;
103 struct callback *idle_cb;
104 struct event_idle *idle_ev;
108 static void draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos, int dir);
109 static void graphics_process_selection(struct graphics *gra, struct displaylist *dl);
112 graphics_set_attr_do(struct graphics *gra, struct attr *attr)
114 switch (attr->type) {
116 gra->gamma=attr->u.num;
118 case attr_brightness:
119 gra->brightness=attr->u.num;
122 gra->contrast=attr->u.num;
127 gra->colormgmt=(gra->gamma != 655536 || gra->brightness != 65536 || gra->contrast != 65536);
132 graphics_set_attr(struct graphics *gra, struct attr *attr)
136 if (gra->meth.set_attr)
137 ret=gra->meth.set_attr(gra->priv, attr);
139 ret=graphics_set_attr_do(gra, attr);
144 graphics_set_rect(struct graphics *gra, struct point_rect *pr)
150 * Creates a new graphics object
154 * @author Martin Schaller (04/2008)
156 struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
158 struct graphics *this_;
159 struct attr *type_attr;
160 struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl);
162 if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
166 graphicstype_new=plugin_get_graphics_type(type_attr->u.str);
167 if (! graphicstype_new)
169 this_=g_new0(struct graphics, 1);
170 this_->cbl=callback_list_new();
171 this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, attrs, this_->cbl);
172 this_->attrs=attr_list_dup(attrs);
174 this_->contrast=65536;
177 graphics_set_attr_do(this_,*attrs);
187 * @author Martin Schaller (04/2008)
189 int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
191 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
198 * @author Martin Schaller (04/2008)
200 struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h, int alpha, int wraparound)
202 struct graphics *this_;
203 if (!parent->meth.overlay_new)
205 this_=g_new0(struct graphics, 1);
206 this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h, alpha, wraparound);
215 * @brief Alters the size, position, alpha and wraparound for an overlay
217 * @param this_ The overlay's graphics struct
218 * @param p The new position of the overlay
219 * @param w The new width of the overlay
220 * @param h The new height of the overlay
221 * @param alpha The new alpha of the overlay
222 * @param wraparound The new wraparound of the overlay
225 graphics_overlay_resize(struct graphics *this_, struct point *p, int w, int h, int alpha, int wraparound)
227 if (! this_->meth.overlay_resize) {
231 this_->meth.overlay_resize(this_->priv, p, w, h, alpha, wraparound);
239 * @author Martin Schaller (04/2008)
241 void graphics_init(struct graphics *this_)
245 this_->gc[0]=graphics_gc_new(this_);
246 graphics_gc_set_background(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7, 0xffff});
247 graphics_gc_set_foreground(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7, 0xffff });
248 this_->gc[1]=graphics_gc_new(this_);
249 graphics_gc_set_background(this_->gc[1], &(struct color) { 0x0000, 0x0000, 0x0000, 0xffff });
250 graphics_gc_set_foreground(this_->gc[1], &(struct color) { 0xffff, 0xffff, 0xffff, 0xffff });
251 this_->gc[2]=graphics_gc_new(this_);
252 graphics_gc_set_background(this_->gc[2], &(struct color) { 0xffff, 0xffff, 0xffff, 0xffff });
253 graphics_gc_set_foreground(this_->gc[2], &(struct color) { 0x0000, 0x0000, 0x0000, 0xffff });
254 graphics_background_gc(this_, this_->gc[0]);
261 * @author Martin Schaller (04/2008)
263 void * graphics_get_data(struct graphics *this_, char *type)
265 return (this_->meth.get_data(this_->priv, type));
268 void graphics_add_callback(struct graphics *this_, struct callback *cb)
270 callback_list_add(this_->cbl, cb);
273 void graphics_remove_callback(struct graphics *this_, struct callback *cb)
275 callback_list_remove(this_->cbl, cb);
282 * @author Martin Schaller (04/2008)
284 struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags)
286 struct graphics_font *this_;
288 this_=g_new0(struct graphics_font,1);
289 this_->priv=gra->meth.font_new(gra->priv, &this_->meth, gra->default_font, size, flags);
294 * Free all loaded fonts.
295 * Used when switching layouts.
296 * @param gra The graphics instance
298 * @author Sarah Nordstrom (05/2008)
300 void graphics_font_destroy_all(struct graphics *gra)
303 for(i = 0 ; i < gra->font_len; i++) {
304 if(!gra->font[i]) continue;
305 gra->font[i]->meth.font_destroy(gra->font[i]->priv);
314 * @author Martin Schaller (04/2008)
316 struct graphics_gc * graphics_gc_new(struct graphics *gra)
318 struct graphics_gc *this_;
320 this_=g_new0(struct graphics_gc,1);
321 this_->priv=gra->meth.gc_new(gra->priv, &this_->meth);
330 * @author Martin Schaller (04/2008)
332 void graphics_gc_destroy(struct graphics_gc *gc)
334 gc->meth.gc_destroy(gc->priv);
339 graphics_convert_color(struct graphics *gra, struct color *in, struct color *out)
342 if (gra->brightness) {
343 out->r+=gra->brightness;
344 out->g+=gra->brightness;
345 out->b+=gra->brightness;
347 if (gra->contrast != 65536) {
348 out->r=out->r*gra->contrast/65536;
349 out->g=out->g*gra->contrast/65536;
350 out->b=out->b*gra->contrast/65536;
364 if (gra->gamma != 65536) {
365 out->r=pow(out->r/65535.0,gra->gamma/65536.0)*65535.0;
366 out->g=pow(out->g/65535.0,gra->gamma/65536.0)*65535.0;
367 out->b=pow(out->b/65535.0,gra->gamma/65536.0)*65535.0;
375 * @author Martin Schaller (04/2008)
377 void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c)
380 if (gc->gra->colormgmt) {
381 graphics_convert_color(gc->gra, c, &cn);
384 gc->meth.gc_set_foreground(gc->priv, c);
391 * @author Martin Schaller (04/2008)
393 void graphics_gc_set_background(struct graphics_gc *gc, struct color *c)
396 if (gc->gra->colormgmt) {
397 graphics_convert_color(gc->gra, c, &cn);
400 gc->meth.gc_set_background(gc->priv, c);
408 * @author Martin Schaller (04/2008)
410 void graphics_gc_set_stipple(struct graphics_gc *gc, struct graphics_image *img)
412 gc->meth.gc_set_stipple(gc->priv, img ? img->priv : NULL);
420 * @author Martin Schaller (04/2008)
422 void graphics_gc_set_linewidth(struct graphics_gc *gc, int width)
424 gc->meth.gc_set_linewidth(gc->priv, width);
431 * @author Martin Schaller (04/2008)
433 void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsigned char dash_list[], int n)
435 if (gc->meth.gc_set_dashes)
436 gc->meth.gc_set_dashes(gc->priv, width, offset, dash_list, n);
440 * Create a new image from file path scaled to w and h pixels
441 * @param gra the graphics instance
442 * @param path path of the image to load
443 * @param w width to rescale to
444 * @param h height to rescale to
446 * @author Martin Schaller (04/2008)
448 struct graphics_image * graphics_image_new_scaled(struct graphics *gra, char *path, int w, int h)
450 struct graphics_image *this_;
452 this_=g_new0(struct graphics_image,1);
455 this_->priv=gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, 0);
464 * Create a new image from file path scaled to w and h pixels and possibly rotated
465 * @param gra the graphics instance
466 * @param path path of the image to load
467 * @param w width to rescale to
468 * @param h height to rescale to
469 * @param rotate angle to rotate the image. Warning, graphics might only support 90 degree steps here
471 * @author Martin Schaller (04/2008)
473 struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra, char *path, int w, int h, int rotate)
475 struct graphics_image *this_;
477 this_=g_new0(struct graphics_image,1);
480 this_->priv=gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, rotate);
489 * Create a new image from file path
490 * @param gra the graphics instance
491 * @param path path of the image to load
493 * @author Martin Schaller (04/2008)
495 struct graphics_image * graphics_image_new(struct graphics *gra, char *path)
497 return graphics_image_new_scaled(gra, path, -1, -1);
504 * @author Martin Schaller (04/2008)
506 void graphics_image_free(struct graphics *gra, struct graphics_image *img)
508 if (gra->meth.image_free)
509 gra->meth.image_free(gra->priv, img->priv);
517 * @author Martin Schaller (04/2008)
519 void graphics_draw_restore(struct graphics *this_, struct point *p, int w, int h)
521 this_->meth.draw_restore(this_->priv, p, w, h);
528 * @author Martin Schaller (04/2008)
530 void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode)
532 this_->meth.draw_mode(this_->priv, mode);
539 * @author Martin Schaller (04/2008)
541 void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count)
543 this_->meth.draw_lines(this_->priv, gc->priv, p, count);
550 * @author Martin Schaller (04/2008)
552 void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r)
554 this_->meth.draw_circle(this_->priv, gc->priv, p, r);
561 * @author Martin Schaller (04/2008)
563 void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h)
565 this_->meth.draw_rectangle(this_->priv, gc->priv, p, w, h);
568 void graphics_draw_rectangle_rounded(struct graphics *this_, struct graphics_gc *gc, struct point *plu, int w, int h, int r, int fill)
570 struct point p[r*4+32];
571 struct point pi0={plu->x+r,plu->y+r};
572 struct point pi1={plu->x+w-r,plu->y+r};
573 struct point pi2={plu->x+w-r,plu->y+h-r};
574 struct point pi3={plu->x+r,plu->y+h-r};
577 draw_circle(&pi2, r*2, 0, -1, 258, p, &i, 1);
578 draw_circle(&pi1, r*2, 0, 255, 258, p, &i, 1);
579 draw_circle(&pi0, r*2, 0, 511, 258, p, &i, 1);
580 draw_circle(&pi3, r*2, 0, 767, 258, p, &i, 1);
584 this_->meth.draw_polygon(this_->priv, gc->priv, p, i);
586 this_->meth.draw_lines(this_->priv, gc->priv, p, i);
594 * @author Martin Schaller (04/2008)
596 void graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct graphics_gc *gc2, struct graphics_font *font, char *text, struct point *p, int dx, int dy)
598 this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, p, dx, dy);
605 * @author Martin Schaller (04/2008)
607 void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font, char *text, int dx, int dy, struct point *ret, int estimate)
609 this_->meth.get_text_bbox(this_->priv, font->priv, text, dx, dy, ret, estimate);
616 * @author Martin Schaller (04/2008)
618 void graphics_overlay_disable(struct graphics *this_, int disable)
620 if (this_->meth.overlay_disable)
621 this_->meth.overlay_disable(this_->priv, disable);
628 * @author Martin Schaller (04/2008)
630 void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img)
632 this_->meth.draw_image(this_->priv, gc->priv, p, img->priv);
636 //##############################################################################################################
639 //# Authors: Martin Schaller (04/2008)
640 //##############################################################################################################
642 graphics_draw_drag(struct graphics *this_, struct point *p)
644 if (!this_->meth.draw_drag)
646 this_->meth.draw_drag(this_->priv, p);
651 graphics_background_gc(struct graphics *this_, struct graphics_gc *gc)
653 this_->meth.background_gc(this_->priv, gc ? gc->priv : NULL);
662 //##############################################################################################################
665 //# Authors: Martin Schaller (04/2008)
666 //##############################################################################################################
667 static void popup_view_html(struct popup_item *item, char *file)
670 sprintf(command,"firefox %s", file);
674 struct transformatin *tg;
677 //##############################################################################################################
680 //# Authors: Martin Schaller (04/2008)
681 //##############################################################################################################
682 static void graphics_popup(struct display_list *list, struct popup_item **popup)
688 struct popup_item *curr_item,*last=NULL;
690 mr=map_rect_new(item->map, NULL, NULL, 0);
691 printf("id hi=0x%x lo=0x%x\n", item->id_hi, item->id_lo);
692 item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
694 if (item_attr_get(item, attr_name, &attr)) {
695 curr_item=popup_item_new_text(popup,attr.u.str,1);
696 if (item_attr_get(item, attr_info_html, &attr)) {
697 popup_item_new_func(&last,"HTML Info",1, popup_view_html, g_strdup(attr.u.str));
699 if (item_attr_get(item, attr_price_html, &attr)) {
700 popup_item_new_func(&last,"HTML Preis",2, popup_view_html, g_strdup(attr.u.str));
702 curr_item->submenu=last;
705 map_rect_destroy(mr);
713 * @author Martin Schaller (04/2008)
727 * @author Martin Schaller (04/2008)
729 static int xdisplay_free_list(gpointer key, gpointer value, gpointer user_data)
731 GHashTable *hash=value;
733 g_hash_table_destroy(hash);
741 * @author Martin Schaller (04/2008)
743 static void xdisplay_free(GHashTable *display_list)
745 g_hash_table_foreach_remove(display_list, xdisplay_free_list, NULL);
749 displayitem_hash(gconstpointer key)
751 const struct displayitem *di=key;
752 return (di->item.id_hi^di->item.id_lo^(GPOINTER_TO_INT(di->item.map)));
756 displayitem_equal(gconstpointer a, gconstpointer b)
758 const struct displayitem *dia=a;
759 const struct displayitem *dib=b;
760 if (item_is_equal(dia->item, dib->item))
770 * @author Martin Schaller (04/2008)
772 static void display_add(struct displaylist *displaylist, struct item *item, int count, struct coord *c, char *label)
774 struct displayitem *di;
779 len=sizeof(*di)+count*sizeof(*c);
781 len+=strlen(label)+1;
785 di=(struct displayitem *)p;
787 p+=sizeof(*di)+count*sizeof(*c);
791 strcpy(di->label, label);
795 memcpy(di->c, c, count*sizeof(*c));
797 h=g_hash_table_lookup(displaylist->dl, GINT_TO_POINTER(item->type));
799 h=g_hash_table_new_full(displayitem_hash, displayitem_equal, g_free, NULL);
800 g_hash_table_insert(displaylist->dl, GINT_TO_POINTER(item->type), h);
802 g_hash_table_replace(h, di, di);
810 * @author Martin Schaller (04/2008)
812 static void label_line(struct graphics *gra, struct graphics_gc *fg, struct graphics_gc *bg, struct graphics_font *font, struct point *p, int count, char *label)
814 int i,x,y,tl,tlm,th,thm,tlsq,l;
820 if (gra->meth.get_text_bbox) {
821 gra->meth.get_text_bbox(gra->priv, font->priv, label, 0x10000, 0x0, pb, 1);
822 tl=(pb[2].x-pb[0].x);
823 th=(pb[0].y-pb[1].y);
831 for (i = 0 ; i < count-1 ; i++) {
854 dbg(0,"display_text: '%s', %d, %d, %d, %d %d\n", label, x, y, dx*0x10000/l, dy*0x10000/l, l);
856 if (x < gra->r.rl.x && x + tl > gra->r.lu.x && y + tl > gra->r.lu.y && y - tl < gra->r.rl.y)
857 gra->meth.draw_text(gra->priv, fg->priv, bg->priv, font->priv, label, &p_t, dx*0x10000/l, dy*0x10000/l);
862 static void display_draw_arrow(struct point *p, int dx, int dy, int l, struct graphics_gc *gc, struct graphics *gra)
865 pnt[0]=pnt[1]=pnt[2]=*p;
866 pnt[0].x+=-dx*l/65536+dy*l/65536;
867 pnt[0].y+=-dy*l/65536-dx*l/65536;
868 pnt[2].x+=-dx*l/65536-dy*l/65536;
869 pnt[2].y+=-dy*l/65536+dx*l/65536;
870 gra->meth.draw_lines(gra->priv, gc->priv, pnt, 3);
873 static void display_draw_arrows(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count)
877 for (i = 0 ; i < count-1 ; i++) {
878 dx=pnt[i+1].x-pnt[i].x;
879 dy=pnt[i+1].y-pnt[i].y;
887 display_draw_arrow(&p, dx, dy, 10, gc, gra);
891 display_draw_arrow(&p, dx, dy, 10, gc, gra);
897 intersection(struct point * a1, int adx, int ady, struct point * b1, int bdx, int bdy,
901 n = bdy * adx - bdx * ady;
902 a = bdx * (a1->y - b1->y) - bdy * (a1->x - b1->x);
903 b = adx * (a1->y - b1->y) - ady * (a1->x - b1->x);
917 res->x = a1->x + a * adx / n;
918 res->y = a1->y + a * ady / n;
992 draw_circle(struct point *pnt, int diameter, int scale, int start, int len, struct point *res, int *pos, int dir)
997 dbg(0,"diameter=%d start=%d len=%d pos=%d dir=%d\n", diameter, start, len, *pos, dir);
1005 else if (diameter > 64)
1007 else if (diameter > 24)
1009 else if (diameter > 8)
1020 while (i < count && c[i].fowler <= start)
1022 while (i < count && c[i].fowler < end) {
1023 res[*pos].x=pnt->x+((c[i].x*diameter+128)>>8);
1024 res[*pos].y=pnt->y+((c[i].y*diameter+128)>>8);
1032 while (start > 1024) {
1036 while (end < 1024) {
1038 while (i >= 0 && c[i].fowler >= start)
1040 while (i >= 0 && c[i].fowler > end) {
1041 res[*pos].x=pnt->x+((c[i].x*diameter+128)>>8);
1042 res[*pos].y=pnt->y+((c[i].y*diameter+128)>>8);
1054 fowler(int dy, int dx)
1056 int adx, ady; /* Absolute Values of Dx and Dy */
1057 int code; /* Angular Region Classification Code */
1059 adx = (dx < 0) ? -dx : dx; /* Compute the absolute values. */
1060 ady = (dy < 0) ? -dy : dy;
1062 code = (adx < ady) ? 1 : 0;
1070 return (dx == 0) ? 0 : 128*ady / adx; /* [ 0, 45] */
1072 return (256 - (128*adx / ady)); /* ( 45, 90] */
1074 return (256 + (128*adx / ady)); /* ( 90,135) */
1076 return (512 - (128*ady / adx)); /* [135,180] */
1078 return (512 + (128*ady / adx)); /* (180,225] */
1080 return (768 - (128*adx / ady)); /* (225,270) */
1082 return (768 + (128*adx / ady)); /* [270,315) */
1084 return (1024 - (128*ady / adx));/* [315,360) */
1089 int_sqrt(unsigned int n)
1091 unsigned int h, p= 0, q= 1, r= n;
1093 /* avoid q rollover */
1094 if(n >= (1<<(sizeof(n)*8-2))) {
1095 q = 1<<(sizeof(n)*8-2);
1120 calc_offsets(int wi, int l, int dx, int dy, struct offset *res)
1143 graphics_draw_polyline_as_polygon(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count, int *width, int step)
1146 struct point res[maxpoints], pos, poso, neg, nego;
1147 int i, dx=0, dy=0, l=0, dxo=0, dyo=0;
1149 int fow=0, fowo=0, delta;
1150 int wi, ppos = maxpoints/2, npos = maxpoints/2;
1152 int max_circle_points=20;
1158 if (i < count - 1) {
1159 int dxs,dys,lscales;
1161 dx = (pnt[i + 1].x - pnt[i].x);
1162 dy = (pnt[i + 1].y - pnt[i].y);
1164 l = int_sqrt(dx * dx * lscale * lscale + dy * dy * lscale * lscale);
1168 lscales=lscale*lscale;
1169 if (dxs + dys > lscales)
1170 l = int_sqrt(dxs+dys)*lscale;
1172 l = int_sqrt((dxs+dys)*lscales);
1174 fow=fowler(-dy, dx);
1178 if (wi*lscale > 10000)
1180 dbg_assert(wi*lscale < 10000);
1181 calc_offsets(wi*lscale, l, dx, dy, &o);
1182 pos.x = pnt[i].x + o.ny;
1183 pos.y = pnt[i].y + o.px;
1184 neg.x = pnt[i].x + o.py;
1185 neg.y = pnt[i].y + o.nx;
1188 else if (i == count-1)
1190 else if (npos < max_circle_points || ppos >= maxpoints-max_circle_points)
1197 poso.x = pnt[i].x + oo.ny;
1198 poso.y = pnt[i].y + oo.px;
1199 nego.x = pnt[i].x + oo.py;
1200 nego.y = pnt[i].y + oo.nx;
1205 if (intersection(&pos, dx, dy, &poso, dxo, dyo, &res[ppos]))
1209 draw_circle(&pnt[i], wi, prec, fowo-512, -delta, res, &npos, -1);
1213 draw_circle(&pnt[i], wi, prec, fowo, 1024-delta, res, &ppos, 1);
1215 if (intersection(&neg, dx, dy, &nego, dxo, dyo, &res[npos - 1]))
1224 draw_circle(&pnt[i], wi, prec, fow-512, -512, res, &npos, -1);
1227 dbg_assert(npos > 0);
1228 dbg_assert(ppos < maxpoints);
1229 gra->meth.draw_polygon(gra->priv, gc->priv, res+npos, ppos-npos);
1236 draw_circle(&pnt[i], wi, prec, fow+512, 512, res, &ppos, 1);
1245 calc_offsets(wi*lscale, l, dx, dy, &oo);
1260 clipcode(struct wpoint *p, struct point_rect *r)
1276 clip_line(struct wpoint *p1, struct wpoint *p2, struct point_rect *r)
1278 int code1,code2,ret=1;
1280 code1=clipcode(p1, r);
1283 code2=clipcode(p2, r);
1289 while (code1 || code2) {
1293 p1->y+=(r->lu.x-p1->x)*dy/dx;
1294 p1->w+=(r->lu.x-p1->x)*dw/dx;
1296 } else if (code1 & 2) {
1297 p1->y+=(r->rl.x-p1->x)*dy/dx;
1298 p1->w+=(r->rl.x-p1->x)*dw/dx;
1300 } else if (code1 & 4) {
1301 p1->x+=(r->lu.y-p1->y)*dx/dy;
1302 p1->w+=(r->lu.y-p1->y)*dw/dy;
1304 } else if (code1 & 8) {
1305 p1->x+=(r->rl.y-p1->y)*dx/dy;
1306 p1->w+=(r->rl.y-p1->y)*dw/dy;
1309 code1=clipcode(p1, r);
1313 p2->y+=(r->lu.x-p2->x)*dy/dx;
1314 p2->w+=(r->lu.x-p2->x)*dw/dx;
1316 } else if (code2 & 2) {
1317 p2->y+=(r->rl.x-p2->x)*dy/dx;
1318 p2->w+=(r->rl.x-p2->x)*dw/dx;
1320 } else if (code2 & 4) {
1321 p2->x+=(r->lu.y-p2->y)*dx/dy;
1322 p2->w+=(r->lu.y-p2->y)*dw/dy;
1324 } else if (code2 & 8) {
1325 p2->x+=(r->rl.y-p2->y)*dx/dy;
1326 p2->w+=(r->rl.y-p2->y)*dw/dy;
1329 code2=clipcode(p2, r);
1335 graphics_draw_polyline_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pa, int count, int *width, int step, int poly)
1337 struct point p[count+1];
1338 int w[count*step+1];
1339 struct wpoint p1,p2;
1342 struct point_rect r=gra->r;
1346 for (i = 1 ; i < count ; i++) {
1347 if (width[i*step] > wmax)
1357 for (i = 0 ; i < count ; i++) {
1361 p1.w=width[(i-1)*step];
1365 /* 0 = invisible, 1 = completely visible, 3 = start point clipped, 5 = end point clipped, 7 both points clipped */
1366 code=clip_line(&p1, &p2, &r);
1367 if (((code == 1 || code == 5) && i == 1) || (code & 2)) {
1379 if (i == count-1 || (code & 4)) {
1382 graphics_draw_polyline_as_polygon(gra, gc, p, out, w, step);
1384 gra->meth.draw_lines(gra->priv, gc->priv, p, out);
1393 is_inside(struct point *p, struct point_rect *r, int edge)
1397 return p->x >= r->lu.x;
1399 return p->x <= r->rl.x;
1401 return p->y >= r->lu.y;
1403 return p->y <= r->rl.y;
1410 poly_intersection(struct point *p1, struct point *p2, struct point_rect *r, int edge, struct point *ret)
1416 ret->y=p1->y+(r->lu.x-p1->x)*dy/dx;
1420 ret->y=p1->y+(r->rl.x-p1->x)*dy/dx;
1424 ret->x=p1->x+(r->lu.y-p1->y)*dx/dy;
1428 ret->x=p1->x+(r->rl.y-p1->y)*dx/dy;
1435 graphics_draw_polygon_clipped(struct graphics *gra, struct graphics_gc *gc, struct point *pin, int count_in)
1437 struct point_rect r=gra->r;
1438 struct point *pout,*p,*s,pi;
1439 struct point p1[count_in*8+1];
1440 struct point p2[count_in*8+1];
1441 int count_out,edge=3;
1451 for (edge = 0 ; edge < 4 ; edge++) {
1455 for (i = 0 ; i < count_in ; i++) {
1456 if (is_inside(p, &r, edge)) {
1457 if (! is_inside(s, &r, edge)) {
1458 poly_intersection(s,p,&r,edge,&pi);
1459 pout[count_out++]=pi;
1461 pout[count_out++]=*p;
1463 if (is_inside(s, &r, edge)) {
1464 poly_intersection(p,s,&r,edge,&pi);
1465 pout[count_out++]=pi;
1480 gra->meth.draw_polygon(gra->priv, gc->priv, pin, count_in);
1485 display_context_free(struct display_context *dc)
1488 graphics_gc_destroy(dc->gc);
1490 graphics_image_free(dc->gra, dc->img);
1495 static struct graphics_font *
1496 get_font(struct graphics *gra, int size)
1500 if (size >= gra->font_len) {
1501 gra->font=g_renew(struct graphics_font *, gra->font, size+1);
1502 while (gra->font_len <= size)
1503 gra->font[gra->font_len++]=NULL;
1505 if (! gra->font[size])
1506 gra->font[size]=graphics_font_new(gra, size*20, 0);
1507 return gra->font[size];
1511 graphics_icon_path(char *icon)
1513 static char *navit_sharedir;
1514 dbg(1,"enter %s\n",icon);
1516 return g_strdup(icon);
1518 #ifdef HAVE_API_ANDROID
1519 return g_strdup_printf("res/drawable/%s", icon);
1521 if (! navit_sharedir)
1522 navit_sharedir = getenv("NAVIT_SHAREDIR");
1523 return g_strdup_printf("%s/xpm/%s", navit_sharedir, icon);
1529 limit_count(struct coord *c, int count)
1532 for (i = 1 ; i < count ; i++) {
1533 if (c[i].x == c[0].x && c[i].y == c[0].y)
1541 displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc)
1543 int width[dc->maxlen];
1544 int i,count=di->count,mindist=dc->mindist;
1545 struct point pa[dc->maxlen];
1546 struct graphics *gra=dc->gra;
1547 struct graphics_gc *gc=dc->gc;
1548 struct element *e=dc->e;
1549 struct graphics_image *img=dc->img;
1555 gc=graphics_gc_new(gra);
1556 graphics_gc_set_foreground(gc, &e->color);
1558 if (item_type_is_area(dc->type) && (dc->e->type == element_polyline || dc->e->type == element_text))
1559 count=limit_count(di->c, count);
1560 if (dc->type == type_poly_water_tiled)
1562 if (dc->e->type == element_polyline)
1563 count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, e->u.polyline.width, width);
1565 count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, 0, NULL);
1567 case element_polygon:
1571 for (i = 0 ; i < count ; i++) {
1572 dbg(0,"pa[%d]=%d,%d\n", i, pa[i].x, pa[i].y);
1575 dbg(0,"element_polygon count=%d\n",count);
1578 graphics_draw_polygon_clipped(gra, gc, pa, count);
1581 case element_polyline:
1583 if (e->u.polyline.width > 1) {
1584 graphics_draw_polyline_as_polygon(gra, gc, pa, count, width, 0);
1589 if (e->u.polyline.width > 1)
1590 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
1592 gc->meth.gc_set_linewidth(gc->priv, 1);
1597 if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
1598 graphics_gc_set_dashes(gc, e->u.polyline.width,
1599 e->u.polyline.offset,
1600 e->u.polyline.dash_table,
1601 e->u.polyline.dash_num);
1603 if (di->label && !strcmp(di->label, "Bahnhofstr.") && di->item.type != type_street_1_city) {
1604 dbg(0,"0x%x,0x%x %s\n", di->item.id_hi, di->item.id_lo, item_to_name(di->item.type));
1606 for (i = 0 ; i < count ; i++) {
1610 graphics_draw_polyline_clipped(gra, gc, pa, count, width, 1, e->u.polyline.width > 1);
1616 case element_circle:
1618 if (e->u.circle.width > 1)
1619 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
1620 gra->meth.draw_circle(gra->priv, gc->priv, pa, e->u.circle.radius);
1621 if (di->label && e->text_size) {
1622 struct graphics_font *font=get_font(gra, e->text_size);
1626 gra->meth.draw_text(gra->priv, gra->gc[2]->priv, gra->gc[1]->priv, font->priv, di->label, &p, 0x10000, 0);
1628 dbg(0,"Failed to get font with size %d\n",e->text_size);
1633 if (count && di->label) {
1634 struct graphics_font *font=get_font(gra, e->text_size);
1636 label_line(gra, gra->gc[2], gra->gc[1], font, pa, count, di->label);
1638 dbg(0,"Failed to get font with size %d\n",e->text_size);
1644 path=graphics_icon_path(e->u.icon.src);
1645 img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation);
1650 dbg(0,"failed to load icon '%s'\n", e->u.icon.src);
1653 p.x=pa[0].x - img->hot.x;
1654 p.y=pa[0].y - img->hot.y;
1655 gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p, img->priv);
1660 dbg(1,"image: '%s'\n", di->label);
1661 if (gra->meth.draw_image_warp)
1662 gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, pa, count, di->label);
1664 dbg(0,"draw_image_warp not supported by graphics driver drawing '%s'\n", di->label);
1666 case element_arrows:
1667 display_draw_arrows(gra,gc,pa,count);
1670 printf("Unhandled element type %d\n", e->type);
1678 * @author Martin Schaller (04/2008)
1680 static void xdisplay_draw_elements(struct graphics *gra, struct displaylist *display_list, struct itemgra *itm)
1685 struct display_context *dc=&display_list->dc;
1693 dc->type=GPOINTER_TO_INT(types->data);
1694 h=g_hash_table_lookup(display_list->dl, GINT_TO_POINTER(dc->type));
1696 g_hash_table_foreach(h, (GHFunc)displayitem_draw, dc);
1697 display_context_free(dc);
1699 types=g_list_next(types);
1706 graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transformation *t)
1714 struct graphics_gc *gc = NULL;
1715 struct graphics_image *img;
1721 struct element *e=es->data;
1722 int count=e->coord_count;
1723 struct point pnt[count+1];
1725 transform(t, projection_screen, e->coord, pnt, count, 0, 0, NULL);
1727 transform(t, projection_screen, &c, pnt, 1, 0, 0, NULL);
1730 gc=graphics_gc_new(gra);
1731 graphics_gc_set_foreground(gc, &e->color);
1733 case element_polyline:
1734 if (e->u.polyline.width > 1)
1735 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
1736 if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
1737 graphics_gc_set_dashes(gc, e->u.polyline.width,
1738 e->u.polyline.offset,
1739 e->u.polyline.dash_table,
1740 e->u.polyline.dash_num);
1741 gra->meth.draw_lines(gra->priv, gc->priv, pnt, count);
1743 case element_polygon:
1744 gra->meth.draw_polygon(gra->priv, gc->priv, pnt, count);
1746 case element_circle:
1747 if (e->u.circle.width > 1)
1748 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
1749 gra->meth.draw_circle(gra->priv, gc->priv, &pnt[0], e->u.circle.radius);
1751 // Leftover code, displayitem_draw is intended to be merged with with graphics_draw_itemgra
1752 if (label && e->text_size) {
1753 struct graphics_font *font=get_font(gra, e->text_size);
1757 gra->meth.draw_text(gra->priv, gra->gc[2]->priv, gra->gc[1]->priv, font->priv, label, &p, 0x10000, 0);
1759 dbg(0,"Failed to get font with size %d\n",e->text_size);
1764 path=graphics_icon_path(e->u.icon.src);
1765 img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation);
1768 dbg(0,"failed to load icon '%s'\n", e->u.icon.src);
1770 p.x=pnt[0].x - img->hot.x;
1771 p.y=pnt[0].y - img->hot.y;
1772 gra->meth.draw_image(gra->priv, gc->priv, &p, img->priv);
1773 graphics_image_free(gra, img);
1777 dbg(0,"don't know how to draw %d\n", e->type);
1779 graphics_gc_destroy(gc);
1788 * @author Martin Schaller (04/2008)
1790 static void xdisplay_draw_layer(struct displaylist *display_list, struct graphics *gra, struct layer *lay, int order)
1793 struct itemgra *itm;
1798 if (order >= itm->order.min && order <= itm->order.max)
1799 xdisplay_draw_elements(gra, display_list, itm);
1800 itms=g_list_next(itms);
1808 * @author Martin Schaller (04/2008)
1810 static void xdisplay_draw(struct displaylist *display_list, struct graphics *gra, struct layout *l, int order)
1818 xdisplay_draw_layer(display_list, gra, lay, order);
1819 lays=g_list_next(lays);
1827 * @author Martin Schaller (04/2008)
1829 extern void *route_selection;
1832 do_draw(struct displaylist *displaylist, int cancel, int flags)
1835 int count,max=displaylist->dc.maxlen,workload=0;
1836 struct coord ca[max];
1841 if (!displaylist->msh)
1842 displaylist->msh=mapset_open(displaylist->ms);
1843 if (!displaylist->m) {
1844 displaylist->m=mapset_next(displaylist->msh, 1);
1845 if (!displaylist->m) {
1846 mapset_close(displaylist->msh);
1847 displaylist->msh=NULL;
1850 displaylist->dc.pro=map_projection(displaylist->m);
1851 displaylist->conv=map_requires_conversion(displaylist->m);
1852 displaylist->sel=transform_get_selection(displaylist->dc.trans, displaylist->dc.pro, displaylist->order);
1853 displaylist->mr=map_rect_new(displaylist->m, displaylist->sel);
1855 if (displaylist->mr) {
1856 while ((item=map_rect_get_item(displaylist->mr))) {
1857 count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, displaylist->sel);
1861 dbg(0,"point count overflow %d for %s "ITEM_ID_FMT"\n", count,item_to_name(item->type),ITEM_ID_ARGS(*item));
1862 displaylist->dc.maxlen=max*2;
1864 if (!item_attr_get(item, attr_label, &attr))
1866 if (displaylist->conv && attr.u.str && attr.u.str[0]) {
1867 char *str=map_convert_string(displaylist->m, attr.u.str);
1868 display_add(displaylist, item, count, ca, str);
1869 map_convert_free(str);
1871 display_add(displaylist, item, count, ca, attr.u.str);
1873 if (workload == displaylist->workload)
1876 map_rect_destroy(displaylist->mr);
1878 map_selection_destroy(displaylist->sel);
1879 displaylist->mr=NULL;
1880 displaylist->sel=NULL;
1881 displaylist->m=NULL;
1883 profile(1,"process_selection\n");
1884 event_remove_idle(displaylist->idle_ev);
1885 displaylist->idle_ev=NULL;
1886 callback_destroy(displaylist->idle_cb);
1887 displaylist->idle_cb=NULL;
1888 displaylist->busy=0;
1889 graphics_process_selection(displaylist->dc.gra, displaylist);
1890 profile(1,"draw\n");
1892 graphics_displaylist_draw(displaylist->dc.gra, displaylist, displaylist->dc.trans, displaylist->layout, flags);
1893 map_rect_destroy(displaylist->mr);
1894 map_selection_destroy(displaylist->sel);
1895 mapset_close(displaylist->msh);
1896 displaylist->mr=NULL;
1897 displaylist->sel=NULL;
1898 displaylist->m=NULL;
1899 displaylist->msh=NULL;
1900 profile(1,"callback\n");
1901 callback_call_1(displaylist->cb, cancel);
1909 * @author Martin Schaller (04/2008)
1911 void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, struct layout *l, int flags)
1913 int order=transform_get_order(trans);
1914 displaylist->dc.trans=trans;
1915 displaylist->dc.gra=gra;
1916 displaylist->dc.mindist=transform_get_scale(trans)/2;
1917 // FIXME find a better place to set the background color
1919 graphics_gc_set_background(gra->gc[0], &l->color);
1920 graphics_gc_set_foreground(gra->gc[0], &l->color);
1921 gra->default_font = g_strdup(l->font);
1923 graphics_background_gc(gra, gra->gc[0]);
1924 gra->meth.draw_mode(gra->priv, (flags & 8)?draw_mode_begin_clear:draw_mode_begin);
1926 gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &gra->r.lu, gra->r.rl.x-gra->r.lu.x, gra->r.rl.y-gra->r.lu.y);
1928 xdisplay_draw(displaylist, gra, l, order+l->order_delta);
1930 callback_list_call_attr_0(gra->cbl, attr_postdraw);
1932 gra->meth.draw_mode(gra->priv, draw_mode_end);
1935 static void graphics_load_mapset(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset, struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags)
1937 int order=transform_get_order(trans);
1940 if (displaylist->busy) {
1943 do_draw(displaylist, 1, flags);
1945 xdisplay_free(displaylist->dl);
1946 dbg(1,"order=%d\n", order);
1948 displaylist->dc.gra=gra;
1949 displaylist->ms=mapset;
1950 displaylist->dc.trans=trans;
1951 displaylist->workload=async ? 100 : 0;
1954 order+=l->order_delta;
1955 displaylist->order=order;
1956 displaylist->busy=1;
1957 displaylist->layout=l;
1959 if (! displaylist->idle_cb)
1960 displaylist->idle_cb=callback_new_3(callback_cast(do_draw), displaylist, 0, flags);
1961 displaylist->idle_ev=event_add_idle(50, displaylist->idle_cb);
1963 do_draw(displaylist, 0, flags);
1969 * @author Martin Schaller (04/2008)
1971 void graphics_draw(struct graphics *gra, struct displaylist *displaylist, struct mapset *mapset, struct transformation *trans, struct layout *l, int async, struct callback *cb, int flags)
1973 graphics_load_mapset(gra, displaylist, mapset, trans, l, async, cb, flags);
1977 graphics_draw_cancel(struct graphics *gra, struct displaylist *displaylist)
1979 if (!displaylist->busy)
1981 do_draw(displaylist, 1, 0);
1989 * @author Martin Schaller (04/2008)
1991 struct displaylist_handle {
1992 GList *hl_head,*hl,*l_head,*l;
1999 * @author Martin Schaller (04/2008)
2001 struct displaylist_handle * graphics_displaylist_open(struct displaylist *displaylist)
2003 struct displaylist_handle *ret;
2005 ret=g_new0(struct displaylist_handle, 1);
2006 if (!displaylist->dl)
2008 ret->hl_head=ret->hl=g_hash_to_list(displaylist->dl);
2013 ret->l_head=ret->l=g_hash_to_list_keys(ret->hl->data);
2022 * @author Martin Schaller (04/2008)
2024 struct displayitem * graphics_displaylist_next(struct displaylist_handle *dlh)
2026 struct displayitem *ret;
2030 dlh->hl=g_list_next(dlh->hl);
2033 g_list_free(dlh->l_head);
2034 dlh->l_head=dlh->l=g_hash_to_list_keys(dlh->hl->data);
2037 dlh->l=g_list_next(dlh->l);
2045 * @author Martin Schaller (04/2008)
2047 void graphics_displaylist_close(struct displaylist_handle *dlh)
2050 g_list_free(dlh->hl_head);
2051 g_list_free(dlh->l_head);
2060 * @author Martin Schaller (04/2008)
2062 struct displaylist * graphics_displaylist_new(void)
2064 struct displaylist *ret=g_new0(struct displaylist, 1);
2066 ret->dl=g_hash_table_new(NULL,NULL);
2067 ret->dc.maxlen=16384;
2076 * @author Martin Schaller (04/2008)
2078 struct item * graphics_displayitem_get_item(struct displayitem *di)
2084 graphics_displayitem_get_coord_count(struct displayitem *di)
2093 * @author Martin Schaller (04/2008)
2095 char * graphics_displayitem_get_label(struct displayitem *di)
2101 graphics_displayitem_get_displayed(struct displayitem *di)
2103 return di->displayed;
2110 * @author Martin Schaller (04/2008)
2112 static int within_dist_point(struct point *p0, struct point *p1, int dist)
2114 if (p0->x == 32767 || p0->y == 32767 || p1->x == 32767 || p1->y == 32767)
2116 if (p0->x == -32768 || p0->y == -32768 || p1->x == -32768 || p1->y == -32768)
2118 if ((p0->x-p1->x)*(p0->x-p1->x) + (p0->y-p1->y)*(p0->y-p1->y) <= dist*dist) {
2128 * @author Martin Schaller (04/2008)
2130 static int within_dist_line(struct point *p, struct point *line_p0, struct point *line_p1, int dist)
2134 struct point line_p;
2136 if (line_p0->x < line_p1->x) {
2137 if (p->x < line_p0->x - dist)
2139 if (p->x > line_p1->x + dist)
2142 if (p->x < line_p1->x - dist)
2144 if (p->x > line_p0->x + dist)
2147 if (line_p0->y < line_p1->y) {
2148 if (p->y < line_p0->y - dist)
2150 if (p->y > line_p1->y + dist)
2153 if (p->y < line_p1->y - dist)
2155 if (p->y > line_p0->y + dist)
2159 vx=line_p1->x-line_p0->x;
2160 vy=line_p1->y-line_p0->y;
2166 return within_dist_point(p, line_p0, dist);
2169 return within_dist_point(p, line_p1, dist);
2171 line_p.x=line_p0->x+vx*c1/c2;
2172 line_p.y=line_p0->y+vy*c1/c2;
2173 return within_dist_point(p, &line_p, dist);
2180 * @author Martin Schaller (04/2008)
2182 static int within_dist_polyline(struct point *p, struct point *line_pnt, int count, int dist, int close)
2185 for (i = 0 ; i < count-1 ; i++) {
2186 if (within_dist_line(p,line_pnt+i,line_pnt+i+1,dist)) {
2191 return (within_dist_line(p,line_pnt,line_pnt+count-1,dist));
2199 * @author Martin Schaller (04/2008)
2201 static int within_dist_polygon(struct point *p, struct point *poly_pnt, int count, int dist)
2204 for (i = 0, j = count-1; i < count; j = i++) {
2205 if ((((poly_pnt[i].y <= p->y) && ( p->y < poly_pnt[j].y )) ||
2206 ((poly_pnt[j].y <= p->y) && ( p->y < poly_pnt[i].y))) &&
2207 (p->x < (poly_pnt[j].x - poly_pnt[i].x) * (p->y - poly_pnt[i].y) / (poly_pnt[j].y - poly_pnt[i].y) + poly_pnt[i].x))
2211 return within_dist_polyline(p, poly_pnt, count, dist, 1);
2219 * @author Martin Schaller (04/2008)
2221 int graphics_displayitem_within_dist(struct displaylist *displaylist, struct displayitem *di, struct point *p, int dist)
2223 struct point pa[displaylist->dc.maxlen];
2226 count=transform(displaylist->dc.trans, displaylist->dc.pro, di->c, pa, di->count, 1, 0, NULL);
2228 if (di->item.type < type_line) {
2229 return within_dist_point(p, &pa[0], dist);
2231 if (di->item.type < type_area) {
2232 return within_dist_polyline(p, pa, count, dist, 0);
2234 return within_dist_polygon(p, pa, count, dist);
2239 graphics_process_selection_item(struct displaylist *dl, struct item *item)
2241 struct displayitem di,*di_res;
2243 int count,max=dl->dc.maxlen;
2244 struct coord ca[max];
2246 struct map_rect *mr;
2252 h=g_hash_table_lookup(dl->dl, GINT_TO_POINTER(di.item.type));
2254 di_res=g_hash_table_lookup(h, &di);
2256 di.item.type=(enum item_type)item->priv_data;
2257 display_add(dl, &di.item, di_res->count, di_res->c, NULL);
2261 mr=map_rect_new(item->map, NULL);
2262 item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
2263 count=item_coord_get(item, ca, item->type < type_line ? 1: max);
2264 if (!item_attr_get(item, attr_label, &attr))
2266 if (dl->conv && attr.u.str && attr.u.str[0]) {
2267 char *str=map_convert_string(item->map, attr.u.str);
2268 display_add(dl, item, count, ca, str);
2269 map_convert_free(str);
2271 display_add(dl, item, count, ca, attr.u.str);
2272 map_rect_destroy(mr);
2276 graphics_add_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl)
2278 struct item *item_dup=g_new(struct item, 1);
2280 item_dup->priv_data=(void *)type;
2281 gra->selection=g_list_append(gra->selection, item_dup);
2283 graphics_process_selection_item(dl, item_dup);
2287 graphics_remove_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl)
2293 curr=gra->selection;
2296 struct item *sitem=curr->data;
2297 if (item_is_equal(*item,*sitem)) {
2299 struct displayitem di;
2306 h=g_hash_table_lookup(dl->dl, GINT_TO_POINTER(di.item.type));
2308 g_hash_table_remove(h, &di);
2311 gra->selection=g_list_remove(gra->selection, curr->data);
2322 graphics_clear_selection(struct graphics *gra, struct displaylist *dl)
2324 while (gra->selection) {
2325 struct item *item=(struct item *)gra->selection->data;
2326 graphics_remove_selection(gra, item, (enum item_type)item->priv_data,dl);
2331 graphics_process_selection(struct graphics *gra, struct displaylist *dl)
2335 curr=gra->selection;
2337 struct item *item=curr->data;
2338 graphics_process_selection_item(dl, item);
2339 curr=g_list_next(curr);