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 bool wxPen::operator == (const wxPen
& pen
) const
108 return m_refData
== pen
.m_refData
;
111 bool wxPen::operator != (const wxPen
& pen
) const
113 return m_refData
!= pen
.m_refData
;
116 void wxPen::SetColour(const wxColour
&colour
)
119 M_PENDATA
->m_colour
= colour
;
122 void wxPen::SetDashes(int number_of_dashes
, const wxDash
*dash
)
125 M_PENDATA
->m_countDashes
= number_of_dashes
;
126 M_PENDATA
->m_dash
= (wxDash
*)dash
; /* TODO */
129 void wxPen::SetColour(unsigned char red
, unsigned char green
, unsigned char blue
)
132 M_PENDATA
->m_colour
.Set(red
, green
, blue
);
135 void wxPen::SetCap(int capStyle
)
138 M_PENDATA
->m_capStyle
= capStyle
;
141 void wxPen::SetJoin(int joinStyle
)
144 M_PENDATA
->m_joinStyle
= joinStyle
;
147 void wxPen::SetStyle(int style
)
150 M_PENDATA
->m_style
= style
;
153 void wxPen::SetStipple(const wxBitmap
& stipple
)
155 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
156 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
157 _T("stipple bitmap must be 8x8") );
160 M_PENDATA
->m_stipple
= stipple
;
161 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
164 void wxPen::SetWidth(int width
)
167 M_PENDATA
->m_width
= width
;
170 int wxPen::GetDashes(wxDash
**ptr
) const
172 *ptr
= (M_PENDATA
? (wxDash
*)M_PENDATA
->m_dash
: (wxDash
*) NULL
);
173 return (M_PENDATA
? M_PENDATA
->m_countDashes
: 0);
176 int wxPen::GetDashCount() const
178 return (M_PENDATA
->m_countDashes
);
181 wxDash
* wxPen::GetDash() const
183 return (wxDash
*)M_PENDATA
->m_dash
;
186 int wxPen::GetCap() const
188 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
190 return M_PENDATA
->m_capStyle
;
193 int wxPen::GetJoin() const
195 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
197 return M_PENDATA
->m_joinStyle
;
200 int wxPen::GetStyle() const
202 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
204 return M_PENDATA
->m_style
;
207 int wxPen::GetWidth() const
209 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
211 return M_PENDATA
->m_width
;
214 wxColour
&wxPen::GetColour() const
216 wxCHECK_MSG( Ok(), wxNullColour
, wxT("invalid pen") );
218 return M_PENDATA
->m_colour
;
221 wxBitmap
*wxPen::GetStipple() const
223 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
225 return &(M_PENDATA
->m_stipple
);
228 void* wxPen::GetPixPattern() const
230 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
232 return (void*)&(M_PENDATA
->m_pixPattern
);
236 bool wxPen::Ok() const
238 return (m_refData
!= NULL
);
241 wxObjectRefData
*wxPen::CreateRefData() const
243 return new wxPenRefData
;
246 wxObjectRefData
*wxPen::CloneRefData(const wxObjectRefData
*data
) const
248 return new wxPenRefData(*(wxPenRefData
*)data
);