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