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

@@ -48,8 +48,10 @@ provided array. {\it fillStyle} parameter may have values
{\bf NB:} This constructor is only implemented for Win32 and GTK+ wxWidgets ports.
\func{}{wxRegion}{\param{const wxBitmap\&}{ bmp}}
\func{}{wxRegion}{\param{const wxBitmap\&}{ bmp},
\param{const wxColour\&}{ transColour = wxNullColour},
\param{const wxColour\&}{ transColour},
\param{int}{ tolerance = 0}}
Constructs a region using the non-transparent pixels of a bitmap. See
@@ -183,13 +185,19 @@ Finds the union of this region and another, rectangular region.
Finds the union of this region and another region.
\func{bool}{Union}{\param{const wxBitmap\&}{ bmp}}
Finds the union of this region and the the non-transparent pixels of a
bitmap. Bitmap's mask is used to determine transparency. If the bitmap doesn't
have a mask, solid rectangle of bitmap's dimensions is used.
\func{bool}{Union}{\param{const wxBitmap\&}{ bmp},
\param{const wxColour\&}{ transColour = wxNullColour},
\param{const wxColour\&}{ transColour},
\param{int}{ tolerance = 0}}
Finds the union of this region and the the non-transparent pixels of a
bitmap. If the bitmap has a mask then it will be used, otherwise the
colour to be treated as transparent may be specified, along with an
bitmap. Colour to be treated as transparent is specified in the
\arg{transColour} argument, along with an
optional colour tolerance value.
\wxheading{Return value}

View File

@@ -30,13 +30,13 @@ public:
: wxRegionGeneric(rect)
{}
wxRegion() {}
wxRegion(const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0)
wxRegion(const wxBitmap& bmp)
: wxRegionGeneric()
{
Union(bmp, transColour, tolerance);
}
{ Union(bmp); }
wxRegion(const wxBitmap& bmp,
const wxColour& transColour, int tolerance = 0)
: wxRegionGeneric()
{ Union(bmp, transColour, tolerance); }
~wxRegion() {}
wxRegion(const wxRegion& r)
: wxRegionGeneric(r)
@@ -49,13 +49,13 @@ public:
wxRegion(const NSRect *rects, int count);
// Use the non-transparent pixels of a wxBitmap for the region to combine
// with this region. If the bitmap has a mask then it will be used,
// otherwise the colour to be treated as transparent may be specified,
// with this region. First version takes transparency from bitmap's mask,
// second lets the user specify the colour to be treated as transparent
// along with an optional tolerance value.
// NOTE: implemented in common/rgncmn.cpp
bool Union(const wxBitmap& bmp);
bool Union(const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0);
const wxColour& transColour, int tolerance = 0);
/* And because of function hiding: */
bool Union(long x, long y, long width, long height)
{ return wxRegionGeneric::Union(x,y,width,height); }

View File

@@ -72,9 +72,12 @@ public:
wxRegion( size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
wxRegion( const wxBitmap& bmp)
{
Union(bmp);
}
wxRegion( const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0)
const wxColour& transColour, int tolerance = 0)
{
Union(bmp, transColour, tolerance);
}
@@ -127,12 +130,13 @@ public:
wxBitmap ConvertToBitmap() const;
// Use the non-transparent pixels of a wxBitmap for the region to combine
// with this region. If the bitmap has a mask then it will be used,
// otherwise the colour to be treated as transparent may be specified,
// with this region. First version takes transparency from bitmap's mask,
// second lets the user specify the colour to be treated as transparent
// along with an optional tolerance value.
// NOTE: implemented in common/rgncmn.cpp
bool Union(const wxBitmap& bmp);
bool Union(const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0);
const wxColour& transColour, int tolerance = 0);
public:

View File

@@ -72,9 +72,12 @@ public:
wxRegion( size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
wxRegion( const wxBitmap& bmp)
{
Union(bmp);
}
wxRegion( const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0)
const wxColour& transColour, int tolerance = 0)
{
Union(bmp, transColour, tolerance);
}
@@ -127,12 +130,13 @@ public:
wxBitmap ConvertToBitmap() const;
// Use the non-transparent pixels of a wxBitmap for the region to combine
// with this region. If the bitmap has a mask then it will be used,
// otherwise the colour to be treated as transparent may be specified,
// with this region. First version takes transparency from bitmap's mask,
// second lets the user specify the colour to be treated as transparent
// along with an optional tolerance value.
// NOTE: implemented in common/rgncmn.cpp
bool Union(const wxBitmap& bmp);
bool Union(const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0);
const wxColour& transColour, int tolerance = 0);
public:

