]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/pen.cpp
Hopefully fixed library names generated by wx-config for OS/2's PM port.
[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)
65571936 7// Licence: wxWindows licence
32b8ec41
VZ
8/////////////////////////////////////////////////////////////////////////////
9
10
14f355c2 11#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
32b8ec41
VZ
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"
c3d15542 24#include "wx/colour.h"
32b8ec41
VZ
25#include "wx/mgl/private.h"
26
27//-----------------------------------------------------------------------------
28// wxPen
29//-----------------------------------------------------------------------------
30
31class 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
50wxPenRefData::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
66wxPenRefData::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
88IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
89
32b8ec41
VZ
90wxPen::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;
32b8ec41
VZ
96}
97
98wxPen::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);
32b8ec41
VZ
109}
110
111wxPen::wxPen(const wxPen& pen)
112{
113 Ref(pen);
32b8ec41
VZ
114}
115
116wxPen& wxPen::operator = (const wxPen& pen)
117{
118 if (*this == pen) return (*this);
119 Ref(pen);
120 return *this;
121}
122
123bool wxPen::operator == (const wxPen& pen) const
124{
125 return m_refData == pen.m_refData;
126}
127
128bool wxPen::operator != (const wxPen& pen) const
129{
130 return m_refData != pen.m_refData;
131}
132
133void wxPen::SetColour(const wxColour &colour)
134{
6d7ee9e8 135 AllocExclusive();
32b8ec41
VZ
136 M_PENDATA->m_colour = colour;
137}
138
139void wxPen::SetDashes(int number_of_dashes, const wxDash *dash)
140{
6d7ee9e8 141 AllocExclusive();
32b8ec41
VZ
142 M_PENDATA->m_countDashes = number_of_dashes;
143 M_PENDATA->m_dash = (wxDash *)dash; /* TODO */
144}
145
146void wxPen::SetColour(int red, int green, int blue)
147{
6d7ee9e8 148 AllocExclusive();
32b8ec41
VZ
149 M_PENDATA->m_colour.Set(red, green, blue);
150}
151
152void wxPen::SetCap(int capStyle)
153{
6d7ee9e8 154 AllocExclusive();
32b8ec41
VZ
155 M_PENDATA->m_capStyle = capStyle;
156}
157
158void wxPen::SetJoin(int joinStyle)
159{
6d7ee9e8 160 AllocExclusive();
32b8ec41
VZ
161 M_PENDATA->m_joinStyle = joinStyle;
162}
163
164void wxPen::SetStyle(int style)
165{
6d7ee9e8 166 AllocExclusive();
32b8ec41
VZ
167 M_PENDATA->m_style = style;
168}
169
170void 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
6d7ee9e8 176 AllocExclusive();
32b8ec41
VZ
177 M_PENDATA->m_stipple = stipple;
178 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
179}
180
181void wxPen::SetWidth(int width)
182{
6d7ee9e8 183 AllocExclusive();
32b8ec41
VZ
184 M_PENDATA->m_width = width;
185}
186
187int 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
193int wxPen::GetDashCount() const
194{
195 return (M_PENDATA->m_countDashes);
196}
197
198wxDash* wxPen::GetDash() const
199{
200 return (wxDash*)M_PENDATA->m_dash;
201}
202
203int wxPen::GetCap() const
204{
205 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
206
207 return M_PENDATA->m_capStyle;
208}
209
210int wxPen::GetJoin() const
211{
212 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
213
214 return M_PENDATA->m_joinStyle;
215}
216
217int wxPen::GetStyle() const
218{
219 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
220
221 return M_PENDATA->m_style;
222}
223
224int wxPen::GetWidth() const
225{
226 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
227
228 return M_PENDATA->m_width;
229}
230
231wxColour &wxPen::GetColour() const
232{
233 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
234
235 return M_PENDATA->m_colour;
236}
237
238wxBitmap *wxPen::GetStipple() const
239{
240 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
241
242 return &(M_PENDATA->m_stipple);
243}
244
245void* wxPen::GetPixPattern() const
246{
247 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
248
249 return (void*)&(M_PENDATA->m_pixPattern);
250}
251
252
253bool wxPen::Ok() const
254{
255 return (m_refData != NULL);
256}
257
6d7ee9e8 258wxObjectRefData *wxPen::CreateRefData() const
32b8ec41 259{
6d7ee9e8
VS
260 return new wxPenRefData;
261}
262
263wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
264{
265 return new wxPenRefData(*(wxPenRefData *)data);
32b8ec41
VZ
266}
267