1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mgl/pen.cpp
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
20 #include "wx/bitmap.h"
21 #include "wx/colour.h"
24 #include "wx/mgl/private.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 class wxPenRefData
: public wxObjectRefData
34 wxPenRefData(const wxPenRefData
& data
);
36 bool operator==(const wxPenRefData
& data
) const
38 // we intentionally don't compare m_hPen fields here
39 return m_style
== data
.m_style
&&
40 m_width
== data
.m_width
&&
41 m_pixPattern
== data
.m_pixPattern
&&
42 m_capStyle
== data
.m_capStyle
&&
43 m_joinStyle
== data
.m_joinStyle
&&
44 m_colour
== data
.m_colour
&&
45 (m_style
!= wxSTIPPLE
|| m_stipple
.IsSameAs(data
.m_stipple
)) &&
46 (m_style
!= wxUSER_DASH
||
47 (m_dash
== data
.m_dash
&&
48 memcmp(m_dash
, data
.m_dash
, m_countDashes
*sizeof(wxDash
)) == 0));
55 pixpattern24_t m_pixPattern
;
57 // not used by wxMGL, but we want to preserve values
64 wxPenRefData::wxPenRefData()
68 m_joinStyle
= wxJOIN_ROUND
;
69 m_capStyle
= wxCAP_ROUND
;
70 m_dash
= (wxDash
*) NULL
;
74 for (y
= 0; y
< 8; y
++)
75 for (x
= 0; x
< 8; x
++)
76 for (c
= 0; c
< 3; c
++)
77 m_pixPattern
.p
[x
][y
][c
] = 0;
80 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
82 m_style
= data
.m_style
;
83 m_width
= data
.m_width
;
84 m_joinStyle
= data
.m_joinStyle
;
85 m_capStyle
= data
.m_capStyle
;
86 m_colour
= data
.m_colour
;
87 m_countDashes
= data
.m_countDashes
;
89 m_stipple
= data
.m_stipple
;
92 for (y
= 0; y
< 8; y
++)
93 for (x
= 0; x
< 8; x
++)
94 for (c
= 0; c
< 3; c
++)
95 m_pixPattern
.p
[x
][y
][c
] = data
.m_pixPattern
.p
[x
][y
][c
];
98 //-----------------------------------------------------------------------------
100 #define M_PENDATA ((wxPenRefData *)m_refData)
102 IMPLEMENT_DYNAMIC_CLASS(wxPen
,wxGDIObject
)
104 wxPen::wxPen(const wxColour
&colour
, int width
, int style
)
106 m_refData
= new wxPenRefData();
107 M_PENDATA
->m_width
= width
;
108 M_PENDATA
->m_style
= style
;
109 M_PENDATA
->m_colour
= colour
;
112 wxPen::wxPen(const wxBitmap
& stipple
, int width
)
114 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
115 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
116 _T("stipple bitmap must be 8x8") );
118 m_refData
= new wxPenRefData();
119 M_PENDATA
->m_width
= width
;
120 M_PENDATA
->m_style
= wxSTIPPLE
;
121 M_PENDATA
->m_stipple
= stipple
;
122 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
125 bool wxPen::operator == (const wxPen
& pen
) const
127 if (m_refData
== pen
.m_refData
) return true;
129 if (!m_refData
|| !pen
.m_refData
) return false;
131 return ( *(wxPenRefData
*)m_refData
== *(wxPenRefData
*)pen
.m_refData
);
134 bool wxPen::operator != (const wxPen
& pen
) const
136 return m_refData
!= pen
.m_refData
;
139 void wxPen::SetColour(const wxColour
&colour
)
142 M_PENDATA
->m_colour
= colour
;
145 void wxPen::SetDashes(int number_of_dashes
, const wxDash
*dash
)
148 M_PENDATA
->m_countDashes
= number_of_dashes
;
149 M_PENDATA
->m_dash
= (wxDash
*)dash
; /* TODO */
152 void wxPen::SetColour(unsigned char red
, unsigned char green
, unsigned char blue
)
155 M_PENDATA
->m_colour
.Set(red
, green
, blue
);
158 void wxPen::SetCap(int capStyle
)
161 M_PENDATA
->m_capStyle
= capStyle
;
164 void wxPen::SetJoin(int joinStyle
)
167 M_PENDATA
->m_joinStyle
= joinStyle
;
170 void wxPen::SetStyle(int style
)
173 M_PENDATA
->m_style
= style
;
176 void wxPen::SetStipple(const wxBitmap
& stipple
)
178 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
179 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
180 _T("stipple bitmap must be 8x8") );
183 M_PENDATA
->m_stipple
= stipple
;
184 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
187 void wxPen::SetWidth(int width
)
190 M_PENDATA
->m_width
= width
;
193 int wxPen::GetDashes(wxDash
**ptr
) const
195 *ptr
= (M_PENDATA
? (wxDash
*)M_PENDATA
->m_dash
: (wxDash
*) NULL
);
196 return (M_PENDATA
? M_PENDATA
->m_countDashes
: 0);
199 int wxPen::GetDashCount() const
201 return (M_PENDATA
->m_countDashes
);
204 wxDash
* wxPen::GetDash() const
206 return (wxDash
*)M_PENDATA
->m_dash
;
209 int wxPen::GetCap() const
211 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
213 return M_PENDATA
->m_capStyle
;
216 int wxPen::GetJoin() const
218 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
220 return M_PENDATA
->m_joinStyle
;
223 int wxPen::GetStyle() const
225 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
227 return M_PENDATA
->m_style
;
230 int wxPen::GetWidth() const
232 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
234 return M_PENDATA
->m_width
;
237 wxColour
&wxPen::GetColour() const
239 wxCHECK_MSG( Ok(), wxNullColour
, wxT("invalid pen") );
241 return M_PENDATA
->m_colour
;
244 wxBitmap
*wxPen::GetStipple() const
246 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
248 return &(M_PENDATA
->m_stipple
);
251 void* wxPen::GetPixPattern() const
253 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
255 return (void*)&(M_PENDATA
->m_pixPattern
);
259 bool wxPen::IsOk() const
261 return (m_refData
!= NULL
);
264 wxObjectRefData
*wxPen::CreateRefData() const
266 return new wxPenRefData
;
269 wxObjectRefData
*wxPen::CloneRefData(const wxObjectRefData
*data
) const
271 return new wxPenRefData(*(wxPenRefData
*)data
);