## Am I understanding this code about regions correctly?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
wx_n00b
In need of some credit
Posts: 9
Joined: Thu Sep 05, 2013 12:07 am

### Am I understanding this code about regions correctly?

Hi, I found the following code online. Now, I'm trying to figure what it does based on the code itself and online docs. I figured that if I can explain what the code does in layman's terms, I'll be able to understand what's going (at the very least have some sense of what is happening.) Are my explanations correct?

If you're curious, I found the code here:
http://zetcode.com/gui/wxwidgets/gdi/

Code: Select all

``````  // RECTANGLE 2
dc.SetBrush(wxBrush(white));

// draw two rectangles.  The inside of the rectangles will be white with
//  gray borders.
dc.DrawRectangle(101, 20, 50, 50);
dc.DrawRectangle(110, 40, 50, 50);

// create two regions that we'll use.  Since regions do not have borders and
//  instead are hidden and exist only in concept, make sure that they share
//  the same coordiates.
wxRegion region1(100, 20, 50, 50);
wxRegion region2(110, 40, 50, 50);

// intersect the two regions.
region1.Intersect(region2);

// after the intersection, get the resulting box (the outer bounds of the
//  region.)
wxRect rect1 = region1.GetBox();

// create a region where we can draw and only there.
dc.SetClippingRegion(region1);
// set the color of the brush (which is used to fill in a rectangle.)
dc.SetBrush(wxBrush(red));
// draw the rectangle that we desire.
dc.DrawRectangle(rect1);
// clean up after ourselves.
dc.DestroyClippingRegion();
// RECTANGLE 2``````

doublemax
Moderator
Posts: 14782
Joined: Fri Apr 21, 2006 8:03 pm
Location: \$FCE2

### Re: Am I understanding this code about regions correctly?

Sounds right. But the method descriptions together with the screenshot in the tutorial should be clear.
Use the source, Luke!