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