View File

@@ -45,9 +45,12 @@ public:
wxRegion(const wxRect& rect);
wxRegion( WXHRGN hRegion );
wxRegion();
wxRegion(const wxBitmap& bmp)
{
Union(bmp);
}
wxRegion(const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0)
const wxColour& transColour, int tolerance = 0)
{
Union(bmp, transColour, tolerance);
}
@@ -122,12 +125,13 @@ public:
wxBitmap ConvertToBitmap() const;
// Use the non-transparent pixels of a wxBitmap for the region to combine
// with this region. If the bitmap has a mask then it will be used,
// otherwise the colour to be treated as transparent may be specified,
// with this region. First version takes transparency from bitmap's mask,
// second lets the user specify the colour to be treated as transparent
// along with an optional tolerance value.
// NOTE: implemented in common/rgncmn.cpp
bool Union(const wxBitmap& bmp);
bool Union(const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0);
const wxColour& transColour, int tolerance = 0);
// Internal
bool Combine(long x, long y, long width, long height, wxRegionOp op);

View File

@@ -45,9 +45,12 @@ public:
wxRegion(const wxRect& rect);
wxRegion( WXHRGN hRegion );
wxRegion();
wxRegion( const wxBitmap& bmp)
{
Union(bmp);
}
wxRegion( const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0)
const wxColour& transColour, int tolerance = 0)
{
Union(bmp, transColour, tolerance);
}
@@ -122,12 +125,13 @@ public:
wxBitmap ConvertToBitmap() const;
// Use the non-transparent pixels of a wxBitmap for the region to combine
// with this region. If the bitmap has a mask then it will be used,
// otherwise the colour to be treated as transparent may be specified,
// with this region. First version takes transparency from bitmap's mask,
// second lets the user specify the colour to be treated as transparent
// along with an optional tolerance value.
// NOTE: implemented in common/rgncmn.cpp
bool Union(const wxBitmap& bmp);
bool Union(const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0);
const wxColour& transColour, int tolerance = 0);
// Internal
bool Combine(long x, long y, long width, long height, wxRegionOp op);

View File

@@ -41,9 +41,12 @@ public:
wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
wxRegion(const wxRect& rect);
wxRegion(const MGLRegion& region);
wxRegion( const wxBitmap& bmp)
{
Union(bmp);
}
wxRegion( const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0)
const wxColour& transColour, int tolerance = 0)
{
Union(bmp, transColour, tolerance);
}
@@ -108,12 +111,13 @@ public:
wxBitmap ConvertToBitmap() const;
// Use the non-transparent pixels of a wxBitmap for the region to combine
// with this region. If the bitmap has a mask then it will be used,
// otherwise the colour to be treated as transparent may be specified,
// with this region. First version takes transparency from bitmap's mask,
// second lets the user specify the colour to be treated as transparent
// along with an optional tolerance value.
// NOTE: implemented in common/rgncmn.cpp
bool Union(const wxBitmap& bmp);
bool Union(const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0);
const wxColour& transColour, int tolerance = 0);
// implementation from now on:

View File

@@ -48,9 +48,12 @@ public:
wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
wxRegion(const wxRect& rect);
wxRegion();
wxRegion( const wxBitmap& bmp)
{
Union(bmp);
}
wxRegion( const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0)
const wxColour& transColour, int tolerance = 0)
{
Union(bmp, transColour, tolerance);
}
@@ -112,12 +115,13 @@ public:
wxBitmap ConvertToBitmap() const;
// Use the non-transparent pixels of a wxBitmap for the region to combine
// with this region. If the bitmap has a mask then it will be used,
// otherwise the colour to be treated as transparent may be specified,
// with this region. First version takes transparency from bitmap's mask,
// second lets the user specify the colour to be treated as transparent
// along with an optional tolerance value.
// NOTE: implemented in common/rgncmn.cpp
bool Union(const wxBitmap& bmp);
bool Union(const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0);
const wxColour& transColour, int tolerance = 0);
// Internal
bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op);

View File

