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