]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/pen.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
15 #include "wx/colour.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 class wxPenRefData
: public wxGDIRefData
30 m_style
= wxPENSTYLE_SOLID
;
31 m_joinStyle
= wxJOIN_ROUND
;
32 m_capStyle
= wxCAP_ROUND
;
37 wxPenRefData( const wxPenRefData
& data
)
40 m_style
= data
.m_style
;
41 m_width
= data
.m_width
;
42 m_joinStyle
= data
.m_joinStyle
;
43 m_capStyle
= data
.m_capStyle
;
44 m_colour
= data
.m_colour
;
45 m_countDashes
= data
.m_countDashes
;
49 bool operator == (const wxPenRefData
& data
) const
51 if ( m_countDashes
!= data
.m_countDashes
)
57 memcmp(m_dash
, data
.m_dash
, m_countDashes
*sizeof(wxGTKDash
)) )
62 else if ( data
.m_dash
)
68 return m_style
== data
.m_style
&&
69 m_width
== data
.m_width
&&
70 m_joinStyle
== data
.m_joinStyle
&&
71 m_capStyle
== data
.m_capStyle
&&
72 m_colour
== data
.m_colour
;
77 wxPenJoin m_joinStyle
;
84 //-----------------------------------------------------------------------------
86 #define M_PENDATA ((wxPenRefData *)m_refData)
88 IMPLEMENT_DYNAMIC_CLASS(wxPen
,wxGDIObject
)
90 wxPen::wxPen( const wxColour
&colour
, int width
, wxPenStyle style
)
92 m_refData
= new wxPenRefData();
93 M_PENDATA
->m_width
= width
;
94 M_PENDATA
->m_style
= style
;
95 M_PENDATA
->m_colour
= colour
;
98 #if FUTURE_WXWIN_COMPATIBILITY_3_0
99 wxPen::wxPen(const wxColour
& colour
, int width
, int style
)
101 m_refData
= new wxPenRefData();
102 M_PENDATA
->m_width
= width
;
103 M_PENDATA
->m_style
= (wxPenStyle
)style
;
104 M_PENDATA
->m_colour
= colour
;
110 // m_refData unrefed in ~wxObject
113 wxGDIRefData
*wxPen::CreateGDIRefData() const
115 return new wxPenRefData
;
118 wxGDIRefData
*wxPen::CloneGDIRefData(const wxGDIRefData
*data
) const
120 return new wxPenRefData(*(wxPenRefData
*)data
);
123 bool wxPen::operator == ( const wxPen
& pen
) const
125 if (m_refData
== pen
.m_refData
) return true;
127 if (!m_refData
|| !pen
.m_refData
) return false;
129 return ( *(wxPenRefData
*)m_refData
== *(wxPenRefData
*)pen
.m_refData
);
132 void wxPen::SetColour( const wxColour
&colour
)
136 M_PENDATA
->m_colour
= colour
;
139 void wxPen::SetDashes( int number_of_dashes
, const wxDash
*dash
)
143 M_PENDATA
->m_countDashes
= number_of_dashes
;
144 M_PENDATA
->m_dash
= (wxGTKDash
*)dash
;
147 void wxPen::SetColour( unsigned char red
, unsigned char green
, unsigned char blue
)
151 M_PENDATA
->m_colour
.Set( red
, green
, blue
);
154 void wxPen::SetCap( wxPenCap capStyle
)
158 M_PENDATA
->m_capStyle
= capStyle
;
161 void wxPen::SetJoin( wxPenJoin joinStyle
)
165 M_PENDATA
->m_joinStyle
= joinStyle
;
168 void wxPen::SetStyle( wxPenStyle style
)
172 M_PENDATA
->m_style
= style
;
175 void wxPen::SetWidth( int width
)
179 M_PENDATA
->m_width
= width
;
182 int wxPen::GetDashes( wxDash
**ptr
) const
184 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
186 *ptr
= (wxDash
*)M_PENDATA
->m_dash
;
187 return M_PENDATA
->m_countDashes
;
190 int wxPen::GetDashCount() const
192 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
194 return (M_PENDATA
->m_countDashes
);
197 wxDash
* wxPen::GetDash() const
199 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid pen") );
201 return (wxDash
*)M_PENDATA
->m_dash
;
204 wxPenCap
wxPen::GetCap() const
206 wxCHECK_MSG( IsOk(), wxCAP_INVALID
, wxT("invalid pen") );
208 return M_PENDATA
->m_capStyle
;
211 wxPenJoin
wxPen::GetJoin() const
213 wxCHECK_MSG( IsOk(), wxJOIN_INVALID
, wxT("invalid pen") );
215 return M_PENDATA
->m_joinStyle
;
218 wxPenStyle
wxPen::GetStyle() const
220 wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID
, wxT("invalid pen") );
222 return M_PENDATA
->m_style
;
225 int wxPen::GetWidth() const
227 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
229 return M_PENDATA
->m_width
;
232 wxColour
wxPen::GetColour() const
234 wxCHECK_MSG( IsOk(), wxNullColour
, wxT("invalid pen") );
236 return M_PENDATA
->m_colour
;
239 // stippled pens are not supported by wxGTK
240 void wxPen::SetStipple(const wxBitmap
& WXUNUSED(stipple
))
242 wxFAIL_MSG( "stippled pens not supported" );
245 wxBitmap
*wxPen::GetStipple() const