Working through the zetcode wxwidgets tutorial:Device Contexts:Pen/Regions

Everything, is fairly straight forward in the pen example. It uses wxDC::DrawRectangle where is an abstract data class for wxPaintDC. Basically a bunch of rectangles are drawn with different patterns.
The patterns are defined constructor in wxPen

So… on to Regions… Now piece of sample codes gets a little more interesting to me…
This is one of those instance where a picture is worth a thousand words…

On a side note, at some point I need to get back to drag and drop. I just fired up Inkscape and dragged and dropped the png into it.  I’m thinking about adding some  some notes on the graphic.  I’m going to have to learn how to do that… I basically bypassed it in this tutorial..

In zetcode’s sample code nearly each set of squares is build around the same template.

dc.SetBrush(wxBrush(white));
dc.DrawRectangle(100, 20, 50, 50);
dc.DrawRectangle(110, 40, 50, 50);
wxRegion region1(100, 20, 50, 50);
wxRegion region2(110, 40, 50, 50);
region1.Intersect(region2);
wxRect rect1 = region1.GetBox();
dc.SetClippingRegion(region1);
dc.SetBrush(wxBrush(red));
dc.DrawRectangle(rect1);
dc.DestroyClippingRegion();

Ok.. lets see. SetBrush, Drawrectangle, been there/ done that..
wxRegion, SetClippingRegion , DestroyClippingRegion are new for me.

I basically copied this from the wxsite

wxRegion

A wxRegion represents a simple or complex region on a device context or window.

This class uses reference counting and copy-on-write internally so that assignments between two instances of this class are very cheap. You can therefore use actual objects instead of pointers without efficiency problems. If an instance of this class is changed it will create its own data internally so that other instances, which previously shared the data using the reference counting, are not affected.

Derived from

wxGDIObject
wxObject

Include files

<wx/region.h>

See also

wxRegionIterator

Members

wxRegion::wxRegion
wxRegion::~wxRegion
wxRegion::Clear
wxRegion::Contains
wxRegion::ConvertToBitmap
wxRegion::GetBox
wxRegion::Intersect
wxRegion::IsEmpty
wxRegion::IsEqual
wxRegion::Subtract
wxRegion::Offset
wxRegion::Union
wxRegion::Xor
wxRegion::operator =

This entry was posted in OpenCascade, Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *