]>
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "rgncmn.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
24 #include "wx/region.h"
25 #include "wx/bitmap.h"
29 #include "wx/dcmemory.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
)
110 wxImage image
= bmp
.ConvertToImage();
111 wxASSERT_MSG( image
.HasMask(), _T("wxBitmap::ConvertToImage doesn't preserve mask?") );
112 return DoRegionUnion(*this, image
,
114 image
.GetMaskGreen(),
120 return Union(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
124 bool wxRegion::Union(const wxBitmap
& bmp
,
125 const wxColour
& transColour
,
128 wxImage image
= bmp
.ConvertToImage();
129 return DoRegionUnion(*this, image
,
138 bool wxRegion::Union(const wxBitmap
& WXUNUSED(bmp
))
140 // No wxImage support
144 bool wxRegion::Union(const wxBitmap
& WXUNUSED(bmp
),
145 const wxColour
& WXUNUSED(transColour
),
146 int WXUNUSED(tolerance
))
148 // No wxImage support
154 //---------------------------------------------------------------------------