summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wildemann <gta04@metalstrolche.de>2019-09-24 00:38:44 +0200
committerWildemann Stefan <stefan.wildemann@corpuls.com>2019-09-24 10:22:14 +0200
commite666d1a2e1015b8575cf327f59e6ae36c4ce0ef8 (patch)
treec0987a7be224380bb0558c2891002750da3b15bf
parenta75edc4d6d6e0c49d346e319fb209dfd773ef386 (diff)
downloadnavit-e666d1a2e1015b8575cf327f59e6ae36c4ce0ef8.tar.gz
feature:layout:draw arrows on oneway streets
Allow drawing only on oneway streets by adding the "oneway" tag to itemgras and by enhancing the "arrow" itemgra used for displaying the route graph. One can draw quite nice arrows on oneway streets that way
-rw-r--r--navit/attr_def.h1
-rw-r--r--navit/graphics.c70
-rw-r--r--navit/layout.c22
-rw-r--r--navit/layout.h4
4 files changed, 80 insertions, 17 deletions
diff --git a/navit/attr_def.h b/navit/attr_def.h
index b36c09cce..45764ebb2 100644
--- a/navit/attr_def.h
+++ b/navit/attr_def.h
@@ -263,6 +263,7 @@ ATTR(waypoints_flag) /* toggle for "set as destination" to switch between start
ATTR(no_warning_if_map_file_missing)
ATTR(duplicate)
ATTR(has_menu_button)
+ATTR(oneway)
ATTR2(0x0002ffff,type_int_end)
ATTR2(0x00030000,type_string_begin)
ATTR(type)
diff --git a/navit/graphics.c b/navit/graphics.c
index e867a2ec3..09e8a097e 100644
--- a/navit/graphics.c
+++ b/navit/graphics.c
@@ -1547,19 +1547,30 @@ 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];
+static void display_draw_arrow(struct point *p, long dx, long dy, int width, struct display_context *dc,
+ struct graphics *gra, int filled) {
+ struct point pnt[4];
+ /* half the width in every direction */
+ width /= 2;
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;
- graphics_draw_lines(gra, gc, pnt, 3);
+ pnt[0].x+=-dx*width/65536+dy*width/65536;
+ pnt[0].y+=-dy*width/65536-dx*width/65536;
+ pnt[2].x+=-dx*width/65536-dy*width/65536;
+ pnt[2].y+=-dy*width/65536+dx*width/65536;
+ if(filled) {
+ pnt[3]=pnt[0];
+ graphics_draw_polygon(gra, dc->gc, pnt, 4);
+ } else {
+ graphics_draw_lines(gra, dc->gc, pnt, 3);
+ }
+
}
-static void display_draw_arrows(struct graphics *gra, struct graphics_gc *gc, struct point *pnt, int count) {
- int i,dx,dy,l;
+static void display_draw_arrows(struct graphics *gra, struct display_context *dc, struct point *pnt, int count,
+ int *width, int filled) {
+ long i,dx,dy,l;
struct point p;
+ struct element *e=dc->e;
for (i = 0 ; i < count-1 ; i++) {
dx=pnt[i+1].x-pnt[i].x;
dy=pnt[i+1].y-pnt[i].y;
@@ -1568,13 +1579,29 @@ static void display_draw_arrows(struct graphics *gra, struct graphics_gc *gc, st
dx=dx*65536/l;
dy=dy*65536/l;
p=pnt[i];
- p.x+=dx*15/65536;
- p.y+=dy*15/65536;
- display_draw_arrow(&p, dx, dy, 10, gc, gra);
- p=pnt[i+1];
- p.x-=dx*15/65536;
- p.y-=dy*15/65536;
- display_draw_arrow(&p, dx, dy, 10, gc, gra);
+ if(filled) {
+ /* print arrow at middle point */
+ p.x+=dx*(l/2)/65536;
+ p.y+=dy*(l/2)/65536;
+ display_draw_arrow(&p, dx, dy, width[i], dc, gra, filled);
+ /* if line is quite long, print arrows at 1/4 and 3/4 length */
+ if(l > (20*width[i])) {
+ p.x+=dx*(l/4)/65536;
+ p.y+=dy*(l/4)/65536;
+ display_draw_arrow(&p, dx, dy, width[i], dc, gra, filled);
+ p.x+=dx*3*(l/4)/65536;
+ p.y+=dy*3*(l/4)/65536;
+ display_draw_arrow(&p, dx, dy, width[i], dc, gra, filled);
+ }
+ } else {
+ p.x+=dx*15/65536;
+ p.y+=dy*15/65536;
+ display_draw_arrow(&p, dx, dy, 20, dc, gra, filled);
+ p=pnt[i+1];
+ p.x-=dx*15/65536;
+ p.y-=dy*15/65536;
+ display_draw_arrow(&p, dx, dy, 20, dc, gra, filled);
+ }
}
}
}
@@ -2692,6 +2719,13 @@ static void displayitem_draw(struct displayitem *di, struct layout *l, struct di
di->z_order=++(gra->current_z_order);
+ /* Skip elements that are to be drawn on oneway streets only
+ * if street is not oneway */
+ if((e->oneway) && (!(di->flags & AF_ONEWAY))) {
+ di=di->next;
+ continue;
+ }
+
if (! dc->gc) {
struct graphics_gc * gc=graphics_gc_new(gra);
dc->gc=gc;
@@ -2725,6 +2759,8 @@ static void displayitem_draw(struct displayitem *di, struct layout *l, struct di
mindist=0;
if (dc->e->type == element_polyline)
count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, e->u.polyline.width, width);
+ else if (dc->e->type == element_arrows)
+ count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, e->u.arrows.width, width);
else
count=transform(dc->trans, dc->pro, di->c, pa, count, mindist, 0, NULL);
switch (e->type) {
@@ -2747,7 +2783,7 @@ static void displayitem_draw(struct displayitem *di, struct layout *l, struct di
displayitem_draw_image (di, dc, gra, pa, count);
break;
case element_arrows:
- display_draw_arrows(gra,dc->gc,pa,count);
+ display_draw_arrows(gra,dc,pa,count, width, e->oneway);
break;
default:
dbg(lvl_error, "Unhandled element type %d", e->type);
diff --git a/navit/layout.c b/navit/layout.c
index 0fe48ac4e..65e4b7265 100644
--- a/navit/layout.c
+++ b/navit/layout.c
@@ -406,6 +406,13 @@ int itemgra_add_attr(struct itemgra *itemgra, struct attr *attr) {
}
}
+static void element_set_oneway(struct element *e, struct attr **attrs) {
+ struct attr *oneway;
+ oneway=attr_search(attrs, NULL, attr_oneway);
+ if (oneway)
+ e->oneway=oneway->u.num;
+}
+
static void element_set_color(struct element *e, struct attr **attrs) {
struct attr *color;
color=attr_search(attrs, NULL, attr_color);
@@ -429,6 +436,15 @@ static void element_set_text_size(struct element *e, struct attr **attrs) {
e->text_size=text_size->u.num;
}
+static void element_set_arrows_width(struct element *e, struct attr **attrs) {
+ struct attr *width;
+ width=attr_search(attrs, NULL, attr_width);
+ if (width)
+ e->u.arrows.width=width->u.num;
+ else
+ e->u.arrows.width=10;
+}
+
static void element_set_polyline_width(struct element *e, struct attr **attrs) {
struct attr *width;
width=attr_search(attrs, NULL, attr_width);
@@ -485,6 +501,7 @@ polygon_new(struct attr *parent, struct attr **attrs) {
e = g_new0(struct element, 1);
e->type=element_polygon;
element_set_color(e, attrs);
+ element_set_oneway(e, attrs);
return (struct polygon *)e;
}
@@ -496,6 +513,7 @@ polyline_new(struct attr *parent, struct attr **attrs) {
e = g_new0(struct element, 1);
e->type=element_polyline;
element_set_color(e, attrs);
+ element_set_oneway(e, attrs);
element_set_polyline_width(e, attrs);
element_set_polyline_directed(e, attrs);
element_set_polyline_dash(e, attrs);
@@ -515,6 +533,7 @@ circle_new(struct attr *parent, struct attr **attrs) {
e->u.circle.background_color = color_white;
element_set_color(e, attrs);
element_set_background_color(&e->u.circle.background_color, attrs);
+ element_set_oneway(e, attrs);
element_set_text_size(e, attrs);
element_set_circle_width(e, attrs);
element_set_circle_radius(e, attrs);
@@ -535,6 +554,7 @@ text_new(struct attr *parent, struct attr **attrs) {
e->u.text.background_color = color_white;
element_set_color(e, attrs);
element_set_background_color(&e->u.text.background_color, attrs);
+ element_set_oneway(e, attrs);
return (struct text *)e;
}
@@ -589,6 +609,8 @@ arrows_new(struct attr *parent, struct attr **attrs) {
e = g_malloc0(sizeof(*e));
e->type=element_arrows;
element_set_color(e, attrs);
+ element_set_oneway(e, attrs);
+ element_set_arrows_width(e, attrs);
return (struct arrows *)e;
}
diff --git a/navit/layout.h b/navit/layout.h
index f5629593f..8b8a63194 100644
--- a/navit/layout.h
+++ b/navit/layout.h
@@ -37,6 +37,7 @@ struct element {
enum { element_point, element_polyline, element_polygon, element_circle, element_text, element_icon, element_image, element_arrows } type;
struct color color;
int text_size;
+ int oneway;
union {
struct element_point {
char stub;
@@ -67,6 +68,9 @@ struct element {
struct element_text {
struct color background_color;
} text;
+ struct element_arrows {
+ int width;
+ } arrows;
} u;
int coord_count;
struct coord *coord;