From 85f6b408dfd796805b1c43718e69549506353ca7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Thu, 3 Jun 2004 21:13:52 +0000 Subject: [PATCH] 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 --- docs/latex/wx/region.tex | 16 +++++-- include/wx/cocoa/region.h | 18 +++---- include/wx/gtk/region.h | 16 ++++--- include/wx/gtk1/region.h | 16 ++++--- include/wx/mac/carbon/region.h | 18 ++++--- include/wx/mac/classic/region.h | 16 ++++--- include/wx/mgl/region.h | 16 ++++--- include/wx/motif/region.h | 16 ++++--- include/wx/msw/region.h | 16 ++++--- include/wx/os2/region.h | 22 ++++++--- include/wx/x11/region.h | 16 ++++--- src/common/rgncmn.cpp | 84 +++++++++++++++++++++------------ src/unix/taskbarx11.cpp | 5 +- 13 files changed, 172 insertions(+), 103 deletions(-) diff --git a/docs/latex/wx/region.tex b/docs/latex/wx/region.tex index 2246cba2cb..09b6beb2ad 100644 --- a/docs/latex/wx/region.tex +++ b/docs/latex/wx/region.tex @@ -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} diff --git a/include/wx/cocoa/region.h b/include/wx/cocoa/region.h index 652b5c8b47..24ac542e83 100644 --- a/include/wx/cocoa/region.h +++ b/include/wx/cocoa/region.h @@ -30,13 +30,13 @@ public: : wxRegionGeneric(rect) {} wxRegion() {} + wxRegion(const wxBitmap& bmp) + : wxRegionGeneric() + { Union(bmp); } wxRegion(const wxBitmap& bmp, - const wxColour& transColour = wxNullColour, - int tolerance = 0) + const wxColour& transColour, int tolerance = 0) : wxRegionGeneric() - { - Union(bmp, transColour, tolerance); - } + { 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); } diff --git a/include/wx/gtk/region.h b/include/wx/gtk/region.h index 90356ba2ea..5eec88fe82 100644 --- a/include/wx/gtk/region.h +++ b/include/wx/gtk/region.h @@ -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: diff --git a/include/wx/gtk1/region.h b/include/wx/gtk1/region.h index 90356ba2ea..5eec88fe82 100644 --- a/include/wx/gtk1/region.h +++ b/include/wx/gtk1/region.h @@ -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: diff --git a/include/wx/mac/carbon/region.h b/include/wx/mac/carbon/region.h index ab04dd8975..24c060337f 100644 --- a/include/wx/mac/carbon/region.h +++ b/include/wx/mac/carbon/region.h @@ -45,9 +45,12 @@ public: wxRegion(const wxRect& rect); wxRegion( WXHRGN hRegion ); wxRegion(); - wxRegion( const wxBitmap& bmp, - const wxColour& transColour = wxNullColour, - int tolerance = 0) + wxRegion(const wxBitmap& bmp) + { + Union(bmp); + } + wxRegion(const wxBitmap& bmp, + 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); diff --git a/include/wx/mac/classic/region.h b/include/wx/mac/classic/region.h index ab04dd8975..f71565a964 100644 --- a/include/wx/mac/classic/region.h +++ b/include/wx/mac/classic/region.h @@ -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); diff --git a/include/wx/mgl/region.h b/include/wx/mgl/region.h index ec8f4474a2..c9ba07c32b 100644 --- a/include/wx/mgl/region.h +++ b/include/wx/mgl/region.h @@ -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: diff --git a/include/wx/motif/region.h b/include/wx/motif/region.h index 9fe9acd613..a03e4e8ced 100644 --- a/include/wx/motif/region.h +++ b/include/wx/motif/region.h @@ -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); diff --git a/include/wx/msw/region.h b/include/wx/msw/region.h index f145db6025..4539ec1d81 100644 --- a/include/wx/msw/region.h +++ b/include/wx/msw/region.h @@ -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); diff --git a/include/wx/os2/region.h b/include/wx/os2/region.h index 4a60ed3fa0..6205315f22 100644 --- a/include/wx/os2/region.h +++ b/include/wx/os2/region.h @@ -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? diff --git a/include/wx/x11/region.h b/include/wx/x11/region.h index 0b3c967d3c..6d25a33e0d 100644 --- a/include/wx/x11/region.h +++ b/include/wx/x11/region.h @@ -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: diff --git a/src/common/rgncmn.cpp b/src/common/rgncmn.cpp index 581ecbf68e..2b1b5b6600 100644 --- a/src/common/rgncmn.cpp +++ b/src/common/rgncmn.cpp @@ -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; +} + + +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 } +#endif + //--------------------------------------------------------------------------- diff --git a/src/unix/taskbarx11.cpp b/src/unix/taskbarx11.cpp index 759be00a01..a4d1798111 100644 --- a/src/unix/taskbarx11.cpp +++ b/src/unix/taskbarx11.cpp @@ -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); + region.Union(m_bmp); // if the bitmap is smaller than the window, offset it: if (winsize != iconsize) -- 2.45.2