1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
12 #pragma implementation "pen.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
23 #include "wx/bitmap.h"
24 #include "wx/colour.h"
25 #include "wx/mgl/private.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 class wxPenRefData
: public wxObjectRefData
35 wxPenRefData(const wxPenRefData
& data
);
41 pixpattern24_t m_pixPattern
;
43 // not used by wxMGL, but we want to preserve values
50 wxPenRefData::wxPenRefData()
54 m_joinStyle
= wxJOIN_ROUND
;
55 m_capStyle
= wxCAP_ROUND
;
56 m_dash
= (wxDash
*) NULL
;
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;
66 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
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
;
75 m_stipple
= data
.m_stipple
;
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
];
84 //-----------------------------------------------------------------------------
86 #define M_PENDATA ((wxPenRefData *)m_refData)
88 IMPLEMENT_DYNAMIC_CLASS(wxPen
,wxGDIObject
)
90 wxPen::wxPen(const wxColour
&colour
, int width
, int style
)
92 m_refData
= new wxPenRefData();
93 M_PENDATA
->m_width
= width
;
94 M_PENDATA
->m_style
= style
;
95 M_PENDATA
->m_colour
= colour
;
98 wxPen::wxPen(const wxBitmap
& stipple
, int width
)
100 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
101 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
102 _T("stipple bitmap must be 8x8") );
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
);
111 wxPen::wxPen(const wxPen
& pen
)
116 wxPen
& wxPen::operator = (const wxPen
& pen
)
118 if (*this == pen
) return (*this);
123 bool wxPen::operator == (const wxPen
& pen
) const
125 return m_refData
== pen
.m_refData
;
128 bool wxPen::operator != (const wxPen
& pen
) const
130 return m_refData
!= pen
.m_refData
;
133 void wxPen::SetColour(const wxColour
&colour
)
136 M_PENDATA
->m_colour
= colour
;
139 void wxPen::SetDashes(int number_of_dashes
, const wxDash
*dash
)
142 M_PENDATA
->m_countDashes
= number_of_dashes
;
143 M_PENDATA
->m_dash
= (wxDash
*)dash
; /* TODO */
146 void wxPen::SetColour(int red
, int green
, int blue
)
149 M_PENDATA
->m_colour
.Set(red
, green
, blue
);
152 void wxPen::SetCap(int capStyle
)
155 M_PENDATA
->m_capStyle
= capStyle
;
158 void wxPen::SetJoin(int joinStyle
)
161 M_PENDATA
->m_joinStyle
= joinStyle
;
164 void wxPen::SetStyle(int style
)
167 M_PENDATA
->m_style
= style
;
170 void wxPen::SetStipple(const wxBitmap
& stipple
)
172 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
173 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
174 _T("stipple bitmap must be 8x8") );
177 M_PENDATA
->m_stipple
= stipple
;
178 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
181 void wxPen::SetWidth(int width
)
184 M_PENDATA
->m_width
= width
;
187 int wxPen::GetDashes(wxDash
**ptr
) const
189 *ptr
= (M_PENDATA
? (wxDash
*)M_PENDATA
->m_dash
: (wxDash
*) NULL
);
190 return (M_PENDATA
? M_PENDATA
->m_countDashes
: 0);
193 int wxPen::GetDashCount() const
195 return (M_PENDATA
->m_countDashes
);
198 wxDash
* wxPen::GetDash() const
200 return (wxDash
*)M_PENDATA
->m_dash
;
203 int wxPen::GetCap() const
205 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
207 return M_PENDATA
->m_capStyle
;
210 int wxPen::GetJoin() const
212 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
214 return M_PENDATA
->m_joinStyle
;
217 int wxPen::GetStyle() const
219 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
221 return M_PENDATA
->m_style
;
224 int wxPen::GetWidth() const
226 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
228 return M_PENDATA
->m_width
;
231 wxColour
&wxPen::GetColour() const
233 wxCHECK_MSG( Ok(), wxNullColour
, wxT("invalid pen") );
235 return M_PENDATA
->m_colour
;
238 wxBitmap
*wxPen::GetStipple() const
240 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
242 return &(M_PENDATA
->m_stipple
);
245 void* wxPen::GetPixPattern() const
247 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
249 return (void*)&(M_PENDATA
->m_pixPattern
);
253 bool wxPen::Ok() const
255 return (m_refData
!= NULL
);
258 wxObjectRefData
*wxPen::CreateRefData() const
260 return new wxPenRefData
;
263 wxObjectRefData
*wxPen::CloneRefData(const wxObjectRefData
*data
) const
265 return new wxPenRefData(*(wxPenRefData
*)data
);