void MyCanvas::shadeRect(const GRect& rect, GShader* shader) { assert(shader != nullptr); if (rect.isEmpty()) { printf("Error: ShadeRect rectangle is empty\n"); return; } /* Convert the rectangle into points, then CTM the resulting points */ auto Points = Utility::RectToPoints(rect); CTMPoints(Points); if ( !CTM.preservesRect()) //If the CTM does not preserve a rectangle, draw a polygon { auto Edges = pointsToEdges(Points); shadeDevicePolygon(Edges, shader); return; } //Convert the CTM'd points back into a rect since we know it preserves it GIRect ConvertedRect = Utility::PointsToRect(Points).round(); // Make sure rect is not an empty one and clip the edges from the bitmap with intersect if (ConvertedRect.isEmpty() || !ConvertedRect.intersect(BmpRect)) { return; } shadeDeviceRect(ConvertedRect, shader); }
virtual void fillRect(const GRect& rect, const GColor& color) { GPixel c = color.premulToPixel(); if (0 == GPixel_GetA(c)) { return; } GIRect ir = fIBounds; if (ir.intersect(rect.round())) { srcover_rect(fDevice, ir, c); } }