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