static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n) { int i; if (mode != CD_BEZIER && mode != CD_PATH) { for (i = 0; i < n; i++) { if (ctxcanvas->canvas->use_matrix) cdMatrixTransformPoint(ctxcanvas->xmatrix, poly[i].x, poly[i].y, &(poly[i].x), &(poly[i].y)); } } switch( mode ) { case CD_FILL: if (ctxcanvas->canvas->new_region) { GdkRegion* rgn = gdk_region_polygon((GdkPoint*)poly, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE); sCombineRegion(ctxcanvas, rgn); } else gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, TRUE, (GdkPoint*)poly, n); break; case CD_CLOSED_LINES: cdgdkCheckSolidStyle(ctxcanvas, 1); gdk_draw_polygon(ctxcanvas->wnd, ctxcanvas->gc, FALSE, (GdkPoint*)poly, n); cdgdkCheckSolidStyle(ctxcanvas, 0); break; case CD_OPEN_LINES: cdgdkCheckSolidStyle(ctxcanvas, 1); gdk_draw_lines(ctxcanvas->wnd, ctxcanvas->gc, (GdkPoint*)poly, n); cdgdkCheckSolidStyle(ctxcanvas, 0); break; case CD_CLIP: ctxcanvas->clip_rgn = gdk_region_polygon((GdkPoint*)poly, n, ctxcanvas->canvas->fill_mode == CD_EVENODD ? GDK_EVEN_ODD_RULE : GDK_WINDING_RULE); if (ctxcanvas->canvas->clip_mode == CD_CLIPPOLYGON) cdclip(ctxcanvas, CD_CLIPPOLYGON); break; case CD_BEZIER: cdSimPolyBezier(ctxcanvas->canvas, poly, n); break; case CD_PATH: cdSimPolyPath(ctxcanvas->canvas, poly, n); break; } }
static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n) { int i; if (mode == CD_CLIP) return; if (mode == CD_BEZIER) { int i, prec = 100; float (*points)[3] = malloc(n * sizeof(*points)); for(i = 0; i < n; i++) { points[i][0] = (float)poly[i].x; points[i][1] = (float)poly[i].y; points[i][2] = 0; } glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, n, &points[0][0]); glEnable(GL_MAP1_VERTEX_3); glMapGrid1f(prec, 0.0, 1.0); glEvalMesh1(GL_LINE, 0, prec); glDisable(GL_MAP1_VERTEX_3); free(points); return; } if (mode == CD_PATH) { cdSimPolyPath(ctxcanvas->canvas, poly, n); return; } switch (mode) { case CD_CLOSED_LINES : glBegin(GL_LINE_LOOP); break; case CD_OPEN_LINES : glBegin(GL_LINE_STRIP); break; case CD_FILL : if(ctxcanvas->canvas->back_opacity == CD_OPAQUE && glIsEnabled(GL_POLYGON_STIPPLE)) { /* draw twice, one with background color only, and one with foreground color */ glDisable(GL_POLYGON_STIPPLE); glColor4ub(cdRed(ctxcanvas->canvas->background), cdGreen(ctxcanvas->canvas->background), cdBlue(ctxcanvas->canvas->background), cdAlpha(ctxcanvas->canvas->background)); glBegin(GL_POLYGON); for(i = 0; i < n; i++) glVertex2i(poly[i].x, poly[i].y); glEnd(); /* restore the foreground color */ glColor4ub(cdRed(ctxcanvas->canvas->foreground), cdGreen(ctxcanvas->canvas->foreground), cdBlue(ctxcanvas->canvas->foreground), cdAlpha(ctxcanvas->canvas->foreground)); glEnable(GL_POLYGON_STIPPLE); } glBegin(GL_POLYGON); break; } for(i = 0; i < n; i++) glVertex2i(poly[i].x, poly[i].y); glEnd(); (void)ctxcanvas; }