diff options
author | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2008-09-25 21:09:14 +0000 |
---|---|---|
committer | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2008-09-25 21:09:14 +0000 |
commit | edd42e879f5ed8d846650c21190c5c8a2689363b (patch) | |
tree | 637de030a56af4cace13668155b3a03771a6074b | |
parent | d676ed1b3b9d64952053ce066a0e59a1d2f3c5e9 (diff) | |
download | navit-edd42e879f5ed8d846650c21190c5c8a2689363b.tar.gz |
Add:Core:Added support for arrows showing the direction of lines
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1417 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r-- | navit/graphics.c | 37 | ||||
-rw-r--r-- | navit/layout.c | 15 | ||||
-rw-r--r-- | navit/layout.h | 2 | ||||
-rw-r--r-- | navit/xmlconfig.c | 12 |
4 files changed, 65 insertions, 1 deletions
diff --git a/navit/graphics.c b/navit/graphics.c index 33c4aef2d..5b2da6e5e 100644 --- a/navit/graphics.c +++ b/navit/graphics.c @@ -630,6 +630,40 @@ static void label_line(struct graphics *gra, struct graphics_gc *fg, struct grap } } +static void display_draw_arrow(struct point *p, int dx, int dy, int l, struct graphics_gc *gc, struct graphics *gra) +{ + struct point pnt[3]; + pnt[0]=pnt[1]=pnt[2]=*p; + pnt[0].x+=-dx*l/65536+dy*l/65536; + pnt[0].y+=-dy*l/65536-dx*l/65536; + pnt[2].x+=-dx*l/65536-dy*l/65536; + pnt[2].y+=-dy*l/65536+dx*l/65536; + gra->meth.draw_lines(gra->priv, gc->priv, pnt, 3); +} + +static void display_draw_arrows(struct displayitem *di, struct graphics_gc *gc, struct graphics *gra) +{ + int i,dx,dy,l; + struct point p; + for (i = 0 ; i < di->count-1 ; i++) { + dx=di->pnt[i+1].x-di->pnt[i].x; + dy=di->pnt[i+1].y-di->pnt[i].y; + l=sqrt(dx*dx+dy*dy); + if (l) { + dx=dx*65536/l; + dy=dy*65536/l; + p=di->pnt[i]; + p.x+=dx*15/65536; + p.y+=dy*15/65536; + display_draw_arrow(&p, dx, dy, 10, gc, gra); + p=di->pnt[i+1]; + p.x-=dx*15/65536; + p.y-=dy*15/65536; + display_draw_arrow(&p, dx, dy, 10, gc, gra); + } + } +} + /** * FIXME * @param <> @@ -721,6 +755,9 @@ static void xdisplay_draw_elements(struct graphics *gra, GHashTable *display_lis else dbg(0,"draw_image_warp not supported by graphics driver drawing '%s'\n", di->label); break; + case element_arrows: + display_draw_arrows(di,gc,gra); + break; default: printf("Unhandled element type %d\n", e->type); diff --git a/navit/layout.c b/navit/layout.c index eb124dfad..890e3660c 100644 --- a/navit/layout.c +++ b/navit/layout.c @@ -20,6 +20,7 @@ #include <glib.h> #include <string.h> #include "item.h" +#include "attr.h" #include "layout.h" struct layout * layout_new(struct attr *parent, struct attr **attrs) @@ -169,3 +170,17 @@ image_new(void) return e; } +struct element * +arrows_new(struct attr **attrs) +{ + struct element *e; + struct attr *color=attr_search(attrs, NULL, attr_color); + + e = g_malloc0(sizeof(*e)); + e->type=element_arrows; + if (color) + e->color=*color->u.color; + + return e; +} + diff --git a/navit/layout.h b/navit/layout.h index dda983431..6e615b5e1 100644 --- a/navit/layout.h +++ b/navit/layout.h @@ -27,7 +27,7 @@ struct element_line; struct element_text; struct element { - enum { element_point, element_polyline, element_polygon, element_circle, element_label, element_icon, element_image } type; + enum { element_point, element_polyline, element_polygon, element_circle, element_label, element_icon, element_image, element_arrows } type; struct color color; int label_size; union { diff --git a/navit/xmlconfig.c b/navit/xmlconfig.c index cb5b258cf..1c69adbdf 100644 --- a/navit/xmlconfig.c +++ b/navit/xmlconfig.c @@ -615,6 +615,17 @@ xmlconfig_image(struct xmlstate *state) return 1; } +static int +xmlconfig_arrows(struct xmlstate *state) +{ + state->element_attr.u.data=arrows_new(convert_to_attrs(state)); + if (! state->element_attr.u.data) + return 0; + itemtype_add_element(state->parent->element_attr.u.data, state->element_attr.u.data); + + return 1; +} + #define NEW(x) (void *(*)(struct attr *, struct attr **))(x) #define ADD(x) (int (*)(void *, struct attr *attr))(x) #define INIT(x) (int (*)(void *))(x) @@ -628,6 +639,7 @@ struct element_func { int (*init)(void *); void (*destroy)(void *); } elements[] = { + { "arrows", "item", xmlconfig_arrows}, { "config", NULL, xmlconfig_config}, { "debug", "config", xmlconfig_debug}, { "navit", "config", NULL, NEW(navit_new), ADD(navit_add_attr), INIT(navit_init), DESTROY(navit_destroy)}, |