diff options
author | metalstrolch <stefan.wildemann@metalstrolche.de> | 2020-04-22 16:15:53 +0200 |
---|---|---|
committer | metalstrolch <stefan.wildemann@metalstrolche.de> | 2020-04-22 16:15:53 +0200 |
commit | e67fa33f47f0f9cd74c96b24275f3f907146a18e (patch) | |
tree | 94ea744aae6135cc9b31f809720e80710092e1df | |
parent | d820f1f018505a87d5b8ea75dfac3fd982ecb330 (diff) | |
download | navit-e67fa33f47f0f9cd74c96b24275f3f907146a18e.tar.gz |
add texture support out of icons directory.
-rw-r--r-- | navit/graphics.c | 47 | ||||
-rw-r--r-- | navit/graphics.h | 1 | ||||
-rw-r--r-- | navit/graphics/qt5/graphics_qt5.cpp | 23 | ||||
-rw-r--r-- | navit/graphics/qt5/graphics_qt5.h | 3 | ||||
-rw-r--r-- | navit/layout.c | 40 | ||||
-rw-r--r-- | navit/layout.h | 8 |
6 files changed, 92 insertions, 30 deletions
diff --git a/navit/graphics.c b/navit/graphics.c index 5fb72d2f4..d4ad89cc7 100644 --- a/navit/graphics.c +++ b/navit/graphics.c @@ -710,13 +710,27 @@ void graphics_gc_set_background(struct graphics_gc *gc, struct color *c) { } /** - * FIXME - * @param <> - * @returns <> - * @author Martin Schaller (04/2008) + * Set textured background to current graphics context. + * @param gc Graphics context handle + * @param img Allocated image + * @returns void + * @author metalstrolch (04/2020) +*/ +void graphics_gc_set_texture(struct graphics_gc *gc, struct graphics_image *img) { + if(graphics_gc_has_texture(gc)) + gc->meth.gc_set_texture(gc->priv, img->priv); +} + +/** + * Check if graphic context supports textured backgrounds + * @param gc Graphics context handle + * @returns true if supported otherwise false. + * @author metalstrolch (04/2020) */ -void graphics_gc_set_texture(struct graphics_gc *gc, struct graphics_image *img){ - gc->meth.gc_set_texture(gc->priv, img->priv); +gboolean graphics_gc_has_texture(struct graphics_gc *gc) { + if(gc->meth.gc_set_texture != NULL) + return TRUE; + return FALSE; } /** @@ -913,7 +927,6 @@ struct graphics_image * graphics_image_new_scaled_rotated(struct graphics *gra, struct file_wordexp *we; int i; char **paths; - if ( g_hash_table_lookup_extended( gra->image_cache_hash, hash_key, NULL, (gpointer)&this_) ) { g_free(hash_key); dbg(lvl_debug,"Found cached image%sfor '%s'",this_?" ":" miss ",path); @@ -2682,9 +2695,20 @@ static void displayitem_free_holes(struct displayitem_poly_holes * holes) { } -static inline void displayitem_draw_polygon (struct display_context * dc, struct graphics * gra, struct point * pa, - int count, struct displayitem_poly_holes * holes) { +static inline void displayitem_draw_polygon (struct display_context * dc, struct graphics * gra, + struct point * pa, int count, struct displayitem_poly_holes * holes) { + /* Set texture if any, and supported by graphics */ + if((graphics_gc_has_texture(dc->gc)) && (dc->e->u.polygon.src != NULL)) { + char * path; + struct graphics_image * texture; + path=graphics_icon_path(dc->e->u.polygon.src); + texture = graphics_image_new_scaled_rotated(gra, path, dc->e->u.polygon.width, dc->e->u.polygon.height, + dc->e->u.polygon.rotation); + g_free(path); + if(texture != NULL) + graphics_gc_set_texture(dc->gc, texture); + } if((holes != NULL) && (holes->count > 0)) graphics_draw_polygon_with_holes_clipped(gra, dc->gc, pa, count, holes->count, holes->ccount, (struct point **)holes->coords); @@ -2875,11 +2899,6 @@ static void displayitem_draw(struct displayitem *di, struct layout *l, struct di draw_underground=0; } } - /* Set texture if any - struct graphics_image * texture = graphics_image_new_scaled(gra, "cave.svg" , 50, 50); - if(texture != NULL) - graphics_gc_set_texture(dc->gc, texture); - */ if (item_type_is_area(dc->type) && (dc->e->type == element_polyline || dc->e->type == element_text)) limit = 0; diff --git a/navit/graphics.h b/navit/graphics.h index bb3d04cb9..c3588282b 100644 --- a/navit/graphics.h +++ b/navit/graphics.h @@ -255,6 +255,7 @@ void graphics_gc_set_background(struct graphics_gc *gc, struct color *c); void graphics_gc_set_texture(struct graphics_gc *gc, struct graphics_image *img); void graphics_gc_set_linewidth(struct graphics_gc *gc, int width); void graphics_gc_set_dashes(struct graphics_gc *gc, int width, int offset, unsigned char dash_list[], int n); +gboolean graphics_gc_has_texture(struct graphics_gc *gc); struct graphics_image *graphics_image_new_scaled(struct graphics *gra, char *path, int w, int h); struct graphics_image *graphics_image_new_scaled_rotated(struct graphics *gra, char *path, int w, int h, int rotate); struct graphics_image *graphics_image_new(struct graphics *gra, char *path); diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index 26e861bd0..c87479219 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -271,20 +271,19 @@ static void gc_set_background(struct graphics_gc_priv* gc, struct color* c) { void gc_set_texture (struct graphics_gc_priv *gc, struct graphics_image_priv *img) { if(img == NULL) { //disable texture mode - gc->brush->setStyle(Qt::SolidPattern); - } - else { + gc->brush->setStyle(Qt::SolidPattern); + } else { //set and enable texture - //Use a new pixmap - QPixmap background(img->pixmap->size()); - //Use fill color - background.fill(gc->brush->color()); - //Get a painter - QPainter painter(&background); - //Blit the (transparent) image on pixmap. + //Use a new pixmap + QPixmap background(img->pixmap->size()); + //Use fill color + background.fill(gc->brush->color()); + //Get a painter + QPainter painter(&background); + //Blit the (transparent) image on pixmap. painter.drawPixmap(0, 0, *(img->pixmap)); - //Set the texture to the brush. - gc->brush->setTexture(background); + //Set the texture to the brush. + gc->brush->setTexture(background); } } diff --git a/navit/graphics/qt5/graphics_qt5.h b/navit/graphics/qt5/graphics_qt5.h index 0eed89510..8d7d5ab19 100644 --- a/navit/graphics/qt5/graphics_qt5.h +++ b/navit/graphics/qt5/graphics_qt5.h @@ -61,7 +61,8 @@ struct graphics_priv; #if USE_QML class GraphicsPriv : public QObject { Q_OBJECT -public: GraphicsPriv(struct graphics_priv* gp); +public: + GraphicsPriv(struct graphics_priv* gp); ~GraphicsPriv(); void emit_update(); diff --git a/navit/layout.c b/navit/layout.c index 7ecea6c27..deed09ef0 100644 --- a/navit/layout.c +++ b/navit/layout.c @@ -499,10 +499,47 @@ static void element_set_circle_radius(struct element *e, struct attr **attrs) { struct polygon * polygon_new(struct attr *parent, struct attr **attrs) { struct element *e; - e = g_new0(struct element, 1); + int add_size_to_e=0; + struct attr *src,*w,*h,*rotation,*x,*y; + /* search fot icon src first as this increases the required memory for e*/ + src=attr_search(attrs, NULL, attr_src); + if (src != NULL) { + add_size_to_e += strlen(src->u.str)+1; + } + + e = g_malloc0(sizeof(*e)+add_size_to_e); e->type=element_polygon; element_set_color(e, attrs); element_set_oneway(e, attrs); + e->u.polygon.src=NULL; + + /* copy over image url if any, and probe icon parameters */ + if (src != NULL) { + e->u.polygon.src=(char *)(e+1); + strcpy(e->u.polygon.src,src->u.str); + if ((w=attr_search(attrs, NULL, attr_w))) + e->u.polygon.width=w->u.num; + else + e->u.polygon.width=-1; + + if ((h=attr_search(attrs, NULL, attr_h))) + e->u.polygon.height=h->u.num; + else + e->u.polygon.height=-1; + + if ((x=attr_search(attrs, NULL, attr_x))) + e->u.polygon.x=x->u.num; + else + e->u.polygon.x=-1; + + if ((y=attr_search(attrs, NULL, attr_y))) + e->u.polygon.y=y->u.num; + else + e->u.polygon.y=-1; + + if ((rotation=attr_search(attrs, NULL, attr_rotation))) + e->u.polygon.rotation=rotation->u.num; + } return (struct polygon *)e; } @@ -567,7 +604,6 @@ icon_new(struct attr *parent, struct attr **attrs) { src=attr_search(attrs, NULL, attr_src); if (! src) return NULL; - e = g_malloc0(sizeof(*e)+strlen(src->u.str)+1); e->type=element_icon; e->u.icon.src=(char *)(e+1); diff --git a/navit/layout.h b/navit/layout.h index 7f19460e2..47b078ab1 100644 --- a/navit/layout.h +++ b/navit/layout.h @@ -50,7 +50,13 @@ struct element { unsigned char dash_table[4]; } polyline; struct element_polygon { - char stub; + /* for texture */ + char *src; + int width; + int height; + int rotation; + int x; + int y; } polygon; struct element_circle { int width; |