1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
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/mgl/private.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 class wxPenRefData
: public wxObjectRefData
34 wxPenRefData(const wxPenRefData
& data
);
40 pixpattern24_t m_pixPattern
;
42 // not used by wxMGL, but we want to preserve values
49 wxPenRefData::wxPenRefData()
53 m_joinStyle
= wxJOIN_ROUND
;
54 m_capStyle
= wxCAP_ROUND
;
55 m_dash
= (wxDash
*) NULL
;
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;
65 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
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
;
74 m_stipple
= data
.m_stipple
;
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
];
83 //-----------------------------------------------------------------------------
85 #define M_PENDATA ((wxPenRefData *)m_refData)
87 IMPLEMENT_DYNAMIC_CLASS(wxPen
,wxGDIObject
)
89 wxPen::wxPen(const wxColour
&colour
, int width
, int style
)
91 m_refData
= new wxPenRefData();
92 M_PENDATA
->m_width
= width
;
93 M_PENDATA
->m_style
= style
;
94 M_PENDATA
->m_colour
= colour
;
97 wxPen::wxPen(const wxBitmap
& stipple
, int width
)
99 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
100 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
101 _T("stipple bitmap must be 8x8") );
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
);
110 wxPen::wxPen(const wxPen
& pen
)
115 wxPen
& wxPen::operator = (const wxPen
& pen
)
117 if (*this == pen
) return (*this);
122 bool wxPen::operator == (const wxPen
& pen
) const
124 return m_refData
== pen
.m_refData
;
127 bool wxPen::operator != (const wxPen
& pen
) const
129 return m_refData
!= pen
.m_refData
;
132 void wxPen::SetColour(const wxColour
&colour
)
135 M_PENDATA
->m_colour
= colour
;
138 void wxPen::SetDashes(int number_of_dashes
, const wxDash
*dash
)
141 M_PENDATA
->m_countDashes
= number_of_dashes
;
142 M_PENDATA
->m_dash
= (wxDash
*)dash
; /* TODO */
145 void wxPen::SetColour(int red
, int green
, int blue
)
148 M_PENDATA
->m_colour
.Set(red
, green
, blue
);
151 void wxPen::SetCap(int capStyle
)
154 M_PENDATA
->m_capStyle
= capStyle
;
157 void wxPen::SetJoin(int joinStyle
)
160 M_PENDATA
->m_joinStyle
= joinStyle
;
163 void wxPen::SetStyle(int style
)
166 M_PENDATA
->m_style
= style
;
169 void wxPen::SetStipple(const wxBitmap
& stipple
)
171 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
172 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
173 _T("stipple bitmap must be 8x8") );
176 M_PENDATA
->m_stipple
= stipple
;
177 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
180 void wxPen::SetWidth(int width
)
183 M_PENDATA
->m_width
= width
;
186 int wxPen::GetDashes(wxDash
**ptr
) const
188 *ptr
= (M_PENDATA
? (wxDash
*)M_PENDATA
->m_dash
: (wxDash
*) NULL
);
189 return (M_PENDATA
? M_PENDATA
->m_countDashes
: 0);
192 int wxPen::GetDashCount() const
194 return (M_PENDATA
->m_countDashes
);
197 wxDash
* wxPen::GetDash() const
199 return (wxDash
*)M_PENDATA
->m_dash
;
202 int wxPen::GetCap() const
204 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
206 return M_PENDATA
->m_capStyle
;
209 int wxPen::GetJoin() const
211 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
213 return M_PENDATA
->m_joinStyle
;
216 int wxPen::GetStyle() const
218 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
220 return M_PENDATA
->m_style
;
223 int wxPen::GetWidth() const
225 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
227 return M_PENDATA
->m_width
;
230 wxColour
&wxPen::GetColour() const
232 wxCHECK_MSG( Ok(), wxNullColour
, wxT("invalid pen") );
234 return M_PENDATA
->m_colour
;
237 wxBitmap
*wxPen::GetStipple() const
239 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
241 return &(M_PENDATA
->m_stipple
);
244 void* wxPen::GetPixPattern() const
246 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
248 return (void*)&(M_PENDATA
->m_pixPattern
);
252 bool wxPen::Ok() const
254 return (m_refData
!= NULL
);
257 wxObjectRefData
*wxPen::CreateRefData() const
259 return new wxPenRefData
;
262 wxObjectRefData
*wxPen::CloneRefData(const wxObjectRefData
*data
) const
264 return new wxPenRefData(*(wxPenRefData
*)data
);