I’m having a little trouble with the reduceClipRegion() call. To try to figure out what I’m doing wrong, I wrote a little code
int theTop = theFrameRect.getY();
int theBottom = theFrameRect.getBottom();
int theWidth = theFrameRect.getWidth();
int theLeft = theFrameRect.getX();
g.drawRect(theFrameRect); //draw a frame around the drawing area Path theInclusionArea; //draw a triangle in the bottom left corner theInclusionArea.startNewSubPath(theLeft, theTop); theInclusionArea.addLineSegment(Line<float>(theLeft, theTop,theWidth, theBottom),1); theInclusionArea.addLineSegment(Line<float>(theWidth, theBottom,theLeft, theBottom), 1); theInclusionArea.closeSubPath(); g.strokePath(theInclusionArea, 1, AffineTransform::identity); //draw the area we're clipping to g.reduceClipRegion(theInclusionArea); g.drawVerticalLine(theWidth/2, theTop, theBottom); //draw a line down the vertical center g.drawHorizontalLine(theBottom/2, theLeft, theWidth); //and across the horizontal center[/code]
I would have expected to see the a vertical and horizontal line crossing the rectangle, but only shown below the diagonal from top left to bottom right. What has happened here?
Oddly, if I change the clip region to an ellipse, I get exactly the results I would have expected: the only drawing that happens subsequent to the call to reduceClipRegion is within the ellipse.