1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/brush.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/bitmap.h"
20 #include "wx/colour.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 class wxBrushRefData
: public wxGDIRefData
32 m_style
= wxBRUSHSTYLE_INVALID
;
35 wxBrushRefData( const wxBrushRefData
& data
)
37 m_style
= data
.m_style
;
38 m_stipple
= data
.m_stipple
;
39 m_colour
= data
.m_colour
;
42 bool operator == (const wxBrushRefData
& data
) const
44 return (m_style
== data
.m_style
&&
45 m_stipple
.IsSameAs(data
.m_stipple
) &&
46 m_colour
== data
.m_colour
);
54 //-----------------------------------------------------------------------------
56 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
58 IMPLEMENT_DYNAMIC_CLASS(wxBrush
,wxGDIObject
)
60 wxBrush::wxBrush( const wxColour
&colour
, wxBrushStyle style
)
62 m_refData
= new wxBrushRefData();
63 M_BRUSHDATA
->m_style
= style
;
64 M_BRUSHDATA
->m_colour
= colour
;
67 #if FUTURE_WXWIN_COMPATIBILITY_3_0
68 wxBrush::wxBrush(const wxColour
& col
, int style
)
70 m_refData
= new wxBrushRefData
;
71 M_BRUSHDATA
->m_style
= (wxBrushStyle
)style
;
72 M_BRUSHDATA
->m_colour
= col
;
76 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
78 m_refData
= new wxBrushRefData();
79 M_BRUSHDATA
->m_colour
= *wxBLACK
;
81 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
83 if (M_BRUSHDATA
->m_stipple
.GetMask())
84 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
86 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK
;
91 // m_refData unrefed in ~wxObject
94 wxGDIRefData
*wxBrush::CreateGDIRefData() const
96 return new wxBrushRefData
;
99 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
101 return new wxBrushRefData(*(wxBrushRefData
*)data
);
104 bool wxBrush::operator == ( const wxBrush
& brush
) const
106 if (m_refData
== brush
.m_refData
) return true;
108 if (!m_refData
|| !brush
.m_refData
) return false;
110 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
113 wxBrushStyle
wxBrush::GetStyle() const
115 wxCHECK_MSG( Ok(), wxBRUSHSTYLE_INVALID
, _T("invalid brush") );
117 return M_BRUSHDATA
->m_style
;
120 wxColour
&wxBrush::GetColour() const
122 wxCHECK_MSG( Ok(), wxNullColour
, _T("invalid brush") );
124 return M_BRUSHDATA
->m_colour
;
127 wxBitmap
*wxBrush::GetStipple() const
129 wxCHECK_MSG( Ok(), NULL
, _T("invalid brush") );
131 return &M_BRUSHDATA
->m_stipple
;
134 void wxBrush::SetColour( const wxColour
& col
)
138 M_BRUSHDATA
->m_colour
= col
;
141 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
145 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
148 void wxBrush::SetStyle( wxBrushStyle style
)
152 M_BRUSHDATA
->m_style
= style
;
155 void wxBrush::SetStipple( const wxBitmap
& stipple
)
159 M_BRUSHDATA
->m_stipple
= stipple
;
160 if (M_BRUSHDATA
->m_stipple
.GetMask())
161 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
163 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK
;