]>
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"
32 wxBitmap
wxRegion::ConvertToBitmap() const
34 wxRect box
= GetBox();
35 wxBitmap
bmp(box
.GetRight(), box
.GetBottom());
38 dc
.SetBackground(*wxBLACK_BRUSH
);
40 dc
.SetClippingRegion(*this);
41 dc
.SetBackground(*wxWHITE_BRUSH
);
43 dc
.SelectObject(wxNullBitmap
);
47 //---------------------------------------------------------------------------
50 static bool DoRegionUnion(wxRegion
& region
,
57 unsigned char hiR
, hiG
, hiB
;
59 hiR
= (unsigned char)wxMin(0xFF, loR
+ tolerance
);
60 hiG
= (unsigned char)wxMin(0xFF, loG
+ tolerance
);
61 hiB
= (unsigned char)wxMin(0xFF, loB
+ tolerance
);
63 // Loop through the image row by row, pixel by pixel, building up
64 // rectangles to add to the region.
65 int width
= image
.GetWidth();
66 int height
= image
.GetHeight();
67 for (int y
=0; y
< height
; y
++)
73 for (int x
=0; x
< width
; x
++)
75 // search for a continuous range of non-transparent pixels
79 unsigned char R
= image
.GetRed(x
,y
);
80 unsigned char G
= image
.GetGreen(x
,y
);
81 unsigned char B
= image
.GetBlue(x
,y
);
82 if (( R
>= loR
&& R
<= hiR
) &&
83 ( G
>= loG
&& G
<= hiG
) &&
84 ( B
>= loB
&& B
<= hiB
)) // It's transparent
89 // Add the run of non-transparent pixels (if any) to the region
102 bool wxRegion::Union(const wxBitmap
& bmp
)
104 #if (!defined(__WXMSW__) || wxUSE_WXDIB)
107 wxImage image
= bmp
.ConvertToImage();
108 wxASSERT_MSG( image
.HasMask(), _T("wxBitmap::ConvertToImage doesn't preserve mask?") );
109 return DoRegionUnion(*this, image
,
111 image
.GetMaskGreen(),
118 return Union(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
122 bool wxRegion::Union(const wxBitmap
& bmp
,
123 const wxColour
& transColour
,
126 #if (!defined(__WXMSW__) || wxUSE_WXDIB)
127 wxImage image
= bmp
.ConvertToImage();
128 return DoRegionUnion(*this, image
,
140 bool wxRegion::Union(const wxBitmap
& WXUNUSED(bmp
))
142 // No wxImage support
146 bool wxRegion::Union(const wxBitmap
& WXUNUSED(bmp
),
147 const wxColour
& WXUNUSED(transColour
),
148 int WXUNUSED(tolerance
))
150 // No wxImage support