]>
git.saurik.com Git - wxWidgets.git/blob - src/common/rgncmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Methods of wxRegion that have a generic implementation
6 // Created: 27-Mar-2003
8 // Copyright: (c) Robin Dunn
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/region.h"
20 #include "wx/bitmap.h"
24 #include "wx/dcmemory.h"
27 //---------------------------------------------------------------------------
31 wxBitmap
wxRegion::ConvertToBitmap() const
33 wxRect box
= GetBox();
34 wxBitmap
bmp(box
.GetRight(), box
.GetBottom());
37 dc
.SetBackground(*wxBLACK_BRUSH
);
39 dc
.SetClippingRegion(*this);
40 dc
.SetBackground(*wxWHITE_BRUSH
);
42 dc
.SelectObject(wxNullBitmap
);
46 //---------------------------------------------------------------------------
49 static bool DoRegionUnion(wxRegion
& region
,
56 unsigned char hiR
, hiG
, hiB
;
58 hiR
= (unsigned char)wxMin(0xFF, loR
+ tolerance
);
59 hiG
= (unsigned char)wxMin(0xFF, loG
+ tolerance
);
60 hiB
= (unsigned char)wxMin(0xFF, loB
+ tolerance
);
62 // Loop through the image row by row, pixel by pixel, building up
63 // rectangles to add to the region.
64 int width
= image
.GetWidth();
65 int height
= image
.GetHeight();
66 for (int y
=0; y
< height
; y
++)
72 for (int x
=0; x
< width
; x
++)
74 // search for a continuous range of non-transparent pixels
78 unsigned char R
= image
.GetRed(x
,y
);
79 unsigned char G
= image
.GetGreen(x
,y
);
80 unsigned char B
= image
.GetBlue(x
,y
);
81 if (( R
>= loR
&& R
<= hiR
) &&
82 ( G
>= loG
&& G
<= hiG
) &&
83 ( B
>= loB
&& B
<= hiB
)) // It's transparent
88 // Add the run of non-transparent pixels (if any) to the region
101 bool wxRegion::Union(const wxBitmap
& bmp
)
103 #if (!defined(__WXMSW__) || wxUSE_WXDIB)
106 wxImage image
= bmp
.ConvertToImage();
107 wxASSERT_MSG( image
.HasMask(), _T("wxBitmap::ConvertToImage doesn't preserve mask?") );
108 return DoRegionUnion(*this, image
,
110 image
.GetMaskGreen(),
117 return Union(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
121 bool wxRegion::Union(const wxBitmap
& bmp
,
122 const wxColour
& transColour
,
125 #if (!defined(__WXMSW__) || wxUSE_WXDIB)
126 wxImage image
= bmp
.ConvertToImage();
127 return DoRegionUnion(*this, image
,
139 bool wxRegion::Union(const wxBitmap
& WXUNUSED(bmp
))
141 // No wxImage support
145 bool wxRegion::Union(const wxBitmap
& WXUNUSED(bmp
),
146 const wxColour
& WXUNUSED(transColour
),
147 int WXUNUSED(tolerance
))
149 // No wxImage support
155 //---------------------------------------------------------------------------