]>
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"
25 #include "wx/bitmap.h"
32 //---------------------------------------------------------------------------
36 wxBitmap
wxRegion::ConvertToBitmap() const
38 wxRect box
= GetBox();
39 wxBitmap
bmp(box
.GetRight(), box
.GetBottom());
42 dc
.SetBackground(*wxBLACK_BRUSH
);
44 dc
.SetClippingRegion(*this);
45 dc
.SetBackground(*wxWHITE_BRUSH
);
47 dc
.SelectObject(wxNullBitmap
);
51 //---------------------------------------------------------------------------
54 static bool DoRegionUnion(wxRegion
& region
,
61 unsigned char hiR
, hiG
, hiB
;
63 hiR
= (unsigned char)wxMin(0xFF, loR
+ tolerance
);
64 hiG
= (unsigned char)wxMin(0xFF, loG
+ tolerance
);
65 hiB
= (unsigned char)wxMin(0xFF, loB
+ tolerance
);
67 // Loop through the image row by row, pixel by pixel, building up
68 // rectangles to add to the region.
69 int width
= image
.GetWidth();
70 int height
= image
.GetHeight();
71 for (int y
=0; y
< height
; y
++)
77 for (int x
=0; x
< width
; x
++)
79 // search for a continuous range of non-transparent pixels
83 unsigned char R
= image
.GetRed(x
,y
);
84 unsigned char G
= image
.GetGreen(x
,y
);
85 unsigned char B
= image
.GetBlue(x
,y
);
86 if (( R
>= loR
&& R
<= hiR
) &&
87 ( G
>= loG
&& G
<= hiG
) &&
88 ( B
>= loB
&& B
<= hiB
)) // It's transparent
93 // Add the run of non-transparent pixels (if any) to the region
106 bool wxRegion::Union(const wxBitmap
& bmp
)
108 #if (!defined(__WXMSW__) || wxUSE_WXDIB)
111 wxImage image
= bmp
.ConvertToImage();
112 wxASSERT_MSG( image
.HasMask(), _T("wxBitmap::ConvertToImage doesn't preserve mask?") );
113 return DoRegionUnion(*this, image
,
115 image
.GetMaskGreen(),
122 return Union(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
126 bool wxRegion::Union(const wxBitmap
& bmp
,
127 const wxColour
& transColour
,
130 #if (!defined(__WXMSW__) || wxUSE_WXDIB)
131 wxImage image
= bmp
.ConvertToImage();
132 return DoRegionUnion(*this, image
,
144 bool wxRegion::Union(const wxBitmap
& WXUNUSED(bmp
))
146 // No wxImage support
150 bool wxRegion::Union(const wxBitmap
& WXUNUSED(bmp
),
151 const wxColour
& WXUNUSED(transColour
),
152 int WXUNUSED(tolerance
))
154 // No wxImage support
160 //---------------------------------------------------------------------------