some more build fix for wxPen/wxBrush style changes
[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 memcmp(&m_pixPattern,
42 &data.m_pixPattern, sizeof(m_pixPattern)) == 0 &&
43 m_capStyle == data.m_capStyle &&
44 m_joinStyle == data.m_joinStyle &&
45 m_colour == data.m_colour &&
46 (m_style != wxPENSTYLE_STIPPLE || m_stipple.IsSameAs(data.m_stipple)) &&
47 (m_style != wxPENSTYLE_USER_DASH ||
48 (m_dash == data.m_dash &&
49 memcmp(m_dash, data.m_dash, m_countDashes*sizeof(wxDash)) == 0));
50 }
51
52 int m_width;
53 wxPenStyle m_style;
54 wxColour m_colour;
55 wxBitmap m_stipple;
56 pixpattern24_t m_pixPattern;
57
58 // not used by wxMGL, but we want to preserve values
59 wxPenJoin m_joinStyle;
60 wxPenCap m_capStyle;
61 int m_countDashes;
62 wxDash *m_dash;
63 };
64
65 wxPenRefData::wxPenRefData()
66 {
67 m_width = 1;
68 m_style = wxPENSTYLE_SOLID;
69 m_joinStyle = wxJOIN_ROUND;
70 m_capStyle = wxCAP_ROUND;
71 m_dash = (wxDash*) NULL;
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
81 wxPenRefData::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
103 IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
104
105 wxPen::wxPen(const wxColour &colour, int width, wxPenStyle style)
106 {
107 m_refData = new wxPenRefData();
108 M_PENDATA->m_width = width;
109 M_PENDATA->m_style = style;
110 M_PENDATA->m_colour = colour;
111 }
112
113 wxPen::wxPen(const wxColour& colour, int width, wxBrushStyle style)
114 {
115 m_refData = new wxPenRefData();
116 M_PENDATA->m_width = width;
117 M_PENDATA->m_style = (wxPenStyle)style;
118 M_PENDATA->m_colour = colour;
119 }
120
121 wxPen::wxPen(const wxBitmap& stipple, int width)
122 {
123 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
124 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
125 _T("stipple bitmap must be 8x8") );
126
127 m_refData = new wxPenRefData();
128 M_PENDATA->m_width = width;
129 M_PENDATA->m_style = wxPENSTYLE_STIPPLE;
130 M_PENDATA->m_stipple = stipple;
131 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
132 }
133
134 bool wxPen::operator == (const wxPen& pen) const
135 {
136 if (m_refData == pen.m_refData) return true;
137
138 if (!m_refData || !pen.m_refData) return false;
139
140 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
141 }
142
143 bool wxPen::operator != (const wxPen& pen) const
144 {
145 return m_refData != pen.m_refData;
146 }
147
148 void wxPen::SetColour(const wxColour &colour)
149 {
150 AllocExclusive();
151 M_PENDATA->m_colour = colour;
152 }
153
154 void wxPen::SetDashes(int number_of_dashes, const wxDash *dash)
155 {
156 AllocExclusive();
157 M_PENDATA->m_countDashes = number_of_dashes;
158 M_PENDATA->m_dash = (wxDash *)dash; /* TODO */
159 }
160
161 void wxPen::SetColour(unsigned char red, unsigned char green, unsigned char blue)
162 {
163 AllocExclusive();
164 M_PENDATA->m_colour.Set(red, green, blue);
165 }
166
167 void wxPen::SetCap(wxPenCap capStyle)
168 {
169 AllocExclusive();
170 M_PENDATA->m_capStyle = capStyle;
171 }
172
173 void wxPen::SetJoin(wxPenJoin joinStyle)
174 {
175 AllocExclusive();
176 M_PENDATA->m_joinStyle = joinStyle;
177 }
178
179 void wxPen::SetStyle(wxPenStyle style)
180 {
181 AllocExclusive();
182 M_PENDATA->m_style = style;
183 }
184
185 void wxPen::SetStipple(const wxBitmap& stipple)
186 {
187 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
188 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
189 _T("stipple bitmap must be 8x8") );
190
191 AllocExclusive();
192 M_PENDATA->m_stipple = stipple;
193 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
194 }
195
196 void wxPen::SetWidth(int width)
197 {
198 AllocExclusive();
199 M_PENDATA->m_width = width;
200 }
201
202 int wxPen::GetDashes(wxDash **ptr) const
203 {
204 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
205 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
206 }
207
208 int wxPen::GetDashCount() const
209 {
210 return (M_PENDATA->m_countDashes);
211 }
212
213 wxDash* wxPen::GetDash() const
214 {
215 return (wxDash*)M_PENDATA->m_dash;
216 }
217
218 wxPenCap wxPen::GetCap() const
219 {
220 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
221
222 return M_PENDATA->m_capStyle;
223 }
224
225 wxPenJoin wxPen::GetJoin() const
226 {
227 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
228
229 return M_PENDATA->m_joinStyle;
230 }
231
232 wxPenStyle wxPen::GetStyle() const
233 {
234 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
235
236 return M_PENDATA->m_style;
237 }
238
239 int wxPen::GetWidth() const
240 {
241 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
242
243 return M_PENDATA->m_width;
244 }
245
246 wxColour &wxPen::GetColour() const
247 {
248 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
249
250 return M_PENDATA->m_colour;
251 }
252
253 wxBitmap *wxPen::GetStipple() const
254 {
255 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
256
257 return &(M_PENDATA->m_stipple);
258 }
259
260 void* wxPen::GetPixPattern() const
261 {
262 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
263
264 return (void*)&(M_PENDATA->m_pixPattern);
265 }
266
267
268 wxGDIRefData *wxPen::CreateGDIRefData() const
269 {
270 return new wxPenRefData;
271 }
272
273 wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
274 {
275 return new wxPenRefData(*(wxPenRefData *)data);
276 }