]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/brush.cpp
Performance optimization
[wxWidgets.git] / src / mac / carbon / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/brush.cpp
3 // Purpose: wxBrush
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/brush.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/utils.h"
18 #endif
19
20 #include "wx/mac/private.h"
21
22 IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
23
24 class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
25 {
26 public:
27 wxBrushRefData(const wxColour& colour = wxNullColour, int style = wxSOLID);
28 wxBrushRefData(const wxBitmap& stipple);
29 wxBrushRefData(const wxBrushRefData& data);
30 virtual ~wxBrushRefData();
31
32 bool operator==(const wxBrushRefData& data) const;
33
34 const wxColour& GetColour() const { return m_colour; }
35 int GetStyle() const { return m_style; }
36 wxBitmap *GetStipple() { return &m_stipple; }
37
38 void SetColour(const wxColour& colour) { m_colour = colour; }
39 void SetStyle(int style) { m_style = style; }
40 void SetStipple(const wxBitmap& stipple) { DoSetStipple(stipple); }
41
42 protected:
43 void DoSetStipple(const wxBitmap& stipple);
44
45 wxBitmap m_stipple ;
46 wxColour m_colour;
47 int m_style;
48 };
49
50 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
51
52 wxBrushRefData::wxBrushRefData(const wxColour& colour, int style)
53 : m_colour(colour), m_style( style )
54 {
55 }
56
57 wxBrushRefData::wxBrushRefData(const wxBitmap& stipple)
58 {
59 DoSetStipple( stipple );
60 }
61
62 wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
63 : wxGDIRefData() ,
64 m_stipple(data.m_stipple),
65 m_colour(data.m_colour),
66 m_style(data.m_style)
67 {
68 }
69
70 wxBrushRefData::~wxBrushRefData()
71 {
72 }
73
74 bool wxBrushRefData::operator==(const wxBrushRefData& data) const
75 {
76 return m_style == data.m_style &&
77 m_colour == data.m_colour &&
78 m_stipple.IsSameAs(data.m_stipple);
79 }
80
81 void wxBrushRefData::DoSetStipple(const wxBitmap& stipple)
82 {
83 m_stipple = stipple;
84 m_style = stipple.GetMask() ? wxSTIPPLE_MASK_OPAQUE : wxSTIPPLE;
85 }
86 //
87 //
88 //
89
90 wxBrush::wxBrush()
91 {
92 }
93
94 wxBrush::~wxBrush()
95 {
96 }
97
98 wxBrush::wxBrush(const wxColour& col, int style)
99 {
100 m_refData = new wxBrushRefData( col, style );
101 }
102
103 wxBrush::wxBrush(const wxBitmap& stipple)
104 {
105 m_refData = new wxBrushRefData( stipple );
106 }
107
108 // ----------------------------------------------------------------------------
109 // wxBrush house keeping stuff
110 // ----------------------------------------------------------------------------
111
112 bool wxBrush::operator==(const wxBrush& brush) const
113 {
114 const wxBrushRefData *brushData = (wxBrushRefData *)brush.m_refData;
115
116 // an invalid brush is considered to be only equal to another invalid brush
117 return m_refData ? (brushData && *M_BRUSHDATA == *brushData) : !brushData;
118 }
119
120 wxGDIRefData *wxBrush::CreateGDIRefData() const
121 {
122 return new wxBrushRefData;
123 }
124
125 wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
126 {
127 return new wxBrushRefData(*(const wxBrushRefData *)data);
128 }
129
130 // ----------------------------------------------------------------------------
131 // wxBrush accessors
132 // ----------------------------------------------------------------------------
133
134 const wxColour& wxBrush::GetColour() const
135 {
136 wxCHECK_MSG( Ok(), wxNullColour, _T("invalid brush") );
137
138 return M_BRUSHDATA->GetColour();
139 }
140
141 int wxBrush::GetStyle() const
142 {
143 wxCHECK_MSG( Ok(), 0, _T("invalid brush") );
144
145 return M_BRUSHDATA->GetStyle();
146 }
147
148 wxBitmap *wxBrush::GetStipple() const
149 {
150 wxCHECK_MSG( Ok(), NULL, _T("invalid brush") );
151
152 return M_BRUSHDATA->GetStipple();
153 }
154
155 // ----------------------------------------------------------------------------
156 // wxBrush setters
157 // ----------------------------------------------------------------------------
158
159 void wxBrush::SetColour(const wxColour& col)
160 {
161 AllocExclusive();
162
163 M_BRUSHDATA->SetColour(col);
164 }
165
166 void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
167 {
168 AllocExclusive();
169
170 M_BRUSHDATA->SetColour(wxColour(r, g, b));
171 }
172
173 void wxBrush::SetStyle(int style)
174 {
175 AllocExclusive();
176
177 M_BRUSHDATA->SetStyle(style);
178 }
179
180 void wxBrush::SetStipple(const wxBitmap& stipple)
181 {
182 AllocExclusive();
183
184 M_BRUSHDATA->SetStipple(stipple);
185 }