void polyfill(int n, vec2 points[]) { int i; int xoff, yoff; MWPOINT pv[MAXPOLY]; if(!hdc) return; /* calc window offset*/ xoff = hdc->hwnd->clirect.left; yoff = hdc->hwnd->clirect.top; /* only plot non-trivial polygons*/ if(n > 2) { for(i=0; i<n; ++i) { pv[i].x = fx(points[i].x) + xoff; pv[i].y = fy(points[i].y) + yoff; /* fix: floating round error, y intercept difference * with GdLine */ /*pv[i].x = fx(points[i].x + xoff);*/ /*pv[i].y = fy(points[i].y + yoff);*/ } GdSetForegroundColor(hdc->psd, hdc->pen->color); GdFillPoly(hdc->psd, n, pv); } }
BOOL WINAPI Polygon(HDC hdc, CONST POINT *lpPoints, int nCount) { HWND hwnd; int i; LPPOINT pp, ppAlloc = NULL; hwnd = MwPrepareDC(hdc); if(!hwnd) return FALSE; if(MwIsClientDC(hdc)) { /* convert points to client coords*/ ppAlloc = (LPPOINT)malloc(nCount * sizeof(POINT)); if(!ppAlloc) return FALSE; memcpy(ppAlloc, lpPoints, nCount*sizeof(POINT)); pp = ppAlloc; for(i=0; i<nCount; ++i) ClientToScreen(hwnd, pp++); pp = ppAlloc; } else pp = (LPPOINT)lpPoints; /* fill polygon in current brush color*/ if(hdc->brush->style != BS_NULL) { GdSetForegroundColor(hdc->psd, hdc->brush->color); GdFillPoly(hdc->psd, nCount, pp); } /* draw polygon outline in current pen color*/ if(hdc->pen->style != PS_NULL) { GdSetForegroundColor(hdc->psd, hdc->pen->color); GdPoly(hdc->psd, nCount, pp); } if(ppAlloc) free(ppAlloc); return TRUE; }