]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/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"
14 #include "wx/colour.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 class wxBrushRefData
: public wxObjectRefData
30 wxBrushRefData( const wxBrushRefData
& data
)
33 m_style
= data
.m_style
;
34 m_stipple
= data
.m_stipple
;
35 m_colour
= data
.m_colour
;
38 bool operator == (const wxBrushRefData
& data
) const
40 return (m_style
== data
.m_style
&&
41 m_stipple
== data
.m_stipple
&&
42 m_colour
== data
.m_colour
);
50 //-----------------------------------------------------------------------------
52 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
54 IMPLEMENT_DYNAMIC_CLASS(wxBrush
,wxGDIObject
)
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
;
63 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
65 m_refData
= new wxBrushRefData();
66 M_BRUSHDATA
->m_colour
= *wxBLACK
;
68 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
70 if (M_BRUSHDATA
->m_stipple
.GetMask())
71 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
73 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
78 // m_refData unrefed in ~wxObject
81 wxObjectRefData
*wxBrush::CreateRefData() const
83 return new wxBrushRefData
;
86 wxObjectRefData
*wxBrush::CloneRefData(const wxObjectRefData
*data
) const
88 return new wxBrushRefData(*(wxBrushRefData
*)data
);
91 bool wxBrush::operator == ( const wxBrush
& brush
) const
93 if (m_refData
== brush
.m_refData
) return true;
95 if (!m_refData
|| !brush
.m_refData
) return false;
97 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
100 int wxBrush::GetStyle() const
102 if (m_refData
== NULL
)
104 wxFAIL_MSG( wxT("invalid brush") );
108 return M_BRUSHDATA
->m_style
;
111 wxColour
&wxBrush::GetColour() const
113 if (m_refData
== NULL
)
115 wxFAIL_MSG( wxT("invalid brush") );
119 return M_BRUSHDATA
->m_colour
;
122 wxBitmap
*wxBrush::GetStipple() const
124 if (m_refData
== NULL
)
126 wxFAIL_MSG( wxT("invalid brush") );
127 return &wxNullBitmap
;
130 return &M_BRUSHDATA
->m_stipple
;
133 void wxBrush::SetColour( const wxColour
& col
)
137 M_BRUSHDATA
->m_colour
= col
;
140 void wxBrush::SetColour( const unsigned char r
, const unsigned char g
, const unsigned char b
)
144 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
147 void wxBrush::SetStyle( int style
)
151 M_BRUSHDATA
->m_style
= style
;
154 void wxBrush::SetStipple( const wxBitmap
& stipple
)
158 M_BRUSHDATA
->m_stipple
= stipple
;
159 if (M_BRUSHDATA
->m_stipple
.GetMask())
161 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
165 M_BRUSHDATA
->m_style
= wxSTIPPLE
;