1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/brush.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 wxBrushRefData
: public wxGDIRefData
29 m_style
= wxBRUSHSTYLE_INVALID
;
32 wxBrushRefData( const wxBrushRefData
& data
)
35 m_style
= data
.m_style
;
36 m_stipple
= data
.m_stipple
;
37 m_colour
= data
.m_colour
;
40 bool operator == (const wxBrushRefData
& data
) const
42 return (m_style
== data
.m_style
&&
43 m_stipple
.IsSameAs(data
.m_stipple
) &&
44 m_colour
== data
.m_colour
);
52 //-----------------------------------------------------------------------------
54 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
56 IMPLEMENT_DYNAMIC_CLASS(wxBrush
,wxGDIObject
)
58 wxBrush::wxBrush( const wxColour
&colour
, wxBrushStyle style
)
60 m_refData
= new wxBrushRefData();
61 M_BRUSHDATA
->m_style
= style
;
62 M_BRUSHDATA
->m_colour
= colour
;
65 #if FUTURE_WXWIN_COMPATIBILITY_3_0
66 wxBrush::wxBrush(const wxColour
& col
, int style
)
68 m_refData
= new wxBrushRefData
;
69 M_BRUSHDATA
->m_style
= (wxBrushStyle
)style
;
70 M_BRUSHDATA
->m_colour
= col
;
74 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
76 m_refData
= new wxBrushRefData();
77 M_BRUSHDATA
->m_colour
= *wxBLACK
;
79 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
81 if (M_BRUSHDATA
->m_stipple
.GetMask())
82 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
84 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK
;
89 // m_refData unrefed in ~wxObject
92 wxGDIRefData
*wxBrush::CreateGDIRefData() const
94 return new wxBrushRefData
;
97 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
99 return new wxBrushRefData(*(wxBrushRefData
*)data
);
102 bool wxBrush::operator == ( const wxBrush
& brush
) const
104 if (m_refData
== brush
.m_refData
) return true;
106 if (!m_refData
|| !brush
.m_refData
) return false;
108 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
111 wxBrushStyle
wxBrush::GetStyle() const
113 wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID
, wxT("invalid brush") );
115 return M_BRUSHDATA
->m_style
;
118 wxColour
wxBrush::GetColour() const
120 wxCHECK_MSG( IsOk(), wxNullColour
, wxT("invalid brush") );
122 return M_BRUSHDATA
->m_colour
;
125 wxBitmap
*wxBrush::GetStipple() const
127 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid brush") );
129 return &M_BRUSHDATA
->m_stipple
;
132 void wxBrush::SetColour( const wxColour
& col
)
136 M_BRUSHDATA
->m_colour
= col
;
139 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
143 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
146 void wxBrush::SetStyle( wxBrushStyle style
)
150 M_BRUSHDATA
->m_style
= style
;
153 void wxBrush::SetStipple( const wxBitmap
& stipple
)
157 M_BRUSHDATA
->m_stipple
= stipple
;
158 if (M_BRUSHDATA
->m_stipple
.GetMask())
159 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
161 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK
;