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"
42 #include "transform.h"
52 static char *navit_sharedir;
54 //##############################################################################################################
57 //# Authors: Martin Schaller (04/2008)
58 //##############################################################################################################
61 struct graphics_priv *priv;
62 struct graphics_methods meth;
64 struct graphics_font *font[16];
65 struct graphics_gc *gc[3];
67 struct callback_list *cbl;
80 graphics_resize(struct graphics *gra, int w, int h)
87 * Creates a new graphics object
91 * @author Martin Schaller (04/2008)
93 struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
95 struct graphics *this_;
96 struct attr *type_attr;
97 struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl);
99 if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
103 graphicstype_new=plugin_get_graphics_type(type_attr->u.str);
104 if (! graphicstype_new)
106 this_=g_new0(struct graphics, 1);
107 this_->cbl=callback_list_new();
108 this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, attrs, this_->cbl);
109 this_->attrs=attr_list_dup(attrs);
117 * @author Martin Schaller (04/2008)
119 int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
121 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
128 * @author Martin Schaller (04/2008)
130 struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h, int alpha, int wraparound)
132 struct graphics *this_;
133 if (!parent->meth.overlay_new)
135 this_=g_new0(struct graphics, 1);
136 this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h, alpha, wraparound);
148 * @author Martin Schaller (04/2008)
150 void graphics_init(struct graphics *this_)
152 this_->gc[0]=graphics_gc_new(this_);
153 graphics_gc_set_background(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7, 0xffff});
154 graphics_gc_set_foreground(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7, 0xffff });
155 this_->gc[1]=graphics_gc_new(this_);
156 graphics_gc_set_background(this_->gc[1], &(struct color) { 0x0000, 0x0000, 0x0000, 0xffff });
157 graphics_gc_set_foreground(this_->gc[1], &(struct color) { 0xffff, 0xffff, 0xffff, 0xffff });
158 this_->gc[2]=graphics_gc_new(this_);
159 graphics_gc_set_background(this_->gc[2], &(struct color) { 0xffff, 0xffff, 0xffff, 0xffff });
160 graphics_gc_set_foreground(this_->gc[2], &(struct color) { 0x0000, 0x0000, 0x0000, 0xffff });
161 graphics_background_gc(this_, this_->gc[0]);
162 navit_sharedir = getenv("NAVIT_SHAREDIR");
169 * @author Martin Schaller (04/2008)
171 void * graphics_get_data(struct graphics *this_, char *type)
173 return (this_->meth.get_data(this_->priv, type));
176 void graphics_add_callback(struct graphics *this_, struct callback *cb)
178 callback_list_add(this_->cbl, cb);
185 * @author Martin Schaller (04/2008)
187 struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags)
189 struct graphics_font *this_;
191 this_=g_new0(struct graphics_font,1);
192 this_->priv=gra->meth.font_new(gra->priv, &this_->meth, gra->default_font, size, flags);
197 * Free all loaded fonts.
198 * Used when switching layouts.
199 * @param gra The graphics instance
201 * @author Sarah Nordstrom (05/2008)
203 void graphics_font_destroy_all(struct graphics *gra)
206 for(i = 0 ; i < sizeof(gra->font) / sizeof(gra->font[0]); i++) {
207 if(!gra->font[i]) continue;
208 gra->font[i]->meth.font_destroy(gra->font[i]->priv);
217 * @author Martin Schaller (04/2008)
219 struct graphics_gc * graphics_gc_new(struct graphics *gra)
221 struct graphics_gc *this_;
223 this_=g_new0(struct graphics_gc,1);
224 this_->priv=gra->meth.gc_new(gra->priv, &this_->meth);
232 * @author Martin Schaller (04/2008)
234 void graphics_gc_destroy(struct graphics_gc *gc)
236 gc->meth.gc_destroy(gc->priv);
244 * @author Martin Schaller (04/2008)
246 void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c)
248 gc->meth.gc_set_foreground(gc->priv, c);
255 * @author Martin Schaller (04/2008)
257 void graphics_gc_set_background(struct graphics_gc *gc, struct color *c)
259 gc->meth.gc_set_background(gc->priv, c);
266 * @author Martin Schaller (04/2008)
268 void graphics_gc_set_linewidth(struct graphics_gc *gc, int width)
270 gc->meth.gc_set_linewidth(gc->priv, width);
277 * @author Martin Schaller (04/2008)
279 void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsigned char dash_list[], int n)
281 if (gc->meth.gc_set_dashes)
282 gc->meth.gc_set_dashes(gc->priv, width, offset, dash_list, n);
286 * Create a new image from file path scaled to w and h pixels
287 * @param gra the graphics instance
288 * @param path path of the image to load
289 * @param w width to rescale to
290 * @param h height to rescale to
292 * @author Martin Schaller (04/2008)
294 struct graphics_image * graphics_image_new_scaled(struct graphics *gra, char *path, int w, int h)
296 struct graphics_image *this_;
298 this_=g_new0(struct graphics_image,1);
301 this_->priv=gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, 0);
310 * Create a new image from file path scaled to w and h pixels and possibly rotated
311 * @param gra the graphics instance
312 * @param path path of the image to load
313 * @param w width to rescale to
314 * @param h height to rescale to
315 * @param rotate angle to rotate the image. Warning, graphics might only support 90 degree steps here
317 * @author Martin Schaller (04/2008)
319 struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra, char *path, int w, int h, int rotate)
321 struct graphics_image *this_;
323 this_=g_new0(struct graphics_image,1);
326 this_->priv=gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, rotate);
335 * Create a new image from file path
336 * @param gra the graphics instance
337 * @param path path of the image to load
339 * @author Martin Schaller (04/2008)
341 struct graphics_image * graphics_image_new(struct graphics *gra, char *path)
343 return graphics_image_new_scaled(gra, path, -1, -1);
350 * @author Martin Schaller (04/2008)
352 void graphics_image_free(struct graphics *gra, struct graphics_image *img)
354 if (gra->meth.image_free)
355 gra->meth.image_free(gra->priv, img->priv);
363 * @author Martin Schaller (04/2008)
365 void graphics_draw_restore(struct graphics *this_, struct point *p, int w, int h)
367 this_->meth.draw_restore(this_->priv, p, w, h);
374 * @author Martin Schaller (04/2008)
376 void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode)
378 this_->meth.draw_mode(this_->priv, mode);
385 * @author Martin Schaller (04/2008)
387 void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count)
389 this_->meth.draw_lines(this_->priv, gc->priv, p, count);
396 * @author Martin Schaller (04/2008)
398 void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r)
400 this_->meth.draw_circle(this_->priv, gc->priv, p, r);
407 * @author Martin Schaller (04/2008)
409 void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h)
411 this_->meth.draw_rectangle(this_->priv, gc->priv, p, w, h);
418 * @author Martin Schaller (04/2008)
420 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)
422 this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, p, dx, dy);
429 * @author Martin Schaller (04/2008)
431 void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font, char *text, int dx, int dy, struct point *ret, int estimate)
433 this_->meth.get_text_bbox(this_->priv, font->priv, text, dx, dy, ret, estimate);
440 * @author Martin Schaller (04/2008)
442 void graphics_overlay_disable(struct graphics *this_, int disable)
444 if (this_->meth.overlay_disable)
445 this_->meth.overlay_disable(this_->priv, disable);
452 * @author Martin Schaller (04/2008)
454 void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img)
456 this_->meth.draw_image(this_->priv, gc->priv, p, img->priv);
460 //##############################################################################################################
463 //# Authors: Martin Schaller (04/2008)
464 //##############################################################################################################
466 graphics_draw_drag(struct graphics *this_, struct point *p)
468 if (!this_->meth.draw_drag)
470 this_->meth.draw_drag(this_->priv, p);
475 graphics_background_gc(struct graphics *this_, struct graphics_gc *gc)
477 this_->meth.background_gc(this_->priv, gc ? gc->priv : NULL);
486 //##############################################################################################################
489 //# Authors: Martin Schaller (04/2008)
490 //##############################################################################################################
491 static void popup_view_html(struct popup_item *item, char *file)
494 sprintf(command,"firefox %s", file);
498 //##############################################################################################################
501 //# Authors: Martin Schaller (04/2008)
502 //##############################################################################################################
503 static void graphics_popup(struct display_list *list, struct popup_item **popup)
509 struct popup_item *curr_item,*last=NULL;
511 mr=map_rect_new(item->map, NULL, NULL, 0);
512 printf("id hi=0x%x lo=0x%x\n", item->id_hi, item->id_lo);
513 item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
515 if (item_attr_get(item, attr_name, &attr)) {
516 curr_item=popup_item_new_text(popup,attr.u.str,1);
517 if (item_attr_get(item, attr_info_html, &attr)) {
518 popup_item_new_func(&last,"HTML Info",1, popup_view_html, g_strdup(attr.u.str));
520 if (item_attr_get(item, attr_price_html, &attr)) {
521 popup_item_new_func(&last,"HTML Preis",2, popup_view_html, g_strdup(attr.u.str));
523 curr_item->submenu=last;
526 map_rect_destroy(mr);
534 * @author Martin Schaller (04/2008)
548 * @author Martin Schaller (04/2008)
550 static int xdisplay_free_list(gpointer key, gpointer value, gpointer user_data)
556 struct displayitem *di=l->data;
557 if (! di->displayed && di->item.type < type_line)
558 dbg(1,"warning: item '%s' not displayed\n", item_to_name(di->item.type));
570 * @author Martin Schaller (04/2008)
572 static void xdisplay_free(GHashTable *display_list)
574 g_hash_table_foreach_remove(display_list, xdisplay_free_list, NULL);
581 * @author Martin Schaller (04/2008)
583 void display_add(struct displaylist *displaylist, struct item *item, int count, struct point *pnt, char *label)
585 struct displayitem *di;
590 len=sizeof(*di)+count*sizeof(*pnt);
592 len+=strlen(label)+1;
596 di=(struct displayitem *)p;
598 p+=sizeof(*di)+count*sizeof(*pnt);
602 strcpy(di->label, label);
606 memcpy(di->pnt, pnt, count*sizeof(*pnt));
608 l=g_hash_table_lookup(displaylist->dl, GINT_TO_POINTER(item->type));
609 l=g_list_prepend(l, di);
610 g_hash_table_insert(displaylist->dl, GINT_TO_POINTER(item->type), l);
618 * @author Martin Schaller (04/2008)
620 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)
622 int i,x,y,tl,tlm,th,thm,tlsq,l;
628 if (gra->meth.get_text_bbox) {
629 gra->meth.get_text_bbox(gra->priv, font->priv, label, 0x10000, 0x0, pb, 1);
630 tl=(pb[2].x-pb[0].x);
631 th=(pb[0].y-pb[1].y);
639 for (i = 0 ; i < count-1 ; i++) {
662 dbg(0,"display_text: '%s', %d, %d, %d, %d %d\n", label, x, y, dx*0x10000/l, dy*0x10000/l, l);
664 if (x < gra->w && x + tl > 0 && y + tl > 0 && y - tl < gra->h)
665 gra->meth.draw_text(gra->priv, fg->priv, bg->priv, font->priv, label, &p_t, dx*0x10000/l, dy*0x10000/l);
670 static void display_draw_arrow(struct point *p, int dx, int dy, int l, struct graphics_gc *gc, struct graphics *gra)
673 pnt[0]=pnt[1]=pnt[2]=*p;
674 pnt[0].x+=-dx*l/65536+dy*l/65536;
675 pnt[0].y+=-dy*l/65536-dx*l/65536;
676 pnt[2].x+=-dx*l/65536-dy*l/65536;
677 pnt[2].y+=-dy*l/65536+dx*l/65536;
678 gra->meth.draw_lines(gra->priv, gc->priv, pnt, 3);
681 static void display_draw_arrows(struct displayitem *di, struct graphics_gc *gc, struct graphics *gra)
685 for (i = 0 ; i < di->count-1 ; i++) {
686 dx=di->pnt[i+1].x-di->pnt[i].x;
687 dy=di->pnt[i+1].y-di->pnt[i].y;
695 display_draw_arrow(&p, dx, dy, 10, gc, gra);
699 display_draw_arrow(&p, dx, dy, 10, gc, gra);
708 * @author Martin Schaller (04/2008)
710 static void xdisplay_draw_elements(struct graphics *gra, GHashTable *display_list, struct itemgra *itm)
713 GList *l,*ls,*es,*types;
715 struct graphics_gc *gc = NULL;
716 struct graphics_image *img;
725 type=GPOINTER_TO_INT(types->data);
726 ls=g_hash_table_lookup(display_list, GINT_TO_POINTER(type));
729 graphics_gc_destroy(gc);
733 struct displayitem *di;
737 gc=graphics_gc_new(gra);
738 gc->meth.gc_set_foreground(gc->priv, &e->color);
741 case element_polygon:
742 gra->meth.draw_polygon(gra->priv, gc->priv, di->pnt, di->count);
744 case element_polyline:
745 if (e->u.polyline.width > 1)
746 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
747 if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
748 graphics_gc_set_dashes(gc, e->u.polyline.width,
749 e->u.polyline.offset,
750 e->u.polyline.dash_table,
751 e->u.polyline.dash_num);
752 gra->meth.draw_lines(gra->priv, gc->priv, di->pnt, di->count);
755 if (e->u.circle.width > 1)
756 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
757 gra->meth.draw_circle(gra->priv, gc->priv, &di->pnt[0], e->u.circle.radius);
758 if (di->label && e->text_size) {
761 if (! gra->font[e->text_size])
762 gra->font[e->text_size]=graphics_font_new(gra, e->text_size*20, 0);
763 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);
768 if (! gra->font[e->text_size])
769 gra->font[e->text_size]=graphics_font_new(gra, e->text_size*20, 0);
770 label_line(gra, gra->gc[2], gra->gc[1], gra->font[e->text_size], di->pnt, di->count, di->label);
775 if (e->u.icon.src[0] == '/')
776 strcpy(path,e->u.icon.src);
778 sprintf(path,"%s/xpm/%s", navit_sharedir, e->u.icon.src);
779 img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation);
781 dbg(0,"failed to load icon '%s'\n", e->u.icon.src);
784 p.x=di->pnt[0].x - img->hot.x;
785 p.y=di->pnt[0].y - img->hot.y;
786 gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p, img->priv);
787 graphics_image_free(gra, img);
792 dbg(1,"image: '%s'\n", di->label);
793 if (gra->meth.draw_image_warp)
794 gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, di->pnt, di->count, di->label);
796 dbg(0,"draw_image_warp not supported by graphics driver drawing '%s'\n", di->label);
799 display_draw_arrows(di,gc,gra);
802 printf("Unhandled element type %d\n", e->type);
807 types=g_list_next(types);
812 graphics_gc_destroy(gc);
816 graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transformation *t)
822 struct graphics_gc *gc = NULL;
823 struct graphics_image *img;
829 struct element *e=es->data;
830 int count=e->coord_count;
831 struct point pnt[count+1];
833 transform(t, projection_screen, e->coord, pnt, count, 0);
835 transform(t, projection_screen, &c, pnt, 1, 0);
838 gc=graphics_gc_new(gra);
839 gc->meth.gc_set_foreground(gc->priv, &e->color);
841 case element_polyline:
842 if (e->u.polyline.width > 1)
843 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
844 if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
845 graphics_gc_set_dashes(gc, e->u.polyline.width,
846 e->u.polyline.offset,
847 e->u.polyline.dash_table,
848 e->u.polyline.dash_num);
849 gra->meth.draw_lines(gra->priv, gc->priv, pnt, count);
852 if (e->u.circle.width > 1)
853 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
854 gra->meth.draw_circle(gra->priv, gc->priv, &pnt[0], e->u.circle.radius);
855 if (label && e->text_size) {
858 if (! gra->font[e->text_size])
859 gra->font[e->text_size]=graphics_font_new(gra, e->text_size*20, 0);
860 gra->meth.draw_text(gra->priv, gra->gc[2]->priv, gra->gc[1]->priv, gra->font[e->text_size]->priv, label, &p, 0x10000, 0);
864 if (e->u.icon.src[0] == '/')
865 strcpy(path,e->u.icon.src);
867 sprintf(path,"%s/xpm/%s", navit_sharedir, e->u.icon.src);
868 img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation);
870 dbg(0,"failed to load icon '%s'\n", e->u.icon.src);
872 p.x=pnt[0].x - img->hot.x;
873 p.y=pnt[0].y - img->hot.y;
874 gra->meth.draw_image(gra->priv, gc->priv, &p, img->priv);
875 graphics_image_free(gra, img);
879 dbg(0,"dont know how to draw %d\n", e->type);
881 graphics_gc_destroy(gc);
890 * @author Martin Schaller (04/2008)
892 static void xdisplay_draw_layer(GHashTable *display_list, struct graphics *gra, struct layer *lay, int order)
900 if (order >= itm->order.min && order <= itm->order.max)
901 xdisplay_draw_elements(gra, display_list, itm);
902 itms=g_list_next(itms);
910 * @author Martin Schaller (04/2008)
912 static void xdisplay_draw(GHashTable *display_list, struct graphics *gra, struct layout *l, int order)
920 xdisplay_draw_layer(display_list, gra, lay, order);
921 lays=g_list_next(lays);
929 * @author Martin Schaller (04/2008)
931 extern void *route_selection;
937 * @author Martin Schaller (04/2008)
939 static void do_draw_map(struct displaylist *displaylist, struct transformation *t, struct map *m, int order)
944 int conv,count,max=16384;
945 struct point pnt[max];
946 struct coord ca[max];
948 struct map_selection *sel;
950 pro=map_projection(m);
951 conv=map_requires_conversion(m);
952 sel=transform_get_selection(t, pro, order);
954 mr=map_rect_new(m, route_selection);
956 mr=map_rect_new(m, sel);
958 map_selection_destroy(sel);
961 while ((item=map_rect_get_item(mr))) {
962 count=item_coord_get(item, ca, item->type < type_line ? 1: max);
963 if (item->type >= type_line && count < 2) {
964 dbg(1,"poly from map has only %d points\n", count);
967 if (item->type < type_line) {
968 if (! map_selection_contains_point(sel, &ca[0])) {
969 dbg(1,"point not visible\n");
972 } else if (item->type < type_area) {
973 if (! map_selection_contains_polyline(sel, ca, count)) {
974 dbg(1,"polyline not visible\n");
978 if (! map_selection_contains_polygon(sel, ca, count)) {
979 dbg(1,"polygon not visible\n");
984 dbg(0,"point count overflow\n", count);
985 count=transform(t, pro, ca, pnt, count, 1);
986 if (item->type >= type_line && count < 2) {
987 dbg(1,"poly from transform has only %d points\n", count);
990 if (!item_attr_get(item, attr_label, &attr))
992 if (conv && attr.u.str && attr.u.str[0]) {
993 char *str=map_convert_string(m, attr.u.str);
994 display_add(displaylist, item, count, pnt, str);
995 map_convert_free(str);
997 display_add(displaylist, item, count, pnt, attr.u.str);
999 map_rect_destroy(mr);
1000 map_selection_destroy(sel);
1007 * @author Martin Schaller (04/2008)
1009 static void do_draw(struct displaylist *displaylist, struct transformation *t, GList *mapsets, int order)
1013 struct mapset_handle *h;
1019 while ((m=mapset_next(h, 1))) {
1020 do_draw_map(displaylist, t, m, order);
1029 * @author Martin Schaller (04/2008)
1031 int graphics_ready(struct graphics *this_)
1033 return this_->ready;
1040 * @author Martin Schaller (04/2008)
1042 void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, struct layout *l, int callback)
1044 int order=transform_get_order(trans);
1048 // FIXME find a better place to set the background color
1050 graphics_gc_set_background(gra->gc[0], &l->color);
1051 graphics_gc_set_foreground(gra->gc[0], &l->color);
1052 gra->default_font = g_strdup(l->font);
1054 graphics_background_gc(gra, gra->gc[0]);
1055 gra->meth.draw_mode(gra->priv, draw_mode_begin);
1056 gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &p, 32767, 32767);
1058 xdisplay_draw(displaylist->dl, gra, l, order+l->order_delta);
1060 callback_list_call_attr_0(gra->cbl, attr_postdraw);
1061 gra->meth.draw_mode(gra->priv, draw_mode_end);
1068 * @author Martin Schaller (04/2008)
1070 void graphics_displaylist_move(struct displaylist *displaylist, int dx, int dy)
1072 struct displaylist_handle *dlh;
1073 struct displayitem *di;
1076 dlh=graphics_displaylist_open(displaylist);
1077 while ((di=graphics_displaylist_next(dlh))) {
1078 for (i = 0 ; i < di->count ; i++) {
1083 graphics_displaylist_close(dlh);
1090 * @author Martin Schaller (04/2008)
1092 void graphics_draw(struct graphics *gra, struct displaylist *displaylist, GList *mapsets, struct transformation *trans, struct layout *l)
1094 int order=transform_get_order(trans);
1099 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));
1102 xdisplay_free(displaylist->dl);
1103 dbg(1,"order=%d\n", order);
1107 for (i = 0 ; i < data_window_type_end; i++) {
1108 data_window_begin(co->data_window[i]);
1113 order+=l->order_delta;
1115 do_draw(displaylist, trans, mapsets, order);
1116 // profile(1,"do_draw");
1117 graphics_displaylist_draw(gra, displaylist, trans, l, 1);
1118 profile(1,"xdisplay_draw");
1122 for (i = 0 ; i < data_window_type_end; i++) {
1123 data_window_end(co->data_window[i]);
1133 * @author Martin Schaller (04/2008)
1135 struct displaylist_handle {
1136 GList *hl_head,*hl,*l;
1143 * @author Martin Schaller (04/2008)
1145 struct displaylist_handle * graphics_displaylist_open(struct displaylist *displaylist)
1147 struct displaylist_handle *ret;
1149 ret=g_new0(struct displaylist_handle, 1);
1150 ret->hl_head=ret->hl=g_hash_to_list(displaylist->dl);
1159 * @author Martin Schaller (04/2008)
1161 struct displayitem * graphics_displaylist_next(struct displaylist_handle *dlh)
1163 struct displayitem *ret;
1167 dlh->l=dlh->hl->data;
1168 dlh->hl=g_list_next(dlh->hl);
1171 dlh->l=g_list_next(dlh->l);
1179 * @author Martin Schaller (04/2008)
1181 void graphics_displaylist_close(struct displaylist_handle *dlh)
1183 g_list_free(dlh->hl_head);
1191 * @author Martin Schaller (04/2008)
1193 struct displaylist * graphics_displaylist_new(void)
1195 struct displaylist *ret=g_new(struct displaylist, 1);
1197 ret->dl=g_hash_table_new(NULL,NULL);
1206 * @author Martin Schaller (04/2008)
1208 struct item * graphics_displayitem_get_item(struct displayitem *di)
1217 * @author Martin Schaller (04/2008)
1219 char * graphics_displayitem_get_label(struct displayitem *di)
1228 * @author Martin Schaller (04/2008)
1230 static int within_dist_point(struct point *p0, struct point *p1, int dist)
1232 if (p0->x == 32767 || p0->y == 32767 || p1->x == 32767 || p1->y == 32767)
1234 if (p0->x == -32768 || p0->y == -32768 || p1->x == -32768 || p1->y == -32768)
1236 if ((p0->x-p1->x)*(p0->x-p1->x) + (p0->y-p1->y)*(p0->y-p1->y) <= dist*dist) {
1246 * @author Martin Schaller (04/2008)
1248 static int within_dist_line(struct point *p, struct point *line_p0, struct point *line_p1, int dist)
1252 struct point line_p;
1254 vx=line_p1->x-line_p0->x;
1255 vy=line_p1->y-line_p0->y;
1261 return within_dist_point(p, line_p0, dist);
1264 return within_dist_point(p, line_p1, dist);
1266 line_p.x=line_p0->x+vx*c1/c2;
1267 line_p.y=line_p0->y+vy*c1/c2;
1268 return within_dist_point(p, &line_p, dist);
1275 * @author Martin Schaller (04/2008)
1277 static int within_dist_polyline(struct point *p, struct point *line_pnt, int count, int dist, int close)
1280 for (i = 0 ; i < count-1 ; i++) {
1281 if (within_dist_line(p,line_pnt+i,line_pnt+i+1,dist)) {
1286 return (within_dist_line(p,line_pnt,line_pnt+count-1,dist));
1294 * @author Martin Schaller (04/2008)
1296 static int within_dist_polygon(struct point *p, struct point *poly_pnt, int count, int dist)
1299 for (i = 0, j = count-1; i < count; j = i++) {
1300 if ((((poly_pnt[i].y <= p->y) && ( p->y < poly_pnt[j].y )) ||
1301 ((poly_pnt[j].y <= p->y) && ( p->y < poly_pnt[i].y))) &&
1302 (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))
1306 return within_dist_polyline(p, poly_pnt, count, dist, 1);
1314 * @author Martin Schaller (04/2008)
1316 int graphics_displayitem_within_dist(struct displayitem *di, struct point *p, int dist)
1318 if (di->item.type < type_line) {
1319 return within_dist_point(p, &di->pnt[0], dist);
1321 if (di->item.type < type_area) {
1322 return within_dist_polyline(p, di->pnt, di->count, dist, 0);
1324 return within_dist_polygon(p, di->pnt, di->count, dist);