]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/brush.cpp
added a cast to wxDecodeSurrogate() to fix wxMSW cross-compilation
[wxWidgets.git] / src / mgl / brush.cpp
CommitLineData
32b8ec41 1/////////////////////////////////////////////////////////////////////////////
46562151 2// Name: src/mgl/brush.cpp
32b8ec41
VZ
3// Purpose:
4// Author: Vaclav Slavik
5// Id: $Id$
c41c20a5 6// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
46562151 7// Licence: wxWindows licence
32b8ec41
VZ
8/////////////////////////////////////////////////////////////////////////////
9
32b8ec41
VZ
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
17#include "wx/brush.h"
18#include "wx/mgl/private.h"
19#include "wx/mgl/dcmemory.h"
20
21
22// ---------------------------------------------------------------------------
23// helper functions
24// ---------------------------------------------------------------------------
25
26// This function converts wxBitmap into pixpattern24_t representation
27// (used by wxBrush and wxPen)
28
46562151 29void wxBitmapToPixPattern(const wxBitmap& bitmap,
32b8ec41
VZ
30 pixpattern24_t *pix, pattern_t *mask)
31{
32 wxMemoryDC mem;
33 MGLDevCtx *dc;
34 int x, y;
46562151 35
32b8ec41
VZ
36 if ( pix != NULL )
37 {
38 mem.SelectObject(bitmap);
39 dc = mem.GetMGLDC();
40 wxCurrentDCSwitcher curDC(dc);
41 dc->beginPixel();
42 for (y = 0; y < 8; y++)
43 for (x = 0; x < 8; x++)
46562151 44 dc->unpackColorFast(dc->getPixelFast(x, y),
32b8ec41 45 pix->p[y][x][2],
46562151 46 pix->p[y][x][1],
32b8ec41
VZ
47 pix->p[y][x][0]);
48 dc->endPixel();
49 }
50
51 if ( mask && bitmap.GetMask() )
52 {
53 mem.SelectObject(*bitmap.GetMask()->GetBitmap());
54 dc = mem.GetMGLDC();
55 wxCurrentDCSwitcher curDC(dc);
56 dc->beginPixel();
57 for (y = 0; y < 8; y++)
58 {
59 mask->p[y] = 0;
60 for (x = 0; x < 8; x++)
61 if ( dc->getPixelFast(x, y) != 0 )
127eab18 62 mask->p[y] = (uchar)(mask->p[y] | (1 << (7 - x)));
32b8ec41
VZ
63 }
64 dc->endPixel();
65 }
66}
67
68
69//-----------------------------------------------------------------------------
70// wxBrush
71//-----------------------------------------------------------------------------
72
73class wxBrushRefData: public wxObjectRefData
74{
75public:
76 wxBrushRefData();
77 wxBrushRefData(const wxBrushRefData& data);
78
79 int m_style;
80 wxColour m_colour;
81 wxBitmap m_stipple;
82 pixpattern24_t m_pixPattern;
83 pattern_t m_maskPattern;
84};
85
86wxBrushRefData::wxBrushRefData()
87{
88 m_style = 0;
89
90 int x, y, c;
91 for (y = 0; y < 8; y++)
92 for (x = 0; x < 8; x++)
93 for (c = 0; c < 3; c++)
94 m_pixPattern.p[y][x][c] = 0;
95 for (y = 0; y < 8; y++)
96 m_maskPattern.p[y] = 0;
97}
98
99wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
100{
101 m_style = data.m_style;
102 m_stipple = data.m_stipple;
103 m_colour = data.m_colour;
104
105 int x, y, c;
106 for (y = 0; y < 8; y++)
107 for (x = 0; x < 8; x++)
108 for (c = 0; c < 3; c++)
109 m_pixPattern.p[y][x][c] = data.m_pixPattern.p[y][x][c];
110 for (y = 0; y < 8; y++)
111 m_maskPattern.p[y] = data.m_maskPattern.p[y];
112}
113
114//-----------------------------------------------------------------------------
115
116#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
117
118IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
119
32b8ec41
VZ
120wxBrush::wxBrush(const wxColour &colour, int style)
121{
122 m_refData = new wxBrushRefData();
123 M_BRUSHDATA->m_style = style;
124 M_BRUSHDATA->m_colour = colour;
32b8ec41
VZ
125}
126
127wxBrush::wxBrush(const wxBitmap &stippleBitmap)
128{
129 wxCHECK_RET( stippleBitmap.Ok(), _T("invalid bitmap") );
46562151 130 wxCHECK_RET( stippleBitmap.GetWidth() == 8 && stippleBitmap.GetHeight() == 8,
32b8ec41
VZ
131 _T("stipple bitmap must be 8x8") );
132
133 m_refData = new wxBrushRefData();
134 M_BRUSHDATA->m_colour = *wxBLACK;
46562151 135
32b8ec41 136 M_BRUSHDATA->m_stipple = stippleBitmap;
46562151 137 wxBitmapToPixPattern(stippleBitmap, &(M_BRUSHDATA->m_pixPattern),
32b8ec41
VZ
138 &(M_BRUSHDATA->m_maskPattern));
139
140 if (M_BRUSHDATA->m_stipple.GetMask())
46562151
WS
141 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
142 else
143 M_BRUSHDATA->m_style = wxSTIPPLE;
32b8ec41
VZ
144}
145
32b8ec41
VZ
146bool wxBrush::operator == (const wxBrush& brush) const
147{
148 return m_refData == brush.m_refData;
149}
150
151bool wxBrush::operator != (const wxBrush& brush) const
152{
153 return m_refData != brush.m_refData;
154}
155
156bool wxBrush::Ok() const
157{
158 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
159}
160
161int wxBrush::GetStyle() const
162{
163 if (m_refData == NULL)
164 {
165 wxFAIL_MSG( wxT("invalid brush") );
166 return 0;
167 }
168
169 return M_BRUSHDATA->m_style;
170}
171
172wxColour &wxBrush::GetColour() const
173{
174 if (m_refData == NULL)
175 {
176 wxFAIL_MSG( wxT("invalid brush") );
177 return wxNullColour;
178 }
179
180 return M_BRUSHDATA->m_colour;
181}
182
183wxBitmap *wxBrush::GetStipple() const
184{
185 if (m_refData == NULL)
186 {
187 wxFAIL_MSG( wxT("invalid brush") );
188 return &wxNullBitmap;
189 }
190
191 return &M_BRUSHDATA->m_stipple;
192}
193
194void* wxBrush::GetMaskPattern() const
195{
196 wxCHECK_MSG( Ok(), NULL, wxT("invalid brush") );
197
198 return (void*)&(M_BRUSHDATA->m_maskPattern);
199}
200
201void* wxBrush::GetPixPattern() const
202{
203 wxCHECK_MSG( Ok(), NULL, wxT("invalid brush") );
204
205 return (void*)&(M_BRUSHDATA->m_pixPattern);
206}
207
208void wxBrush::SetColour(const wxColour& col)
209{
6d7ee9e8 210 AllocExclusive();
32b8ec41
VZ
211 M_BRUSHDATA->m_colour = col;
212}
213
1a1498c0 214void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
32b8ec41 215{
6d7ee9e8 216 AllocExclusive();
32b8ec41
VZ
217 M_BRUSHDATA->m_colour.Set(r, g, b);
218}
219
220void wxBrush::SetStyle( int style )
221{
6d7ee9e8 222 AllocExclusive();
32b8ec41
VZ
223 M_BRUSHDATA->m_style = style;
224}
225
226void wxBrush::SetStipple(const wxBitmap& stipple)
227{
6d7ee9e8 228 AllocExclusive();
32b8ec41
VZ
229
230 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
46562151 231 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
32b8ec41
VZ
232 _T("stipple bitmap must be 8x8") );
233
234 M_BRUSHDATA->m_stipple = stipple;
235 wxBitmapToPixPattern(stipple, &(M_BRUSHDATA->m_pixPattern),
236 &(M_BRUSHDATA->m_maskPattern));
237
238 if (M_BRUSHDATA->m_stipple.GetMask())
239 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
240 else
241 M_BRUSHDATA->m_style = wxSTIPPLE;
242}
243
6d7ee9e8 244wxObjectRefData *wxBrush::CreateRefData() const
32b8ec41 245{
6d7ee9e8
VS
246 return new wxBrushRefData;
247}
248
249wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
250{
251 return new wxBrushRefData(*(wxBrushRefData *)data);
32b8ec41 252}