]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: 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 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "pen.h" | |
13 | #endif | |
14 | ||
15 | // For compilers that support precompilation, includes "wx.h". | |
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
22 | #include "wx/pen.h" | |
23 | #include "wx/bitmap.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 | wxPen::wxPen(const wxPen& pen) | |
111 | { | |
112 | Ref(pen); | |
113 | } | |
114 | ||
115 | wxPen& wxPen::operator = (const wxPen& pen) | |
116 | { | |
117 | if (*this == pen) return (*this); | |
118 | Ref(pen); | |
119 | return *this; | |
120 | } | |
121 | ||
122 | bool wxPen::operator == (const wxPen& pen) const | |
123 | { | |
124 | return m_refData == pen.m_refData; | |
125 | } | |
126 | ||
127 | bool wxPen::operator != (const wxPen& pen) const | |
128 | { | |
129 | return m_refData != pen.m_refData; | |
130 | } | |
131 | ||
132 | void wxPen::SetColour(const wxColour &colour) | |
133 | { | |
134 | AllocExclusive(); | |
135 | M_PENDATA->m_colour = colour; | |
136 | } | |
137 | ||
138 | void wxPen::SetDashes(int number_of_dashes, const wxDash *dash) | |
139 | { | |
140 | AllocExclusive(); | |
141 | M_PENDATA->m_countDashes = number_of_dashes; | |
142 | M_PENDATA->m_dash = (wxDash *)dash; /* TODO */ | |
143 | } | |
144 | ||
145 | void wxPen::SetColour(int red, int green, int blue) | |
146 | { | |
147 | AllocExclusive(); | |
148 | M_PENDATA->m_colour.Set(red, green, blue); | |
149 | } | |
150 | ||
151 | void wxPen::SetCap(int capStyle) | |
152 | { | |
153 | AllocExclusive(); | |
154 | M_PENDATA->m_capStyle = capStyle; | |
155 | } | |
156 | ||
157 | void wxPen::SetJoin(int joinStyle) | |
158 | { | |
159 | AllocExclusive(); | |
160 | M_PENDATA->m_joinStyle = joinStyle; | |
161 | } | |
162 | ||
163 | void wxPen::SetStyle(int style) | |
164 | { | |
165 | AllocExclusive(); | |
166 | M_PENDATA->m_style = style; | |
167 | } | |
168 | ||
169 | void wxPen::SetStipple(const wxBitmap& stipple) | |
170 | { | |
171 | wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") ); | |
172 | wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8, | |
173 | _T("stipple bitmap must be 8x8") ); | |
174 | ||
175 | AllocExclusive(); | |
176 | M_PENDATA->m_stipple = stipple; | |
177 | wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL); | |
178 | } | |
179 | ||
180 | void wxPen::SetWidth(int width) | |
181 | { | |
182 | AllocExclusive(); | |
183 | M_PENDATA->m_width = width; | |
184 | } | |
185 | ||
186 | int wxPen::GetDashes(wxDash **ptr) const | |
187 | { | |
188 | *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL); | |
189 | return (M_PENDATA ? M_PENDATA->m_countDashes : 0); | |
190 | } | |
191 | ||
192 | int wxPen::GetDashCount() const | |
193 | { | |
194 | return (M_PENDATA->m_countDashes); | |
195 | } | |
196 | ||
197 | wxDash* wxPen::GetDash() const | |
198 | { | |
199 | return (wxDash*)M_PENDATA->m_dash; | |
200 | } | |
201 | ||
202 | int wxPen::GetCap() const | |
203 | { | |
204 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
205 | ||
206 | return M_PENDATA->m_capStyle; | |
207 | } | |
208 | ||
209 | int wxPen::GetJoin() const | |
210 | { | |
211 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
212 | ||
213 | return M_PENDATA->m_joinStyle; | |
214 | } | |
215 | ||
216 | int wxPen::GetStyle() const | |
217 | { | |
218 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
219 | ||
220 | return M_PENDATA->m_style; | |
221 | } | |
222 | ||
223 | int wxPen::GetWidth() const | |
224 | { | |
225 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
226 | ||
227 | return M_PENDATA->m_width; | |
228 | } | |
229 | ||
230 | wxColour &wxPen::GetColour() const | |
231 | { | |
232 | wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") ); | |
233 | ||
234 | return M_PENDATA->m_colour; | |
235 | } | |
236 | ||
237 | wxBitmap *wxPen::GetStipple() const | |
238 | { | |
239 | wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") ); | |
240 | ||
241 | return &(M_PENDATA->m_stipple); | |
242 | } | |
243 | ||
244 | void* wxPen::GetPixPattern() const | |
245 | { | |
246 | wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") ); | |
247 | ||
248 | return (void*)&(M_PENDATA->m_pixPattern); | |
249 | } | |
250 | ||
251 | ||
252 | bool wxPen::Ok() const | |
253 | { | |
254 | return (m_refData != NULL); | |
255 | } | |
256 | ||
257 | wxObjectRefData *wxPen::CreateRefData() const | |
258 | { | |
259 | return new wxPenRefData; | |
260 | } | |
261 | ||
262 | wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const | |
263 | { | |
264 | return new wxPenRefData(*(wxPenRefData *)data); | |
265 | } | |
266 |