]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/pen.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
14 #include "wx/colour.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 class wxPenRefData
: public wxObjectRefData
29 m_joinStyle
= wxJOIN_ROUND
;
30 m_capStyle
= wxCAP_ROUND
;
31 m_dash
= (wxGTKDash
*) NULL
;
35 wxPenRefData( const wxPenRefData
& data
)
38 m_style
= data
.m_style
;
39 m_width
= data
.m_width
;
40 m_joinStyle
= data
.m_joinStyle
;
41 m_capStyle
= data
.m_capStyle
;
42 m_colour
= data
.m_colour
;
43 m_countDashes
= data
.m_countDashes
;
47 bool operator == (const wxPenRefData
& data
) const
49 if ( m_countDashes
!= data
.m_countDashes
)
55 memcmp(m_dash
, data
.m_dash
, m_countDashes
*sizeof(wxGTKDash
)) )
60 else if ( data
.m_dash
)
66 return m_style
== data
.m_style
&&
67 m_width
== data
.m_width
&&
68 m_joinStyle
== data
.m_joinStyle
&&
69 m_capStyle
== data
.m_capStyle
&&
70 m_colour
== data
.m_colour
;
82 //-----------------------------------------------------------------------------
84 #define M_PENDATA ((wxPenRefData *)m_refData)
86 IMPLEMENT_DYNAMIC_CLASS(wxPen
,wxGDIObject
)
88 wxPen::wxPen( const wxColour
&colour
, int width
, int style
)
90 m_refData
= new wxPenRefData();
91 M_PENDATA
->m_width
= width
;
92 M_PENDATA
->m_style
= style
;
93 M_PENDATA
->m_colour
= colour
;
98 // m_refData unrefed in ~wxObject
101 wxObjectRefData
*wxPen::CreateRefData() const
103 return new wxPenRefData
;
106 wxObjectRefData
*wxPen::CloneRefData(const wxObjectRefData
*data
) const
108 return new wxPenRefData(*(wxPenRefData
*)data
);
111 bool wxPen::operator == ( const wxPen
& pen
) const
113 if (m_refData
== pen
.m_refData
) return true;
115 if (!m_refData
|| !pen
.m_refData
) return false;
117 return ( *(wxPenRefData
*)m_refData
== *(wxPenRefData
*)pen
.m_refData
);
120 void wxPen::SetColour( const wxColour
&colour
)
124 M_PENDATA
->m_colour
= colour
;
127 void wxPen::SetDashes( int number_of_dashes
, const wxDash
*dash
)
131 M_PENDATA
->m_countDashes
= number_of_dashes
;
132 M_PENDATA
->m_dash
= (wxGTKDash
*)dash
;
135 void wxPen::SetColour( unsigned char red
, unsigned char green
, unsigned char blue
)
139 M_PENDATA
->m_colour
.Set( red
, green
, blue
);
142 void wxPen::SetCap( int capStyle
)
146 M_PENDATA
->m_capStyle
= capStyle
;
149 void wxPen::SetJoin( int joinStyle
)
153 M_PENDATA
->m_joinStyle
= joinStyle
;
156 void wxPen::SetStyle( int style
)
160 M_PENDATA
->m_style
= style
;
163 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
;