]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/brush.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"
16 #include "wx/colour.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 class wxBrushRefData
: public wxGDIRefData
33 wxBrushRefData( const wxBrushRefData
& data
)
36 m_style
= data
.m_style
;
37 m_stipple
= data
.m_stipple
;
38 m_colour
= data
.m_colour
;
41 bool operator == (const wxBrushRefData
& data
) const
43 return (m_style
== data
.m_style
&&
44 m_stipple
.IsSameAs(data
.m_stipple
) &&
45 m_colour
== data
.m_colour
);
53 //-----------------------------------------------------------------------------
55 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
57 IMPLEMENT_DYNAMIC_CLASS(wxBrush
,wxGDIObject
)
59 wxBrush::wxBrush( const wxColour
&colour
, int style
)
61 m_refData
= new wxBrushRefData();
62 M_BRUSHDATA
->m_style
= style
;
63 M_BRUSHDATA
->m_colour
= colour
;
66 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
68 m_refData
= new wxBrushRefData();
69 M_BRUSHDATA
->m_colour
= *wxBLACK
;
71 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
73 if (M_BRUSHDATA
->m_stipple
.GetMask())
74 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
76 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
81 // m_refData unrefed in ~wxObject
84 wxGDIRefData
*wxBrush::CreateGDIRefData() const
86 return new wxBrushRefData
;
89 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
91 return new wxBrushRefData(*(wxBrushRefData
*)data
);
94 bool wxBrush::operator == ( const wxBrush
& brush
) const
96 if (m_refData
== brush
.m_refData
) return true;
98 if (!m_refData
|| !brush
.m_refData
) return false;
100 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
103 int wxBrush::GetStyle() const
105 if (m_refData
== NULL
)
107 wxFAIL_MSG( wxT("invalid brush") );
111 return M_BRUSHDATA
->m_style
;
114 wxColour
&wxBrush::GetColour() const
116 if (m_refData
== NULL
)
118 wxFAIL_MSG( wxT("invalid brush") );
122 return M_BRUSHDATA
->m_colour
;
125 wxBitmap
*wxBrush::GetStipple() const
127 if (m_refData
== NULL
)
129 wxFAIL_MSG( wxT("invalid brush") );
130 return &wxNullBitmap
;
133 return &M_BRUSHDATA
->m_stipple
;
136 void wxBrush::SetColour( const wxColour
& col
)
140 M_BRUSHDATA
->m_colour
= col
;
143 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
147 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
150 void wxBrush::SetStyle( int style
)
154 M_BRUSHDATA
->m_style
= style
;
157 void wxBrush::SetStipple( const wxBitmap
& stipple
)
161 M_BRUSHDATA
->m_stipple
= stipple
;
162 if (M_BRUSHDATA
->m_stipple
.GetMask())
164 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
168 M_BRUSHDATA
->m_style
= wxSTIPPLE
;