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