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 #if FUTURE_WXWIN_COMPATIBILITY_3_0
65 wxBrush::wxBrush(const wxColour
& col
, int style
)
67 m_refData
= new wxBrushRefData(col
, (wxBrushStyle
)style
);
71 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
73 wxBrushStyle style
= wxBRUSHSTYLE_STIPPLE
;
74 if (stippleBitmap
.GetMask())
75 style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
77 m_refData
= new wxBrushRefData(*wxBLACK
, style
);
78 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
83 // m_refData unrefed in ~wxObject
86 wxGDIRefData
*wxBrush::CreateGDIRefData() const
88 return new wxBrushRefData
;
91 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*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 wxBrushStyle
wxBrush::GetStyle() const
107 wxCHECK_MSG( Ok(), wxBRUSHSTYLE_INVALID
, _T("invalid brush") );
109 return M_BRUSHDATA
->m_style
;
112 wxColour
&wxBrush::GetColour() const
114 wxCHECK_MSG( Ok(), wxNullColour
, _T("invalid brush") );
116 return M_BRUSHDATA
->m_colour
;
119 wxBitmap
*wxBrush::GetStipple() const
121 wxCHECK_MSG( Ok(), NULL
, _T("invalid brush") );
123 return &M_BRUSHDATA
->m_stipple
;
126 void wxBrush::SetColour( const wxColour
& col
)
130 M_BRUSHDATA
->m_colour
= col
;
133 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
137 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
140 void wxBrush::SetStyle( wxBrushStyle style
)
144 M_BRUSHDATA
->m_style
= style
;
147 void wxBrush::SetStipple( const wxBitmap
& stipple
)
151 M_BRUSHDATA
->m_stipple
= stipple
;
152 if (M_BRUSHDATA
->m_stipple
.GetMask())
154 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
158 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE
;