Skip to content

Commit

Permalink
Add:graphics/windows: draw polygon with holes (#855)
Browse files Browse the repository at this point in the history
* Add:graphics/windows: drawing polygons with holes

For all Windows except windows CE.
  • Loading branch information
metalstrolch authored Aug 29, 2019
1 parent b7e9727 commit a76e302
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions navit/graphics/win32/graphics_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,62 @@ static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
SelectObject( gr->hMemDC, holdpen);
}

#if HAVE_API_WIN32_CE
/*
* Windows CE doesn't support PaintPath used for other versions. No polygon with holes support for CE yet.
*/
#else
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) {
/* remeber pen and brush */
HPEN holdpen = SelectObject( gr->hMemDC, gc->hpen );
HBRUSH holdbrush = SelectObject( gr->hMemDC, gc->hbrush );
/* remember fill mode */
int holdmode = GetPolyFillMode( gr->hMemDC );

/* set polygon fill mode */
SetPolyFillMode( gr->hMemDC, ALTERNATE );

/* use poly path */
if(BeginPath(gr->hMemDC)) {
int a;
/* add outer polygon */
if (sizeof(POINT) != sizeof(struct point)) {
int i;
POINT* points=g_alloca(sizeof(POINT)*count);
for ( i=0; i< count; i++ ) {
points[i].x = p[i].x;
points[i].y = p[i].y;
}
Polyline( gr->hMemDC, points, count );
} else
Polyline( gr->hMemDC, (POINT *)p, count);
/* add inner polygons */
for(a = 0; a<hole_count; a ++) {
if (sizeof(POINT) != sizeof(struct point)) {
int i;
POINT* points=g_alloca(sizeof(POINT)*ccount[a]);
for ( i=0; i< ccount[a]; i++ ) {
points[i].x = holes[a][i].x;
points[i].y = holes[a][i].y;
}
Polyline( gr->hMemDC, points, ccount[a] );
} else
Polyline( gr->hMemDC, (POINT *)(holes[a]), ccount[a]);
}
/* done with this path */
EndPath(gr->hMemDC);
/* fill the shape */
FillPath(gr->hMemDC);
}

/* restore fill mode */
SetPolyFillMode(gr->hMemDC, holdmode);
/* restore pen and brush */
SelectObject( gr->hMemDC, holdbrush);
SelectObject( gr->hMemDC, holdpen);
}
#endif

static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
HPEN holdpen = SelectObject( gr->hMemDC, gc->hpen );
Expand Down Expand Up @@ -1462,8 +1518,15 @@ static struct graphics_methods graphics_methods = {
get_text_bbox,
overlay_disable,
overlay_resize,
NULL, /* set_attr */
NULL, /* show_native_keyboard */
NULL, /* hide_native_keyboard */
NULL, /* get dpi */
#if HAVE_API_WIN32_CE
NULL, /* draw_polygon_with_holes */
#else
draw_polygon_with_holes
#endif
};


Expand Down

0 comments on commit a76e302

Please sign in to comment.