diff options
author | metalstrolch <stefan.wildemann@metalstrolche.de> | 2020-04-22 00:37:02 +0200 |
---|---|---|
committer | metalstrolch <stefan.wildemann@metalstrolche.de> | 2020-04-22 00:37:02 +0200 |
commit | d820f1f018505a87d5b8ea75dfac3fd982ecb330 (patch) | |
tree | 035b654d6100b2309060ee4d70039a84b3a0f050 | |
parent | f82ea8d97d5f10433197306e8afd6b6c10e294f2 (diff) | |
download | navit-d820f1f018505a87d5b8ea75dfac3fd982ecb330.tar.gz |
graphics:core:Add support for textured polygons
-rw-r--r-- | navit/graphics.c | 16 | ||||
-rw-r--r-- | navit/graphics.h | 2 | ||||
-rw-r--r-- | navit/graphics/qt5/graphics_qt5.cpp | 23 |
3 files changed, 39 insertions, 2 deletions
diff --git a/navit/graphics.c b/navit/graphics.c index 662a74f0b..5fb72d2f4 100644 --- a/navit/graphics.c +++ b/navit/graphics.c @@ -709,6 +709,15 @@ void graphics_gc_set_background(struct graphics_gc *gc, struct color *c) { gc->meth.gc_set_background(gc->priv, c); } +/** + * FIXME + * @param <> + * @returns <> + * @author Martin Schaller (04/2008) +*/ +void graphics_gc_set_texture(struct graphics_gc *gc, struct graphics_image *img){ + gc->meth.gc_set_texture(gc->priv, img->priv); +} /** * FIXME @@ -2675,6 +2684,7 @@ 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) { + 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); @@ -2865,7 +2875,11 @@ 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 9a3a33730..bb3d04cb9 100644 --- a/navit/graphics.h +++ b/navit/graphics.h @@ -180,6 +180,7 @@ struct graphics_gc_methods { void (*gc_set_dashes)(struct graphics_gc_priv *gc, int width, int offset, unsigned char dash_list[], int n); void (*gc_set_foreground)(struct graphics_gc_priv *gc, struct color *c); 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); }; /** @@ -251,6 +252,7 @@ struct graphics_gc *graphics_gc_new(struct graphics *gra); void graphics_gc_destroy(struct graphics_gc *gc); void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c); 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); struct graphics_image *graphics_image_new_scaled(struct graphics *gra, char *path, int w, int h); diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index cb9b4c456..26e861bd0 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -268,12 +268,33 @@ static void gc_set_background(struct graphics_gc_priv* gc, struct color* c) { //gc->brush->setColor(col); } +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 { + //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. + painter.drawPixmap(0, 0, *(img->pixmap)); + //Set the texture to the brush. + gc->brush->setTexture(background); + } +} + static struct graphics_gc_methods gc_methods = { gc_destroy, gc_set_linewidth, gc_set_dashes, gc_set_foreground, - gc_set_background + gc_set_background, + gc_set_texture }; static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics_gc_methods* meth) { |