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