1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
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
)
82 wxPen::wxPen(const wxColour
&colour
, int width
, int style
)
84 m_refData
= new wxPenRefData();
85 M_PENDATA
->m_width
= width
;
86 M_PENDATA
->m_style
= style
;
87 M_PENDATA
->m_colour
= colour
;
90 wxPen::wxPen(const wxBitmap
& stipple
, int width
)
92 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
93 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
94 _T("stipple bitmap must be 8x8") );
96 m_refData
= new wxPenRefData();
97 M_PENDATA
->m_width
= width
;
98 M_PENDATA
->m_style
= wxSTIPPLE
;
99 M_PENDATA
->m_stipple
= stipple
;
100 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
103 wxPen::wxPen(const wxPen
& pen
)
108 wxPen
& wxPen::operator = (const wxPen
& pen
)
110 if (*this == pen
) return (*this);
115 bool wxPen::operator == (const wxPen
& pen
) const
117 return m_refData
== pen
.m_refData
;
120 bool wxPen::operator != (const wxPen
& pen
) const
122 return m_refData
!= pen
.m_refData
;
125 void wxPen::SetColour(const wxColour
&colour
)
128 M_PENDATA
->m_colour
= colour
;
131 void wxPen::SetDashes(int number_of_dashes
, const wxDash
*dash
)
134 M_PENDATA
->m_countDashes
= number_of_dashes
;
135 M_PENDATA
->m_dash
= (wxDash
*)dash
; /* TODO */
138 void wxPen::SetColour(int red
, int green
, int blue
)
141 M_PENDATA
->m_colour
.Set(red
, green
, blue
);
144 void wxPen::SetCap(int capStyle
)
147 M_PENDATA
->m_capStyle
= capStyle
;
150 void wxPen::SetJoin(int joinStyle
)
153 M_PENDATA
->m_joinStyle
= joinStyle
;
156 void wxPen::SetStyle(int style
)
159 M_PENDATA
->m_style
= style
;
162 void wxPen::SetStipple(const wxBitmap
& stipple
)
164 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
165 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
166 _T("stipple bitmap must be 8x8") );
169 M_PENDATA
->m_stipple
= stipple
;
170 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
173 void wxPen::SetWidth(int width
)
176 M_PENDATA
->m_width
= width
;
179 int wxPen::GetDashes(wxDash
**ptr
) const
181 *ptr
= (M_PENDATA
? (wxDash
*)M_PENDATA
->m_dash
: (wxDash
*) NULL
);
182 return (M_PENDATA
? M_PENDATA
->m_countDashes
: 0);
185 int wxPen::GetDashCount() const
187 return (M_PENDATA
->m_countDashes
);
190 wxDash
* wxPen::GetDash() const
192 return (wxDash
*)M_PENDATA
->m_dash
;
195 int wxPen::GetCap() const
197 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
199 return M_PENDATA
->m_capStyle
;
202 int wxPen::GetJoin() const
204 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
206 return M_PENDATA
->m_joinStyle
;
209 int wxPen::GetStyle() const
211 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
213 return M_PENDATA
->m_style
;
216 int wxPen::GetWidth() const
218 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
220 return M_PENDATA
->m_width
;
223 wxColour
&wxPen::GetColour() const
225 wxCHECK_MSG( Ok(), wxNullColour
, wxT("invalid pen") );
227 return M_PENDATA
->m_colour
;
230 wxBitmap
*wxPen::GetStipple() const
232 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
234 return &(M_PENDATA
->m_stipple
);
237 void* wxPen::GetPixPattern() const
239 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
241 return (void*)&(M_PENDATA
->m_pixPattern
);
245 bool wxPen::Ok() const
247 return (m_refData
!= NULL
);
250 void wxPen::Unshare()
254 m_refData
= new wxPenRefData();
258 wxPenRefData
* ref
= new wxPenRefData( *(wxPenRefData
*)m_refData
);