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
);
40 pixpattern24_t m_pixPattern
;
42 // not used by wxMGL, but we want to preserve values
49 wxPenRefData::wxPenRefData()
53 m_joinStyle
= wxJOIN_ROUND
;
54 m_capStyle
= wxCAP_ROUND
;
55 m_dash
= (wxDash
*) NULL
;
59 for (y
= 0; y
< 8; y
++)
60 for (x
= 0; x
< 8; x
++)
61 for (c
= 0; c
< 3; c
++)
62 m_pixPattern
.p
[x
][y
][c
] = 0;
65 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
67 m_style
= data
.m_style
;
68 m_width
= data
.m_width
;
69 m_joinStyle
= data
.m_joinStyle
;
70 m_capStyle
= data
.m_capStyle
;
71 m_colour
= data
.m_colour
;
72 m_countDashes
= data
.m_countDashes
;
74 m_stipple
= data
.m_stipple
;
77 for (y
= 0; y
< 8; y
++)
78 for (x
= 0; x
< 8; x
++)
79 for (c
= 0; c
< 3; c
++)
80 m_pixPattern
.p
[x
][y
][c
] = data
.m_pixPattern
.p
[x
][y
][c
];
83 //-----------------------------------------------------------------------------
85 #define M_PENDATA ((wxPenRefData *)m_refData)
87 IMPLEMENT_DYNAMIC_CLASS(wxPen
,wxGDIObject
)
89 wxPen::wxPen(const wxColour
&colour
, int width
, int style
)
91 m_refData
= new wxPenRefData();
92 M_PENDATA
->m_width
= width
;
93 M_PENDATA
->m_style
= style
;
94 M_PENDATA
->m_colour
= colour
;
97 wxPen::wxPen(const wxBitmap
& stipple
, int width
)
99 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
100 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
101 _T("stipple bitmap must be 8x8") );
103 m_refData
= new wxPenRefData();
104 M_PENDATA
->m_width
= width
;
105 M_PENDATA
->m_style
= wxSTIPPLE
;
106 M_PENDATA
->m_stipple
= stipple
;
107 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
110 bool wxPen::operator == (const wxPen
& pen
) const
112 return m_refData
== pen
.m_refData
;
115 bool wxPen::operator != (const wxPen
& pen
) const
117 return m_refData
!= pen
.m_refData
;
120 void wxPen::SetColour(const wxColour
&colour
)
123 M_PENDATA
->m_colour
= colour
;
126 void wxPen::SetDashes(int number_of_dashes
, const wxDash
*dash
)
129 M_PENDATA
->m_countDashes
= number_of_dashes
;
130 M_PENDATA
->m_dash
= (wxDash
*)dash
; /* TODO */
133 void wxPen::SetColour(unsigned char red
, unsigned char green
, unsigned char blue
)
136 M_PENDATA
->m_colour
.Set(red
, green
, blue
);
139 void wxPen::SetCap(int capStyle
)
142 M_PENDATA
->m_capStyle
= capStyle
;
145 void wxPen::SetJoin(int joinStyle
)
148 M_PENDATA
->m_joinStyle
= joinStyle
;
151 void wxPen::SetStyle(int style
)
154 M_PENDATA
->m_style
= style
;
157 void wxPen::SetStipple(const wxBitmap
& stipple
)
159 wxCHECK_RET( stipple
.Ok(), _T("invalid bitmap") );
160 wxCHECK_RET( stipple
.GetWidth() == 8 && stipple
.GetHeight() == 8,
161 _T("stipple bitmap must be 8x8") );
164 M_PENDATA
->m_stipple
= stipple
;
165 wxBitmapToPixPattern(stipple
, &(M_PENDATA
->m_pixPattern
), NULL
);
168 void wxPen::SetWidth(int width
)
171 M_PENDATA
->m_width
= width
;
174 int wxPen::GetDashes(wxDash
**ptr
) const
176 *ptr
= (M_PENDATA
? (wxDash
*)M_PENDATA
->m_dash
: (wxDash
*) NULL
);
177 return (M_PENDATA
? M_PENDATA
->m_countDashes
: 0);
180 int wxPen::GetDashCount() const
182 return (M_PENDATA
->m_countDashes
);
185 wxDash
* wxPen::GetDash() const
187 return (wxDash
*)M_PENDATA
->m_dash
;
190 int wxPen::GetCap() const
192 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
194 return M_PENDATA
->m_capStyle
;
197 int wxPen::GetJoin() const
199 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
201 return M_PENDATA
->m_joinStyle
;
204 int wxPen::GetStyle() const
206 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
208 return M_PENDATA
->m_style
;
211 int wxPen::GetWidth() const
213 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
215 return M_PENDATA
->m_width
;
218 wxColour
&wxPen::GetColour() const
220 wxCHECK_MSG( Ok(), wxNullColour
, wxT("invalid pen") );
222 return M_PENDATA
->m_colour
;
225 wxBitmap
*wxPen::GetStipple() const
227 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
229 return &(M_PENDATA
->m_stipple
);
232 void* wxPen::GetPixPattern() const
234 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
236 return (void*)&(M_PENDATA
->m_pixPattern
);
240 bool wxPen::IsOk() const
242 return (m_refData
!= NULL
);
245 wxObjectRefData
*wxPen::CreateRefData() const
247 return new wxPenRefData
;
250 wxObjectRefData
*wxPen::CloneRefData(const wxObjectRefData
*data
) const
252 return new wxPenRefData(*(wxPenRefData
*)data
);