]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/pen.cpp
added wxEXEC_NOHIDE flag, modified wxExecute() to take a combination of bit flags...
[wxWidgets.git] / src / mgl / pen.cpp
CommitLineData
32b8ec41
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: pen.cpp
3// Purpose:
4// Author: Vaclav Slavik
5// Id: $Id$
c41c20a5 6// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
32b8ec41
VZ
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation "pen.h"
13#endif
14
a246f95e
VS
15// For compilers that support precompilation, includes "wx.h".
16#include "wx/wxprec.h"
17
18#ifdef __BORLANDC__
19 #pragma hdrstop
20#endif
21
32b8ec41
VZ
22#include "wx/pen.h"
23#include "wx/bitmap.h"
24#include "wx/mgl/private.h"
25
26//-----------------------------------------------------------------------------
27// wxPen
28//-----------------------------------------------------------------------------
29
30class 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
49wxPenRefData::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
65wxPenRefData::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
87IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
88
32b8ec41
VZ
89wxPen::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;
32b8ec41
VZ
95}
96
97wxPen::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);
32b8ec41
VZ
108}
109
110wxPen::wxPen(const wxPen& pen)
111{
112 Ref(pen);
32b8ec41
VZ
113}
114
115wxPen& wxPen::operator = (const wxPen& pen)
116{
117 if (*this == pen) return (*this);
118 Ref(pen);
119 return *this;
120}
121
122bool wxPen::operator == (const wxPen& pen) const
123{
124 return m_refData == pen.m_refData;
125}
126
127bool wxPen::operator != (const wxPen& pen) const
128{
129 return m_refData != pen.m_refData;
130}
131
132void wxPen::SetColour(const wxColour &colour)
133{
6d7ee9e8 134 AllocExclusive();
32b8ec41
VZ
135 M_PENDATA->m_colour = colour;
136}
137
138void wxPen::SetDashes(int number_of_dashes, const wxDash *dash)
139{
6d7ee9e8 140 AllocExclusive();
32b8ec41
VZ
141 M_PENDATA->m_countDashes = number_of_dashes;
142 M_PENDATA->m_dash = (wxDash *)dash; /* TODO */
143}
144
145void wxPen::SetColour(int red, int green, int blue)
146{
6d7ee9e8 147 AllocExclusive();
32b8ec41
VZ
148 M_PENDATA->m_colour.Set(red, green, blue);
149}
150
151void wxPen::SetCap(int capStyle)
152{
6d7ee9e8 153 AllocExclusive();
32b8ec41
VZ
154 M_PENDATA->m_capStyle = capStyle;
155}
156
157void wxPen::SetJoin(int joinStyle)
158{
6d7ee9e8 159 AllocExclusive();
32b8ec41
VZ
160 M_PENDATA->m_joinStyle = joinStyle;
161}
162
163void wxPen::SetStyle(int style)
164{
6d7ee9e8 165 AllocExclusive();
32b8ec41
VZ
166 M_PENDATA->m_style = style;
167}
168
169void 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
6d7ee9e8 175 AllocExclusive();
32b8ec41
VZ
176 M_PENDATA->m_stipple = stipple;
177 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
178}
179
180void wxPen::SetWidth(int width)
181{
6d7ee9e8 182 AllocExclusive();
32b8ec41
VZ
183 M_PENDATA->m_width = width;
184}
185
186int 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
192int wxPen::GetDashCount() const
193{
194 return (M_PENDATA->m_countDashes);
195}
196
197wxDash* wxPen::GetDash() const
198{
199 return (wxDash*)M_PENDATA->m_dash;
200}
201
202int wxPen::GetCap() const
203{
204 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
205
206 return M_PENDATA->m_capStyle;
207}
208
209int wxPen::GetJoin() const
210{
211 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
212
213 return M_PENDATA->m_joinStyle;
214}
215
216int wxPen::GetStyle() const
217{
218 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
219
220 return M_PENDATA->m_style;
221}
222
223int wxPen::GetWidth() const
224{
225 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
226
227 return M_PENDATA->m_width;
228}
229
230wxColour &wxPen::GetColour() const
231{
232 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
233
234 return M_PENDATA->m_colour;
235}
236
237wxBitmap *wxPen::GetStipple() const
238{
239 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
240
241 return &(M_PENDATA->m_stipple);
242}
243
244void* wxPen::GetPixPattern() const
245{
246 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
247
248 return (void*)&(M_PENDATA->m_pixPattern);
249}
250
251
252bool wxPen::Ok() const
253{
254 return (m_refData != NULL);
255}
256
6d7ee9e8 257wxObjectRefData *wxPen::CreateRefData() const
32b8ec41 258{
6d7ee9e8
VS
259 return new wxPenRefData;
260}
261
262wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
263{
264 return new wxPenRefData(*(wxPenRefData *)data);
32b8ec41
VZ
265}
266