summaryrefslogtreecommitdiff
path: root/navit/graphics
diff options
context:
space:
mode:
authorStefan Wildemann <gta04@metalstrolche.de>2019-07-28 22:31:34 +0200
committerStefan Wildemann <gta04@metalstrolche.de>2019-07-28 22:31:34 +0200
commit864d83c33a998c52a5afff3eb543a0665c98ce02 (patch)
treee24478466e0e9cdc701606ff4f7113c9080e7679 /navit/graphics
parentf682af2c26869d8f1a5501a021f55dedb4c49e05 (diff)
downloadnavit-864d83c33a998c52a5afff3eb543a0665c98ce02.tar.gz
implement drawing of polygons with holes for qt5
Diffstat (limited to 'navit/graphics')
-rw-r--r--navit/graphics/qt5/graphics_qt5.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp
index 535b370dc..10784d6b3 100644
--- a/navit/graphics/qt5/graphics_qt5.cpp
+++ b/navit/graphics/qt5/graphics_qt5.cpp
@@ -418,6 +418,44 @@ static void draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc,
gr->painter->drawPolygon(polygon);
}
+static void draw_polygon_with_holes (struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count,
+ int hole_count, int* ccount, struct point **holes) {
+ int i;
+ int j;
+ QPainterPath path;
+ QPainterPath inner;
+ QPolygon polygon;
+ //dbg(lvl_error,"enter gr=%p, gc=%p, (%d, %d) holes %d", gr, gc, p->x, p->y, hole_count);
+ if (gr->painter == NULL)
+ return;
+ gr->painter->setPen(*gc->pen);
+ gr->painter->setBrush(*gc->brush);
+ /* construct outer polygon */
+ for (i = 0; i < count; i++)
+ polygon.putPoints(i, 1, p[i].x, p[i].y);
+ /* add it to outer path */
+ path.addPolygon(polygon);
+ /* construct the polygons for the holes and add them to inner */
+ for(j=0; j<hole_count; j ++) {
+ QPolygon hole;
+ for (i = 0; i < ccount[j]; i++)
+ hole.putPoints(i, 1, holes[j][i].x, holes[j][i].y);
+ inner.addPolygon(hole);
+ }
+ /* intersect */
+ if(hole_count > 0)
+ path = path.subtracted(inner);
+
+ /* if the polygon is transparent, we need to clear it first */
+ if (!gc->brush->isOpaque()) {
+ QPainter::CompositionMode mode = gr->painter->compositionMode();
+ gr->painter->setCompositionMode(QPainter::CompositionMode_Clear);
+ gr->painter->drawPath(path);
+ gr->painter->setCompositionMode(mode);
+ }
+ gr->painter->drawPath(path);
+}
+
static void draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int w, int h) {
// dbg(lvl_debug,"gr=%p gc=%p %d,%d,%d,%d", gr, gc, p->x, p->y, w, h);
if (gr->painter == NULL)
@@ -851,7 +889,8 @@ static struct graphics_methods graphics_methods = {
NULL, //set_attr
NULL, //show_native_keyboard
NULL, //hide_native_keyboard
- get_dpi
+ get_dpi,
+ draw_polygon_with_holes
};
/* create new graphics context on given context */