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;
76 * Creates a new graphics object
80 * @author Martin Schaller (04/2008)
82 struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
84 struct graphics *this_;
85 struct attr *type_attr;
86 struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl);
88 if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
92 graphicstype_new=plugin_get_graphics_type(type_attr->u.str);
93 if (! graphicstype_new)
95 this_=g_new0(struct graphics, 1);
96 this_->cbl=callback_list_new();
97 this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, attrs, this_->cbl);
98 this_->attrs=attr_list_dup(attrs);
106 * @author Martin Schaller (04/2008)
108 int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
110 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
117 * @author Martin Schaller (04/2008)
119 struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h, int alpha, int wraparound)
121 struct graphics *this_;
122 if (!parent->meth.overlay_new)
124 this_=g_new0(struct graphics, 1);
125 this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h, alpha, wraparound);
137 * @author Martin Schaller (04/2008)
139 void graphics_init(struct graphics *this_)
141 this_->gc[0]=graphics_gc_new(this_);
142 graphics_gc_set_background(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7, 0xffff});
143 graphics_gc_set_foreground(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7, 0xffff });
144 this_->gc[1]=graphics_gc_new(this_);
145 graphics_gc_set_background(this_->gc[1], &(struct color) { 0x0000, 0x0000, 0x0000, 0xffff });
146 graphics_gc_set_foreground(this_->gc[1], &(struct color) { 0xffff, 0xffff, 0xffff, 0xffff });
147 this_->gc[2]=graphics_gc_new(this_);
148 graphics_gc_set_background(this_->gc[2], &(struct color) { 0xffff, 0xffff, 0xffff, 0xffff });
149 graphics_gc_set_foreground(this_->gc[2], &(struct color) { 0x0000, 0x0000, 0x0000, 0xffff });
150 graphics_background_gc(this_, this_->gc[0]);
151 navit_sharedir = getenv("NAVIT_SHAREDIR");
158 * @author Martin Schaller (04/2008)
160 void * graphics_get_data(struct graphics *this_, char *type)
162 return (this_->meth.get_data(this_->priv, type));
165 void graphics_add_callback(struct graphics *this_, struct callback *cb)
167 callback_list_add(this_->cbl, cb);
174 * @author Martin Schaller (04/2008)
176 struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags)
178 struct graphics_font *this_;
180 this_=g_new0(struct graphics_font,1);
181 this_->priv=gra->meth.font_new(gra->priv, &this_->meth, gra->default_font, size, flags);
186 * Free all loaded fonts.
187 * Used when switching layouts.
188 * @param gra The graphics instance
190 * @author Sarah Nordstrom (05/2008)
192 void graphics_font_destroy_all(struct graphics *gra)
195 for(i = 0 ; i < sizeof(gra->font) / sizeof(gra->font[0]); i++) {
196 if(!gra->font[i]) continue;
197 gra->font[i]->meth.font_destroy(gra->font[i]->priv);
206 * @author Martin Schaller (04/2008)
208 struct graphics_gc * graphics_gc_new(struct graphics *gra)
210 struct graphics_gc *this_;
212 this_=g_new0(struct graphics_gc,1);
213 this_->priv=gra->meth.gc_new(gra->priv, &this_->meth);
221 * @author Martin Schaller (04/2008)
223 void graphics_gc_destroy(struct graphics_gc *gc)
225 gc->meth.gc_destroy(gc->priv);
233 * @author Martin Schaller (04/2008)
235 void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c)
237 gc->meth.gc_set_foreground(gc->priv, c);
244 * @author Martin Schaller (04/2008)
246 void graphics_gc_set_background(struct graphics_gc *gc, struct color *c)
248 gc->meth.gc_set_background(gc->priv, c);
255 * @author Martin Schaller (04/2008)
257 void graphics_gc_set_linewidth(struct graphics_gc *gc, int width)
259 gc->meth.gc_set_linewidth(gc->priv, width);
266 * @author Martin Schaller (04/2008)
268 void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsigned char dash_list[], int n)
270 if (gc->meth.gc_set_dashes)
271 gc->meth.gc_set_dashes(gc->priv, width, offset, dash_list, n);
275 * Create a new image from file path scaled to w and h pixels
276 * @param gra the graphics instance
277 * @param path path of the image to load
278 * @param w width to rescale to
279 * @param h height to rescale to
281 * @author Martin Schaller (04/2008)
283 struct graphics_image * graphics_image_new_scaled(struct graphics *gra, char *path, int w, int h)
285 struct graphics_image *this_;
287 this_=g_new0(struct graphics_image,1);
290 this_->priv=gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, 0);
299 * Create a new image from file path scaled to w and h pixels and possibly rotated
300 * @param gra the graphics instance
301 * @param path path of the image to load
302 * @param w width to rescale to
303 * @param h height to rescale to
304 * @param rotate angle to rotate the image. Warning, graphics might only support 90 degree steps here
306 * @author Martin Schaller (04/2008)
308 struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra, char *path, int w, int h, int rotate)
310 struct graphics_image *this_;
312 this_=g_new0(struct graphics_image,1);
315 this_->priv=gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot, rotate);
324 * Create a new image from file path
325 * @param gra the graphics instance
326 * @param path path of the image to load
328 * @author Martin Schaller (04/2008)
330 struct graphics_image * graphics_image_new(struct graphics *gra, char *path)
332 return graphics_image_new_scaled(gra, path, -1, -1);
339 * @author Martin Schaller (04/2008)
341 void graphics_image_free(struct graphics *gra, struct graphics_image *img)
343 if (gra->meth.image_free)
344 gra->meth.image_free(gra->priv, img->priv);
352 * @author Martin Schaller (04/2008)
354 void graphics_draw_restore(struct graphics *this_, struct point *p, int w, int h)
356 this_->meth.draw_restore(this_->priv, p, w, h);
363 * @author Martin Schaller (04/2008)
365 void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode)
367 this_->meth.draw_mode(this_->priv, mode);
374 * @author Martin Schaller (04/2008)
376 void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count)
378 this_->meth.draw_lines(this_->priv, gc->priv, p, count);
385 * @author Martin Schaller (04/2008)
387 void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r)
389 this_->meth.draw_circle(this_->priv, gc->priv, p, r);
396 * @author Martin Schaller (04/2008)
398 void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h)
400 this_->meth.draw_rectangle(this_->priv, gc->priv, p, w, h);
407 * @author Martin Schaller (04/2008)
409 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)
411 this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, p, dx, dy);
418 * @author Martin Schaller (04/2008)
420 void graphics_get_text_bbox(struct graphics *this_, struct graphics_font *font, char *text, int dx, int dy, struct point *ret)
422 this_->meth.get_text_bbox(this_->priv, font->priv, text, dx, dy, ret);
429 * @author Martin Schaller (04/2008)
431 void graphics_overlay_disable(struct graphics *this_, int disable)
433 if (this_->meth.overlay_disable)
434 this_->meth.overlay_disable(this_->priv, disable);
441 * @author Martin Schaller (04/2008)
443 void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img)
445 this_->meth.draw_image(this_->priv, gc->priv, p, img->priv);
449 //##############################################################################################################
452 //# Authors: Martin Schaller (04/2008)
453 //##############################################################################################################
455 graphics_draw_drag(struct graphics *this_, struct point *p)
457 if (!this_->meth.draw_drag)
459 this_->meth.draw_drag(this_->priv, p);
464 graphics_background_gc(struct graphics *this_, struct graphics_gc *gc)
466 this_->meth.background_gc(this_->priv, gc ? gc->priv : NULL);
475 //##############################################################################################################
478 //# Authors: Martin Schaller (04/2008)
479 //##############################################################################################################
480 static void popup_view_html(struct popup_item *item, char *file)
483 sprintf(command,"firefox %s", file);
487 //##############################################################################################################
490 //# Authors: Martin Schaller (04/2008)
491 //##############################################################################################################
492 static void graphics_popup(struct display_list *list, struct popup_item **popup)
498 struct popup_item *curr_item,*last=NULL;
500 mr=map_rect_new(item->map, NULL, NULL, 0);
501 printf("id hi=0x%x lo=0x%x\n", item->id_hi, item->id_lo);
502 item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
504 if (item_attr_get(item, attr_name, &attr)) {
505 curr_item=popup_item_new_text(popup,attr.u.str,1);
506 if (item_attr_get(item, attr_info_html, &attr)) {
507 popup_item_new_func(&last,"HTML Info",1, popup_view_html, g_strdup(attr.u.str));
509 if (item_attr_get(item, attr_price_html, &attr)) {
510 popup_item_new_func(&last,"HTML Preis",2, popup_view_html, g_strdup(attr.u.str));
512 curr_item->submenu=last;
515 map_rect_destroy(mr);
523 * @author Martin Schaller (04/2008)
537 * @author Martin Schaller (04/2008)
539 static int xdisplay_free_list(gpointer key, gpointer value, gpointer user_data)
545 struct displayitem *di=l->data;
546 if (! di->displayed && di->item.type < type_line)
547 dbg(1,"warning: item '%s' not displayed\n", item_to_name(di->item.type));
559 * @author Martin Schaller (04/2008)
561 static void xdisplay_free(GHashTable *display_list)
563 g_hash_table_foreach_remove(display_list, xdisplay_free_list, NULL);
570 * @author Martin Schaller (04/2008)
572 void display_add(struct displaylist *displaylist, struct item *item, int count, struct point *pnt, char *label)
574 struct displayitem *di;
579 len=sizeof(*di)+count*sizeof(*pnt);
581 len+=strlen(label)+1;
585 di=(struct displayitem *)p;
587 p+=sizeof(*di)+count*sizeof(*pnt);
591 strcpy(di->label, label);
595 memcpy(di->pnt, pnt, count*sizeof(*pnt));
597 l=g_hash_table_lookup(displaylist->dl, GINT_TO_POINTER(item->type));
598 l=g_list_prepend(l, di);
599 g_hash_table_insert(displaylist->dl, GINT_TO_POINTER(item->type), l);
607 * @author Martin Schaller (04/2008)
609 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)
615 tl=strlen(label)*400;
616 for (i = 0 ; i < count-1 ; i++) {
621 l=(int)sqrt((float)(dx*dx+dy*dy));
638 printf("display_text: '%s', %d, %d, %d, %d %d\n", label, x, y, dx*0x10000/l, dy*0x10000/l, l);
640 gra->meth.draw_text(gra->priv, fg->priv, bg->priv, font->priv, label, &p_t, dx*0x10000/l, dy*0x10000/l);
645 static void display_draw_arrow(struct point *p, int dx, int dy, int l, struct graphics_gc *gc, struct graphics *gra)
648 pnt[0]=pnt[1]=pnt[2]=*p;
649 pnt[0].x+=-dx*l/65536+dy*l/65536;
650 pnt[0].y+=-dy*l/65536-dx*l/65536;
651 pnt[2].x+=-dx*l/65536-dy*l/65536;
652 pnt[2].y+=-dy*l/65536+dx*l/65536;
653 gra->meth.draw_lines(gra->priv, gc->priv, pnt, 3);
656 static void display_draw_arrows(struct displayitem *di, struct graphics_gc *gc, struct graphics *gra)
660 for (i = 0 ; i < di->count-1 ; i++) {
661 dx=di->pnt[i+1].x-di->pnt[i].x;
662 dy=di->pnt[i+1].y-di->pnt[i].y;
670 display_draw_arrow(&p, dx, dy, 10, gc, gra);
674 display_draw_arrow(&p, dx, dy, 10, gc, gra);
683 * @author Martin Schaller (04/2008)
685 static void xdisplay_draw_elements(struct graphics *gra, GHashTable *display_list, struct itemgra *itm)
688 GList *l,*ls,*es,*types;
690 struct graphics_gc *gc = NULL;
691 struct graphics_image *img;
700 type=GPOINTER_TO_INT(types->data);
701 ls=g_hash_table_lookup(display_list, GINT_TO_POINTER(type));
704 graphics_gc_destroy(gc);
708 struct displayitem *di;
712 gc=graphics_gc_new(gra);
713 gc->meth.gc_set_foreground(gc->priv, &e->color);
716 case element_polygon:
717 gra->meth.draw_polygon(gra->priv, gc->priv, di->pnt, di->count);
719 case element_polyline:
720 if (e->u.polyline.width > 1)
721 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
722 if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
723 graphics_gc_set_dashes(gc, e->u.polyline.width,
724 e->u.polyline.offset,
725 e->u.polyline.dash_table,
726 e->u.polyline.dash_num);
727 gra->meth.draw_lines(gra->priv, gc->priv, di->pnt, di->count);
730 if (e->u.circle.width > 1)
731 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
732 gra->meth.draw_circle(gra->priv, gc->priv, &di->pnt[0], e->u.circle.radius);
733 if (di->label && e->text_size) {
736 if (! gra->font[e->text_size])
737 gra->font[e->text_size]=graphics_font_new(gra, e->text_size*20, 0);
738 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);
743 if (! gra->font[e->text_size])
744 gra->font[e->text_size]=graphics_font_new(gra, e->text_size*20, 0);
745 label_line(gra, gra->gc[2], gra->gc[1], gra->font[e->text_size], di->pnt, di->count, di->label);
750 sprintf(path,"%s/xpm/%s", navit_sharedir, e->u.icon.src);
751 img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation);
753 dbg(0,"failed to load icon '%s'\n", e->u.icon.src);
756 p.x=di->pnt[0].x - img->hot.x;
757 p.y=di->pnt[0].y - img->hot.y;
758 gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p, img->priv);
759 graphics_image_free(gra, img);
764 dbg(1,"image: '%s'\n", di->label);
765 if (gra->meth.draw_image_warp)
766 gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, di->pnt, di->count, di->label);
768 dbg(0,"draw_image_warp not supported by graphics driver drawing '%s'\n", di->label);
771 display_draw_arrows(di,gc,gra);
774 printf("Unhandled element type %d\n", e->type);
779 types=g_list_next(types);
784 graphics_gc_destroy(gc);
788 graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct transformation *t)
794 struct graphics_gc *gc = NULL;
795 struct graphics_image *img;
801 struct element *e=es->data;
802 int count=e->coord_count;
803 struct point pnt[count+1];
805 transform(t, projection_screen, e->coord, pnt, count, 0);
807 transform(t, projection_screen, &c, pnt, 1, 0);
810 gc=graphics_gc_new(gra);
811 gc->meth.gc_set_foreground(gc->priv, &e->color);
813 case element_polyline:
814 if (e->u.polyline.width > 1)
815 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
816 if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
817 graphics_gc_set_dashes(gc, e->u.polyline.width,
818 e->u.polyline.offset,
819 e->u.polyline.dash_table,
820 e->u.polyline.dash_num);
821 gra->meth.draw_lines(gra->priv, gc->priv, pnt, count);
824 if (e->u.circle.width > 1)
825 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
826 gra->meth.draw_circle(gra->priv, gc->priv, &pnt[0], e->u.circle.radius);
827 if (label && e->text_size) {
830 if (! gra->font[e->text_size])
831 gra->font[e->text_size]=graphics_font_new(gra, e->text_size*20, 0);
832 gra->meth.draw_text(gra->priv, gra->gc[2]->priv, gra->gc[1]->priv, gra->font[e->text_size]->priv, label, &p, 0x10000, 0);
836 sprintf(path,"%s/xpm/%s", navit_sharedir, e->u.icon.src);
837 img=graphics_image_new_scaled_rotated(gra, path, e->u.icon.width, e->u.icon.height, e->u.icon.rotation);
839 dbg(0,"failed to load icon '%s'\n", e->u.icon.src);
841 p.x=pnt[0].x - img->hot.x;
842 p.y=pnt[0].y - img->hot.y;
843 gra->meth.draw_image(gra->priv, gc->priv, &p, img->priv);
844 graphics_image_free(gra, img);
848 dbg(0,"dont know how to draw %d\n", e->type);
850 graphics_gc_destroy(gc);
859 * @author Martin Schaller (04/2008)
861 static void xdisplay_draw_layer(GHashTable *display_list, struct graphics *gra, struct layer *lay, int order)
869 if (order >= itm->order.min && order <= itm->order.max)
870 xdisplay_draw_elements(gra, display_list, itm);
871 itms=g_list_next(itms);
879 * @author Martin Schaller (04/2008)
881 static void xdisplay_draw(GHashTable *display_list, struct graphics *gra, struct layout *l, int order)
889 xdisplay_draw_layer(display_list, gra, lay, order);
890 lays=g_list_next(lays);
898 * @author Martin Schaller (04/2008)
900 extern void *route_selection;
906 * @author Martin Schaller (04/2008)
908 static void do_draw_map(struct displaylist *displaylist, struct transformation *t, struct map *m, int order)
913 int conv,count,max=16384;
914 struct point pnt[max];
915 struct coord ca[max];
917 struct map_selection *sel;
919 pro=map_projection(m);
920 conv=map_requires_conversion(m);
921 sel=transform_get_selection(t, pro, order);
923 mr=map_rect_new(m, route_selection);
925 mr=map_rect_new(m, sel);
927 map_selection_destroy(sel);
930 while ((item=map_rect_get_item(mr))) {
931 count=item_coord_get(item, ca, item->type < type_line ? 1: max);
932 if (item->type >= type_line && count < 2) {
933 dbg(1,"poly from map has only %d points\n", count);
936 if (item->type < type_line) {
937 if (! map_selection_contains_point(sel, &ca[0])) {
938 dbg(1,"point not visible\n");
941 } else if (item->type < type_area) {
942 if (! map_selection_contains_polyline(sel, ca, count)) {
943 dbg(1,"polyline not visible\n");
947 if (! map_selection_contains_polygon(sel, ca, count)) {
948 dbg(1,"polygon not visible\n");
953 dbg(0,"point count overflow\n", count);
954 count=transform(t, pro, ca, pnt, count, 1);
955 if (item->type >= type_line && count < 2) {
956 dbg(1,"poly from transform has only %d points\n", count);
959 if (!item_attr_get(item, attr_label, &attr))
961 if (conv && attr.u.str && attr.u.str[0]) {
962 char *str=map_convert_string(m, attr.u.str);
963 display_add(displaylist, item, count, pnt, str);
964 map_convert_free(str);
966 display_add(displaylist, item, count, pnt, attr.u.str);
968 map_rect_destroy(mr);
969 map_selection_destroy(sel);
976 * @author Martin Schaller (04/2008)
978 static void do_draw(struct displaylist *displaylist, struct transformation *t, GList *mapsets, int order)
982 struct mapset_handle *h;
988 while ((m=mapset_next(h, 1))) {
989 do_draw_map(displaylist, t, m, order);
998 * @author Martin Schaller (04/2008)
1000 int graphics_ready(struct graphics *this_)
1002 return this_->ready;
1009 * @author Martin Schaller (04/2008)
1011 void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, struct layout *l, int callback)
1013 int order=transform_get_order(trans);
1017 // FIXME find a better place to set the background color
1018 graphics_gc_set_background(gra->gc[0], &l->color);
1019 graphics_gc_set_foreground(gra->gc[0], &l->color);
1020 gra->default_font = g_strdup(l->font);
1021 graphics_background_gc(gra, gra->gc[0]);
1022 gra->meth.draw_mode(gra->priv, draw_mode_begin);
1023 gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &p, 32767, 32767);
1024 xdisplay_draw(displaylist->dl, gra, l, order+l->order_delta);
1026 callback_list_call_attr_0(gra->cbl, attr_postdraw);
1027 gra->meth.draw_mode(gra->priv, draw_mode_end);
1034 * @author Martin Schaller (04/2008)
1036 void graphics_displaylist_move(struct displaylist *displaylist, int dx, int dy)
1038 struct displaylist_handle *dlh;
1039 struct displayitem *di;
1042 dlh=graphics_displaylist_open(displaylist);
1043 while ((di=graphics_displaylist_next(dlh))) {
1044 for (i = 0 ; i < di->count ; i++) {
1049 graphics_displaylist_close(dlh);
1056 * @author Martin Schaller (04/2008)
1058 void graphics_draw(struct graphics *gra, struct displaylist *displaylist, GList *mapsets, struct transformation *trans, struct layout *l)
1060 int order=transform_get_order(trans);
1065 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));
1068 xdisplay_free(displaylist->dl);
1069 dbg(1,"order=%d\n", order);
1073 for (i = 0 ; i < data_window_type_end; i++) {
1074 data_window_begin(co->data_window[i]);
1078 order+=l->order_delta;
1079 do_draw(displaylist, trans, mapsets, order);
1080 // profile(1,"do_draw");
1081 graphics_displaylist_draw(gra, displaylist, trans, l, 1);
1082 profile(1,"xdisplay_draw");
1086 for (i = 0 ; i < data_window_type_end; i++) {
1087 data_window_end(co->data_window[i]);
1097 * @author Martin Schaller (04/2008)
1099 struct displaylist_handle {
1100 GList *hl_head,*hl,*l;
1107 * @author Martin Schaller (04/2008)
1109 struct displaylist_handle * graphics_displaylist_open(struct displaylist *displaylist)
1111 struct displaylist_handle *ret;
1113 ret=g_new0(struct displaylist_handle, 1);
1114 ret->hl_head=ret->hl=g_hash_to_list(displaylist->dl);
1123 * @author Martin Schaller (04/2008)
1125 struct displayitem * graphics_displaylist_next(struct displaylist_handle *dlh)
1127 struct displayitem *ret;
1131 dlh->l=dlh->hl->data;
1132 dlh->hl=g_list_next(dlh->hl);
1135 dlh->l=g_list_next(dlh->l);
1143 * @author Martin Schaller (04/2008)
1145 void graphics_displaylist_close(struct displaylist_handle *dlh)
1147 g_list_free(dlh->hl_head);
1155 * @author Martin Schaller (04/2008)
1157 struct displaylist * graphics_displaylist_new(void)
1159 struct displaylist *ret=g_new(struct displaylist, 1);
1161 ret->dl=g_hash_table_new(NULL,NULL);
1170 * @author Martin Schaller (04/2008)
1172 struct item * graphics_displayitem_get_item(struct displayitem *di)
1181 * @author Martin Schaller (04/2008)
1183 char * graphics_displayitem_get_label(struct displayitem *di)
1192 * @author Martin Schaller (04/2008)
1194 static int within_dist_point(struct point *p0, struct point *p1, int dist)
1196 if (p0->x == 32767 || p0->y == 32767 || p1->x == 32767 || p1->y == 32767)
1198 if (p0->x == -32768 || p0->y == -32768 || p1->x == -32768 || p1->y == -32768)
1200 if ((p0->x-p1->x)*(p0->x-p1->x) + (p0->y-p1->y)*(p0->y-p1->y) <= dist*dist) {
1210 * @author Martin Schaller (04/2008)
1212 static int within_dist_line(struct point *p, struct point *line_p0, struct point *line_p1, int dist)
1216 struct point line_p;
1218 vx=line_p1->x-line_p0->x;
1219 vy=line_p1->y-line_p0->y;
1225 return within_dist_point(p, line_p0, dist);
1228 return within_dist_point(p, line_p1, dist);
1230 line_p.x=line_p0->x+vx*c1/c2;
1231 line_p.y=line_p0->y+vy*c1/c2;
1232 return within_dist_point(p, &line_p, dist);
1239 * @author Martin Schaller (04/2008)
1241 static int within_dist_polyline(struct point *p, struct point *line_pnt, int count, int dist, int close)
1244 for (i = 0 ; i < count-1 ; i++) {
1245 if (within_dist_line(p,line_pnt+i,line_pnt+i+1,dist)) {
1250 return (within_dist_line(p,line_pnt,line_pnt+count-1,dist));
1258 * @author Martin Schaller (04/2008)
1260 static int within_dist_polygon(struct point *p, struct point *poly_pnt, int count, int dist)
1263 for (i = 0, j = count-1; i < count; j = i++) {
1264 if ((((poly_pnt[i].y <= p->y) && ( p->y < poly_pnt[j].y )) ||
1265 ((poly_pnt[j].y <= p->y) && ( p->y < poly_pnt[i].y))) &&
1266 (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))
1270 return within_dist_polyline(p, poly_pnt, count, dist, 1);
1278 * @author Martin Schaller (04/2008)
1280 int graphics_displayitem_within_dist(struct displayitem *di, struct point *p, int dist)
1282 if (di->item.type < type_line) {
1283 return within_dist_point(p, &di->pnt[0], dist);
1285 if (di->item.type < type_area) {
1286 return within_dist_polyline(p, di->pnt, di->count, dist, 0);
1288 return within_dist_polygon(p, di->pnt, di->count, dist);