]>
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: wxWidgets 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 bool wxRegion::Union(const wxBitmap
& bmp
,
55 const wxColour
& transColour
,
58 bool wxRegion::Union(const wxBitmap
& WXUNUSED(bmp
),
59 const wxColour
& WXUNUSED(transColour
),
60 int WXUNUSED(tolerance
))
64 unsigned char loR
, loG
, loB
;
65 unsigned char hiR
, hiG
, hiB
;
67 wxCHECK_MSG((bmp
.GetMask() != NULL
) || transColour
.Ok(),
69 wxT("Either the bitmap should have a mask or a colour should be given."));
71 wxImage image
= bmp
.ConvertToImage();
75 loR
= image
.GetMaskRed();
76 loG
= image
.GetMaskGreen();
77 loB
= image
.GetMaskBlue();
81 loR
= transColour
.Red();
82 loG
= transColour
.Green();
83 loB
= transColour
.Blue();
86 hiR
= wxMin(0xFF, loR
+ tolerance
);
87 hiG
= wxMin(0xFF, loG
+ tolerance
);
88 hiB
= wxMin(0xFF, loB
+ tolerance
);
90 // Loop through the image row by row, pixel by pixel, building up
91 // rectangles to add to the region.
92 int width
= image
.GetWidth();
93 int height
= image
.GetHeight();
94 for (int y
=0; y
< height
; y
++)
100 for (int x
=0; x
< width
; x
++)
102 // search for a continuous range of non-transparent pixels
106 unsigned char R
= image
.GetRed(x
,y
);
107 unsigned char G
= image
.GetGreen(x
,y
);
108 unsigned char B
= image
.GetBlue(x
,y
);
109 if (( R
>= loR
&& R
<= hiR
) &&
110 ( G
>= loG
&& G
<= hiG
) &&
111 ( B
>= loB
&& B
<= hiB
)) // It's transparent
116 // Add the run of non-transparent pixels (if any) to the region
127 // No wxImage support
132 //---------------------------------------------------------------------------