]>
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 | { | |
32 | public: | |
33 | wxPenRefData(); | |
34 | wxPenRefData(const wxPenRefData& data); | |
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 && | |
41 | m_pixPattern == data.m_pixPattern && | |
42 | m_capStyle == data.m_capStyle && | |
43 | m_joinStyle == data.m_joinStyle && | |
44 | m_colour == data.m_colour && | |
a3ab1c18 | 45 | (m_style != wxSTIPPLE || m_stipple.IsSameAs(data.m_stipple)) && |
55ccdb93 VZ |
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 | ||
32b8ec41 VZ |
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 | ||
32b8ec41 VZ |
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; | |
32b8ec41 VZ |
110 | } |
111 | ||
112 | wxPen::wxPen(const wxBitmap& stipple, int width) | |
113 | { | |
114 | wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") ); | |
46562151 | 115 | wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8, |
32b8ec41 VZ |
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); | |
32b8ec41 VZ |
123 | } |
124 | ||
32b8ec41 VZ |
125 | bool wxPen::operator == (const wxPen& pen) const |
126 | { | |
55ccdb93 VZ |
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 ); | |
32b8ec41 VZ |
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 | { | |
6d7ee9e8 | 141 | AllocExclusive(); |
32b8ec41 VZ |
142 | M_PENDATA->m_colour = colour; |
143 | } | |
144 | ||
145 | void wxPen::SetDashes(int number_of_dashes, const wxDash *dash) | |
146 | { | |
6d7ee9e8 | 147 | AllocExclusive(); |
32b8ec41 VZ |
148 | M_PENDATA->m_countDashes = number_of_dashes; |
149 | M_PENDATA->m_dash = (wxDash *)dash; /* TODO */ | |
150 | } | |
151 | ||
1a1498c0 | 152 | void wxPen::SetColour(unsigned char red, unsigned char green, unsigned char blue) |
32b8ec41 | 153 | { |
6d7ee9e8 | 154 | AllocExclusive(); |
32b8ec41 VZ |
155 | M_PENDATA->m_colour.Set(red, green, blue); |
156 | } | |
157 | ||
158 | void wxPen::SetCap(int capStyle) | |
159 | { | |
6d7ee9e8 | 160 | AllocExclusive(); |
32b8ec41 VZ |
161 | M_PENDATA->m_capStyle = capStyle; |
162 | } | |
163 | ||
164 | void wxPen::SetJoin(int joinStyle) | |
165 | { | |
6d7ee9e8 | 166 | AllocExclusive(); |
32b8ec41 VZ |
167 | M_PENDATA->m_joinStyle = joinStyle; |
168 | } | |
169 | ||
170 | void wxPen::SetStyle(int style) | |
171 | { | |
6d7ee9e8 | 172 | AllocExclusive(); |
32b8ec41 VZ |
173 | M_PENDATA->m_style = style; |
174 | } | |
175 | ||
176 | void wxPen::SetStipple(const wxBitmap& stipple) | |
177 | { | |
178 | wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") ); | |
46562151 | 179 | wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8, |
32b8ec41 VZ |
180 | _T("stipple bitmap must be 8x8") ); |
181 | ||
6d7ee9e8 | 182 | AllocExclusive(); |
32b8ec41 VZ |
183 | M_PENDATA->m_stipple = stipple; |
184 | wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL); | |
185 | } | |
186 | ||
187 | void wxPen::SetWidth(int width) | |
188 | { | |
6d7ee9e8 | 189 | AllocExclusive(); |
32b8ec41 VZ |
190 | M_PENDATA->m_width = width; |
191 | } | |
192 | ||
46562151 | 193 | int wxPen::GetDashes(wxDash **ptr) const |
32b8ec41 | 194 | { |
46562151 | 195 | *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL); |
32b8ec41 VZ |
196 | return (M_PENDATA ? M_PENDATA->m_countDashes : 0); |
197 | } | |
198 | ||
46562151 WS |
199 | int wxPen::GetDashCount() const |
200 | { | |
201 | return (M_PENDATA->m_countDashes); | |
32b8ec41 VZ |
202 | } |
203 | ||
46562151 WS |
204 | wxDash* wxPen::GetDash() const |
205 | { | |
206 | return (wxDash*)M_PENDATA->m_dash; | |
32b8ec41 VZ |
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 | ||
b7cacb43 | 259 | bool wxPen::IsOk() const |
32b8ec41 VZ |
260 | { |
261 | return (m_refData != NULL); | |
262 | } | |
263 | ||
6d7ee9e8 | 264 | wxObjectRefData *wxPen::CreateRefData() const |
32b8ec41 | 265 | { |
6d7ee9e8 VS |
266 | return new wxPenRefData; |
267 | } | |
268 | ||
269 | wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const | |
270 | { | |
271 | return new wxPenRefData(*(wxPenRefData *)data); | |
32b8ec41 | 272 | } |