]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/brush.cpp
don't use obsolete functions (mostly copystring() and Count()), remove their document...
[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"
51b7f946 19#include "wx/dcmemory.h"
32b8ec41
VZ
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 {
cf6824d9 38 mem.SelectObjectAsSource(bitmap);
32b8ec41
VZ
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 {
cf6824d9 53 mem.SelectObjectAsSource(bitmap.GetMask()->GetBitmap());
32b8ec41
VZ
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
55ccdb93
VZ
79 bool operator == (const wxBrushRefData& data) const
80 {
81 return (m_style == data.m_style &&
a3ab1c18 82 m_stipple.IsSameAs(data.m_stipple) &&
55ccdb93
VZ
83 m_colour == data.m_colour);
84 }
85
32b8ec41
VZ
86 int m_style;
87 wxColour m_colour;
88 wxBitmap m_stipple;
89 pixpattern24_t m_pixPattern;
90 pattern_t m_maskPattern;
91};
92
93wxBrushRefData::wxBrushRefData()
94{
95 m_style = 0;
96
97 int x, y, c;
98 for (y = 0; y < 8; y++)
99 for (x = 0; x < 8; x++)
100 for (c = 0; c < 3; c++)
101 m_pixPattern.p[y][x][c] = 0;
102 for (y = 0; y < 8; y++)
103 m_maskPattern.p[y] = 0;
104}
105
106wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
107{
108 m_style = data.m_style;
109 m_stipple = data.m_stipple;
110 m_colour = data.m_colour;
111
112 int x, y, c;
113 for (y = 0; y < 8; y++)
114 for (x = 0; x < 8; x++)
115 for (c = 0; c < 3; c++)
116 m_pixPattern.p[y][x][c] = data.m_pixPattern.p[y][x][c];
117 for (y = 0; y < 8; y++)
118 m_maskPattern.p[y] = data.m_maskPattern.p[y];
119}
120
121//-----------------------------------------------------------------------------
122
123#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
124
125IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
126
32b8ec41
VZ
127wxBrush::wxBrush(const wxColour &colour, int style)
128{
129 m_refData = new wxBrushRefData();
130 M_BRUSHDATA->m_style = style;
131 M_BRUSHDATA->m_colour = colour;
32b8ec41
VZ
132}
133
134wxBrush::wxBrush(const wxBitmap &stippleBitmap)
135{
136 wxCHECK_RET( stippleBitmap.Ok(), _T("invalid bitmap") );
46562151 137 wxCHECK_RET( stippleBitmap.GetWidth() == 8 && stippleBitmap.GetHeight() == 8,
32b8ec41
VZ
138 _T("stipple bitmap must be 8x8") );
139
140 m_refData = new wxBrushRefData();
141 M_BRUSHDATA->m_colour = *wxBLACK;
46562151 142
32b8ec41 143 M_BRUSHDATA->m_stipple = stippleBitmap;
46562151 144 wxBitmapToPixPattern(stippleBitmap, &(M_BRUSHDATA->m_pixPattern),
32b8ec41
VZ
145 &(M_BRUSHDATA->m_maskPattern));
146
147 if (M_BRUSHDATA->m_stipple.GetMask())
46562151
WS
148 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
149 else
150 M_BRUSHDATA->m_style = wxSTIPPLE;
32b8ec41
VZ
151}
152
32b8ec41
VZ
153bool wxBrush::operator == (const wxBrush& brush) const
154{
55ccdb93
VZ
155 if (m_refData == brush.m_refData) return true;
156
157 if (!m_refData || !brush.m_refData) return false;
158
159 return *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData;
32b8ec41
VZ
160}
161
162bool wxBrush::operator != (const wxBrush& brush) const
163{
164 return m_refData != brush.m_refData;
165}
166
b7cacb43 167bool wxBrush::IsOk() const
32b8ec41
VZ
168{
169 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
170}
171
172int wxBrush::GetStyle() const
173{
174 if (m_refData == NULL)
175 {
176 wxFAIL_MSG( wxT("invalid brush") );
177 return 0;
178 }
179
180 return M_BRUSHDATA->m_style;
181}
182
183wxColour &wxBrush::GetColour() const
184{
185 if (m_refData == NULL)
186 {
187 wxFAIL_MSG( wxT("invalid brush") );
188 return wxNullColour;
189 }
190
191 return M_BRUSHDATA->m_colour;
192}
193
194wxBitmap *wxBrush::GetStipple() const
195{
196 if (m_refData == NULL)
197 {
198 wxFAIL_MSG( wxT("invalid brush") );
199 return &wxNullBitmap;
200 }
201
202 return &M_BRUSHDATA->m_stipple;
203}
204
205void* wxBrush::GetMaskPattern() const
206{
207 wxCHECK_MSG( Ok(), NULL, wxT("invalid brush") );
208
209 return (void*)&(M_BRUSHDATA->m_maskPattern);
210}
211
212void* wxBrush::GetPixPattern() const
213{
214 wxCHECK_MSG( Ok(), NULL, wxT("invalid brush") );
215
216 return (void*)&(M_BRUSHDATA->m_pixPattern);
217}
218
219void wxBrush::SetColour(const wxColour& col)
220{
6d7ee9e8 221 AllocExclusive();
32b8ec41
VZ
222 M_BRUSHDATA->m_colour = col;
223}
224
1a1498c0 225void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
32b8ec41 226{
6d7ee9e8 227 AllocExclusive();
32b8ec41
VZ
228 M_BRUSHDATA->m_colour.Set(r, g, b);
229}
230
231void wxBrush::SetStyle( int style )
232{
6d7ee9e8 233 AllocExclusive();
32b8ec41
VZ
234 M_BRUSHDATA->m_style = style;
235}
236
237void wxBrush::SetStipple(const wxBitmap& stipple)
238{
6d7ee9e8 239 AllocExclusive();
32b8ec41
VZ
240
241 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
46562151 242 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
32b8ec41
VZ
243 _T("stipple bitmap must be 8x8") );
244
245 M_BRUSHDATA->m_stipple = stipple;
246 wxBitmapToPixPattern(stipple, &(M_BRUSHDATA->m_pixPattern),
247 &(M_BRUSHDATA->m_maskPattern));
248
249 if (M_BRUSHDATA->m_stipple.GetMask())
250 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
251 else
252 M_BRUSHDATA->m_style = wxSTIPPLE;
253}
254
6d7ee9e8 255wxObjectRefData *wxBrush::CreateRefData() const
32b8ec41 256{
6d7ee9e8
VS
257 return new wxBrushRefData;
258}
259
260wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
261{
262 return new wxBrushRefData(*(wxBrushRefData *)data);
32b8ec41 263}