1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2001 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "pen.h"
16 #include "wx/bitmap.h"
17 #include "wx/mgl/private.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 class wxPenRefData
: public wxObjectRefData
27 wxPenRefData(const wxPenRefData
& data
);
33 pixpattern24_t m_pixPattern
;
35 // not used by wxMGL, but we want to preserve values
42 wxPenRefData::wxPenRefData()
46 m_joinStyle
= wxJOIN_ROUND
;
47 m_capStyle
= wxCAP_ROUND
;
48 m_dash
= (wxDash
*) NULL
;
52 for (y
= 0; y
< 8; y
++)
53 for (x
= 0; x
< 8; x
++)
54 for (c
= 0; c
< 3; c
++)
55 m_pixPattern
.p
[x
][y
][c
] = 0;
58 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
60 m_style
= data
.m_style
;
61 m_width
= data
.m_width
;
62 m_joinStyle
= data
.m_joinStyle
;
63 m_capStyle
= data
.m_capStyle
;
64 m_colour
= data
.m_colour
;
65 m_countDashes
= data
.m_countDashes
;
67 m_stipple
= data
.m_stipple
;
70 for (y
= 0; y
< 8; y
++)
71 for (x
= 0; x
< 8; x
++)
72 for (c
= 0; c
< 3; c
++)
73 m_pixPattern
.p
[x
][y
][c
] = data
.m_pixPattern
.p
[x
][y
][c
];
76 //-----------------------------------------------------------------------------
78 #define M_PENDATA ((wxPenRefData *)m_refData)
80 IMPLEMENT_DYNAMIC_CLASS(wxPen
,wxGDIObject
)
85 wxThePenList
->AddPen(this);
88 wxPen::wxPen(const wxColour
&colour
, int width
, int style
)
90 m_refData
= new wxPenRefData();
91 M_PENDATA
->m_width
= width
;
92 M_PENDATA
->m_style
= style
;
93 M_PENDATA
->m_colour
= colour
;
96 wxThePenList
->AddPen(this);
99 wxPen::wxPen(const wxBitmap
& stipple
, int width
)
101 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
102 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
103 _T("stipple bitmap must be 8x8") );
105 m_refData
= new wxPenRefData();
106 M_PENDATA
->m_width
= width
;
107 M_PENDATA
->m_style
= wxSTIPPLE
;
108 M_PENDATA
->m_stipple
= stipple
;
109 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
112 wxThePenList
->AddPen(this);
115 wxPen::wxPen(const wxPen
& pen
)
119 wxThePenList
->AddPen(this);
125 wxThePenList
->RemovePen(this);
128 wxPen
& wxPen::operator = (const wxPen
& pen
)
130 if (*this == pen
) return (*this);
135 bool wxPen::operator == (const wxPen
& pen
) const
137 return m_refData
== pen
.m_refData
;
140 bool wxPen::operator != (const wxPen
& pen
) const
142 return m_refData
!= pen
.m_refData
;
145 void wxPen::SetColour(const wxColour
&colour
)
148 M_PENDATA
->m_colour
= colour
;
151 void wxPen::SetDashes(int number_of_dashes
, const wxDash
*dash
)
154 M_PENDATA
->m_countDashes
= number_of_dashes
;
155 M_PENDATA
->m_dash
= (wxDash
*)dash
; /* TODO */
158 void wxPen::SetColour(int red
, int green
, int blue
)
161 M_PENDATA
->m_colour
.Set(red
, green
, blue
);
164 void wxPen::SetCap(int capStyle
)
167 M_PENDATA
->m_capStyle
= capStyle
;
170 void wxPen::SetJoin(int joinStyle
)
173 M_PENDATA
->m_joinStyle
= joinStyle
;
176 void wxPen::SetStyle(int style
)
179 M_PENDATA
->m_style
= style
;
182 void wxPen::SetStipple(const wxBitmap
& stipple
)
184 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
185 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
186 _T("stipple bitmap must be 8x8") );
189 M_PENDATA
->m_stipple
= stipple
;
190 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
193 void wxPen::SetWidth(int width
)
196 M_PENDATA
->m_width
= width
;
199 int wxPen::GetDashes(wxDash
**ptr
) const
201 *ptr
= (M_PENDATA
? (wxDash
*)M_PENDATA
->m_dash
: (wxDash
*) NULL
);
202 return (M_PENDATA
? M_PENDATA
->m_countDashes
: 0);
205 int wxPen::GetDashCount() const
207 return (M_PENDATA
->m_countDashes
);
210 wxDash
* wxPen::GetDash() const
212 return (wxDash
*)M_PENDATA
->m_dash
;
215 int wxPen::GetCap() const
217 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
219 return M_PENDATA
->m_capStyle
;
222 int wxPen::GetJoin() const
224 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
226 return M_PENDATA
->m_joinStyle
;
229 int wxPen::GetStyle() const
231 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
233 return M_PENDATA
->m_style
;
236 int wxPen::GetWidth() const
238 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
240 return M_PENDATA
->m_width
;
243 wxColour
&wxPen::GetColour() const
245 wxCHECK_MSG( Ok(), wxNullColour
, wxT("invalid pen") );
247 return M_PENDATA
->m_colour
;
250 wxBitmap
*wxPen::GetStipple() const
252 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
254 return &(M_PENDATA
->m_stipple
);
257 void* wxPen::GetPixPattern() const
259 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
261 return (void*)&(M_PENDATA
->m_pixPattern
);
265 bool wxPen::Ok() const
267 return (m_refData
!= NULL
);
270 void wxPen::Unshare()
274 m_refData
= new wxPenRefData();
278 wxPenRefData
* ref
= new wxPenRefData( *(wxPenRefData
*)m_refData
);