]> git.saurik.com Git - wxWidgets.git/blob - src/mgl/pen.cpp
Include wx/bitmap.h according to precompiled headers of wx/wx.h (with other minor...
[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 #endif
22
23 #include "wx/colour.h"
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 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
49 wxPenRefData::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
65 wxPenRefData::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
87 IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
88
89 wxPen::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;
95 }
96
97 wxPen::wxPen(const wxBitmap& stipple, int width)
98 {
99 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
100 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
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);
108 }
109
110 bool wxPen::operator == (const wxPen& pen) const
111 {
112 return m_refData == pen.m_refData;
113 }
114
115 bool wxPen::operator != (const wxPen& pen) const
116 {
117 return m_refData != pen.m_refData;
118 }
119
120 void wxPen::SetColour(const wxColour &colour)
121 {
122 AllocExclusive();
123 M_PENDATA->m_colour = colour;
124 }
125
126 void wxPen::SetDashes(int number_of_dashes, const wxDash *dash)
127 {
128 AllocExclusive();
129 M_PENDATA->m_countDashes = number_of_dashes;
130 M_PENDATA->m_dash = (wxDash *)dash; /* TODO */
131 }
132
133 void wxPen::SetColour(unsigned char red, unsigned char green, unsigned char blue)
134 {
135 AllocExclusive();
136 M_PENDATA->m_colour.Set(red, green, blue);
137 }
138
139 void wxPen::SetCap(int capStyle)
140 {
141 AllocExclusive();
142 M_PENDATA->m_capStyle = capStyle;
143 }
144
145 void wxPen::SetJoin(int joinStyle)
146 {
147 AllocExclusive();
148 M_PENDATA->m_joinStyle = joinStyle;
149 }
150
151 void wxPen::SetStyle(int style)
152 {
153 AllocExclusive();
154 M_PENDATA->m_style = style;
155 }
156
157 void wxPen::SetStipple(const wxBitmap& stipple)
158 {
159 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
160 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
161 _T("stipple bitmap must be 8x8") );
162
163 AllocExclusive();
164 M_PENDATA->m_stipple = stipple;
165 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
166 }
167
168 void wxPen::SetWidth(int width)
169 {
170 AllocExclusive();
171 M_PENDATA->m_width = width;
172 }
173
174 int wxPen::GetDashes(wxDash **ptr) const
175 {
176 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
177 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
178 }
179
180 int wxPen::GetDashCount() const
181 {
182 return (M_PENDATA->m_countDashes);
183 }
184
185 wxDash* wxPen::GetDash() const
186 {
187 return (wxDash*)M_PENDATA->m_dash;
188 }
189
190 int wxPen::GetCap() const
191 {
192 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
193
194 return M_PENDATA->m_capStyle;
195 }
196
197 int wxPen::GetJoin() const
198 {
199 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
200
201 return M_PENDATA->m_joinStyle;
202 }
203
204 int wxPen::GetStyle() const
205 {
206 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
207
208 return M_PENDATA->m_style;
209 }
210
211 int wxPen::GetWidth() const
212 {
213 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
214
215 return M_PENDATA->m_width;
216 }
217
218 wxColour &wxPen::GetColour() const
219 {
220 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
221
222 return M_PENDATA->m_colour;
223 }
224
225 wxBitmap *wxPen::GetStipple() const
226 {
227 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
228
229 return &(M_PENDATA->m_stipple);
230 }
231
232 void* wxPen::GetPixPattern() const
233 {
234 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
235
236 return (void*)&(M_PENDATA->m_pixPattern);
237 }
238
239
240 bool wxPen::Ok() const
241 {
242 return (m_refData != NULL);
243 }
244
245 wxObjectRefData *wxPen::CreateRefData() const
246 {
247 return new wxPenRefData;
248 }
249
250 wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
251 {
252 return new wxPenRefData(*(wxPenRefData *)data);
253 }