Reset clip region on Graphics


#1

For example, having this:

[code]// reduce clip region to certain part of screen
g.reduceClipRegion(clip_x,clip_y,clip_w,clip_h);

// draw stuff here (clipped to the region reduced above)
// …

// end clipping
g.setClipRegion(RectangleList(Rectangle(0,0,w,h)));[/code]

Just wondering if there’s a more elegant call to restore default clip region for the current graphic context, because under osx seems the last line throws assertion (doesnt do under WinXP).


Expand clip region
#2

You can save the clip and restore it like this:

    const RectangleList originalClipRegion (g.getClipRegion());

    ...

    g.setClipRegion (originalClipRegion);

It’s very dodgy to set it to your own rectangle, because this might push it beyond the edges of the image it’s drawing onto.


#3

Thanks.


#4

Sorry for kicking this old topic, but how would this be done in the latest version of JUCE? There’s no more Graphics.setClipRegion function…

I’m pretty new to JUCE, and I’m probably missing something stupidly obvious here, but I can’t find how to increase/reset the clipping rectangle.

graphics->reduceClipRegion(100, 100, 50, 50);

//This obviously doesn't work, as it isn't much of a reduction:
//graphics->reduceClipRegion(0,0,1024,1024);

Thanks!


#5

There’s no way to do that, and no need.

If you want to reduce the clip and then reset it, you’d do something like this:

[code]g.saveState();
g.reduceClipRegion (…);
…draw here with the reduced region
g.restoreState();

…and it’s back to normal here[/code]


#6

Thanks! :smiley:


#7