1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/brush.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
15 #include "wx/bitmap.h"
16 #include "wx/colour.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 class wxBrushRefData
: public wxGDIRefData
26 wxBrushRefData(const wxColour
& colour
= wxNullColour
, wxBrushStyle style
= wxBRUSHSTYLE_SOLID
)
32 wxBrushRefData( const wxBrushRefData
& data
)
35 m_style
= data
.m_style
;
36 m_stipple
= data
.m_stipple
;
37 m_colour
= data
.m_colour
;
40 bool operator == (const wxBrushRefData
& data
) const
42 return (m_style
== data
.m_style
&&
43 m_stipple
.IsSameAs(data
.m_stipple
) &&
44 m_colour
== data
.m_colour
);
52 //-----------------------------------------------------------------------------
54 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
56 IMPLEMENT_DYNAMIC_CLASS(wxBrush
,wxGDIObject
)
58 wxBrush::wxBrush( const wxColour
&colour
, wxBrushStyle style
)
60 m_refData
= new wxBrushRefData(colour
, style
);
63 #if FUTURE_WXWIN_COMPATIBILITY_3_0
64 wxBrush::wxBrush(const wxColour
& col
, int style
)
66 m_refData
= new wxBrushRefData(col
, (wxBrushStyle
)style
);
70 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
72 wxBrushStyle style
= wxBRUSHSTYLE_STIPPLE
;
73 if (stippleBitmap
.GetMask())
74 style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
76 m_refData
= new wxBrushRefData(*wxBLACK
, style
);
77 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
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 wxBrushStyle
wxBrush::GetStyle() const
106 wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID
, wxT("invalid brush") );
108 return M_BRUSHDATA
->m_style
;
111 wxColour
wxBrush::GetColour() const
113 wxCHECK_MSG( IsOk(), wxNullColour
, wxT("invalid brush") );
115 return M_BRUSHDATA
->m_colour
;
118 wxBitmap
*wxBrush::GetStipple() const
120 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid brush") );
122 return &M_BRUSHDATA
->m_stipple
;
125 void wxBrush::SetColour( const wxColour
& col
)
129 M_BRUSHDATA
->m_colour
= col
;
132 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
136 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
139 void wxBrush::SetStyle( wxBrushStyle style
)
143 M_BRUSHDATA
->m_style
= style
;
146 void wxBrush::SetStipple( const wxBitmap
& stipple
)
150 M_BRUSHDATA
->m_stipple
= stipple
;
151 if (M_BRUSHDATA
->m_stipple
.GetMask())
153 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
;
157 M_BRUSHDATA
->m_style
= wxBRUSHSTYLE_STIPPLE
;