]> git.saurik.com Git - wxWidgets.git/blob - src/x11/brush.cpp
cleanup
[wxWidgets.git] / src / x11 / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/brush.cpp
3 // Purpose: wxBrush
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/brush.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/utils.h"
19 #include "wx/bitmap.h"
20 #include "wx/colour.h"
21 #endif
22
23 //-----------------------------------------------------------------------------
24 // wxBrush
25 //-----------------------------------------------------------------------------
26
27 class wxBrushRefData: public wxObjectRefData
28 {
29 public:
30 wxBrushRefData()
31 {
32 m_style = 0;
33 }
34
35 wxBrushRefData( const wxBrushRefData& data )
36 {
37 m_style = data.m_style;
38 m_stipple = data.m_stipple;
39 m_colour = data.m_colour;
40 }
41
42 bool operator == (const wxBrushRefData& data) const
43 {
44 return (m_style == data.m_style &&
45 m_stipple.IsSameAs(data.m_stipple) &&
46 m_colour == data.m_colour);
47 }
48
49 int m_style;
50 wxColour m_colour;
51 wxBitmap m_stipple;
52 };
53
54 //-----------------------------------------------------------------------------
55
56 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
57
58 IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
59
60 wxBrush::wxBrush( const wxColour &colour, int style )
61 {
62 m_refData = new wxBrushRefData();
63 M_BRUSHDATA->m_style = style;
64 M_BRUSHDATA->m_colour = colour;
65 }
66
67 wxBrush::wxBrush( const wxBitmap &stippleBitmap )
68 {
69 m_refData = new wxBrushRefData();
70 M_BRUSHDATA->m_colour = *wxBLACK;
71
72 M_BRUSHDATA->m_stipple = stippleBitmap;
73
74 if (M_BRUSHDATA->m_stipple.GetMask())
75 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
76 else
77 M_BRUSHDATA->m_style = wxSTIPPLE;
78 }
79
80 wxBrush::~wxBrush()
81 {
82 // m_refData unrefed in ~wxObject
83 }
84
85 wxObjectRefData *wxBrush::CreateRefData() const
86 {
87 return new wxBrushRefData;
88 }
89
90 wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
91 {
92 return new wxBrushRefData(*(wxBrushRefData *)data);
93 }
94
95 bool wxBrush::operator == ( const wxBrush& brush ) const
96 {
97 if (m_refData == brush.m_refData) return true;
98
99 if (!m_refData || !brush.m_refData) return false;
100
101 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
102 }
103
104 int wxBrush::GetStyle() const
105 {
106 if (m_refData == NULL)
107 {
108 wxFAIL_MSG( wxT("invalid brush") );
109 return 0;
110 }
111
112 return M_BRUSHDATA->m_style;
113 }
114
115 wxColour &wxBrush::GetColour() const
116 {
117 if (m_refData == NULL)
118 {
119 wxFAIL_MSG( wxT("invalid brush") );
120 return wxNullColour;
121 }
122
123 return M_BRUSHDATA->m_colour;
124 }
125
126 wxBitmap *wxBrush::GetStipple() const
127 {
128 if (m_refData == NULL)
129 {
130 wxFAIL_MSG( wxT("invalid brush") );
131 return &wxNullBitmap;
132 }
133
134 return &M_BRUSHDATA->m_stipple;
135 }
136
137 void wxBrush::SetColour( const wxColour& col )
138 {
139 AllocExclusive();
140
141 M_BRUSHDATA->m_colour = col;
142 }
143
144 void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
145 {
146 AllocExclusive();
147
148 M_BRUSHDATA->m_colour.Set( r, g, b );
149 }
150
151 void wxBrush::SetStyle( int style )
152 {
153 AllocExclusive();
154
155 M_BRUSHDATA->m_style = style;
156 }
157
158 void wxBrush::SetStipple( const wxBitmap& stipple )
159 {
160 AllocExclusive();
161
162 M_BRUSHDATA->m_stipple = stipple;
163 if (M_BRUSHDATA->m_stipple.GetMask())
164 {
165 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
166 }
167 else
168 {
169 M_BRUSHDATA->m_style = wxSTIPPLE;
170 }
171 }