@@ -48,9 +48,12 @@ public:
wxRegion(const wxRect& rect);
wxRegion(WXHRGN hRegion); // Hangs on to this region
wxRegion(size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
wxRegion( const wxBitmap& bmp)
{
Union(bmp);
}
wxRegion( const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0)
const wxColour& transColour, int tolerance = 0)
{
Union(bmp, transColour, tolerance);
}
@@ -119,12 +122,13 @@ public:
wxBitmap ConvertToBitmap() const;
// Use the non-transparent pixels of a wxBitmap for the region to combine
// with this region. If the bitmap has a mask then it will be used,
// otherwise the colour to be treated as transparent may be specified,
// with this region. First version takes transparency from bitmap's mask,
// second lets the user specify the colour to be treated as transparent
// along with an optional tolerance value.
// NOTE: implemented in common/rgncmn.cpp
bool Union(const wxBitmap& bmp);
bool Union(const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0);
const wxColour& transColour, int tolerance = 0);
// Internal
bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op);

View File

@@ -15,6 +15,7 @@
#include "wx/list.h"
#include "wx/gdiobj.h"
#include "wx/gdicmn.h"
#include "wx/bitmap.h"
#include "wx/os2/private.h"
class WXDLLEXPORT wxRect;
@@ -45,6 +46,15 @@ public:
);
wxRegion(const wxRect& rRect);
wxRegion(WXHRGN hRegion, WXHDC hPS); // Hangs on to this region
wxRegion( const wxBitmap& bmp)
{
Union(bmp);
}
wxRegion( const wxBitmap& bmp,
const wxColour& transColour, int tolerance = 0)
{
Union(bmp, transColour, tolerance);
}
wxRegion();
~wxRegion();
@@ -179,13 +189,13 @@ public:
wxBitmap ConvertToBitmap(void) const;
// Use the non-transparent pixels of a wxBitmap for the region to combine
// with this region. If the bitmap has a mask then it will be used,
// otherwise the colour to be treated as transparent may be specified,
// with this region. First version takes transparency from bitmap's mask,
// second lets the user specify the colour to be treated as transparent
// along with an optional tolerance value.
bool Union( const wxBitmap& rBmp
,const wxColour& rTransColour = wxNullColour
,int nTolerance = 0
);
// NOTE: implemented in common/rgncmn.cpp
bool Union(const wxBitmap& bmp);
bool Union(const wxBitmap& bmp,
const wxColour& transColour, int tolerance = 0);
//
// Does the region contain the point pt?

View File

@@ -74,9 +74,12 @@ public:
wxRegion( size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
wxRegion( const wxBitmap& bmp)
{
Union(bmp);
}
wxRegion( const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0)
const wxColour& transColour, int tolerance = 0)
{
Union(bmp, transColour, tolerance);
}
@@ -127,12 +130,13 @@ public:
wxBitmap ConvertToBitmap() const;
// Use the non-transparent pixels of a wxBitmap for the region to combine
// with this region. If the bitmap has a mask then it will be used,
// otherwise the colour to be treated as transparent may be specified,
// with this region. First version takes transparency from bitmap's mask,
// second lets the user specify the colour to be treated as transparent
// along with an optional tolerance value.
// NOTE: implemented in common/rgncmn.cpp
bool Union(const wxBitmap& bmp);
bool Union(const wxBitmap& bmp,
const wxColour& transColour = wxNullColour,
int tolerance = 0);
const wxColour& transColour, int tolerance = 0);
public:

View File

@@ -51,38 +51,15 @@ wxBitmap wxRegion::ConvertToBitmap() const
//---------------------------------------------------------------------------
#if wxUSE_IMAGE
bool wxRegion::Union(const wxBitmap& bmp,
const wxColour& transColour,
static bool DoRegionUnion(wxRegion& region,
const wxImage& image,
unsigned char loR,
unsigned char loG,
unsigned char loB,
int tolerance)
#else
bool wxRegion::Union(const wxBitmap& WXUNUSED(bmp),
const wxColour& WXUNUSED(transColour),
int WXUNUSED(tolerance))
#endif
{
#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
//---------------------------------------------------------------------------

View File

@@ -150,10 +150,7 @@ void wxTaskBarIconArea::SetTrayIcon(const wxBitmap& bmp)
}
wxRegion region;
if (m_bmp.GetMask())
region.Union(m_bmp);
else
region.Union(0,0, iconsize.x, iconsize.y);
// if the bitmap is smaller than the window, offset it:
if (winsize != iconsize)