1 //##############################################################################################################
6 //# Authors: Martin Schaller (04/2008)
8 //##############################################################################################################
16 #include "draw_info.h"
19 #include "projection.h"
22 #include "transform.h"
30 //##############################################################################################################
33 //# Authors: Martin Schaller (04/2008)
34 //##############################################################################################################
37 struct graphics_priv *priv;
38 struct graphics_methods meth;
39 struct graphics_font *font[16];
40 struct graphics_gc *gc[3];
44 //##############################################################################################################
47 //# Authors: Martin Schaller (04/2008)
48 //##############################################################################################################
52 //##############################################################################################################
53 //# Description: Creates a new graphics object
54 //# Comment: attr type required
55 //# Authors: Martin Schaller (04/2008)
56 //##############################################################################################################
57 struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
59 struct graphics *this_;
60 struct attr *type_attr;
61 struct graphics_priv * (*graphicstype_new)(struct graphics_methods *meth, struct attr **attrs);
63 if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
67 graphicstype_new=plugin_get_graphics_type(type_attr->u.str);
68 if (! graphicstype_new)
70 this_=g_new0(struct graphics, 1);
71 this_->priv=(*graphicstype_new)(&this_->meth, attrs);
72 this_->attrs=attr_list_dup(attrs);
76 //##############################################################################################################
79 //# Authors: Martin Schaller (04/2008)
80 //##############################################################################################################
81 int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
83 return attr_generic_get_attr(this_->attrs, type, attr, iter);
86 //##############################################################################################################
89 //# Authors: Martin Schaller (04/2008)
90 //##############################################################################################################
91 struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h)
93 struct graphics *this_;
94 this_=g_new0(struct graphics, 1);
95 this_->priv=parent->meth.overlay_new(parent->priv, &this_->meth, p, w, h);
99 //##############################################################################################################
102 //# Authors: Martin Schaller (04/2008)
103 //##############################################################################################################
104 void graphics_init(struct graphics *this_)
106 this_->gc[0]=graphics_gc_new(this_);
107 graphics_gc_set_background(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7 });
108 graphics_gc_set_foreground(this_->gc[0], &(struct color) { 0xffff, 0xefef, 0xb7b7 });
109 this_->gc[1]=graphics_gc_new(this_);
110 graphics_gc_set_background(this_->gc[1], &(struct color) { 0x0000, 0x0000, 0x0000 });
111 graphics_gc_set_foreground(this_->gc[1], &(struct color) { 0xffff, 0xffff, 0xffff });
112 this_->gc[2]=graphics_gc_new(this_);
113 graphics_gc_set_background(this_->gc[2], &(struct color) { 0xffff, 0xffff, 0xffff });
114 graphics_gc_set_foreground(this_->gc[2], &(struct color) { 0xffff, 0xffff, 0xffff });
115 this_->meth.background_gc(this_->priv, this_->gc[0]->priv);
118 //##############################################################################################################
121 //# Authors: Martin Schaller (04/2008)
122 //##############################################################################################################
123 void * graphics_get_data(struct graphics *this_, char *type)
125 return (this_->meth.get_data(this_->priv, type));
128 //##############################################################################################################
131 //# Authors: Martin Schaller (04/2008)
132 //##############################################################################################################
133 void graphics_register_resize_callback(struct graphics *this_, void (*callback)(void *data, int w, int h), void *data)
135 this_->meth.register_resize_callback(this_->priv, callback, data);
138 //##############################################################################################################
140 //# Comment: Called in navit.c
141 //# Authors: Martin Schaller (04/2008)
142 //##############################################################################################################
143 void graphics_register_button_callback(struct graphics *this_, void (*callback)(void *data, int pressed, int button, struct point *p), void *data)
145 this_->meth.register_button_callback(this_->priv, callback, data);
148 //##############################################################################################################
151 //# Authors: Martin Schaller (04/2008)
152 //##############################################################################################################
153 void graphics_register_motion_callback(struct graphics *this_, void (*callback)(void *data, struct point *p), void *data)
155 this_->meth.register_motion_callback(this_->priv, callback, data);
158 //##############################################################################################################
161 //# Authors: Martin Schaller (04/2008)
162 //##############################################################################################################
163 struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags)
165 struct graphics_font *this_;
167 this_=g_new0(struct graphics_font,1);
168 this_->priv=gra->meth.font_new(gra->priv, &this_->meth, size, flags);
172 //##############################################################################################################
175 //# Authors: Martin Schaller (04/2008)
176 //##############################################################################################################
177 struct graphics_gc * graphics_gc_new(struct graphics *gra)
179 struct graphics_gc *this_;
181 this_=g_new0(struct graphics_gc,1);
182 this_->priv=gra->meth.gc_new(gra->priv, &this_->meth);
186 //##############################################################################################################
189 //# Authors: Martin Schaller (04/2008)
190 //##############################################################################################################
191 void graphics_gc_destroy(struct graphics_gc *gc)
193 gc->meth.gc_destroy(gc->priv);
197 //##############################################################################################################
200 //# Authors: Martin Schaller (04/2008)
201 //##############################################################################################################
202 void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c)
204 gc->meth.gc_set_foreground(gc->priv, c);
207 //##############################################################################################################
210 //# Authors: Martin Schaller (04/2008)
211 //##############################################################################################################
212 void graphics_gc_set_background(struct graphics_gc *gc, struct color *c)
214 gc->meth.gc_set_background(gc->priv, c);
217 //##############################################################################################################
220 //# Authors: Martin Schaller (04/2008)
221 //##############################################################################################################
222 void graphics_gc_set_linewidth(struct graphics_gc *gc, int width)
224 gc->meth.gc_set_linewidth(gc->priv, width);
227 //##############################################################################################################
230 //# Authors: Martin Schaller (04/2008)
231 //##############################################################################################################
232 void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsigned char dash_list[], int n)
234 if (gc->meth.gc_set_dashes)
235 gc->meth.gc_set_dashes(gc->priv, width, offset, dash_list, n);
238 //##############################################################################################################
241 //# Authors: Martin Schaller (04/2008)
242 //##############################################################################################################
243 struct graphics_image * graphics_image_new(struct graphics *gra, char *path)
245 struct graphics_image *this_;
247 this_=g_new0(struct graphics_image,1);
248 this_->priv=gra->meth.image_new(gra->priv, &this_->meth, path, &this_->width, &this_->height, &this_->hot);
256 //##############################################################################################################
259 //# Authors: Martin Schaller (04/2008)
260 //##############################################################################################################
261 void graphics_image_free(struct graphics *gra, struct graphics_image *img)
263 if (gra->meth.image_free)
264 gra->meth.image_free(gra->priv, img->priv);
268 //##############################################################################################################
271 //# Authors: Martin Schaller (04/2008)
272 //##############################################################################################################
273 void graphics_draw_restore(struct graphics *this_, struct point *p, int w, int h)
275 this_->meth.draw_restore(this_->priv, p, w, h);
278 //##############################################################################################################
281 //# Authors: Martin Schaller (04/2008)
282 //##############################################################################################################
283 void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode)
285 this_->meth.draw_mode(this_->priv, mode);
288 //##############################################################################################################
291 //# Authors: Martin Schaller (04/2008)
292 //##############################################################################################################
293 void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count)
295 this_->meth.draw_lines(this_->priv, gc->priv, p, count);
298 //##############################################################################################################
301 //# Authors: Martin Schaller (04/2008)
302 //##############################################################################################################
303 void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r)
305 this_->meth.draw_circle(this_->priv, gc->priv, p, r);
308 //##############################################################################################################
311 //# Authors: Martin Schaller (04/2008)
312 //##############################################################################################################
313 void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h)
315 this_->meth.draw_rectangle(this_->priv, gc->priv, p, w, h);
318 //##############################################################################################################
321 //# Authors: Martin Schaller (04/2008)
322 //##############################################################################################################
323 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)
325 this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, p, dx, dy);
328 //##############################################################################################################
331 //# Authors: Martin Schaller (04/2008)
332 //##############################################################################################################
333 void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img)
335 this_->meth.draw_image(this_->priv, gc->priv, p, img->priv);
344 //##############################################################################################################
347 //# Authors: Martin Schaller (04/2008)
348 //##############################################################################################################
349 static void popup_view_html(struct popup_item *item, char *file)
352 sprintf(command,"firefox %s", file);
356 //##############################################################################################################
359 //# Authors: Martin Schaller (04/2008)
360 //##############################################################################################################
361 static void graphics_popup(struct display_list *list, struct popup_item **popup)
367 struct popup_item *curr_item,*last=NULL;
369 mr=map_rect_new(item->map, NULL, NULL, 0);
370 printf("id hi=0x%x lo=0x%x\n", item->id_hi, item->id_lo);
371 item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo);
373 if (item_attr_get(item, attr_name, &attr)) {
374 curr_item=popup_item_new_text(popup,attr.u.str,1);
375 if (item_attr_get(item, attr_info_html, &attr)) {
376 popup_item_new_func(&last,"HTML Info",1, popup_view_html, g_strdup(attr.u.str));
378 if (item_attr_get(item, attr_price_html, &attr)) {
379 popup_item_new_func(&last,"HTML Preis",2, popup_view_html, g_strdup(attr.u.str));
381 curr_item->submenu=last;
384 map_rect_destroy(mr);
388 //##############################################################################################################
391 //# Authors: Martin Schaller (04/2008)
392 //##############################################################################################################
401 //##############################################################################################################
404 //# Authors: Martin Schaller (04/2008)
405 //##############################################################################################################
406 static int xdisplay_free_list(gpointer key, gpointer value, gpointer user_data)
412 struct displayitem *di=l->data;
413 if (! di->displayed && di->item.type < type_line)
414 dbg(1,"warning: item '%s' not displayed\n", item_to_name(di->item.type));
422 //##############################################################################################################
425 //# Authors: Martin Schaller (04/2008)
426 //##############################################################################################################
427 static void xdisplay_free(GHashTable *display_list)
429 g_hash_table_foreach_remove(display_list, xdisplay_free_list, NULL);
432 //##############################################################################################################
435 //# Authors: Martin Schaller (04/2008)
436 //##############################################################################################################
437 void display_add(struct displaylist *displaylist, struct item *item, int count, struct point *pnt, char *label)
439 struct displayitem *di;
444 len=sizeof(*di)+count*sizeof(*pnt);
446 len+=strlen(label)+1;
450 di=(struct displayitem *)p;
452 p+=sizeof(*di)+count*sizeof(*pnt);
456 strcpy(di->label, label);
460 memcpy(di->pnt, pnt, count*sizeof(*pnt));
462 l=g_hash_table_lookup(displaylist->dl, GINT_TO_POINTER(item->type));
463 l=g_list_prepend(l, di);
464 g_hash_table_insert(displaylist->dl, GINT_TO_POINTER(item->type), l);
468 //##############################################################################################################
471 //# Authors: Martin Schaller (04/2008)
472 //##############################################################################################################
473 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)
479 tl=strlen(label)*400;
480 for (i = 0 ; i < count-1 ; i++) {
485 l=(int)sqrt((float)(dx*dx+dy*dy));
502 printf("display_text: '%s', %d, %d, %d, %d %d\n", label, x, y, dx*0x10000/l, dy*0x10000/l, l);
504 gra->meth.draw_text(gra->priv, fg->priv, bg->priv, font->priv, label, &p_t, dx*0x10000/l, dy*0x10000/l);
509 //##############################################################################################################
512 //# Authors: Martin Schaller (04/2008)
513 //##############################################################################################################
514 static void xdisplay_draw_elements(struct graphics *gra, GHashTable *display_list, struct itemtype *itm)
517 GList *l,*ls,*es,*types;
519 struct graphics_gc *gc = NULL;
520 struct graphics_image *img;
528 type=GPOINTER_TO_INT(types->data);
529 ls=g_hash_table_lookup(display_list, GINT_TO_POINTER(type));
532 graphics_gc_destroy(gc);
536 struct displayitem *di;
540 gc=graphics_gc_new(gra);
541 gc->meth.gc_set_foreground(gc->priv, &e->color);
544 case element_polygon:
545 gra->meth.draw_polygon(gra->priv, gc->priv, di->pnt, di->count);
547 case element_polyline:
548 if (e->u.polyline.width > 1)
549 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
550 if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
551 graphics_gc_set_dashes(gc, e->u.polyline.width, 0,
552 e->u.polyline.dash_table,
553 e->u.polyline.dash_num);
554 gra->meth.draw_lines(gra->priv, gc->priv, di->pnt, di->count);
557 if (e->u.circle.width > 1)
558 gc->meth.gc_set_linewidth(gc->priv, e->u.polyline.width);
559 gra->meth.draw_circle(gra->priv, gc->priv, &di->pnt[0], e->u.circle.radius);
560 if (di->label && e->label_size) {
563 if (! gra->font[e->label_size])
564 gra->font[e->label_size]=graphics_font_new(gra, e->label_size*20, 0);
565 gra->meth.draw_text(gra->priv, gra->gc[2]->priv, gra->gc[1]->priv, gra->font[e->label_size]->priv, di->label, &p, 0x10000, 0);
570 if (! gra->font[e->label_size])
571 gra->font[e->label_size]=graphics_font_new(gra, e->label_size*20, 0);
572 label_line(gra, gra->gc[2], gra->gc[1], gra->font[e->label_size], di->pnt, di->count, di->label);
577 char *icon=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/xpm/", e->u.icon.src, NULL);
578 img=graphics_image_new(gra, icon);
581 g_warning("failed to load icon '%s'\n", e->u.icon.src);
584 p.x=di->pnt[0].x - img->hot.x;
585 p.y=di->pnt[0].y - img->hot.y;
586 gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p, img->priv);
587 graphics_image_free(gra, img);
592 dbg(1,"image: '%s'\n", di->label);
593 if (gra->meth.draw_image_warp)
594 gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, di->pnt, di->count, di->label);
596 dbg(0,"draw_image_warp not supported by graphics driver drawing '%s'\n", di->label);
599 printf("Unhandled element type %d\n", e->type);
604 types=g_list_next(types);
609 graphics_gc_destroy(gc);
612 //##############################################################################################################
615 //# Authors: Martin Schaller (04/2008)
616 //##############################################################################################################
617 static void xdisplay_draw_layer(GHashTable *display_list, struct graphics *gra, struct layer *lay, int order)
620 struct itemtype *itm;
625 if (order >= itm->order_min && order <= itm->order_max)
626 xdisplay_draw_elements(gra, display_list, itm);
627 itms=g_list_next(itms);
631 //##############################################################################################################
634 //# Authors: Martin Schaller (04/2008)
635 //##############################################################################################################
636 static void xdisplay_draw(GHashTable *display_list, struct graphics *gra, struct layout *l, int order)
644 xdisplay_draw_layer(display_list, gra, lay, order);
645 lays=g_list_next(lays);
649 //##############################################################################################################
652 //# Authors: Martin Schaller (04/2008)
653 //##############################################################################################################
654 extern void *route_selection;
656 //##############################################################################################################
659 //# Authors: Martin Schaller (04/2008)
660 //##############################################################################################################
661 static void do_draw_map(struct displaylist *displaylist, struct transformation *t, struct map *m, int order)
666 int conv,count,max=16384;
667 struct point pnt[max];
668 struct coord ca[max];
670 struct map_selection *sel;
672 pro=map_projection(m);
673 conv=map_requires_conversion(m);
674 sel=transform_get_selection(t, pro, order);
676 mr=map_rect_new(m, route_selection);
678 mr=map_rect_new(m, sel);
680 map_selection_destroy(sel);
683 while ((item=map_rect_get_item(mr))) {
684 count=item_coord_get(item, ca, item->type < type_line ? 1: max);
685 if (item->type >= type_line && count < 2) {
686 dbg(1,"poly from map has only %d points\n", count);
689 if (item->type < type_line) {
690 if (! map_selection_contains_point(sel, &ca[0])) {
691 dbg(1,"point not visible\n");
694 } else if (item->type < type_area) {
695 if (! map_selection_contains_polyline(sel, ca, count)) {
696 dbg(1,"polyline not visible\n");
700 if (! map_selection_contains_polygon(sel, ca, count)) {
701 dbg(1,"polygon not visible\n");
706 dbg(0,"point count overflow\n", count);
707 count=transform(t, pro, ca, pnt, count, 1);
708 if (item->type >= type_line && count < 2) {
709 dbg(1,"poly from transform has only %d points\n", count);
712 if (!item_attr_get(item, attr_label, &attr))
714 if (conv && attr.u.str && attr.u.str[0]) {
715 char *str=map_convert_string(m, attr.u.str);
716 display_add(displaylist, item, count, pnt, str);
717 map_convert_free(str);
719 display_add(displaylist, item, count, pnt, attr.u.str);
721 map_rect_destroy(mr);
722 map_selection_destroy(sel);
725 //##############################################################################################################
728 //# Authors: Martin Schaller (04/2008)
729 //##############################################################################################################
730 static void do_draw(struct displaylist *displaylist, struct transformation *t, GList *mapsets, int order)
734 struct mapset_handle *h;
740 while ((m=mapset_next(h, 1))) {
741 do_draw_map(displaylist, t, m, order);
746 //##############################################################################################################
749 //# Authors: Martin Schaller (04/2008)
750 //##############################################################################################################
751 int graphics_ready(struct graphics *this_)
756 //##############################################################################################################
759 //# Authors: Martin Schaller (04/2008)
760 //##############################################################################################################
761 void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, struct layout *l)
763 int order=transform_get_order(trans);
767 // FIXME find a better place to set the background color
768 graphics_gc_set_background(gra->gc[0], l->color);
769 graphics_gc_set_foreground(gra->gc[0], l->color);
770 gra->meth.background_gc(gra->priv, gra->gc[0]->priv);
771 gra->meth.draw_mode(gra->priv, draw_mode_begin);
772 gra->meth.draw_rectangle(gra->priv, gra->gc[0]->priv, &p, 32767, 32767);
773 xdisplay_draw(displaylist->dl, gra, l, order);
774 gra->meth.draw_mode(gra->priv, draw_mode_end);
777 //##############################################################################################################
780 //# Authors: Martin Schaller (04/2008)
781 //##############################################################################################################
782 void graphics_displaylist_move(struct displaylist *displaylist, int dx, int dy)
784 struct displaylist_handle *dlh;
785 struct displayitem *di;
788 dlh=graphics_displaylist_open(displaylist);
789 while ((di=graphics_displaylist_next(dlh))) {
790 for (i = 0 ; i < di->count ; i++) {
795 graphics_displaylist_close(dlh);
798 //##############################################################################################################
801 //# Authors: Martin Schaller (04/2008)
802 //##############################################################################################################
803 void graphics_draw(struct graphics *gra, struct displaylist *displaylist, GList *mapsets, struct transformation *trans, struct layout *l)
805 int order=transform_get_order(trans);
810 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));
813 xdisplay_free(displaylist->dl);
814 dbg(1,"order=%d\n", order);
818 for (i = 0 ; i < data_window_type_end; i++) {
819 data_window_begin(co->data_window[i]);
823 do_draw(displaylist, trans, mapsets, order);
824 // profile(1,"do_draw");
825 graphics_displaylist_draw(gra, displaylist, trans, l);
826 profile(1,"xdisplay_draw");
830 for (i = 0 ; i < data_window_type_end; i++) {
831 data_window_end(co->data_window[i]);
837 //##############################################################################################################
840 //# Authors: Martin Schaller (04/2008)
841 //##############################################################################################################
842 struct displaylist_handle {
843 GList *hl_head,*hl,*l;
846 //##############################################################################################################
849 //# Authors: Martin Schaller (04/2008)
850 //##############################################################################################################
851 struct displaylist_handle * graphics_displaylist_open(struct displaylist *displaylist)
853 struct displaylist_handle *ret;
855 ret=g_new0(struct displaylist_handle, 1);
856 ret->hl_head=ret->hl=g_hash_to_list(displaylist->dl);
861 //##############################################################################################################
864 //# Authors: Martin Schaller (04/2008)
865 //##############################################################################################################
866 struct displayitem * graphics_displaylist_next(struct displaylist_handle *dlh)
868 struct displayitem *ret;
872 dlh->l=dlh->hl->data;
873 dlh->hl=g_list_next(dlh->hl);
876 dlh->l=g_list_next(dlh->l);
880 //##############################################################################################################
883 //# Authors: Martin Schaller (04/2008)
884 //##############################################################################################################
885 void graphics_displaylist_close(struct displaylist_handle *dlh)
887 g_list_free(dlh->hl_head);
891 //##############################################################################################################
894 //# Authors: Martin Schaller (04/2008)
895 //##############################################################################################################
896 struct displaylist * graphics_displaylist_new(void)
898 struct displaylist *ret=g_new(struct displaylist, 1);
900 ret->dl=g_hash_table_new(NULL,NULL);
905 //##############################################################################################################
908 //# Authors: Martin Schaller (04/2008)
909 //##############################################################################################################
910 struct item * graphics_displayitem_get_item(struct displayitem *di)
915 //##############################################################################################################
918 //# Authors: Martin Schaller (04/2008)
919 //##############################################################################################################
920 char * graphics_displayitem_get_label(struct displayitem *di)
925 //##############################################################################################################
928 //# Authors: Martin Schaller (04/2008)
929 //##############################################################################################################
930 static int within_dist_point(struct point *p0, struct point *p1, int dist)
932 if (p0->x == 32767 || p0->y == 32767 || p1->x == 32767 || p1->y == 32767)
934 if (p0->x == -32768 || p0->y == -32768 || p1->x == -32768 || p1->y == -32768)
936 if ((p0->x-p1->x)*(p0->x-p1->x) + (p0->y-p1->y)*(p0->y-p1->y) <= dist*dist) {
942 //##############################################################################################################
945 //# Authors: Martin Schaller (04/2008)
946 //##############################################################################################################
947 static int within_dist_line(struct point *p, struct point *line_p0, struct point *line_p1, int dist)
953 vx=line_p1->x-line_p0->x;
954 vy=line_p1->y-line_p0->y;
960 return within_dist_point(p, line_p0, dist);
963 return within_dist_point(p, line_p1, dist);
965 line_p.x=line_p0->x+vx*c1/c2;
966 line_p.y=line_p0->y+vy*c1/c2;
967 return within_dist_point(p, &line_p, dist);
970 //##############################################################################################################
973 //# Authors: Martin Schaller (04/2008)
974 //##############################################################################################################
975 static int within_dist_polyline(struct point *p, struct point *line_pnt, int count, int dist, int close)
978 for (i = 0 ; i < count-1 ; i++) {
979 if (within_dist_line(p,line_pnt+i,line_pnt+i+1,dist)) {
984 return (within_dist_line(p,line_pnt,line_pnt+count-1,dist));
988 //##############################################################################################################
991 //# Authors: Martin Schaller (04/2008)
992 //##############################################################################################################
993 static int within_dist_polygon(struct point *p, struct point *poly_pnt, int count, int dist)
996 for (i = 0, j = count-1; i < count; j = i++) {
997 if ((((poly_pnt[i].y <= p->y) && ( p->y < poly_pnt[j].y )) ||
998 ((poly_pnt[j].y <= p->y) && ( p->y < poly_pnt[i].y))) &&
999 (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))
1003 return within_dist_polyline(p, poly_pnt, count, dist, 1);
1007 //##############################################################################################################
1010 //# Authors: Martin Schaller (04/2008)
1011 //##############################################################################################################
1012 int graphics_displayitem_within_dist(struct displayitem *di, struct point *p, int dist)
1014 if (di->item.type < type_line) {
1015 return within_dist_point(p, &di->pnt[0], dist);
1017 if (di->item.type < type_area) {
1018 return within_dist_polyline(p, di->pnt, di->count, dist, 0);
1020 return within_dist_polygon(p, di->pnt, di->count, dist);