summaryrefslogtreecommitdiff
path: root/navit/graphics.c
diff options
context:
space:
mode:
authorStefan Wildemann <metalstrolch@users.noreply.github.com>2022-01-01 14:12:44 +0100
committerGitHub <noreply@github.com>2022-01-01 14:12:44 +0100
commit17f1a6ec6aebbc51a67be6ac6064d231ce02a62e (patch)
treeade88ff515cba3763fc9ac00ec2f0a392ec32ba5 /navit/graphics.c
parent13e550f93052ef6d51fcbde76cd6796a3cc6bb4e (diff)
downloadnavit-17f1a6ec6aebbc51a67be6ac6064d231ce02a62e.tar.gz
feature: graphics: allow spiked lines for cliff and embarkments (#1174)
* feature: graphics: allow spiked lines for cliff and embarkments This adds another drwing element to graphics system. It can produce lines with spikes as used for cliffs on maps. Additionally this adds embarlment support for map. * review fixes. Add changes requested by review, plus add paranoia check on xml parameter.
Diffstat (limited to 'navit/graphics.c')
-rw-r--r--navit/graphics.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/navit/graphics.c b/navit/graphics.c
index aabe9b7bc..08de16a1e 100644
--- a/navit/graphics.c
+++ b/navit/graphics.c
@@ -1720,6 +1720,67 @@ static void display_draw_arrows(struct graphics *gra, struct display_context *dc
}
}
+static void display_draw_spike(struct point *p, navit_float dx, navit_float dy, navit_float width,
+ struct display_context *dc,
+ struct graphics *gra) {
+ struct point pnt[2];
+ navit_float l=navit_sqrt(dx*dx+dy*dy);
+ pnt[0]=pnt[1]=*p;
+ pnt[1].x+=(-dy/l)*width;
+ pnt[1].y+=(dx/l)*width;
+ graphics_draw_lines(gra, dc->gc, pnt, 2);
+}
+
+/**
+ * @brief draw spikes along a multi polygon line
+ *
+ * This function draws spikes along a multi polygon line, and scales the
+ * spikes according to current view settings by interpolating sizes at
+ * given spike position,
+ *
+ * @param gra current graphics instance handle
+ * @param dc current drawing context
+ * @param pnt array of points for this polyline
+ * @param count number of points in pnt
+ * @param width array of integers giving the expected line width at the corresponding point
+ * @param distance giving the distance between spikes
+ */
+static void display_draw_spikes(struct graphics *gra, struct display_context *dc, struct point *pnt, int count,
+ int *width, int distance) {
+ navit_float dx,dy,dw,l;
+ int i;
+ struct point p;
+ int w;
+ for (i = 0 ; i < count-1 ; i++) {
+ /* get the X and Y size */
+ dx=pnt[i+1].x-pnt[i].x;
+ dy=pnt[i+1].y-pnt[i].y;
+ dw=width[i+1] - width[i];
+ /* calculate the length of the way segment */
+ l=navit_sqrt(dx*dx+dy*dy);
+ if (l != 0) {
+ /* length is not zero */
+ if(l > width[i]) {
+ /* length is bigger than the length of one spike */
+ int a;
+ int spike_count = l / distance;
+ /* calculate the vector per spike */
+ dx=dx/spike_count;
+ dy=dy/spike_count;
+ dw=dw/spike_count;
+ for( a=0; a < spike_count; a++ ) {
+ p=pnt[i];
+ p.x+=dx*a;
+ p.y+=dy*a;
+ w=width[i];
+ w+=dw*a;
+ display_draw_spike(&p, dx, dy, w, dc, gra);
+ }
+ }
+ }
+ }
+}
+
static int intersection(struct point * a1, int adx, int ady, struct point * b1, int bdx, int bdy, struct point * res) {
int n, a, b;
dbg(lvl_debug,"%d,%d - %d,%d x %d,%d-%d,%d",a1->x,a1->y,a1->x+adx,a1->y+ady,b1->x,b1->y,b1->x+bdx,b1->y+bdy);
@@ -2954,6 +3015,9 @@ static void displayitem_draw(struct displayitem *di, struct layout *l, struct di
else if (dc->e->type == element_arrows)
count=transform_point_buf(dc->trans, dc->pro, di->c, pa, pa_buf_size, count, mindist, e->u.arrows.width,
width);
+ else if (dc->e->type == element_spikes)
+ count=transform_point_buf(dc->trans, dc->pro, di->c, pa, pa_buf_size, count, mindist, e->u.spikes.width,
+ width);
else
count=transform_point_buf(dc->trans, dc->pro, di->c, pa, pa_buf_size, count, mindist, 0, NULL);
switch (e->type) {
@@ -2978,6 +3042,9 @@ static void displayitem_draw(struct displayitem *di, struct layout *l, struct di
case element_arrows:
display_draw_arrows(gra,dc,pa,count, width, e->oneway);
break;
+ case element_spikes:
+ display_draw_spikes(gra,dc,pa,count, width, e->u.spikes.distance);
+ break;
default:
dbg(lvl_error, "Unhandled element type %d", e->type);