]>
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 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
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/colour.h" | |
25 | #include "wx/mgl/private.h" | |
26 | ||
27 | //----------------------------------------------------------------------------- | |
28 | // wxPen | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | class wxPenRefData: public wxObjectRefData | |
32 | { | |
33 | public: | |
34 | wxPenRefData(); | |
35 | wxPenRefData(const wxPenRefData& data); | |
36 | ||
37 | int m_width; | |
38 | int m_style; | |
39 | wxColour m_colour; | |
40 | wxBitmap m_stipple; | |
41 | pixpattern24_t m_pixPattern; | |
42 | ||
43 | // not used by wxMGL, but we want to preserve values | |
44 | int m_joinStyle; | |
45 | int m_capStyle; | |
46 | int m_countDashes; | |
47 | wxDash *m_dash; | |
48 | }; | |
49 | ||
50 | wxPenRefData::wxPenRefData() | |
51 | { | |
52 | m_width = 1; | |
53 | m_style = wxSOLID; | |
54 | m_joinStyle = wxJOIN_ROUND; | |
55 | m_capStyle = wxCAP_ROUND; | |
56 | m_dash = (wxDash*) NULL; | |
57 | m_countDashes = 0; | |
58 | ||
59 | int x, y, c; | |
60 | for (y = 0; y < 8; y++) | |
61 | for (x = 0; x < 8; x++) | |
62 | for (c = 0; c < 3; c++) | |
63 | m_pixPattern.p[x][y][c] = 0; | |
64 | } | |
65 | ||
66 | wxPenRefData::wxPenRefData(const wxPenRefData& data) | |
67 | { | |
68 | m_style = data.m_style; | |
69 | m_width = data.m_width; | |
70 | m_joinStyle = data.m_joinStyle; | |
71 | m_capStyle = data.m_capStyle; | |
72 | m_colour = data.m_colour; | |
73 | m_countDashes = data.m_countDashes; | |
74 | m_dash = data.m_dash; | |
75 | m_stipple = data.m_stipple; | |
76 | ||
77 | int x, y, c; | |
78 | for (y = 0; y < 8; y++) | |
79 | for (x = 0; x < 8; x++) | |
80 | for (c = 0; c < 3; c++) | |
81 | m_pixPattern.p[x][y][c] = data.m_pixPattern.p[x][y][c]; | |
82 | } | |
83 | ||
84 | //----------------------------------------------------------------------------- | |
85 | ||
86 | #define M_PENDATA ((wxPenRefData *)m_refData) | |
87 | ||
88 | IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject) | |
89 | ||
90 | wxPen::wxPen(const wxColour &colour, int width, int style) | |
91 | { | |
92 | m_refData = new wxPenRefData(); | |
93 | M_PENDATA->m_width = width; | |
94 | M_PENDATA->m_style = style; | |
95 | M_PENDATA->m_colour = colour; | |
96 | } | |
97 | ||
98 | wxPen::wxPen(const wxBitmap& stipple, int width) | |
99 | { | |
100 | wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") ); | |
101 | wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8, | |
102 | _T("stipple bitmap must be 8x8") ); | |
103 | ||
104 | m_refData = new wxPenRefData(); | |
105 | M_PENDATA->m_width = width; | |
106 | M_PENDATA->m_style = wxSTIPPLE; | |
107 | M_PENDATA->m_stipple = stipple; | |
108 | wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL); | |
109 | } | |
110 | ||
111 | wxPen::wxPen(const wxPen& pen) | |
112 | { | |
113 | Ref(pen); | |
114 | } | |
115 | ||
116 | wxPen& wxPen::operator = (const wxPen& pen) | |
117 | { | |
118 | if (*this == pen) return (*this); | |
119 | Ref(pen); | |
120 | return *this; | |
121 | } | |
122 | ||
123 | bool wxPen::operator == (const wxPen& pen) const | |
124 | { | |
125 | return m_refData == pen.m_refData; | |
126 | } | |
127 | ||
128 | bool wxPen::operator != (const wxPen& pen) const | |
129 | { | |
130 | return m_refData != pen.m_refData; | |
131 | } | |
132 | ||
133 | void wxPen::SetColour(const wxColour &colour) | |
134 | { | |
135 | AllocExclusive(); | |
136 | M_PENDATA->m_colour = colour; | |
137 | } | |
138 | ||
139 | void wxPen::SetDashes(int number_of_dashes, const wxDash *dash) | |
140 | { | |
141 | AllocExclusive(); | |
142 | M_PENDATA->m_countDashes = number_of_dashes; | |
143 | M_PENDATA->m_dash = (wxDash *)dash; /* TODO */ | |
144 | } | |
145 | ||
146 | void wxPen::SetColour(int red, int green, int blue) | |
147 | { | |
148 | AllocExclusive(); | |
149 | M_PENDATA->m_colour.Set(red, green, blue); | |
150 | } | |
151 | ||
152 | void wxPen::SetCap(int capStyle) | |
153 | { | |
154 | AllocExclusive(); | |
155 | M_PENDATA->m_capStyle = capStyle; | |
156 | } | |
157 | ||
158 | void wxPen::SetJoin(int joinStyle) | |
159 | { | |
160 | AllocExclusive(); | |
161 | M_PENDATA->m_joinStyle = joinStyle; | |
162 | } | |
163 | ||
164 | void wxPen::SetStyle(int style) | |
165 | { | |
166 | AllocExclusive(); | |
167 | M_PENDATA->m_style = style; | |
168 | } | |
169 | ||
170 | void wxPen::SetStipple(const wxBitmap& stipple) | |
171 | { | |
172 | wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") ); | |
173 | wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8, | |
174 | _T("stipple bitmap must be 8x8") ); | |
175 | ||
176 | AllocExclusive(); | |
177 | M_PENDATA->m_stipple = stipple; | |
178 | wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL); | |
179 | } | |
180 | ||
181 | void wxPen::SetWidth(int width) | |
182 | { | |
183 | AllocExclusive(); | |
184 | M_PENDATA->m_width = width; | |
185 | } | |
186 | ||
187 | int wxPen::GetDashes(wxDash **ptr) const | |
188 | { | |
189 | *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL); | |
190 | return (M_PENDATA ? M_PENDATA->m_countDashes : 0); | |
191 | } | |
192 | ||
193 | int wxPen::GetDashCount() const | |
194 | { | |
195 | return (M_PENDATA->m_countDashes); | |
196 | } | |
197 | ||
198 | wxDash* wxPen::GetDash() const | |
199 | { | |
200 | return (wxDash*)M_PENDATA->m_dash; | |
201 | } | |
202 | ||
203 | int wxPen::GetCap() const | |
204 | { | |
205 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
206 | ||
207 | return M_PENDATA->m_capStyle; | |
208 | } | |
209 | ||
210 | int wxPen::GetJoin() const | |
211 | { | |
212 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
213 | ||
214 | return M_PENDATA->m_joinStyle; | |
215 | } | |
216 | ||
217 | int wxPen::GetStyle() const | |
218 | { | |
219 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
220 | ||
221 | return M_PENDATA->m_style; | |
222 | } | |
223 | ||
224 | int wxPen::GetWidth() const | |
225 | { | |
226 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
227 | ||
228 | return M_PENDATA->m_width; | |
229 | } | |
230 | ||
231 | wxColour &wxPen::GetColour() const | |
232 | { | |
233 | wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") ); | |
234 | ||
235 | return M_PENDATA->m_colour; | |
236 | } | |
237 | ||
238 | wxBitmap *wxPen::GetStipple() const | |
239 | { | |
240 | wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") ); | |
241 | ||
242 | return &(M_PENDATA->m_stipple); | |
243 | } | |
244 | ||
245 | void* wxPen::GetPixPattern() const | |
246 | { | |
247 | wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") ); | |
248 | ||
249 | return (void*)&(M_PENDATA->m_pixPattern); | |
250 | } | |
251 | ||
252 | ||
253 | bool wxPen::Ok() const | |
254 | { | |
255 | return (m_refData != NULL); | |
256 | } | |
257 | ||
258 | wxObjectRefData *wxPen::CreateRefData() const | |
259 | { | |
260 | return new wxPenRefData; | |
261 | } | |
262 | ||
263 | wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const | |
264 | { | |
265 | return new wxPenRefData(*(wxPenRefData *)data); | |
266 | } | |
267 |