]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/pen.cpp
vista tree crash fix
[wxWidgets.git] / src / mgl / pen.cpp
CommitLineData
32b8ec41 1/////////////////////////////////////////////////////////////////////////////
46562151 2// Name: src/mgl/pen.cpp
32b8ec41
VZ
3// Purpose:
4// Author: Vaclav Slavik
5// Id: $Id$
c41c20a5 6// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
65571936 7// Licence: wxWindows licence
32b8ec41
VZ
8/////////////////////////////////////////////////////////////////////////////
9
a246f95e
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
32b8ec41 17#include "wx/pen.h"
0bca0373
WS
18
19#ifndef WX_PRECOMP
20 #include "wx/bitmap.h"
7cf41a5d 21 #include "wx/colour.h"
0bca0373
WS
22#endif
23
32b8ec41
VZ
24#include "wx/mgl/private.h"
25
26//-----------------------------------------------------------------------------
27// wxPen
28//-----------------------------------------------------------------------------
29
30class wxPenRefData: public wxObjectRefData
31{
e001091c
VZ
32public:
33 wxPenRefData();
34 wxPenRefData(const wxPenRefData& data);
32b8ec41 35
55ccdb93
VZ
36 bool operator==(const wxPenRefData& data) const
37 {
38 // we intentionally don't compare m_hPen fields here
39 return m_style == data.m_style &&
40 m_width == data.m_width &&
d395dbab
VZ
41 memcmp(&m_pixPattern,
42 &data.m_pixPattern, sizeof(m_pixPattern)) == 0 &&
55ccdb93
VZ
43 m_capStyle == data.m_capStyle &&
44 m_joinStyle == data.m_joinStyle &&
45 m_colour == data.m_colour &&
ed7ec76d
FM
46 (m_style != wxPENSTYLE_STIPPLE || m_stipple.IsSameAs(data.m_stipple)) &&
47 (m_style != wxPENSTYLE_USER_DASH ||
55ccdb93
VZ
48 (m_dash == data.m_dash &&
49 memcmp(m_dash, data.m_dash, m_countDashes*sizeof(wxDash)) == 0));
50 }
51
e001091c 52 int m_width;
82cddbd9 53 wxPenStyle m_style;
e001091c
VZ
54 wxColour m_colour;
55 wxBitmap m_stipple;
56 pixpattern24_t m_pixPattern;
32b8ec41 57
e001091c 58 // not used by wxMGL, but we want to preserve values
82cddbd9
FM
59 wxPenJoin m_joinStyle;
60 wxPenCap m_capStyle;
e001091c
VZ
61 int m_countDashes;
62 wxDash *m_dash;
32b8ec41
VZ
63};
64
65wxPenRefData::wxPenRefData()
66{
67 m_width = 1;
ed7ec76d 68 m_style = wxPENSTYLE_SOLID;
32b8ec41
VZ
69 m_joinStyle = wxJOIN_ROUND;
70 m_capStyle = wxCAP_ROUND;
71 m_dash = (wxDash*) NULL;
72 m_countDashes = 0;
73
74 int x, y, c;
75 for (y = 0; y < 8; y++)
76 for (x = 0; x < 8; x++)
77 for (c = 0; c < 3; c++)
78 m_pixPattern.p[x][y][c] = 0;
79}
80
81wxPenRefData::wxPenRefData(const wxPenRefData& data)
82{
83 m_style = data.m_style;
84 m_width = data.m_width;
85 m_joinStyle = data.m_joinStyle;
86 m_capStyle = data.m_capStyle;
87 m_colour = data.m_colour;
88 m_countDashes = data.m_countDashes;
89 m_dash = data.m_dash;
90 m_stipple = data.m_stipple;
91
92 int x, y, c;
93 for (y = 0; y < 8; y++)
94 for (x = 0; x < 8; x++)
95 for (c = 0; c < 3; c++)
96 m_pixPattern.p[x][y][c] = data.m_pixPattern.p[x][y][c];
97}
98
99//-----------------------------------------------------------------------------
100
101#define M_PENDATA ((wxPenRefData *)m_refData)
102
103IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
104
82cddbd9 105wxPen::wxPen(const wxColour &colour, int width, wxPenStyle style)
32b8ec41
VZ
106{
107 m_refData = new wxPenRefData();
108 M_PENDATA->m_width = width;
109 M_PENDATA->m_style = style;
110 M_PENDATA->m_colour = colour;
32b8ec41
VZ
111}
112
82cddbd9
FM
113wxPen::wxPen(const wxColour& colour, int width, wxBrushStyle style)
114{
115 m_refData = new wxPenRefData();
116 M_PENDATA->m_width = width;
117 M_PENDATA->m_style = (wxPenStyle)style;
118 M_PENDATA->m_colour = colour;
119}
120
32b8ec41
VZ
121wxPen::wxPen(const wxBitmap& stipple, int width)
122{
123 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
46562151 124 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
32b8ec41
VZ
125 _T("stipple bitmap must be 8x8") );
126
127 m_refData = new wxPenRefData();
128 M_PENDATA->m_width = width;
ed7ec76d 129 M_PENDATA->m_style = wxPENSTYLE_STIPPLE;
32b8ec41
VZ
130 M_PENDATA->m_stipple = stipple;
131 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
32b8ec41
VZ
132}
133
32b8ec41
VZ
134bool wxPen::operator == (const wxPen& pen) const
135{
55ccdb93
VZ
136 if (m_refData == pen.m_refData) return true;
137
138 if (!m_refData || !pen.m_refData) return false;
139
140 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
32b8ec41
VZ
141}
142
143bool wxPen::operator != (const wxPen& pen) const
144{
145 return m_refData != pen.m_refData;
146}
147
148void wxPen::SetColour(const wxColour &colour)
149{
6d7ee9e8 150 AllocExclusive();
32b8ec41
VZ
151 M_PENDATA->m_colour = colour;
152}
153
154void wxPen::SetDashes(int number_of_dashes, const wxDash *dash)
155{
6d7ee9e8 156 AllocExclusive();
32b8ec41
VZ
157 M_PENDATA->m_countDashes = number_of_dashes;
158 M_PENDATA->m_dash = (wxDash *)dash; /* TODO */
159}
160
1a1498c0 161void wxPen::SetColour(unsigned char red, unsigned char green, unsigned char blue)
32b8ec41 162{
6d7ee9e8 163 AllocExclusive();
32b8ec41
VZ
164 M_PENDATA->m_colour.Set(red, green, blue);
165}
166
82cddbd9 167void wxPen::SetCap(wxPenCap capStyle)
32b8ec41 168{
6d7ee9e8 169 AllocExclusive();
32b8ec41
VZ
170 M_PENDATA->m_capStyle = capStyle;
171}
172
82cddbd9 173void wxPen::SetJoin(wxPenJoin joinStyle)
32b8ec41 174{
6d7ee9e8 175 AllocExclusive();
32b8ec41
VZ
176 M_PENDATA->m_joinStyle = joinStyle;
177}
178
82cddbd9 179void wxPen::SetStyle(wxPenStyle style)
32b8ec41 180{
6d7ee9e8 181 AllocExclusive();
32b8ec41
VZ
182 M_PENDATA->m_style = style;
183}
184
185void wxPen::SetStipple(const wxBitmap& stipple)
186{
187 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
46562151 188 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
32b8ec41
VZ
189 _T("stipple bitmap must be 8x8") );
190
6d7ee9e8 191 AllocExclusive();
32b8ec41
VZ
192 M_PENDATA->m_stipple = stipple;
193 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
194}
195
196void wxPen::SetWidth(int width)
197{
6d7ee9e8 198 AllocExclusive();
32b8ec41
VZ
199 M_PENDATA->m_width = width;
200}
201
46562151 202int wxPen::GetDashes(wxDash **ptr) const
32b8ec41 203{
46562151 204 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
32b8ec41
VZ
205 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
206}
207
46562151
WS
208int wxPen::GetDashCount() const
209{
210 return (M_PENDATA->m_countDashes);
32b8ec41
VZ
211}
212
46562151
WS
213wxDash* wxPen::GetDash() const
214{
215 return (wxDash*)M_PENDATA->m_dash;
32b8ec41
VZ
216}
217
82cddbd9 218wxPenCap wxPen::GetCap() const
32b8ec41
VZ
219{
220 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
221
222 return M_PENDATA->m_capStyle;
223}
224
82cddbd9 225wxPenJoin wxPen::GetJoin() const
32b8ec41
VZ
226{
227 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
228
229 return M_PENDATA->m_joinStyle;
230}
231
82cddbd9 232wxPenStyle wxPen::GetStyle() const
32b8ec41
VZ
233{
234 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
235
236 return M_PENDATA->m_style;
237}
238
239int wxPen::GetWidth() const
240{
241 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
242
243 return M_PENDATA->m_width;
244}
245
246wxColour &wxPen::GetColour() const
247{
248 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
249
250 return M_PENDATA->m_colour;
251}
252
253wxBitmap *wxPen::GetStipple() const
254{
255 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
256
257 return &(M_PENDATA->m_stipple);
258}
259
260void* wxPen::GetPixPattern() const
261{
262 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
263
264 return (void*)&(M_PENDATA->m_pixPattern);
265}
266
267
8f884a0d 268wxGDIRefData *wxPen::CreateGDIRefData() const
32b8ec41 269{
6d7ee9e8
VS
270 return new wxPenRefData;
271}
272
8f884a0d 273wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
6d7ee9e8
VS
274{
275 return new wxPenRefData(*(wxPenRefData *)data);
32b8ec41 276}