1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/brush.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
16 #include "wx/bitmap.h"
17 #include "wx/colour.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 class wxBrushRefData
: public wxGDIRefData
27 wxBrushRefData(const wxColour
& colour
= wxNullColour
, wxBrushStyle style
= wxBRUSHSTYLE_SOLID
)
33 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(colour
, style
);
64 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
66 wxBrushStyle style
= wxBRUSHSTYLE_STIPPLE
;
67 if (stippleBitmap
.GetMask())
68 style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
70 m_refData
= new wxBrushRefData(*wxBLACK
, style
);
71 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
76 // m_refData unrefed in ~wxObject
79 wxGDIRefData
*wxBrush::CreateGDIRefData() const
81 return new wxBrushRefData
;
84 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
86 return new wxBrushRefData(*(wxBrushRefData
*)data
);
89 bool wxBrush::operator==(const wxBrush
& brush
) const
91 if (m_refData
== brush
.m_refData
) return true;
93 if (!m_refData
|| !brush
.m_refData
) return false;
95 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
98 wxBrushStyle
wxBrush::GetStyle() const
100 if (m_refData
== NULL
)
102 wxFAIL_MSG( wxT("invalid brush") );
103 return wxBRUSHSTYLE_MAX
;
106 return M_BRUSHDATA
->m_style
;
109 wxColour
&wxBrush::GetColour() const
111 if (m_refData
== NULL
)
113 wxFAIL_MSG( wxT("invalid brush") );
117 return M_BRUSHDATA
->m_colour
;
120 wxBitmap
*wxBrush::GetStipple() const
122 if (m_refData
== NULL
)
124 wxFAIL_MSG( wxT("invalid brush") );
125 return &wxNullBitmap
;
128 return &M_BRUSHDATA
->m_stipple
;
131 void wxBrush::SetColour( const wxColour
& col
)
135 M_BRUSHDATA
->m_colour
= col
;
138 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
142 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
145 void wxBrush::SetStyle( wxBrushStyle style
)
149 M_BRUSHDATA
->m_style
= style
;
152 void wxBrush::SetStipple( const wxBitmap
& stipple
)
156 M_BRUSHDATA
->m_stipple
= stipple
;
157 if (M_BRUSHDATA
->m_stipple
.GetMask())
159 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
163 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE
;