]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/pen.cpp
don't compare invalid iterators/node pointers
[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
VZ
17#include "wx/pen.h"
18#include "wx/bitmap.h"
c3d15542 19#include "wx/colour.h"
32b8ec41
VZ
20#include "wx/mgl/private.h"
21
22//-----------------------------------------------------------------------------
23// wxPen
24//-----------------------------------------------------------------------------
25
26class wxPenRefData: public wxObjectRefData
27{
28 public:
29 wxPenRefData();
30 wxPenRefData(const wxPenRefData& data);
31
32 int m_width;
33 int m_style;
34 wxColour m_colour;
35 wxBitmap m_stipple;
36 pixpattern24_t m_pixPattern;
37
38 // not used by wxMGL, but we want to preserve values
39 int m_joinStyle;
40 int m_capStyle;
41 int m_countDashes;
42 wxDash *m_dash;
43};
44
45wxPenRefData::wxPenRefData()
46{
47 m_width = 1;
48 m_style = wxSOLID;
49 m_joinStyle = wxJOIN_ROUND;
50 m_capStyle = wxCAP_ROUND;
51 m_dash = (wxDash*) NULL;
52 m_countDashes = 0;
53
54 int x, y, c;
55 for (y = 0; y < 8; y++)
56 for (x = 0; x < 8; x++)
57 for (c = 0; c < 3; c++)
58 m_pixPattern.p[x][y][c] = 0;
59}
60
61wxPenRefData::wxPenRefData(const wxPenRefData& data)
62{
63 m_style = data.m_style;
64 m_width = data.m_width;
65 m_joinStyle = data.m_joinStyle;
66 m_capStyle = data.m_capStyle;
67 m_colour = data.m_colour;
68 m_countDashes = data.m_countDashes;
69 m_dash = data.m_dash;
70 m_stipple = data.m_stipple;
71
72 int x, y, c;
73 for (y = 0; y < 8; y++)
74 for (x = 0; x < 8; x++)
75 for (c = 0; c < 3; c++)
76 m_pixPattern.p[x][y][c] = data.m_pixPattern.p[x][y][c];
77}
78
79//-----------------------------------------------------------------------------
80
81#define M_PENDATA ((wxPenRefData *)m_refData)
82
83IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
84
32b8ec41
VZ
85wxPen::wxPen(const wxColour &colour, int width, int style)
86{
87 m_refData = new wxPenRefData();
88 M_PENDATA->m_width = width;
89 M_PENDATA->m_style = style;
90 M_PENDATA->m_colour = colour;
32b8ec41
VZ
91}
92
93wxPen::wxPen(const wxBitmap& stipple, int width)
94{
95 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
46562151 96 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
32b8ec41
VZ
97 _T("stipple bitmap must be 8x8") );
98
99 m_refData = new wxPenRefData();
100 M_PENDATA->m_width = width;
101 M_PENDATA->m_style = wxSTIPPLE;
102 M_PENDATA->m_stipple = stipple;
103 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
32b8ec41
VZ
104}
105
32b8ec41
VZ
106bool wxPen::operator == (const wxPen& pen) const
107{
108 return m_refData == pen.m_refData;
109}
110
111bool wxPen::operator != (const wxPen& pen) const
112{
113 return m_refData != pen.m_refData;
114}
115
116void wxPen::SetColour(const wxColour &colour)
117{
6d7ee9e8 118 AllocExclusive();
32b8ec41
VZ
119 M_PENDATA->m_colour = colour;
120}
121
122void wxPen::SetDashes(int number_of_dashes, const wxDash *dash)
123{
6d7ee9e8 124 AllocExclusive();
32b8ec41
VZ
125 M_PENDATA->m_countDashes = number_of_dashes;
126 M_PENDATA->m_dash = (wxDash *)dash; /* TODO */
127}
128
1a1498c0 129void wxPen::SetColour(unsigned char red, unsigned char green, unsigned char blue)
32b8ec41 130{
6d7ee9e8 131 AllocExclusive();
32b8ec41
VZ
132 M_PENDATA->m_colour.Set(red, green, blue);
133}
134
135void wxPen::SetCap(int capStyle)
136{
6d7ee9e8 137 AllocExclusive();
32b8ec41
VZ
138 M_PENDATA->m_capStyle = capStyle;
139}
140
141void wxPen::SetJoin(int joinStyle)
142{
6d7ee9e8 143 AllocExclusive();
32b8ec41
VZ
144 M_PENDATA->m_joinStyle = joinStyle;
145}
146
147void wxPen::SetStyle(int style)
148{
6d7ee9e8 149 AllocExclusive();
32b8ec41
VZ
150 M_PENDATA->m_style = style;
151}
152
153void wxPen::SetStipple(const wxBitmap& stipple)
154{
155 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
46562151 156 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
32b8ec41
VZ
157 _T("stipple bitmap must be 8x8") );
158
6d7ee9e8 159 AllocExclusive();
32b8ec41
VZ
160 M_PENDATA->m_stipple = stipple;
161 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
162}
163
164void wxPen::SetWidth(int width)
165{
6d7ee9e8 166 AllocExclusive();
32b8ec41
VZ
167 M_PENDATA->m_width = width;
168}
169
46562151 170int wxPen::GetDashes(wxDash **ptr) const
32b8ec41 171{
46562151 172 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
32b8ec41
VZ
173 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
174}
175
46562151
WS
176int wxPen::GetDashCount() const
177{
178 return (M_PENDATA->m_countDashes);
32b8ec41
VZ
179}
180
46562151
WS
181wxDash* wxPen::GetDash() const
182{
183 return (wxDash*)M_PENDATA->m_dash;
32b8ec41
VZ
184}
185
186int wxPen::GetCap() const
187{
188 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
189
190 return M_PENDATA->m_capStyle;
191}
192
193int wxPen::GetJoin() const
194{
195 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
196
197 return M_PENDATA->m_joinStyle;
198}
199
200int wxPen::GetStyle() const
201{
202 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
203
204 return M_PENDATA->m_style;
205}
206
207int wxPen::GetWidth() const
208{
209 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
210
211 return M_PENDATA->m_width;
212}
213
214wxColour &wxPen::GetColour() const
215{
216 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
217
218 return M_PENDATA->m_colour;
219}
220
221wxBitmap *wxPen::GetStipple() const
222{
223 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
224
225 return &(M_PENDATA->m_stipple);
226}
227
228void* wxPen::GetPixPattern() const
229{
230 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
231
232 return (void*)&(M_PENDATA->m_pixPattern);
233}
234
235
236bool wxPen::Ok() const
237{
238 return (m_refData != NULL);
239}
240
6d7ee9e8 241wxObjectRefData *wxPen::CreateRefData() const
32b8ec41 242{
6d7ee9e8
VS
243 return new wxPenRefData;
244}
245
246wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
247{
248 return new wxPenRefData(*(wxPenRefData *)data);
32b8ec41 249}