]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: brush.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Created: 01/02/97 | |
6 | // Id: | |
7 | // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "brush.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/brush.h" | |
16 | ||
17 | //----------------------------------------------------------------------------- | |
18 | // wxBrush | |
19 | //----------------------------------------------------------------------------- | |
20 | ||
21 | class wxBrushRefData: public wxObjectRefData | |
22 | { | |
23 | public: | |
24 | ||
25 | wxBrushRefData(void); | |
e55ad60e RR |
26 | wxBrushRefData( const wxBrushRefData& data ); |
27 | ||
c801d85f KB |
28 | int m_style; |
29 | wxBitmap m_stipple; | |
30 | wxColour m_colour; | |
31 | }; | |
32 | ||
33 | wxBrushRefData::wxBrushRefData(void) | |
34 | { | |
35 | m_style = 0; | |
ff7b1510 | 36 | } |
c801d85f | 37 | |
e55ad60e RR |
38 | wxBrushRefData::wxBrushRefData( const wxBrushRefData& data ) |
39 | { | |
40 | m_style = data.m_style; | |
41 | m_stipple = data.m_stipple; | |
42 | m_colour = data.m_colour; | |
43 | } | |
44 | ||
c801d85f KB |
45 | //----------------------------------------------------------------------------- |
46 | ||
47 | #define M_BRUSHDATA ((wxBrushRefData *)m_refData) | |
48 | ||
49 | IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject) | |
50 | ||
51 | wxBrush::wxBrush(void) | |
52 | { | |
53 | if (wxTheBrushList) wxTheBrushList->AddBrush( this ); | |
ff7b1510 | 54 | } |
c801d85f | 55 | |
debe6624 | 56 | wxBrush::wxBrush( const wxColour &colour, int style ) |
c801d85f KB |
57 | { |
58 | m_refData = new wxBrushRefData(); | |
59 | M_BRUSHDATA->m_style = style; | |
60 | M_BRUSHDATA->m_colour = colour; | |
61 | ||
62 | if (wxTheBrushList) wxTheBrushList->AddBrush( this ); | |
ff7b1510 | 63 | } |
c801d85f | 64 | |
c801d85f KB |
65 | wxBrush::wxBrush( const wxBitmap &stippleBitmap ) |
66 | { | |
67 | m_refData = new wxBrushRefData(); | |
68 | M_BRUSHDATA->m_style = wxSTIPPLE; | |
69 | M_BRUSHDATA->m_colour = *wxBLACK; | |
70 | M_BRUSHDATA->m_stipple = stippleBitmap; | |
71 | ||
72 | if (wxTheBrushList) wxTheBrushList->AddBrush( this ); | |
ff7b1510 | 73 | } |
c801d85f KB |
74 | |
75 | wxBrush::wxBrush( const wxBrush &brush ) | |
76 | { | |
77 | Ref( brush ); | |
78 | ||
79 | if (wxTheBrushList) wxTheBrushList->AddBrush( this ); | |
ff7b1510 | 80 | } |
c801d85f KB |
81 | |
82 | wxBrush::wxBrush( const wxBrush *brush ) | |
83 | { | |
84 | if (brush) Ref( *brush ); | |
85 | ||
86 | if (wxTheBrushList) wxTheBrushList->Append( this ); | |
ff7b1510 | 87 | } |
c801d85f KB |
88 | |
89 | wxBrush::~wxBrush(void) | |
90 | { | |
91 | if (wxTheBrushList) wxTheBrushList->RemoveBrush( this ); | |
ff7b1510 | 92 | } |
c801d85f KB |
93 | |
94 | wxBrush& wxBrush::operator = ( const wxBrush& brush ) | |
95 | { | |
96 | if (*this == brush) return (*this); | |
97 | Ref( brush ); | |
98 | return *this; | |
ff7b1510 | 99 | } |
c801d85f KB |
100 | |
101 | bool wxBrush::operator == ( const wxBrush& brush ) | |
102 | { | |
103 | return m_refData == brush.m_refData; | |
ff7b1510 | 104 | } |
c801d85f KB |
105 | |
106 | bool wxBrush::operator != ( const wxBrush& brush ) | |
107 | { | |
108 | return m_refData != brush.m_refData; | |
ff7b1510 | 109 | } |
c801d85f KB |
110 | |
111 | bool wxBrush::Ok(void) const | |
112 | { | |
113 | return ((m_refData) && M_BRUSHDATA->m_colour.Ok()); | |
ff7b1510 | 114 | } |
c801d85f KB |
115 | |
116 | int wxBrush::GetStyle(void) const | |
117 | { | |
e55ad60e RR |
118 | if (m_refData == NULL) |
119 | { | |
120 | wxFAIL_MSG( "invalid brush" ); | |
121 | return 0; | |
122 | } | |
123 | ||
c801d85f | 124 | return M_BRUSHDATA->m_style; |
ff7b1510 | 125 | } |
c801d85f KB |
126 | |
127 | wxColour &wxBrush::GetColour(void) const | |
128 | { | |
e55ad60e RR |
129 | if (m_refData == NULL) |
130 | { | |
131 | wxFAIL_MSG( "invalid brush" ); | |
132 | return wxNullColour; | |
133 | } | |
134 | ||
c801d85f | 135 | return M_BRUSHDATA->m_colour; |
ff7b1510 | 136 | } |
c801d85f KB |
137 | |
138 | wxBitmap *wxBrush::GetStipple(void) const | |
139 | { | |
e55ad60e RR |
140 | if (m_refData == NULL) |
141 | { | |
142 | wxFAIL_MSG( "invalid brush" ); | |
143 | return &wxNullBitmap; | |
144 | } | |
145 | ||
c801d85f | 146 | return &M_BRUSHDATA->m_stipple; |
ff7b1510 | 147 | } |
c801d85f | 148 | |
e55ad60e RR |
149 | void wxBrush::SetColour( const wxColour& col ) |
150 | { | |
151 | Unshare(); | |
152 | M_BRUSHDATA->m_colour = col; | |
153 | } | |
154 | ||
e55ad60e RR |
155 | void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b ) |
156 | { | |
157 | Unshare(); | |
158 | M_BRUSHDATA->m_colour.Set( r, g, b ); | |
159 | } | |
160 | ||
161 | void wxBrush::SetStyle( int style ) | |
162 | { | |
163 | Unshare(); | |
164 | M_BRUSHDATA->m_style = style; | |
165 | } | |
166 | ||
167 | void wxBrush::SetStipple( const wxBitmap& stipple ) | |
168 | { | |
169 | Unshare(); | |
170 | M_BRUSHDATA->m_stipple = stipple; | |
171 | } | |
172 | ||
173 | void wxBrush::Unshare(void) | |
174 | { | |
175 | if (!m_refData) | |
176 | { | |
177 | m_refData = new wxBrushRefData(); | |
178 | } | |
179 | else | |
180 | { | |
181 | wxBrushRefData* ref = new wxBrushRefData( *(wxBrushRefData*)m_refData ); | |
182 | UnRef(); | |
183 | m_refData = ref; | |
184 | } | |
185 | } | |
c801d85f | 186 |