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