split wxRegion(wxBitmap) ctor into two ctors with clearer semantics

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27606 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2004-06-03 21:13:52 +00:00
parent 4772f8e198
commit 85f6b408df
13 changed files with 176 additions and 107 deletions

View File

@@ -51,38 +51,15 @@ wxBitmap wxRegion::ConvertToBitmap() const
//---------------------------------------------------------------------------
#if wxUSE_IMAGE
bool wxRegion::Union(const wxBitmap& bmp,
const wxColour& transColour,
int tolerance)
#else
bool wxRegion::Union(const wxBitmap& WXUNUSED(bmp),
const wxColour& WXUNUSED(transColour),
int WXUNUSED(tolerance))
#endif
static bool DoRegionUnion(wxRegion& region,
const wxImage& image,
unsigned char loR,
unsigned char loG,
unsigned char loB,
int tolerance)
{
#if wxUSE_IMAGE
unsigned char loR, loG, loB;
unsigned char hiR, hiG, hiB;
wxCHECK_MSG((bmp.GetMask() != NULL) || transColour.Ok(),
FALSE,
wxT("Either the bitmap should have a mask or a colour should be given."));
wxImage image = bmp.ConvertToImage();
if (image.HasMask())
{
loR = image.GetMaskRed();
loG = image.GetMaskGreen();
loB = image.GetMaskBlue();
}
else
{
loR = transColour.Red();
loG = transColour.Green();
loB = transColour.Blue();
}
hiR = wxMin(0xFF, loR + tolerance);
hiG = wxMin(0xFF, loG + tolerance);
hiB = wxMin(0xFF, loB + tolerance);
@@ -117,16 +94,61 @@ bool wxRegion::Union(const wxBitmap& WXUNUSED(bmp),
if (x > x0) {
rect.x = x0;
rect.width = x - x0;
Union(rect);
region.Union(rect);
}
}
}
return true;
#else
// No wxImage support
return false;
#endif
}
bool wxRegion::Union(const wxBitmap& bmp)
{
if (bmp.GetMask())
{
wxImage image = bmp.ConvertToImage();
wxASSERT_MSG( image.HasMask(), _T("wxBitmap::ConvertToImage doesn't preserve mask?") );
return DoRegionUnion(*this, image,
image.GetMaskRed(),
image.GetMaskGreen(),
image.GetMaskBlue(),
0);
}
else
{
return Union(0, 0, bmp.GetWidth(), bmp.GetHeight());
}
}
bool wxRegion::Union(const wxBitmap& bmp,
const wxColour& transColour,
int tolerance)
{
wxImage image = bmp.ConvertToImage();
return DoRegionUnion(*this, image,
transColour.Red(),
transColour.Green(),
transColour.Blue(),
tolerance);
}
#else
bool wxRegion::Union(const wxBitmap& WXUNUSED(bmp))
{
// No wxImage support
return false;
}
bool wxRegion::Union(const wxBitmap& WXUNUSED(bmp),
const wxColour& WXUNUSED(transColour),
int WXUNUSED(tolerance))
{
// No wxImage support
return false;
}
#endif
//---------------------------------------------------------------------------