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"
18 #include "wx/bitmap.h"
19 #include "wx/colour.h"
20 #include "wx/mgl/private.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 class wxPenRefData
: public wxObjectRefData
30 wxPenRefData(const wxPenRefData
& data
);
36 pixpattern24_t m_pixPattern
;
38 // not used by wxMGL, but we want to preserve values
45 wxPenRefData::wxPenRefData()
49 m_joinStyle
= wxJOIN_ROUND
;
50 m_capStyle
= wxCAP_ROUND
;
51 m_dash
= (wxDash
*) NULL
;
55 for (y
= 0; y
< 8; y
++)
56 for (x
= 0; x
< 8; x
++)
57 for (c
= 0; c
< 3; c
++)
58 m_pixPattern
.p
[x
][y
][c
] = 0;
61 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
63 m_style
= data
.m_style
;
64 m_width
= data
.m_width
;
65 m_joinStyle
= data
.m_joinStyle
;
66 m_capStyle
= data
.m_capStyle
;
67 m_colour
= data
.m_colour
;
68 m_countDashes
= data
.m_countDashes
;
70 m_stipple
= data
.m_stipple
;
73 for (y
= 0; y
< 8; y
++)
74 for (x
= 0; x
< 8; x
++)
75 for (c
= 0; c
< 3; c
++)
76 m_pixPattern
.p
[x
][y
][c
] = data
.m_pixPattern
.p
[x
][y
][c
];
79 //-----------------------------------------------------------------------------
81 #define M_PENDATA ((wxPenRefData *)m_refData)
83 IMPLEMENT_DYNAMIC_CLASS(wxPen
,wxGDIObject
)
85 wxPen::wxPen(const wxColour
&colour
, int width
, int style
)
87 m_refData
= new wxPenRefData();
88 M_PENDATA
->m_width
= width
;
89 M_PENDATA
->m_style
= style
;
90 M_PENDATA
->m_colour
= colour
;
93 wxPen::wxPen(const wxBitmap
& stipple
, int width
)
95 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
96 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
97 _T("stipple bitmap must be 8x8") );
99 m_refData
= new wxPenRefData();
100 M_PENDATA
->m_width
= width
;
101 M_PENDATA
->m_style
= wxSTIPPLE
;
102 M_PENDATA
->m_stipple
= stipple
;
103 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
106 wxPen::wxPen(const wxPen
& pen
)
111 wxPen
& wxPen::operator = (const wxPen
& pen
)
113 if (*this == pen
) return (*this);
118 bool wxPen::operator == (const wxPen
& pen
) const
120 return m_refData
== pen
.m_refData
;
123 bool wxPen::operator != (const wxPen
& pen
) const
125 return m_refData
!= pen
.m_refData
;
128 void wxPen::SetColour(const wxColour
&colour
)
131 M_PENDATA
->m_colour
= colour
;
134 void wxPen::SetDashes(int number_of_dashes
, const wxDash
*dash
)
137 M_PENDATA
->m_countDashes
= number_of_dashes
;
138 M_PENDATA
->m_dash
= (wxDash
*)dash
; /* TODO */
141 void wxPen::SetColour(unsigned char red
, unsigned char green
, unsigned char blue
)
144 M_PENDATA
->m_colour
.Set(red
, green
, blue
);
147 void wxPen::SetCap(int capStyle
)
150 M_PENDATA
->m_capStyle
= capStyle
;
153 void wxPen::SetJoin(int joinStyle
)
156 M_PENDATA
->m_joinStyle
= joinStyle
;
159 void wxPen::SetStyle(int style
)
162 M_PENDATA
->m_style
= style
;
165 void wxPen::SetStipple(const wxBitmap
& stipple
)
167 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
168 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
169 _T("stipple bitmap must be 8x8") );
172 M_PENDATA
->m_stipple
= stipple
;
173 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
176 void wxPen::SetWidth(int width
)
179 M_PENDATA
->m_width
= width
;
182 int wxPen::GetDashes(wxDash
**ptr
) const
184 *ptr
= (M_PENDATA
? (wxDash
*)M_PENDATA
->m_dash
: (wxDash
*) NULL
);
185 return (M_PENDATA
? M_PENDATA
->m_countDashes
: 0);
188 int wxPen::GetDashCount() const
190 return (M_PENDATA
->m_countDashes
);
193 wxDash
* wxPen::GetDash() const
195 return (wxDash
*)M_PENDATA
->m_dash
;
198 int wxPen::GetCap() const
200 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
202 return M_PENDATA
->m_capStyle
;
205 int wxPen::GetJoin() const
207 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
209 return M_PENDATA
->m_joinStyle
;
212 int wxPen::GetStyle() const
214 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
216 return M_PENDATA
->m_style
;
219 int wxPen::GetWidth() const
221 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
223 return M_PENDATA
->m_width
;
226 wxColour
&wxPen::GetColour() const
228 wxCHECK_MSG( Ok(), wxNullColour
, wxT("invalid pen") );
230 return M_PENDATA
->m_colour
;
233 wxBitmap
*wxPen::GetStipple() const
235 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
237 return &(M_PENDATA
->m_stipple
);
240 void* wxPen::GetPixPattern() const
242 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
244 return (void*)&(M_PENDATA
->m_pixPattern
);
248 bool wxPen::Ok() const
250 return (m_refData
!= NULL
);
253 wxObjectRefData
*wxPen::CreateRefData() const
255 return new wxPenRefData
;
258 wxObjectRefData
*wxPen::CloneRefData(const wxObjectRefData
*data
) const
260 return new wxPenRefData(*(wxPenRefData
*)data
);