public:
/**
Default constructor.
+
+ This constructor creates an invalid, or null, object, i.e. calling
+ IsOk() on it returns @false and IsNull() returns @true.
*/
wxRegion();
/**
/**
Clears the current region.
+
+ The object becomes invalid, or null, after being cleared.
*/
virtual void Clear();
/**
Returns a value indicating whether the given point is contained within the region.
+ This method always returns @c wxOutRegion for an invalid region but
+ may, nevertheless, be safely called in this case.
+
@return The return value is one of @c wxOutRegion and @c wxInRegion.
*/
wxRegionContain Contains(wxCoord x, wxCoord y) const;
/**
Returns a value indicating whether the given point is contained within the region.
+ This method always returns @c wxOutRegion for an invalid region but
+ may, nevertheless, be safely called in this case.
+
@return The return value is one of @c wxOutRegion and @c wxInRegion.
*/
wxRegionContain Contains(const wxPoint& pt) const;
Returns a value indicating whether the given rectangle is contained within the
region.
+ This method always returns @c wxOutRegion for an invalid region but
+ may, nevertheless, be safely called in this case.
+
@return One of ::wxOutRegion, ::wxPartRegion or ::wxInRegion.
@note On Windows, only ::wxOutRegion and ::wxInRegion are returned; a value
Returns a value indicating whether the given rectangle is contained within the
region.
+ This method always returns @c wxOutRegion for an invalid region but
+ may, nevertheless, be safely called in this case.
+
@return One of ::wxOutRegion, ::wxPartRegion or ::wxInRegion.
@note On Windows, only ::wxOutRegion and ::wxInRegion are returned; a value
/**
Convert the region to a black and white bitmap with the white pixels
being inside the region.
+
+ This method can't be used for invalid region.
*/
wxBitmap ConvertToBitmap() const;
//@{
/**
Returns the outer bounds of the region.
+
+ This method returns 0-sized bounding box for invalid regions.
*/
void GetBox(wxCoord& x, wxCoord& y, wxCoord& width,
wxCoord& height) const;
Finds the intersection of this region and another, rectangular region,
specified using position and size.
+ This method always fails, i.e. returns @false, if this region is
+ invalid but may nevertheless be safely used even in this case.
+
@return @true if successful, @false otherwise.
@remarks Creates the intersection of the two regions, that is, the parts
/**
Finds the intersection of this region and another, rectangular region.
+ This method always fails, i.e. returns @false, if this region is
+ invalid but may nevertheless be safely used even in this case.
+
@return @true if successful, @false otherwise.
@remarks Creates the intersection of the two regions, that is, the parts
/**
Finds the intersection of this region and another region.
+ This method always fails, i.e. returns @false, if this region is
+ invalid but may nevertheless be safely used even in this case.
+
@return @true if successful, @false otherwise.
@remarks Creates the intersection of the two regions, that is, the parts
/**
Returns @true if the region is empty, @false otherwise.
+
+ Always returns @true if the region is invalid.
*/
virtual bool IsEmpty() const;
Returns @true if the region is equal to, i.e. covers the same area as,
another one.
- @note If both this region and @a region are invalid, they are
- considered to be equal.
+ If both this region and @a region are both invalid, they are considered
+ to be equal.
*/
bool IsEqual(const wxRegion& region) const;
Moves the region by the specified offsets in horizontal and vertical
directions.
+ This method can't be called if the region is invalid as it doesn't make
+ sense to offset it then. Attempts to do it will result in assert
+ failure.
+
@return @true if successful, @false otherwise (the region is unchanged
then).
*/
/**
Subtracts a rectangular region from this region.
+ This method always fails, i.e. returns @false, if this region is
+ invalid but may nevertheless be safely used even in this case.
+
@return @true if successful, @false otherwise.
@remarks This operation combines the parts of 'this' region that are not
/**
Subtracts a region from this region.
+ This method always fails, i.e. returns @false, if this region is
+ invalid but may nevertheless be safely used even in this case.
+
@return @true if successful, @false otherwise.
@remarks This operation combines the parts of 'this' region that are not
Finds the union of this region and another, rectangular region, specified using
position and size.
+ This method can be used even if this region is invalid and has the
+ natural behaviour in this case, i.e. makes this region equal to the
+ given rectangle.
+
@return @true if successful, @false otherwise.
@remarks This operation creates a region that combines all of this region
/**
Finds the union of this region and another, rectangular region.
+ This method can be used even if this region is invalid and has the
+ natural behaviour in this case, i.e. makes this region equal to the
+ given rectangle.
+
@return @true if successful, @false otherwise.
@remarks This operation creates a region that combines all of this region
/**
Finds the union of this region and another region.
+ This method can be used even if this region is invalid and has the
+ natural behaviour in this case, i.e. makes this region equal to the
+ given @a region.
+
@return @true if successful, @false otherwise.
@remarks This operation creates a region that combines all of this region
Finds the Xor of this region and another, rectangular region, specified using
position and size.
+ This method can be used even if this region is invalid and has the
+ natural behaviour in this case, i.e. makes this region equal to the
+ given rectangle.
+
@return @true if successful, @false otherwise.
@remarks This operation creates a region that combines all of this region
/**
Finds the Xor of this region and another, rectangular region.
+ This method can be used even if this region is invalid and has the
+ natural behaviour in this case, i.e. makes this region equal to the
+ given rectangle.
+
@return @true if successful, @false otherwise.
@remarks This operation creates a region that combines all of this region
/**
Finds the Xor of this region and another region.
+ This method can be used even if this region is invalid and has the
+ natural behaviour in this case, i.e. makes this region equal to the
+ given @a region.
+
@return @true if successful, @false otherwise.
@remarks This operation creates a region that combines all of this region
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: tests/geometry/region.cpp
+// Purpose: wxRegion unit test
+// Author: Vadim Zeitlin
+// Created: 2011-10-12
+// RCS-ID: $Id$
+// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+ #include "wx/region.h"
+#endif // WX_PRECOMP
+
+#include "wx/iosfwrap.h"
+
+// ----------------------------------------------------------------------------
+// helper functions
+// ----------------------------------------------------------------------------
+
+namespace
+{
+
+// This function could be easily added to wxRegionIterator itself, where it
+// could be implemented far more efficiently as all major platforms store the
+// number of rectangles anyhow, but as we only use it for debugging purposes,
+// just keep it here for now.
+unsigned GetRectsCount(const wxRegion& rgn)
+{
+ unsigned count = 0;
+ for ( wxRegionIterator iter(rgn); iter.HaveRects(); ++iter )
+ count++;
+ return count;
+}
+
+} // anonymous namespace
+
+// this operator is needed to use CPPUNIT_ASSERT_EQUAL with wxRegions
+std::ostream& operator<<(std::ostream& os, const wxRegion& rgn)
+{
+ wxRect r = rgn.GetBox();
+ os << "# rects = " << GetRectsCount(rgn)
+ << "; bounding box {"
+ << r.x << ", " << r.y << ", " << r.width << ", " << r.height
+ << "}";
+ return os;
+}
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class RegionTestCase : public CppUnit::TestCase
+{
+public:
+ RegionTestCase() { }
+
+private:
+ CPPUNIT_TEST_SUITE( RegionTestCase );
+ CPPUNIT_TEST( Validity );
+ CPPUNIT_TEST_SUITE_END();
+
+ void Validity();
+
+ wxDECLARE_NO_COPY_CLASS(RegionTestCase);
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( RegionTestCase );
+
+// also include in its own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RegionTestCase, "RegionTestCase" );
+
+void RegionTestCase::Validity()
+{
+ wxRegion r;
+
+ CPPUNIT_ASSERT_MESSAGE
+ (
+ "Default constructed region must be invalid",
+ !r.IsOk()
+ );
+
+ CPPUNIT_ASSERT_MESSAGE
+ (
+ "Invalid region should be empty",
+ r.IsEmpty()
+ );
+
+ // Offsetting an invalid region doesn't make sense.
+ WX_ASSERT_FAILS_WITH_ASSERT( r.Offset(1, 1) );
+
+ CPPUNIT_ASSERT_MESSAGE
+ (
+ "Combining with a valid region should create a valid region",
+ r.Union(0, 0, 10, 10)
+ );
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE
+ (
+ "Union() with invalid region should give the same region",
+ wxRegion(0, 0, 10, 10),
+ r
+ );
+}