summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWildemann Stefan <stefan.wildemann@corpuls.com>2019-09-23 13:22:27 +0200
committerWildemann Stefan <stefan.wildemann@corpuls.com>2019-09-25 13:02:17 +0200
commit58ad98c91ecf207e79aeea4ba746de1e49c78071 (patch)
treea24ff2937fae6fb293733427426f9858c57bf6ab
parent0e2d3b090c3c2f752227b61204042db78d86ed7c (diff)
downloadnavit-58ad98c91ecf207e79aeea4ba746de1e49c78071.tar.gz
enhancement: layout: draw tunnels transparent
-rw-r--r--navit/attr_def.h1
-rw-r--r--navit/color.h4
-rw-r--r--navit/graphics.c38
-rw-r--r--navit/layout.c19
-rw-r--r--navit/layout.h3
5 files changed, 51 insertions, 14 deletions
diff --git a/navit/attr_def.h b/navit/attr_def.h
index 5a82d9d30..b36c09cce 100644
--- a/navit/attr_def.h
+++ b/navit/attr_def.h
@@ -202,6 +202,7 @@ ATTR(autozoom_max)
ATTR(nav_status)
ATTR(virtual_dpi)
ATTR(real_dpi)
+ATTR(underground_alpha)
ATTR2(0x00027500,type_rel_abs_begin)
/* These attributes are int that can either hold relative or absolute values. See the
* documentation of ATTR_REL_RELSHIFT for details.
diff --git a/navit/color.h b/navit/color.h
index dee10a187..83470781a 100644
--- a/navit/color.h
+++ b/navit/color.h
@@ -21,7 +21,7 @@
#define NAVIT_COLOR_H
struct color {
- int r,g,b,a;
+ int r,g,b,a;
};
#define COLOR_BITDEPTH 16
@@ -34,6 +34,8 @@ struct color {
#define COLOR_TRANSPARENT ((struct color) {COLOR_TRANSPARENT_})
#define COLOR_FMT "0x%x,0x%x,0x%x,0x%x"
#define COLOR_ARGS(c) (c).r,(c).g,(c).b,(c).a
+/*default alpha value to apply for all things flagged AF_UNDERGROUND*/
+#define UNDERGROUND_ALPHA_ 0x3333
#define COLOR_IS_SAME(c1,c2) ((c1).r==(c2).r && (c1).g==(c2).g && (c1).b==(c2).b && (c1).a==(c2).a)
#define COLOR_IS_WHITE(c) COLOR_IS_SAME(c, COLOR_WHITE)
diff --git a/navit/graphics.c b/navit/graphics.c
index c502dcec9..a06e8e9da 100644
--- a/navit/graphics.c
+++ b/navit/graphics.c
@@ -1451,7 +1451,7 @@ static void display_add(struct hash_entry *entry, struct item *item, int count,
/* check for and remember flags (for underground drawing) */
item_attr_rewind(item);
if(item_attr_get(item, attr_flags, &attr)) {
- flags = attr.u.num;
+ flags = attr.u.num;
}
/* add length for holes */
item_attr_rewind(item);
@@ -2665,15 +2665,16 @@ static inline void displayitem_draw_image (struct displayitem *di, struct displa
* This function will invoke the appropriate draw primitive depending on the type of the element to draw
*
* @brief di The displayitem to draw
- * @brief dummy Unused
+ * @brief l current layout for getting defaults and underground alpha
* @brief dc The display_context to use to draw items
*/
-static void displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc) {
+static void displayitem_draw(struct displayitem *di, struct layout *l, struct display_context *dc) {
int *width=g_alloca(sizeof(int)*dc->maxlen);
int limit=0;
struct point *pa=g_alloca(sizeof(struct point)*dc->maxlen);
struct graphics *gra=dc->gra;
struct element *e=dc->e;
+ int draw_underground=0;
while (di) {
int count=di->count,mindist=dc->mindist;
@@ -2685,14 +2686,25 @@ static void displayitem_draw(struct displayitem *di, void *dummy, struct display
if (! dc->gc) {
struct graphics_gc * gc=graphics_gc_new(gra);
dc->gc=gc;
+ graphics_gc_set_foreground(dc->gc, &e->color);
}
+
+ /* If the element id flagged AF_UNDERGROUND, we apply predefined transparenc to it if
+ * it's not the text. */
if((di->flags & AF_UNDERGROUND) && (dc->e->type != element_text)) {
- struct color fg_color = e->color;
- fg_color.a=0x33 << 8;
- graphics_gc_set_foreground(dc->gc, &fg_color);
+ if(!draw_underground) {
+ struct color fg_color = e->color;
+ fg_color.a= (l != NULL) ? l->underground_alpha: UNDERGROUND_ALPHA_;
+ graphics_gc_set_foreground(dc->gc, &fg_color);
+ draw_underground=1;
+ }
} else {
- graphics_gc_set_foreground(dc->gc, &e->color);
+ if(draw_underground) {
+ graphics_gc_set_foreground(dc->gc, &e->color);
+ draw_underground=0;
+ }
}
+
if (item_type_is_area(dc->type) && (dc->e->type == element_polyline || dc->e->type == element_text))
limit = 0;
@@ -2744,7 +2756,8 @@ static void displayitem_draw(struct displayitem *di, void *dummy, struct display
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static void xdisplay_draw_elements(struct graphics *gra, struct displaylist *display_list, struct itemgra *itm) {
+static void xdisplay_draw_elements(struct graphics *gra, struct displaylist *display_list, struct itemgra *itm,
+ struct layout * l) {
struct element *e;
GList *es,*types;
struct display_context *dc=&display_list->dc;
@@ -2759,7 +2772,7 @@ static void xdisplay_draw_elements(struct graphics *gra, struct displaylist *dis
dc->type=GPOINTER_TO_INT(types->data);
entry=get_hash_entry(display_list, dc->type);
if (entry && entry->di) {
- displayitem_draw(entry->di, NULL, dc);
+ displayitem_draw(entry->di, l, dc);
display_context_free(dc);
}
types=g_list_next(types);
@@ -2819,7 +2832,8 @@ void graphics_draw_itemgra(struct graphics *gra, struct itemgra *itm, struct tra
* @returns <>
* @author Martin Schaller (04/2008)
*/
-static void xdisplay_draw_layer(struct displaylist *display_list, struct graphics *gra, struct layer *lay, int order) {
+static void xdisplay_draw_layer(struct displaylist *display_list, struct graphics *gra, struct layer *lay, int order,
+ struct layout * l) {
GList *itms;
struct itemgra *itm;
@@ -2827,7 +2841,7 @@ static void xdisplay_draw_layer(struct displaylist *display_list, struct graphic
while (itms) {
itm=itms->data;
if (order >= itm->order.min && order <= itm->order.max)
- xdisplay_draw_elements(gra, display_list, itm);
+ xdisplay_draw_elements(gra, display_list, itm, l);
itms=g_list_next(itms);
}
}
@@ -2850,7 +2864,7 @@ static void xdisplay_draw(struct displaylist *display_list, struct graphics *gra
if (lay->active) {
if (lay->ref)
lay=lay->ref;
- xdisplay_draw_layer(display_list, gra, lay, order);
+ xdisplay_draw_layer(display_list, gra, lay, order, l);
}
lays=g_list_next(lays);
}
diff --git a/navit/layout.c b/navit/layout.c
index f2f3d1a75..0fe48ac4e 100644
--- a/navit/layout.c
+++ b/navit/layout.c
@@ -39,7 +39,9 @@ layout_new(struct attr *parent, struct attr **attrs) {
struct layout *l;
struct navit *navit;
struct color def_color = {COLOR_BACKGROUND_};
- struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr,*day_attr,*night_attr,*active_attr;
+ int def_underground_alpha = UNDERGROUND_ALPHA_;
+ struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr,*day_attr,*night_attr,*active_attr,
+ *underground_alpha_attr,*icon_attr;
if (! (name_attr=attr_search(attrs, NULL, attr_name)))
return NULL;
@@ -67,6 +69,21 @@ layout_new(struct attr *parent, struct attr **attrs) {
l->color = *color_attr->u.color;
else
l->color = def_color;
+ if ((underground_alpha_attr=attr_search(attrs, NULL, attr_underground_alpha))) {
+ int a = underground_alpha_attr->u.num;
+ /* for convenience, the alpha value is just 8 bit as usual if using
+ * corresponding attr. therefore we need to shift that up */
+ l->underground_alpha = (a << 8) | a;
+ } else
+ l->underground_alpha = def_underground_alpha;
+ if ((icon_attr=attr_search(attrs, NULL, attr_icon_w)))
+ l->icon_w = icon_attr->u.num;
+ else
+ l->icon_w = -1;
+ if ((icon_attr=attr_search(attrs, NULL, attr_icon_h)))
+ l->icon_h = icon_attr->u.num;
+ else
+ l->icon_h = -1;
if ((order_delta_attr=attr_search(attrs, NULL, attr_order_delta)))
l->order_delta=order_delta_attr->u.num;
if ((active_attr=attr_search(attrs, NULL, attr_active)))
diff --git a/navit/layout.h b/navit/layout.h
index 700e6245a..f5629593f 100644
--- a/navit/layout.h
+++ b/navit/layout.h
@@ -105,6 +105,9 @@ struct layout {
char* nightname;
char *font;
struct color color;
+ int underground_alpha;
+ int icon_w;
+ int icon_h;
GList *layers;
GList *cursors;
int order_delta;