Graphics::reduceClipRegion() question


#1

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

[code]
Rectangle theFrameRect(g.getClipBounds());
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]

which yields

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.


#2

You’re not creating a triangle, you’re creating two line segments, and clipping to the inside of those lines. Did you mean to call lineTo rather than addLineSegment?


#3

See…I knew it was something stupid!

For the edification of others, AddLineSegment() adds a new subpath, whereas lineTo() adds to the currently open path. There’s not much difference when stroking the whole thing afterwards, but a huge difference if you’re trying to create a region.