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
&&
42 &data
.m_pixPattern
, sizeof(m_pixPattern
)) == 0 &&
43 m_capStyle
== data
.m_capStyle
&&
44 m_joinStyle
== data
.m_joinStyle
&&
45 m_colour
== data
.m_colour
&&
46 (m_style
!= wxPENSTYLE_STIPPLE
|| m_stipple
.IsSameAs(data
.m_stipple
)) &&
47 (m_style
!= wxPENSTYLE_USER_DASH
||
48 (m_dash
== data
.m_dash
&&
49 memcmp(m_dash
, data
.m_dash
, m_countDashes
*sizeof(wxDash
)) == 0));
56 pixpattern24_t m_pixPattern
;
58 // not used by wxMGL, but we want to preserve values
59 wxPenJoin m_joinStyle
;
65 wxPenRefData::wxPenRefData()
68 m_style
= wxPENSTYLE_SOLID
;
69 m_joinStyle
= wxJOIN_ROUND
;
70 m_capStyle
= wxCAP_ROUND
;
75 for (y
= 0; y
< 8; y
++)
76 for (x
= 0; x
< 8; x
++)
77 for (c
= 0; c
< 3; c
++)
78 m_pixPattern
.p
[x
][y
][c
] = 0;
81 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
83 m_style
= data
.m_style
;
84 m_width
= data
.m_width
;
85 m_joinStyle
= data
.m_joinStyle
;
86 m_capStyle
= data
.m_capStyle
;
87 m_colour
= data
.m_colour
;
88 m_countDashes
= data
.m_countDashes
;
90 m_stipple
= data
.m_stipple
;
93 for (y
= 0; y
< 8; y
++)
94 for (x
= 0; x
< 8; x
++)
95 for (c
= 0; c
< 3; c
++)
96 m_pixPattern
.p
[x
][y
][c
] = data
.m_pixPattern
.p
[x
][y
][c
];
99 //-----------------------------------------------------------------------------
101 #define M_PENDATA ((wxPenRefData *)m_refData)
103 IMPLEMENT_DYNAMIC_CLASS(wxPen
,wxGDIObject
)
105 wxPen::wxPen(const wxColour
&colour
, int width
, wxPenStyle style
)
107 m_refData
= new wxPenRefData();
108 M_PENDATA
->m_width
= width
;
109 M_PENDATA
->m_style
= style
;
110 M_PENDATA
->m_colour
= colour
;
113 #if FUTURE_WXWIN_COMPATIBILITY_3_0
114 wxPen::wxPen(const wxColour
& colour
, int width
, int style
)
116 m_refData
= new wxPenRefData();
117 M_PENDATA
->m_width
= width
;
118 M_PENDATA
->m_style
= (wxPenStyle
)style
;
119 M_PENDATA
->m_colour
= colour
;
123 wxPen::wxPen(const wxBitmap
& stipple
, int width
)
125 wxCHECK_RET( stipple
.Ok(), wxT("invalid bitmap") );
126 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
127 wxT("stipple bitmap must be 8x8") );
129 m_refData
= new wxPenRefData();
130 M_PENDATA
->m_width
= width
;
131 M_PENDATA
->m_style
= wxPENSTYLE_STIPPLE
;
132 M_PENDATA
->m_stipple
= stipple
;
133 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
136 bool wxPen::operator == (const wxPen
& pen
) const
138 if (m_refData
== pen
.m_refData
) return true;
140 if (!m_refData
|| !pen
.m_refData
) return false;
142 return ( *(wxPenRefData
*)m_refData
== *(wxPenRefData
*)pen
.m_refData
);
145 bool wxPen::operator != (const wxPen
& pen
) const
147 return m_refData
!= pen
.m_refData
;
150 void wxPen::SetColour(const wxColour
&colour
)
153 M_PENDATA
->m_colour
= colour
;
156 void wxPen::SetDashes(int number_of_dashes
, const wxDash
*dash
)
159 M_PENDATA
->m_countDashes
= number_of_dashes
;
160 M_PENDATA
->m_dash
= (wxDash
*)dash
; /* TODO */
163 void wxPen::SetColour(unsigned char red
, unsigned char green
, unsigned char blue
)
166 M_PENDATA
->m_colour
.Set(red
, green
, blue
);
169 void wxPen::SetCap(wxPenCap capStyle
)
172 M_PENDATA
->m_capStyle
= capStyle
;
175 void wxPen::SetJoin(wxPenJoin joinStyle
)
178 M_PENDATA
->m_joinStyle
= joinStyle
;
181 void wxPen::SetStyle(wxPenStyle style
)
184 M_PENDATA
->m_style
= style
;
187 void wxPen::SetStipple(const wxBitmap
& stipple
)
189 wxCHECK_RET( stipple
.Ok(), wxT("invalid bitmap") );
190 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
191 wxT("stipple bitmap must be 8x8") );
194 M_PENDATA
->m_stipple
= stipple
;
195 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
198 void wxPen::SetWidth(int width
)
201 M_PENDATA
->m_width
= width
;
204 int wxPen::GetDashes(wxDash
**ptr
) const
206 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
208 *ptr
= (wxDash
*)M_PENDATA
->m_dash
;
209 return M_PENDATA
->m_countDashes
;
212 int wxPen::GetDashCount() const
214 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
216 return (M_PENDATA
->m_countDashes
);
219 wxDash
* wxPen::GetDash() const
221 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
223 return (wxDash
*)M_PENDATA
->m_dash
;
226 wxPenCap
wxPen::GetCap() const
228 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
230 return M_PENDATA
->m_capStyle
;
233 wxPenJoin
wxPen::GetJoin() const
235 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
237 return M_PENDATA
->m_joinStyle
;
240 wxPenStyle
wxPen::GetStyle() const
242 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
244 return M_PENDATA
->m_style
;
247 int wxPen::GetWidth() const
249 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
251 return M_PENDATA
->m_width
;
254 wxColour
wxPen::GetColour() const
256 wxCHECK_MSG( Ok(), wxNullColour
, wxT("invalid pen") );
258 return M_PENDATA
->m_colour
;
261 wxBitmap
*wxPen::GetStipple() const
263 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
265 return &(M_PENDATA
->m_stipple
);
268 void* wxPen::GetPixPattern() const
270 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
272 return (void*)&(M_PENDATA
->m_pixPattern
);
276 wxGDIRefData
*wxPen::CreateGDIRefData() const
278 return new wxPenRefData
;
281 wxGDIRefData
*wxPen::CloneGDIRefData(const wxGDIRefData
*data
) const
283 return new wxPenRefData(*(wxPenRefData
*)data
);