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 //##############################################################################################################
35 #include "draw_info.h"
38 #include "projection.h"
41 #include "transform.h"
51 static char *navit_sharedir;
53 //##############################################################################################################
56 //# Authors: Martin Schaller (04/2008)
57 //##############################################################################################################
60 struct graphics_priv *priv;
61 struct graphics_methods meth;
63 struct graphics_font *font[16];
64 struct graphics_gc *gc[3];
66 struct callback_list *cbl;
79 graphics_resize(struct graphics *gra, int w, int h)
86 * Creates a new graphics object
90 * @author Martin Schaller (04/2008)
92 struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
94 struct graphics *this_;
95 struct attr *type_attr;
96 struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl);
98 if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
102 graphicstype_new=plugin_get_graphics_type(type_attr->u.str);
103 if (! graphicstype_new)
105 this_=g_new0(struct graphics, 1);
106 this_->cbl=callback_list_new();
107 this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, attrs, this_->cbl);
108 this_->attrs=attr_list_dup(attrs);
116 * @author Martin Schaller (04/2008)
118 int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
120 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
127 * @author Martin Schaller (04/2008)
129 struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h, int alpha, int wraparound)
131 struct graphics *this_;
132 if (!parent->meth.overlay_new)
134 this_=g_new0(struct graphics, 1);
135 this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h, alpha, wraparound);
147 * @author Martin Schaller (04/2008)
149 void graphics_init(struct graphics *this_)
151 this_->gc[0]=graphics_gc_new(this_);
152 graphics_gc_set_background(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7, 0xffff});
153 graphics_gc_set_foreground(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7, 0xffff });
154 this_->gc[1]=graphics_gc_new(this_);
155 graphics_gc_set_background(this_->gc[1], &(struct color) { 0x0000, 0x0000, 0x0000, 0xffff });
156 graphics_gc_set_foreground(this_->gc[1], &(struct color) { 0xffff, 0xffff, 0xffff, 0xffff });
157 this_->gc[2]=graphics_gc_new(this_);
158 graphics_gc_set_background(this_->gc[2], &(struct color) { 0xffff, 0xffff, 0xffff, 0xffff });
159 graphics_gc_set_foreground(this_->gc[2], &(struct color) { 0x0000, 0x0000, 0x0000, 0xffff });
160 graphics_background_gc(this_, this_->gc[0]);
161 navit_sharedir = getenv("NAVIT_SHAREDIR");
168 * @author Martin Schaller (04/2008)
170 void * graphics_get_data(struct graphics *this_, char *type)
172 return (this_->meth.get_data(this_->priv, type));
175 void graphics_add_callback(struct graphics *this_, struct callback *cb)
177 callback_list_add(this_->cbl, cb);
184 * @author Martin Schaller (04/2008)
186 struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags)
188 struct graphics_font *this_;
190 this_=g_new0(struct graphics_font,1);
191 this_->priv=gra->meth.font_new(gra->priv, &this_->meth, gra->default_font, size, flags);
196 * Free all loaded fonts.
197 * Used when switching layouts.
198 * @param gra The graphics instance
200 * @author Sarah Nordstrom (05/2008)
202 void graphics_font_destroy_all(struct graphics *gra)
205 for(i = 0 ; i < sizeof(gra->font) / sizeof(gra->font[0]); i++) {
206 if(!gra->font[i]) continue;
207 gra->font[i]->meth.font_destroy(gra->font[i]->priv);
216 * @author Martin Schaller (04/2008)
218 struct graphics_gc * graphics_gc_new(struct graphics *gra)
220 struct graphics_gc *this_;
222 this_=g_new0(struct graphics_gc,1);
223 this_->priv=gra->meth.gc_new(gra->priv, &this_->meth);
231 * @author Martin Schaller (04/2008)
233 void graphics_gc_destroy(struct graphics_gc *gc)
235 gc->meth.gc_destroy(gc->priv);
243 * @author Martin Schaller (04/2008)
245 void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c)
247 gc->meth.gc_set_foreground(gc->priv, c);
254 * @author Martin Schaller (04/2008)
256 void graphics_gc_set_background(struct graphics_gc *gc, struct color *c)
258 gc->meth.gc_set_background(gc->priv, c);
265 * @author Martin Schaller (04/2008)
267 void graphics_gc_set_linewidth(struct graphics_gc *gc, int width)
269 gc->meth.gc_set_linewidth(gc->priv, width);
276 * @author Martin Schaller (04/2008)
278 void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsigned char dash_list[], int n)
280 if (gc->meth.gc_set_dashes)
281 gc->meth.gc_set_dashes(gc->priv, width, offset, dash_list, n);
285 * Create a new image from file path scaled to w and h pixels
286 * @param gra the graphics instance
287 * @param path path of the image to load
288 * @param w width to rescale to
289 * @param h height to rescale to
291 * @author Martin Schaller (04/2008)
293 struct graphics_image * graphics_image_new_scaled(struct graphics *gra, char *path, int w, int h)
295 struct graphics_image *this_;
297 this_=g_new0(struct graphics_image,1);
300 this_->priv=gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, 0);
309 * Create a new image from file path scaled to w and h pixels and possibly rotated
310 * @param gra the graphics instance
311 * @param path path of the image to load
312 * @param w width to rescale to
313 * @param h height to rescale to
314 * @param rotate angle to rotate the image. Warning, graphics might only support 90 degree steps here
316 * @author Martin Schaller (04/2008)
318 struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra, char *path, int w, int h, int rotate)
320 struct graphics_image *this_;
322 this_=g_new0(struct graphics_image,1);
325 this_->priv=gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, rotate);
334 * Create a new image from file path
335 * @param gra the graphics instance
336 * @param path path of the image to load
338 * @author Martin Schaller (04/2008)
340 struct graphics_image * graphics_image_new(struct graphics *gra, char *path)
342 return graphics_image_new_scaled(gra, path, -1, -1);
349 * @author Martin Schaller (04/2008)
351 void graphics_image_free(struct graphics *gra, struct graphics_image *img)
353 if (gra->meth.image_free)
354 gra->meth.image_free(gra->priv, img->priv);
362 * @author Martin Schaller (04/2008)
364 void graphics_draw_restore(struct graphics *this_, struct point *p, int w, int h)
366 this_->meth.draw_restore(this_->priv, p, w, h);
373 * @author Martin Schaller (04/2008)
375 void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode)
377 this_->meth.draw_mode(this_->priv, mode);
384 * @author Martin Schaller (04/2008)
386 void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count)
388 this_->meth.draw_lines(this_->priv, gc->priv, p, count);
395 * @author Martin Schaller (04/2008)
397 void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r)
399 this_->meth.draw_circle(this_->priv, gc->priv, p, r);
406 * @author Martin Schaller (04/2008)
408 void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h)
410 this_->meth.draw_rectangle(this_->priv, gc->priv, p, w, h);
417 * @author Martin Schaller (04/2008)
419 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)
421 this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, p, dx, dy);
428 * @author Martin Schaller (04/2008)
430 void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font, char *text, int dx, int dy, struct point *ret, int estimate)
432 this_->meth.get_text_bbox(this_->priv, font->priv, text, dx, dy, ret, estimate);
439 * @author Martin Schaller (04/2008)
441 void graphics_overlay_disable(struct graphics *this_, int disable)
443 if (this_->meth.overlay_disable)
444 this_->meth.overlay_disable(this_->priv, disable);
451 * @author Martin Schaller (04/2008)
453 void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img)
455 this_->meth.draw_image(this_->priv, gc->priv, p, img->priv);
459 //##############################################################################################################
462 //# Authors: Martin Schaller (04/2008)
463 //##############################################################################################################
465 graphics_draw_drag(struct graphics *this_, struct point *p)
467 if (!this_->meth.draw_drag)
469 this_->meth.draw_drag(this_->priv, p);
474 graphics_background_gc(struct graphics *this_, struct graphics_gc *gc)
476 this_->meth.background_gc(this_->priv, gc ? gc->priv : NULL);
485 //##############################################################################################################
488 //# Authors: Martin Schaller (04/2008)
489 //##############################################################################################################
490 static void popup_view_html(struct popup_item *item, char *file)
493 sprintf(command,"firefox %s", file);
497 //##############################################################################################################
500 //# Authors: Martin Schaller (04/2008)
501 //##############################################################################################################
502 static void graphics_popup(struct display_list *list, struct popup_item **popup)
508 struct popup_item *curr_item,*last=NULL;
510 mr=map_rect_new(item->map, NULL, NULL, 0);
511 printf("id hi=0x%x lo=0x%x\n", item->id_hi, item->id_lo);
512 item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
514 if (item_attr_get(item, attr_name, &attr)) {
515 curr_item=popup_item_new_text(popup,attr.u.str,1);
516 if (item_attr_get(item, attr_info_html, &attr)) {
517 popup_item_new_func(&last,"HTML Info",1, popup_view_html, g_strdup(attr.u.str));
519 if (item_attr_get(item, attr_price_html, &attr)) {
520 popup_item_new_func(&last,"HTML Preis",2, popup_view_html, g_strdup(attr.u.str));
522 curr_item->submenu=last;
525 map_rect_destroy(mr);
533 * @author Martin Schaller (04/2008)
547 * @author Martin Schaller (04/2008)
549 static int xdisplay_free_list(gpointer key, gpointer value, gpointer user_data)
555 struct displayitem *di=l->data;
556 if (! di->displayed && di->item.type < type_line)
557 dbg(1,"warning: item '%s' not displayed\n", item_to_name(di->item.type));
569 * @author Martin Schaller (04/2008)
571 static void xdisplay_free(GHashTable *display_list)
573 g_hash_table_foreach_remove(display_list, xdisplay_free_list, NULL);
580 * @author Martin Schaller (04/2008)
582 void display_add(struct displaylist *displaylist, struct item *item, int count, struct point *pnt, char *label)
584 struct displayitem *di;
589 len=sizeof(*di)+count*sizeof(*pnt);
591 len+=strlen(label)+1;
595 di=(struct displayitem *)p;
597 p+=sizeof(*di)+count*sizeof(*pnt);
601 strcpy(di->label, label);
605 memcpy(di->pnt, pnt, count*sizeof(*pnt));
607 l=g_hash_table_lookup(displaylist->dl, GINT_TO_POINTER(item->type));
608 l=g_list_prepend(l, di);
609 g_hash_table_insert(displaylist->dl, GINT_TO_POINTER(item->type), l);
617 * @author Martin Schaller (04/2008)
619 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)
621 int i,x,y,tl,tlm,th,thm,tlsq,l;
627 if (gra->meth.get_text_bbox) {
628 gra->meth.get_text_bbox(gra->priv, font->priv, label, 0x10000, 0x0, pb, 1);
629 tl=(pb[2].x-pb[0].x);
630 th=(pb[0].y-pb[1].y);
638 for (i = 0 ; i < count-1 ; i++) {
661 dbg(0,"display_text: '%s', %d, %d, %d, %d %d\n", label, x, y, dx*0x10000/l, dy*0x10000/l, l);
663 if (x < gra->w && x + tl > 0 && y + tl > 0 && y - tl < gra->h)
664 gra->meth.draw_text(gra->priv, fg->priv, bg->priv, font->priv, label, &p_t, dx*0x10000/l, dy*0x10000/l);
669 static void display_draw_arrow(struct point *p, int dx, int dy, int l, struct graphics_gc *gc, struct graphics *gra)
672 pnt[0]=pnt[1]=pnt[2]=*p;
673 pnt[0].x+=-dx*l/65536+dy*l/65536;
674 pnt[0].y+=-dy*l/65536-dx*l/65536;
675 pnt[2].x+=-dx*l/65536-dy*l/65536;
676 pnt[2].y+=-dy*l/65536+dx*l/65536;
677 gra->meth.draw_lines(gra->priv, gc->priv, pnt, 3);
680 static void display_draw_arrows(struct displayitem *di, struct graphics_gc *gc, struct graphics *gra)
684 for (i = 0 ; i < di->count-1 ; i++) {
685 dx=di->pnt[i+1].x-di->pnt[i].x;
686 dy=di->pnt[i+1].y-di->pnt[i].y;
694 display_draw_arrow(&p, dx, dy, 10, gc, gra);
698 display_draw_arrow(&p, dx, dy, 10, gc, gra);
707 * @author Martin Schaller (04/2008)
709 static void xdisplay_draw_elements(struct graphics *gra, GHashTable *display_list, struct itemgra *itm)
712 GList *l,*ls,*es,*types;
714 struct graphics_gc *gc = NULL;
715 struct graphics_image *img;
724 type=GPOINTER_TO_INT(types->data);
725 ls=g_hash_table_lookup(display_list, GINT_TO_POINTER(type));
728 graphics_gc_destroy(gc);
732 struct displayitem *di;
736 gc=graphics_gc_new(gra);
737 gc->meth.gc_set_foreground(gc->priv, &e->color);
740 case element_polygon:
741 gra->meth.draw_polygon(gra->priv, gc->priv, di->pnt, di->count);
743 case element_polyline:
744 if (e->u.polyline.width > 1)
745 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
746 if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
747 graphics_gc_set_dashes(gc, e->u.polyline.width,
748 e->u.polyline.offset,
749 e->u.polyline.dash_table,
750 e->u.polyline.dash_num);
751 gra->meth.draw_lines(gra->priv, gc->priv, di->pnt, di->count);
754 if (e->u.circle.width > 1)
755 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
756 gra->meth.draw_circle(gra->priv, gc->priv, &di->pnt[0], e->u.circle.radius);
757 if (di->label && e->text_size) {
760 if (! gra->font[e->text_size])
761 gra->font[e->text_size]=graphics_font_new(gra, e->text_size*20, 0);
762 gra->meth.draw_text(gra->priv, gra->gc[2]->priv, gra->gc[1]->priv, gra->font[e->text_size]->priv, di->label, &p, 0x10000, 0);
767 if (! gra->font[e->text_size])
768 gra->font[e->text_size]=graphics_font_new(gra, e->text_size*20, 0);
769 label_line(gra, gra->gc[2], gra->gc[1], gra->font[e->text_size], di->pnt, di->count, di->label);
774 if (e->u.icon.src[0] == '/')
775 strcpy(path,e->u.icon.src);
777 sprintf(path,"%s/xpm/%s", navit_sharedir, e->u.icon.src);
778 img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation);
780 dbg(0,"failed to load icon '%s'\n", e->u.icon.src);
783 p.x=di->pnt[0].x - img->hot.x;
784 p.y=di->pnt[0].y - img->hot.y;
785 gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p, img->priv);
786 graphics_image_free(gra, img);
791 dbg(1,"image: '%s'\n", di->label);
792 if (gra->meth.draw_image_warp)
793 gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, di->pnt, di->count, di->label);
795 dbg(0,"draw_image_warp not supported by graphics driver drawing '%s'\n", di->label);
798 display_draw_arrows(di,gc,gra);
801 printf("Unhandled element type %d\n", e->type);
806 types=g_list_next(types);
811 graphics_gc_destroy(gc);
815 graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transformation *t)
821 struct graphics_gc *gc = NULL;
822 struct graphics_image *img;
828 struct element *e=es->data;
829 int count=e->coord_count;
830 struct point pnt[count+1];
832 transform(t, projection_screen, e->coord, pnt, count, 0);
834 transform(t, projection_screen, &c, pnt, 1, 0);
837 gc=graphics_gc_new(gra);
838 gc->meth.gc_set_foreground(gc->priv, &e->color);
840 case element_polyline:
841 if (e->u.polyline.width > 1)
842 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
843 if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
844 graphics_gc_set_dashes(gc, e->u.polyline.width,
845 e->u.polyline.offset,
846 e->u.polyline.dash_table,
847 e->u.polyline.dash_num);
848 gra->meth.draw_lines(gra->priv, gc->priv, pnt, count);
851 if (e->u.circle.width > 1)
852 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
853 gra->meth.draw_circle(gra->priv, gc->priv, &pnt[0], e->u.circle.radius);
854 if (label && e->text_size) {
857 if (! gra->font[e->text_size])
858 gra->font[e->text_size]=graphics_font_new(gra, e->text_size*20, 0);
859 gra->meth.draw_text(gra->priv, gra->gc[2]->priv, gra->gc[1]->priv, gra->font[e->text_size]->priv, label, &p, 0x10000, 0);
863 if (e->u.icon.src[0] == '/')
864 strcpy(path,e->u.icon.src);
866 sprintf(path,"%s/xpm/%s", navit_sharedir, e->u.icon.src);
867 img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation);
869 dbg(0,"failed to load icon '%s'\n", e->u.icon.src);
871 p.x=pnt[0].x - img->hot.x;
872 p.y=pnt[0].y - img->hot.y;
873 gra->meth.draw_image(gra->priv, gc->priv, &p, img->priv);
874 graphics_image_free(gra, img);
878 dbg(0,"dont know how to draw %d\n", e->type);
880 graphics_gc_destroy(gc);
889 * @author Martin Schaller (04/2008)
891 static void xdisplay_draw_layer(GHashTable *display_list, struct graphics *gra, struct layer *lay, int order)
899 if (order >= itm->order.min && order <= itm->order.max)
900 xdisplay_draw_elements(gra, display_list, itm);
901 itms=g_list_next(itms);
909 * @author Martin Schaller (04/2008)
911 static void xdisplay_draw(GHashTable *display_list, struct graphics *gra, struct layout *l, int order)
919 xdisplay_draw_layer(display_list, gra, lay, order);
920 lays=g_list_next(lays);
928 * @author Martin Schaller (04/2008)
930 extern void *route_selection;
936 * @author Martin Schaller (04/2008)
938 static void do_draw_map(struct displaylist *displaylist, struct transformation *t, struct map *m, int order)
943 int conv,count,max=16384;
944 struct point pnt[max];
945 struct coord ca[max];
947 struct map_selection *sel;
949 pro=map_projection(m);
950 conv=map_requires_conversion(m);
951 sel=transform_get_selection(t, pro, order);
953 mr=map_rect_new(m, route_selection);
955 mr=map_rect_new(m, sel);
957 map_selection_destroy(sel);
960 while ((item=map_rect_get_item(mr))) {
961 count=item_coord_get(item, ca, item->type < type_line ? 1: max);
962 if (item->type >= type_line && count < 2) {
963 dbg(1,"poly from map has only %d points\n", count);
966 if (item->type < type_line) {
967 if (! map_selection_contains_point(sel, &ca[0])) {
968 dbg(1,"point not visible\n");
971 } else if (item->type < type_area) {
972 if (! map_selection_contains_polyline(sel, ca, count)) {
973 dbg(1,"polyline not visible\n");
977 if (! map_selection_contains_polygon(sel, ca, count)) {
978 dbg(1,"polygon not visible\n");
983 dbg(0,"point count overflow\n", count);
984 count=transform(t, pro, ca, pnt, count, 1);
985 if (item->type >= type_line && count < 2) {
986 dbg(1,"poly from transform has only %d points\n", count);
989 if (!item_attr_get(item, attr_label, &attr))
991 if (conv && attr.u.str && attr.u.str[0]) {
992 char *str=map_convert_string(m, attr.u.str);
993 display_add(displaylist, item, count, pnt, str);
994 map_convert_free(str);
996 display_add(displaylist, item, count, pnt, attr.u.str);
998 map_rect_destroy(mr);
999 map_selection_destroy(sel);
1006 * @author Martin Schaller (04/2008)
1008 static void do_draw(struct displaylist *displaylist, struct transformation *t, GList *mapsets, int order)
1012 struct mapset_handle *h;
1018 while ((m=mapset_next(h, 1))) {
1019 do_draw_map(displaylist, t, m, order);
1028 * @author Martin Schaller (04/2008)
1030 int graphics_ready(struct graphics *this_)
1032 return this_->ready;
1039 * @author Martin Schaller (04/2008)
1041 void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, struct layout *l, int callback)
1043 int order=transform_get_order(trans);
1047 // FIXME find a better place to set the background color
1049 graphics_gc_set_background(gra->gc[0], &l->color);
1050 graphics_gc_set_foreground(gra->gc[0], &l->color);
1051 gra->default_font = g_strdup(l->font);
1053 graphics_background_gc(gra, gra->gc[0]);
1054 gra->meth.draw_mode(gra->priv, draw_mode_begin);
1055 gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &p, 32767, 32767);
1057 xdisplay_draw(displaylist->dl, gra, l, order+l->order_delta);
1059 callback_list_call_attr_0(gra->cbl, attr_postdraw);
1060 gra->meth.draw_mode(gra->priv, draw_mode_end);
1067 * @author Martin Schaller (04/2008)
1069 void graphics_displaylist_move(struct displaylist *displaylist, int dx, int dy)
1071 struct displaylist_handle *dlh;
1072 struct displayitem *di;
1075 dlh=graphics_displaylist_open(displaylist);
1076 while ((di=graphics_displaylist_next(dlh))) {
1077 for (i = 0 ; i < di->count ; i++) {
1082 graphics_displaylist_close(dlh);
1089 * @author Martin Schaller (04/2008)
1091 void graphics_draw(struct graphics *gra, struct displaylist *displaylist, GList *mapsets, struct transformation *trans, struct layout *l)
1093 int order=transform_get_order(trans);
1098 printf("scale=%d center=0x%x,0x%x mercator scale=%f\n", scale, co->trans->center.x, co->trans->center.y, transform_scale(co->trans->center.y));
1101 xdisplay_free(displaylist->dl);
1102 dbg(1,"order=%d\n", order);
1106 for (i = 0 ; i < data_window_type_end; i++) {
1107 data_window_begin(co->data_window[i]);
1112 order+=l->order_delta;
1114 do_draw(displaylist, trans, mapsets, order);
1115 // profile(1,"do_draw");
1116 graphics_displaylist_draw(gra, displaylist, trans, l, 1);
1117 profile(1,"xdisplay_draw");
1121 for (i = 0 ; i < data_window_type_end; i++) {
1122 data_window_end(co->data_window[i]);
1132 * @author Martin Schaller (04/2008)
1134 struct displaylist_handle {
1135 GList *hl_head,*hl,*l;
1142 * @author Martin Schaller (04/2008)
1144 struct displaylist_handle * graphics_displaylist_open(struct displaylist *displaylist)
1146 struct displaylist_handle *ret;
1148 ret=g_new0(struct displaylist_handle, 1);
1149 ret->hl_head=ret->hl=g_hash_to_list(displaylist->dl);
1158 * @author Martin Schaller (04/2008)
1160 struct displayitem * graphics_displaylist_next(struct displaylist_handle *dlh)
1162 struct displayitem *ret;
1166 dlh->l=dlh->hl->data;
1167 dlh->hl=g_list_next(dlh->hl);
1170 dlh->l=g_list_next(dlh->l);
1178 * @author Martin Schaller (04/2008)
1180 void graphics_displaylist_close(struct displaylist_handle *dlh)
1182 g_list_free(dlh->hl_head);
1190 * @author Martin Schaller (04/2008)
1192 struct displaylist * graphics_displaylist_new(void)
1194 struct displaylist *ret=g_new(struct displaylist, 1);
1196 ret->dl=g_hash_table_new(NULL,NULL);
1205 * @author Martin Schaller (04/2008)
1207 struct item * graphics_displayitem_get_item(struct displayitem *di)
1216 * @author Martin Schaller (04/2008)
1218 char * graphics_displayitem_get_label(struct displayitem *di)
1227 * @author Martin Schaller (04/2008)
1229 static int within_dist_point(struct point *p0, struct point *p1, int dist)
1231 if (p0->x == 32767 || p0->y == 32767 || p1->x == 32767 || p1->y == 32767)
1233 if (p0->x == -32768 || p0->y == -32768 || p1->x == -32768 || p1->y == -32768)
1235 if ((p0->x-p1->x)*(p0->x-p1->x) + (p0->y-p1->y)*(p0->y-p1->y) <= dist*dist) {
1245 * @author Martin Schaller (04/2008)
1247 static int within_dist_line(struct point *p, struct point *line_p0, struct point *line_p1, int dist)
1251 struct point line_p;
1253 vx=line_p1->x-line_p0->x;
1254 vy=line_p1->y-line_p0->y;
1260 return within_dist_point(p, line_p0, dist);
1263 return within_dist_point(p, line_p1, dist);
1265 line_p.x=line_p0->x+vx*c1/c2;
1266 line_p.y=line_p0->y+vy*c1/c2;
1267 return within_dist_point(p, &line_p, dist);
1274 * @author Martin Schaller (04/2008)
1276 static int within_dist_polyline(struct point *p, struct point *line_pnt, int count, int dist, int close)
1279 for (i = 0 ; i < count-1 ; i++) {
1280 if (within_dist_line(p,line_pnt+i,line_pnt+i+1,dist)) {
1285 return (within_dist_line(p,line_pnt,line_pnt+count-1,dist));
1293 * @author Martin Schaller (04/2008)
1295 static int within_dist_polygon(struct point *p, struct point *poly_pnt, int count, int dist)
1298 for (i = 0, j = count-1; i < count; j = i++) {
1299 if ((((poly_pnt[i].y <= p->y) && ( p->y < poly_pnt[j].y )) ||
1300 ((poly_pnt[j].y <= p->y) && ( p->y < poly_pnt[i].y))) &&
1301 (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))
1305 return within_dist_polyline(p, poly_pnt, count, dist, 1);
1313 * @author Martin Schaller (04/2008)
1315 int graphics_displayitem_within_dist(struct displayitem *di, struct point *p, int dist)
1317 if (di->item.type < type_line) {
1318 return within_dist_point(p, &di->pnt[0], dist);
1320 if (di->item.type < type_area) {
1321 return within_dist_polyline(p, di->pnt, di->count, dist, 0);
1323 return within_dist_polygon(p, di->pnt, di->count, dist);