]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/brush.cpp
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 wxObjectRefData
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
.IsRefTo(&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
, int style
)
60 m_refData
= new wxBrushRefData();
61 M_BRUSHDATA
->m_style
= style
;
62 M_BRUSHDATA
->m_colour
= colour
;
65 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
67 m_refData
= new wxBrushRefData();
68 M_BRUSHDATA
->m_colour
= *wxBLACK
;
70 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
72 if (M_BRUSHDATA
->m_stipple
.GetMask())
73 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
75 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
80 // m_refData unrefed in ~wxObject
83 wxObjectRefData
*wxBrush::CreateRefData() const
85 return new wxBrushRefData
;
88 wxObjectRefData
*wxBrush::CloneRefData(const wxObjectRefData
*data
) const
90 return new wxBrushRefData(*(wxBrushRefData
*)data
);
93 bool wxBrush::operator == ( const wxBrush
& brush
) const
95 if (m_refData
== brush
.m_refData
) return true;
97 if (!m_refData
|| !brush
.m_refData
) return false;
99 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
102 int wxBrush::GetStyle() const
104 if (m_refData
== NULL
)
106 wxFAIL_MSG( wxT("invalid brush") );
110 return M_BRUSHDATA
->m_style
;
113 wxColour
&wxBrush::GetColour() const
115 if (m_refData
== NULL
)
117 wxFAIL_MSG( wxT("invalid brush") );
121 return M_BRUSHDATA
->m_colour
;
124 wxBitmap
*wxBrush::GetStipple() const
126 if (m_refData
== NULL
)
128 wxFAIL_MSG( wxT("invalid brush") );
129 return &wxNullBitmap
;
132 return &M_BRUSHDATA
->m_stipple
;
135 void wxBrush::SetColour( const wxColour
& col
)
139 M_BRUSHDATA
->m_colour
= col
;
142 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
146 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
149 void wxBrush::SetStyle( int style
)
153 M_BRUSHDATA
->m_style
= style
;
156 void wxBrush::SetStipple( const wxBitmap
& stipple
)
160 M_BRUSHDATA
->m_stipple
= stipple
;
161 if (M_BRUSHDATA
->m_stipple
.GetMask())
163 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
167 M_BRUSHDATA
->m_style
= wxSTIPPLE
;