]>
git.saurik.com Git - wxWidgets.git/blob - src/common/rgncmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/rgncmn.cpp
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"
22 #include "wx/dcmemory.h"
23 #include "wx/bitmap.h"
28 wxBitmap
wxRegion::ConvertToBitmap() const
30 wxRect box
= GetBox();
31 wxBitmap
bmp(box
.GetRight(), box
.GetBottom());
34 dc
.SetBackground(*wxBLACK_BRUSH
);
36 dc
.SetClippingRegion(*this);
37 dc
.SetBackground(*wxWHITE_BRUSH
);
39 dc
.SelectObject(wxNullBitmap
);
43 //---------------------------------------------------------------------------
46 static bool DoRegionUnion(wxRegion
& region
,
53 unsigned char hiR
, hiG
, hiB
;
55 hiR
= (unsigned char)wxMin(0xFF, loR
+ tolerance
);
56 hiG
= (unsigned char)wxMin(0xFF, loG
+ tolerance
);
57 hiB
= (unsigned char)wxMin(0xFF, loB
+ tolerance
);
59 // Loop through the image row by row, pixel by pixel, building up
60 // rectangles to add to the region.
61 int width
= image
.GetWidth();
62 int height
= image
.GetHeight();
63 for (int y
=0; y
< height
; y
++)
69 for (int x
=0; x
< width
; x
++)
71 // search for a continuous range of non-transparent pixels
75 unsigned char R
= image
.GetRed(x
,y
);
76 unsigned char G
= image
.GetGreen(x
,y
);
77 unsigned char B
= image
.GetBlue(x
,y
);
78 if (( R
>= loR
&& R
<= hiR
) &&
79 ( G
>= loG
&& G
<= hiG
) &&
80 ( B
>= loB
&& B
<= hiB
)) // It's transparent
85 // Add the run of non-transparent pixels (if any) to the region
98 bool wxRegion::Union(const wxBitmap
& bmp
)
100 #if (!defined(__WXMSW__) || wxUSE_WXDIB)
103 wxImage image
= bmp
.ConvertToImage();
104 wxASSERT_MSG( image
.HasMask(), _T("wxBitmap::ConvertToImage doesn't preserve mask?") );
105 return DoRegionUnion(*this, image
,
107 image
.GetMaskGreen(),
114 return Union(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
118 bool wxRegion::Union(const wxBitmap
& bmp
,
119 const wxColour
& transColour
,
122 #if (!defined(__WXMSW__) || wxUSE_WXDIB)
123 wxImage image
= bmp
.ConvertToImage();
124 return DoRegionUnion(*this, image
,
136 bool wxRegion::Union(const wxBitmap
& WXUNUSED(bmp
))
138 // No wxImage support
142 bool wxRegion::Union(const wxBitmap
& WXUNUSED(bmp
),
143 const wxColour
& WXUNUSED(transColour
),
144 int WXUNUSED(tolerance
))
146 // No wxImage support