]> git.saurik.com Git - wxWidgets.git/blob - src/x11/brush.cpp
non PCH compilation
[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 wxGDIRefData
28 {
29 public:
30 wxBrushRefData()
31 {
32 m_style = wxBRUSHSTYLE_INVALID;
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 wxBrushStyle 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, wxBrushStyle style )
61 {
62 m_refData = new wxBrushRefData();
63 M_BRUSHDATA->m_style = style;
64 M_BRUSHDATA->m_colour = colour;
65 }
66
67 #if FUTURE_WXWIN_COMPATIBILITY_3_0
68 wxBrush::wxBrush(const wxColour& col, int style)
69 {
70 m_refData = new wxBrushRefData;
71 M_BRUSHDATA->m_style = (wxBrushStyle)style;
72 M_BRUSHDATA->m_colour = col;
73 }
74 #endif
75
76 wxBrush::wxBrush( const wxBitmap &stippleBitmap )
77 {
78 m_refData = new wxBrushRefData();
79 M_BRUSHDATA->m_colour = *wxBLACK;
80
81 M_BRUSHDATA->m_stipple = stippleBitmap;
82
83 if (M_BRUSHDATA->m_stipple.GetMask())
84 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
85 else
86 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK;
87 }
88
89 wxBrush::~wxBrush()
90 {
91 // m_refData unrefed in ~wxObject
92 }
93
94 wxGDIRefData *wxBrush::CreateGDIRefData() const
95 {
96 return new wxBrushRefData;
97 }
98
99 wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
100 {
101 return new wxBrushRefData(*(wxBrushRefData *)data);
102 }
103
104 bool wxBrush::operator == ( const wxBrush& brush ) const
105 {
106 if (m_refData == brush.m_refData) return true;
107
108 if (!m_refData || !brush.m_refData) return false;
109
110 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
111 }
112
113 wxBrushStyle wxBrush::GetStyle() const
114 {
115 wxCHECK_MSG( Ok(), wxBRUSHSTYLE_INVALID, wxT("invalid brush") );
116
117 return M_BRUSHDATA->m_style;
118 }
119
120 wxColour wxBrush::GetColour() const
121 {
122 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid brush") );
123
124 return M_BRUSHDATA->m_colour;
125 }
126
127 wxBitmap *wxBrush::GetStipple() const
128 {
129 wxCHECK_MSG( Ok(), NULL, wxT("invalid brush") );
130
131 return &M_BRUSHDATA->m_stipple;
132 }
133
134 void wxBrush::SetColour( const wxColour& col )
135 {
136 AllocExclusive();
137
138 M_BRUSHDATA->m_colour = col;
139 }
140
141 void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
142 {
143 AllocExclusive();
144
145 M_BRUSHDATA->m_colour.Set( r, g, b );
146 }
147
148 void wxBrush::SetStyle( wxBrushStyle style )
149 {
150 AllocExclusive();
151
152 M_BRUSHDATA->m_style = style;
153 }
154
155 void wxBrush::SetStipple( const wxBitmap& stipple )
156 {
157 AllocExclusive();
158
159 M_BRUSHDATA->m_stipple = stipple;
160 if (M_BRUSHDATA->m_stipple.GetMask())
161 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
162 else
163 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK;
164 }