]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "brush.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 class wxBrushRefData
: public wxObjectRefData
26 wxBrushRefData( const wxBrushRefData
& data
);
33 wxBrushRefData::wxBrushRefData()
38 wxBrushRefData::wxBrushRefData( const wxBrushRefData
& data
)
40 m_style
= data
.m_style
;
41 m_stipple
= data
.m_stipple
;
42 m_colour
= data
.m_colour
;
45 //-----------------------------------------------------------------------------
47 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
49 IMPLEMENT_DYNAMIC_CLASS(wxBrush
,wxGDIObject
)
53 if (wxTheBrushList
) wxTheBrushList
->AddBrush( this );
56 wxBrush::wxBrush( const wxColour
&colour
, int style
)
58 m_refData
= new wxBrushRefData();
59 M_BRUSHDATA
->m_style
= style
;
60 M_BRUSHDATA
->m_colour
= colour
;
62 if (wxTheBrushList
) wxTheBrushList
->AddBrush( this );
65 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
67 m_refData
= new wxBrushRefData();
68 M_BRUSHDATA
->m_colour
= *wxBLACK
;
70 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
72 if (M_BRUSHDATA
->m_stipple
.GetMask())
73 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
75 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
77 if (wxTheBrushList
) wxTheBrushList
->AddBrush( this );
80 wxBrush::wxBrush( const wxBrush
&brush
)
84 if (wxTheBrushList
) wxTheBrushList
->AddBrush( this );
89 if (wxTheBrushList
) wxTheBrushList
->RemoveBrush( this );
92 wxBrush
& wxBrush::operator = ( const wxBrush
& brush
)
94 if (*this == brush
) return (*this);
99 bool wxBrush::operator == ( const wxBrush
& brush
) const
101 return m_refData
== brush
.m_refData
;
104 bool wxBrush::operator != ( const wxBrush
& brush
) const
106 return m_refData
!= brush
.m_refData
;
109 bool wxBrush::Ok() const
111 return ((m_refData
) && M_BRUSHDATA
->m_colour
.Ok());
114 int wxBrush::GetStyle() const
116 if (m_refData
== NULL
)
118 wxFAIL_MSG( wxT("invalid brush") );
122 return M_BRUSHDATA
->m_style
;
125 wxColour
&wxBrush::GetColour() const
127 if (m_refData
== NULL
)
129 wxFAIL_MSG( wxT("invalid brush") );
133 return M_BRUSHDATA
->m_colour
;
136 wxBitmap
*wxBrush::GetStipple() const
138 if (m_refData
== NULL
)
140 wxFAIL_MSG( wxT("invalid brush") );
141 return &wxNullBitmap
;
144 return &M_BRUSHDATA
->m_stipple
;
147 void wxBrush::SetColour( const wxColour
& col
)
150 M_BRUSHDATA
->m_colour
= col
;
153 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
156 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
159 void wxBrush::SetStyle( int style
)
162 M_BRUSHDATA
->m_style
= style
;
165 void wxBrush::SetStipple( const wxBitmap
& stipple
)
168 M_BRUSHDATA
->m_stipple
= stipple
;
169 if (M_BRUSHDATA
->m_stipple
.GetMask())
171 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
175 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
179 void wxBrush::Unshare()
183 m_refData
= new wxBrushRefData();
187 wxBrushRefData
* ref
= new wxBrushRefData( *(wxBrushRefData
*)m_refData
);