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