]> git.saurik.com Git - wxWidgets.git/blob - src/x11/brush.cpp
Applied patch [ 1409971 ] wxX11: fix for DoDrawBitmap() when scaling is set
[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/utils.h"
16 #include "wx/brush.h"
17 #include "wx/bitmap.h"
18 #include "wx/colour.h"
19
20 //-----------------------------------------------------------------------------
21 // wxBrush
22 //-----------------------------------------------------------------------------
23
24 class wxBrushRefData: public wxObjectRefData
25 {
26 public:
27 wxBrushRefData()
28 {
29 m_style = 0;
30 }
31
32 wxBrushRefData( const wxBrushRefData& data )
33 {
34 m_style = data.m_style;
35 m_stipple = data.m_stipple;
36 m_colour = data.m_colour;
37 }
38
39 bool operator == (const wxBrushRefData& data) const
40 {
41 return (m_style == data.m_style &&
42 m_stipple == data.m_stipple &&
43 m_colour == data.m_colour);
44 }
45
46 int m_style;
47 wxColour m_colour;
48 wxBitmap m_stipple;
49 };
50
51 //-----------------------------------------------------------------------------
52
53 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
54
55 IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
56
57 wxBrush::wxBrush( const wxColour &colour, int style )
58 {
59 m_refData = new wxBrushRefData();
60 M_BRUSHDATA->m_style = style;
61 M_BRUSHDATA->m_colour = colour;
62 }
63
64 wxBrush::wxBrush( const wxBitmap &stippleBitmap )
65 {
66 m_refData = new wxBrushRefData();
67 M_BRUSHDATA->m_colour = *wxBLACK;
68
69 M_BRUSHDATA->m_stipple = stippleBitmap;
70
71 if (M_BRUSHDATA->m_stipple.GetMask())
72 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
73 else
74 M_BRUSHDATA->m_style = wxSTIPPLE;
75 }
76
77 wxBrush::~wxBrush()
78 {
79 // m_refData unrefed in ~wxObject
80 }
81
82 wxObjectRefData *wxBrush::CreateRefData() const
83 {
84 return new wxBrushRefData;
85 }
86
87 wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
88 {
89 return new wxBrushRefData(*(wxBrushRefData *)data);
90 }
91
92 bool wxBrush::operator == ( const wxBrush& brush ) const
93 {
94 if (m_refData == brush.m_refData) return true;
95
96 if (!m_refData || !brush.m_refData) return false;
97
98 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
99 }
100
101 int wxBrush::GetStyle() const
102 {
103 if (m_refData == NULL)
104 {
105 wxFAIL_MSG( wxT("invalid brush") );
106 return 0;
107 }
108
109 return M_BRUSHDATA->m_style;
110 }
111
112 wxColour &wxBrush::GetColour() const
113 {
114 if (m_refData == NULL)
115 {
116 wxFAIL_MSG( wxT("invalid brush") );
117 return wxNullColour;
118 }
119
120 return M_BRUSHDATA->m_colour;
121 }
122
123 wxBitmap *wxBrush::GetStipple() const
124 {
125 if (m_refData == NULL)
126 {
127 wxFAIL_MSG( wxT("invalid brush") );
128 return &wxNullBitmap;
129 }
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( int 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 {
162 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
163 }
164 else
165 {
166 M_BRUSHDATA->m_style = wxSTIPPLE;
167 }
168 }