int cdCanvasPlay(cdCanvas* canvas, cdContext* context, int xmin, int xmax, int ymin, int ymax, void *data) { assert(context); assert(canvas); if (!_cdCheckCanvas(canvas) || !context || !context->cxPlay) return CD_ERROR; /* the all can be 0 here, do not use cdCheckBoxSize */ if (xmin > xmax) _cdSwapInt(xmin, xmax); if (ymin > ymax) _cdSwapInt(ymin, ymax); return context->cxPlay(canvas, xmin, xmax, ymin, ymax, data); }
void simFillHorizLine(cdSimulation* simulation, int xmin, int y, int xmax) { cdCanvas* canvas = simulation->canvas; if(xmin > xmax) _cdSwapInt(xmin, xmax); switch(canvas->interior_style) { case CD_SOLID: simulation->SolidLine(canvas, xmin,y,xmax, canvas->foreground); break; case CD_PATTERN: simulation->PatternLine(canvas, xmin,xmax,y,canvas->pattern_w, canvas->pattern + canvas->pattern_w*CalcYPat(y, canvas->pattern_h)); break; case CD_HATCH: simulation->HatchLine(canvas, xmin,xmax,y,SimHatchBits[canvas->hatch_style][CalcYHatch(y, 7)]); break; case CD_STIPPLE: simulation->StippleLine(canvas, xmin, xmax, y, canvas->stipple_w, canvas->stipple + canvas->stipple_w*CalcYPat(y, canvas->stipple_h)); } }
void cdCanvasScrollArea(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, int dx, int dy) { assert(canvas); if (!_cdCheckCanvas(canvas)) return; if (!canvas->cxScrollArea) return; if (!cdCheckBoxSize(&xmin, &xmax, &ymin, &ymax)) return; if (dx == 0 && dy == 0) return; if (canvas->use_origin) { xmin += canvas->origin.x; xmax += canvas->origin.x; ymin += canvas->origin.y; ymax += canvas->origin.y; } if (canvas->invert_yaxis) { dy = -dy; ymin = _cdInvertYAxis(canvas, ymin); ymax = _cdInvertYAxis(canvas, ymax); _cdSwapInt(ymin, ymax); } canvas->cxScrollArea(canvas->ctxcanvas, xmin, xmax, ymin, ymax, dx, dy); }
void cdCanvasBox(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax) { assert(canvas); if (!_cdCheckCanvas(canvas)) return; if (canvas->interior_style == CD_HOLLOW) { cdCanvasRect(canvas, xmin, xmax, ymin, ymax); return; } if (!cdCheckBoxSize(&xmin, &xmax, &ymin, &ymax)) return; if (canvas->use_origin) { xmin += canvas->origin.x; xmax += canvas->origin.x; ymin += canvas->origin.y; ymax += canvas->origin.y; } if (canvas->invert_yaxis) { ymin = _cdInvertYAxis(canvas, ymin); ymax = _cdInvertYAxis(canvas, ymax); _cdSwapInt(ymin, ymax); } canvas->cxBox(canvas->ctxcanvas, xmin, xmax, ymin, ymax); }
int simAddSegment(simLineSegment* segment, int x1, int y1, int x2, int y2, int *y_max, int *y_min) { if (x1==x2 && y1==y2) return 0; /* Make sure p2.y > p1.y */ if (y1 > y2) { _cdSwapInt(y1, y2); _cdSwapInt(x1, x2); segment->Swap = 1; } else segment->Swap = 0; segment->x1 = x1; segment->y1 = y1; segment->x2 = x2; segment->y2 = y2; segment->x = x2; /* initial value */ segment->DeltaY = y2 - y1; segment->DeltaX = x2 - x1; if (segment->DeltaX >= 0) segment->XDir = -1; /* inverted from simLineThin since here is from p2 to p1 */ else { segment->XDir = 1; segment->DeltaX = -segment->DeltaX; /* make DeltaX positive */ } segment->ErrorAcc = 0; /* initialize the line error accumulator to 0 */ /* Is this an X-major or Y-major line? */ if (segment->DeltaY > segment->DeltaX) { if (segment->DeltaY==0) /* do not compute for horizontal segments */ return 1; /* Y-major line; calculate 16-bit fixed-point fractional part of a pixel that X advances each time Y advances 1 pixel, truncating the result so that we won't overrun the endpoint along the X axis */ segment->ErrorInc = (unsigned short)(((unsigned long)segment->DeltaX << 16) / (unsigned long)segment->DeltaY); } else { if (segment->DeltaX==0) /* do not compute for vertical segments */ return 1; /* It's an X-major line; calculate 16-bit fixed-point fractional part of a pixel that Y advances each time X advances 1 pixel, truncating the result to avoid overrunning the endpoint along the X axis */ segment->ErrorInc = (unsigned short)(((unsigned long)segment->DeltaY << 16) / (unsigned long)segment->DeltaX); } /* also calculates y_max and y_min of the polygon */ if (y2 > *y_max) *y_max = y2; if (y1 < *y_min) *y_min = y1; return 1; }