]>
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"
21 #include "wx/bitmap.h"
22 #include "wx/colour.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 class wxBrushRefData
: public wxObjectRefData
36 wxBrushRefData( const wxBrushRefData
& data
)
38 m_style
= data
.m_style
;
39 m_stipple
= data
.m_stipple
;
40 m_colour
= data
.m_colour
;
43 bool operator == (const wxBrushRefData
& data
) const
45 return (m_style
== data
.m_style
&&
46 m_stipple
== data
.m_stipple
&&
47 m_colour
== data
.m_colour
);
55 //-----------------------------------------------------------------------------
57 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
59 IMPLEMENT_DYNAMIC_CLASS(wxBrush
,wxGDIObject
)
61 wxBrush::wxBrush( const wxColour
&colour
, int style
)
63 m_refData
= new wxBrushRefData();
64 M_BRUSHDATA
->m_style
= style
;
65 M_BRUSHDATA
->m_colour
= colour
;
68 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
70 m_refData
= new wxBrushRefData();
71 M_BRUSHDATA
->m_colour
= *wxBLACK
;
73 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
75 if (M_BRUSHDATA
->m_stipple
.GetMask())
76 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
78 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
83 // m_refData unrefed in ~wxObject
86 wxObjectRefData
*wxBrush::CreateRefData() const
88 return new wxBrushRefData
;
91 wxObjectRefData
*wxBrush::CloneRefData(const wxObjectRefData
*data
) const
93 return new wxBrushRefData(*(wxBrushRefData
*)data
);
96 bool wxBrush::operator == ( const wxBrush
& brush
) const
98 if (m_refData
== brush
.m_refData
) return true;
100 if (!m_refData
|| !brush
.m_refData
) return false;
102 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
105 int wxBrush::GetStyle() const
107 if (m_refData
== NULL
)
109 wxFAIL_MSG( wxT("invalid brush") );
113 return M_BRUSHDATA
->m_style
;
116 wxColour
&wxBrush::GetColour() const
118 if (m_refData
== NULL
)
120 wxFAIL_MSG( wxT("invalid brush") );
124 return M_BRUSHDATA
->m_colour
;
127 wxBitmap
*wxBrush::GetStipple() const
129 if (m_refData
== NULL
)
131 wxFAIL_MSG( wxT("invalid brush") );
132 return &wxNullBitmap
;
135 return &M_BRUSHDATA
->m_stipple
;
138 void wxBrush::SetColour( const wxColour
& col
)
142 M_BRUSHDATA
->m_colour
= col
;
145 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
149 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
152 void wxBrush::SetStyle( int style
)
156 M_BRUSHDATA
->m_style
= style
;
159 void wxBrush::SetStipple( const wxBitmap
& stipple
)
163 M_BRUSHDATA
->m_stipple
= stipple
;
164 if (M_BRUSHDATA
->m_stipple
.GetMask())
166 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
170 M_BRUSHDATA
->m_style
= wxSTIPPLE
;