1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/brush.cpp
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // for compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #include "wx/bitmap.h"
19 #include "wx/colour.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 class wxBrushRefData
: public wxGDIRefData
31 m_style
= wxBRUSHSTYLE_INVALID
;
34 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
, wxBrushStyle style
)
61 m_refData
= new wxBrushRefData();
62 M_BRUSHDATA
->m_style
= style
;
63 M_BRUSHDATA
->m_colour
= colour
;
66 #if FUTURE_WXWIN_COMPATIBILITY_3_0
67 wxBrush::wxBrush(const wxColour
& col
, int style
)
69 m_refData
= new wxBrushRefData
;
70 M_BRUSHDATA
->m_style
= (wxBrushStyle
)style
;
71 M_BRUSHDATA
->m_colour
= col
;
75 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
77 m_refData
= new wxBrushRefData();
78 M_BRUSHDATA
->m_colour
= *wxBLACK
;
80 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
82 if (M_BRUSHDATA
->m_stipple
.GetMask())
83 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
85 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK
;
90 // m_refData unrefed in ~wxObject
93 wxGDIRefData
*wxBrush::CreateGDIRefData() const
95 return new wxBrushRefData
;
98 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
100 return new wxBrushRefData(*(wxBrushRefData
*)data
);
103 bool wxBrush::operator == ( const wxBrush
& brush
) const
105 if (m_refData
== brush
.m_refData
) return true;
107 if (!m_refData
|| !brush
.m_refData
) return false;
109 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
112 wxBrushStyle
wxBrush::GetStyle() const
114 wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID
, wxT("invalid brush") );
116 return M_BRUSHDATA
->m_style
;
119 wxColour
wxBrush::GetColour() const
121 wxCHECK_MSG( IsOk(), wxNullColour
, wxT("invalid brush") );
123 return M_BRUSHDATA
->m_colour
;
126 wxBitmap
*wxBrush::GetStipple() const
128 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid brush") );
130 return &M_BRUSHDATA
->m_stipple
;
133 void wxBrush::SetColour( const wxColour
& col
)
137 M_BRUSHDATA
->m_colour
= col
;
140 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
144 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
147 void wxBrush::SetStyle( wxBrushStyle 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())
160 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
162 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK
;