]>
git.saurik.com Git - wxWidgets.git/blob - src/x11/brush.cpp
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
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
, int style
)
62 m_refData
= new wxBrushRefData();
63 M_BRUSHDATA
->m_style
= style
;
64 M_BRUSHDATA
->m_colour
= colour
;
67 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
69 m_refData
= new wxBrushRefData();
70 M_BRUSHDATA
->m_colour
= *wxBLACK
;
72 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
74 if (M_BRUSHDATA
->m_stipple
.GetMask())
75 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
77 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
82 // m_refData unrefed in ~wxObject
85 wxGDIRefData
*wxBrush::CreateGDIRefData() const
87 return new wxBrushRefData
;
90 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
92 return new wxBrushRefData(*(wxBrushRefData
*)data
);
95 bool wxBrush::operator == ( const wxBrush
& brush
) const
97 if (m_refData
== brush
.m_refData
) return true;
99 if (!m_refData
|| !brush
.m_refData
) return false;
101 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
104 int wxBrush::GetStyle() const
106 if (m_refData
== NULL
)
108 wxFAIL_MSG( wxT("invalid brush") );
112 return M_BRUSHDATA
->m_style
;
115 wxColour
&wxBrush::GetColour() const
117 if (m_refData
== NULL
)
119 wxFAIL_MSG( wxT("invalid brush") );
123 return M_BRUSHDATA
->m_colour
;
126 wxBitmap
*wxBrush::GetStipple() const
128 if (m_refData
== NULL
)
130 wxFAIL_MSG( wxT("invalid brush") );
131 return &wxNullBitmap
;
134 return &M_BRUSHDATA
->m_stipple
;
137 void wxBrush::SetColour( const wxColour
& col
)
141 M_BRUSHDATA
->m_colour
= col
;
144 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
148 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
151 void wxBrush::SetStyle( int style
)
155 M_BRUSHDATA
->m_style
= style
;
158 void wxBrush::SetStipple( const wxBitmap
& stipple
)
162 M_BRUSHDATA
->m_stipple
= stipple
;
163 if (M_BRUSHDATA
->m_stipple
.GetMask())
165 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
169 M_BRUSHDATA
->m_style
= wxSTIPPLE
;