]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/pen.cpp
Add standard art providers at the bottom of the art providers stack.
[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;
d3b9f782 71 m_dash = NULL;
32b8ec41
VZ
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
ac3688c0
FM
113#if FUTURE_WXWIN_COMPATIBILITY_3_0
114wxPen::wxPen(const wxColour& colour, int width, int style)
82cddbd9
FM
115{
116 m_refData = new wxPenRefData();
117 M_PENDATA->m_width = width;
118 M_PENDATA->m_style = (wxPenStyle)style;
119 M_PENDATA->m_colour = colour;
120}
ac3688c0 121#endif
82cddbd9 122
32b8ec41
VZ
123wxPen::wxPen(const wxBitmap& stipple, int width)
124{
a1b806b9 125 wxCHECK_RET( stipple.IsOk(), wxT("invalid bitmap") );
46562151 126 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
9a83f860 127 wxT("stipple bitmap must be 8x8") );
32b8ec41
VZ
128
129 m_refData = new wxPenRefData();
130 M_PENDATA->m_width = width;
ed7ec76d 131 M_PENDATA->m_style = wxPENSTYLE_STIPPLE;
32b8ec41
VZ
132 M_PENDATA->m_stipple = stipple;
133 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
32b8ec41
VZ
134}
135
32b8ec41
VZ
136bool wxPen::operator == (const wxPen& pen) const
137{
55ccdb93
VZ
138 if (m_refData == pen.m_refData) return true;
139
140 if (!m_refData || !pen.m_refData) return false;
141
142 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
32b8ec41
VZ
143}
144
145bool wxPen::operator != (const wxPen& pen) const
146{
147 return m_refData != pen.m_refData;
148}
149
150void wxPen::SetColour(const wxColour &colour)
151{
6d7ee9e8 152 AllocExclusive();
32b8ec41
VZ
153 M_PENDATA->m_colour = colour;
154}
155
156void wxPen::SetDashes(int number_of_dashes, const wxDash *dash)
157{
6d7ee9e8 158 AllocExclusive();
32b8ec41
VZ
159 M_PENDATA->m_countDashes = number_of_dashes;
160 M_PENDATA->m_dash = (wxDash *)dash; /* TODO */
161}
162
1a1498c0 163void wxPen::SetColour(unsigned char red, unsigned char green, unsigned char blue)
32b8ec41 164{
6d7ee9e8 165 AllocExclusive();
32b8ec41
VZ
166 M_PENDATA->m_colour.Set(red, green, blue);
167}
168
82cddbd9 169void wxPen::SetCap(wxPenCap capStyle)
32b8ec41 170{
6d7ee9e8 171 AllocExclusive();
32b8ec41
VZ
172 M_PENDATA->m_capStyle = capStyle;
173}
174
82cddbd9 175void wxPen::SetJoin(wxPenJoin joinStyle)
32b8ec41 176{
6d7ee9e8 177 AllocExclusive();
32b8ec41
VZ
178 M_PENDATA->m_joinStyle = joinStyle;
179}
180
82cddbd9 181void wxPen::SetStyle(wxPenStyle style)
32b8ec41 182{
6d7ee9e8 183 AllocExclusive();
32b8ec41
VZ
184 M_PENDATA->m_style = style;
185}
186
187void wxPen::SetStipple(const wxBitmap& stipple)
188{
a1b806b9 189 wxCHECK_RET( stipple.IsOk(), wxT("invalid bitmap") );
46562151 190 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
9a83f860 191 wxT("stipple bitmap must be 8x8") );
32b8ec41 192
6d7ee9e8 193 AllocExclusive();
32b8ec41
VZ
194 M_PENDATA->m_stipple = stipple;
195 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
196}
197
198void wxPen::SetWidth(int width)
199{
6d7ee9e8 200 AllocExclusive();
32b8ec41
VZ
201 M_PENDATA->m_width = width;
202}
203
46562151 204int wxPen::GetDashes(wxDash **ptr) const
32b8ec41 205{
a1b806b9 206 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
ac3688c0
FM
207
208 *ptr = (wxDash*)M_PENDATA->m_dash;
209 return M_PENDATA->m_countDashes;
32b8ec41
VZ
210}
211
46562151
WS
212int wxPen::GetDashCount() const
213{
a1b806b9 214 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
ac3688c0 215
46562151 216 return (M_PENDATA->m_countDashes);
32b8ec41
VZ
217}
218
46562151
WS
219wxDash* wxPen::GetDash() const
220{
a1b806b9 221 wxCHECK_MSG( IsOk(), NULL, wxT("invalid pen") );
ac3688c0 222
46562151 223 return (wxDash*)M_PENDATA->m_dash;
32b8ec41
VZ
224}
225
82cddbd9 226wxPenCap wxPen::GetCap() const
32b8ec41 227{
a1b806b9 228 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
32b8ec41
VZ
229
230 return M_PENDATA->m_capStyle;
231}
232
82cddbd9 233wxPenJoin wxPen::GetJoin() const
32b8ec41 234{
a1b806b9 235 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
32b8ec41
VZ
236
237 return M_PENDATA->m_joinStyle;
238}
239
82cddbd9 240wxPenStyle wxPen::GetStyle() const
32b8ec41 241{
a1b806b9 242 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
32b8ec41
VZ
243
244 return M_PENDATA->m_style;
245}
246
247int wxPen::GetWidth() const
248{
a1b806b9 249 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
32b8ec41
VZ
250
251 return M_PENDATA->m_width;
252}
253
231b9591 254wxColour wxPen::GetColour() const
32b8ec41 255{
a1b806b9 256 wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid pen") );
32b8ec41
VZ
257
258 return M_PENDATA->m_colour;
259}
260
261wxBitmap *wxPen::GetStipple() const
262{
a1b806b9 263 wxCHECK_MSG( IsOk(), NULL, wxT("invalid pen") );
32b8ec41
VZ
264
265 return &(M_PENDATA->m_stipple);
266}
267
268void* wxPen::GetPixPattern() const
269{
a1b806b9 270 wxCHECK_MSG( IsOk(), NULL, wxT("invalid pen") );
32b8ec41
VZ
271
272 return (void*)&(M_PENDATA->m_pixPattern);
273}
274
275
8f884a0d 276wxGDIRefData *wxPen::CreateGDIRefData() const
32b8ec41 277{
6d7ee9e8
VS
278 return new wxPenRefData;
279}
280
8f884a0d 281wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
6d7ee9e8
VS
282{
283 return new wxPenRefData(*(wxPenRefData *)data);
32b8ec41 284}