X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f38924e863cd44e2abd49d20d201d72aa773c51e..b3ee9f4d2efa4a5088b4c84eb8a0ba712fa7e7fb:/src/common/rgncmn.cpp?ds=sidebyside diff --git a/src/common/rgncmn.cpp b/src/common/rgncmn.cpp index a32f24e8cf..f70b680303 100644 --- a/src/common/rgncmn.cpp +++ b/src/common/rgncmn.cpp @@ -9,6 +9,10 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -20,38 +24,57 @@ #ifndef WX_PRECOMP #include "wx/dcmemory.h" + #include "wx/bitmap.h" + #include "wx/image.h" #endif //WX_PRECOMP -#include "wx/bitmap.h" +// ============================================================================ +// wxRegionBase implementation +// ============================================================================ -#if wxUSE_IMAGE - #include "wx/image.h" -#endif +// ---------------------------------------------------------------------------- +// region comparison +// ---------------------------------------------------------------------------- +bool wxRegionBase::IsEqual(const wxRegion& region) const +{ + if ( m_refData == region.GetRefData() ) + { + // regions are identical, hence equal + return true; + } -//--------------------------------------------------------------------------- + if ( !m_refData || !region.GetRefData() ) + { + // one, but not both, of the regions is invalid + return false; + } + return DoIsEqual(region); +} +// ---------------------------------------------------------------------------- +// region to/from bitmap conversions +// ---------------------------------------------------------------------------- -wxBitmap wxRegion::ConvertToBitmap() const +wxBitmap wxRegionBase::ConvertToBitmap() const { wxRect box = GetBox(); - wxBitmap bmp(box.GetRight(), box.GetBottom()); + wxBitmap bmp(box.GetRight() + 1, box.GetBottom() + 1); wxMemoryDC dc; dc.SelectObject(bmp); dc.SetBackground(*wxBLACK_BRUSH); dc.Clear(); - dc.SetClippingRegion(*this); + dc.SetDeviceClippingRegion(*static_cast(this)); dc.SetBackground(*wxWHITE_BRUSH); dc.Clear(); dc.SelectObject(wxNullBitmap); return bmp; } -//--------------------------------------------------------------------------- - #if wxUSE_IMAGE -static bool DoRegionUnion(wxRegion& region, + +static bool DoRegionUnion(wxRegionBase& region, const wxImage& image, unsigned char loR, unsigned char loG, @@ -103,13 +126,12 @@ static bool DoRegionUnion(wxRegion& region, } -bool wxRegion::Union(const wxBitmap& bmp) +bool wxRegionBase::Union(const wxBitmap& bmp) { -#if (!defined(__WXMSW__) || wxUSE_WXDIB) if (bmp.GetMask()) { wxImage image = bmp.ConvertToImage(); - wxASSERT_MSG( image.HasMask(), _T("wxBitmap::ConvertToImage doesn't preserve mask?") ); + wxASSERT_MSG( image.HasMask(), wxT("wxBitmap::ConvertToImage doesn't preserve mask?") ); return DoRegionUnion(*this, image, image.GetMaskRed(), image.GetMaskGreen(), @@ -117,44 +139,54 @@ bool wxRegion::Union(const wxBitmap& bmp) 0); } else -#endif { return Union(0, 0, bmp.GetWidth(), bmp.GetHeight()); } } -bool wxRegion::Union(const wxBitmap& bmp, - const wxColour& transColour, - int tolerance) +bool wxRegionBase::Union(const wxBitmap& bmp, + const wxColour& transColour, + int tolerance) { -#if (!defined(__WXMSW__) || wxUSE_WXDIB) wxImage image = bmp.ConvertToImage(); return DoRegionUnion(*this, image, transColour.Red(), transColour.Green(), transColour.Blue(), tolerance); -#else - return false; -#endif } -#else +#endif // wxUSE_IMAGE + +#ifdef wxHAS_REGION_COMBINE +// ============================================================================ +// wxRegionWithCombine +// ============================================================================ -bool wxRegion::Union(const wxBitmap& WXUNUSED(bmp)) +// implement some wxRegionBase pure virtuals in terms of Combine() +bool wxRegionWithCombine::DoUnionWithRect(const wxRect& rect) { - // No wxImage support - return false; + return Combine(rect, wxRGN_OR); } -bool wxRegion::Union(const wxBitmap& WXUNUSED(bmp), - const wxColour& WXUNUSED(transColour), - int WXUNUSED(tolerance)) +bool wxRegionWithCombine::DoUnionWithRegion(const wxRegion& region) { - // No wxImage support - return false; + return DoCombine(region, wxRGN_OR); } -#endif +bool wxRegionWithCombine::DoIntersect(const wxRegion& region) +{ + return DoCombine(region, wxRGN_AND); +} + +bool wxRegionWithCombine::DoSubtract(const wxRegion& region) +{ + return DoCombine(region, wxRGN_DIFF); +} + +bool wxRegionWithCombine::DoXor(const wxRegion& region) +{ + return DoCombine(region, wxRGN_XOR); +} -//--------------------------------------------------------------------------- +#endif // wxHAS_REGION_COMBINE