]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/brush.cpp
Some additions to the 12-bit patch.
[wxWidgets.git] / src / gtk1 / brush.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/brush.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "brush.h"
12#endif
13
14#include "wx/brush.h"
15
16#include <gdk/gdk.h>
17
18//-----------------------------------------------------------------------------
19// wxBrush
20//-----------------------------------------------------------------------------
21
22class wxBrushRefData: public wxObjectRefData
23{
24public:
25 wxBrushRefData();
26 wxBrushRefData( const wxBrushRefData& data );
27
28 int m_style;
29 wxBitmap m_stipple;
30 wxColour m_colour;
31};
32
33wxBrushRefData::wxBrushRefData()
34{
35 m_style = 0;
36}
37
38wxBrushRefData::wxBrushRefData( const wxBrushRefData& data )
39{
40 m_style = data.m_style;
41 m_stipple = data.m_stipple;
42 m_colour = data.m_colour;
43}
44
45//-----------------------------------------------------------------------------
46
47#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
48
49IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
50
51wxBrush::wxBrush()
52{
53}
54
55wxBrush::wxBrush( const wxColour &colour, int style )
56{
57 m_refData = new wxBrushRefData();
58 M_BRUSHDATA->m_style = style;
59 M_BRUSHDATA->m_colour = colour;
60}
61
62wxBrush::wxBrush( const wxBitmap &stippleBitmap )
63{
64 m_refData = new wxBrushRefData();
65 M_BRUSHDATA->m_colour = *wxBLACK;
66
67 M_BRUSHDATA->m_stipple = stippleBitmap;
68
69 if (M_BRUSHDATA->m_stipple.GetMask())
70 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
71 else
72 M_BRUSHDATA->m_style = wxSTIPPLE;
73}
74
75wxBrush::wxBrush( const wxBrush &brush )
76{
77 Ref( brush );
78}
79
80wxBrush::~wxBrush()
81{
82}
83
84wxBrush& wxBrush::operator = ( const wxBrush& brush )
85{
86 if ( m_refData != brush.m_refData )
87 Ref( brush );
88
89 return *this;
90}
91
92bool wxBrush::operator == ( const wxBrush& brush ) const
93{
94 return m_refData == brush.m_refData;
95}
96
97bool wxBrush::operator != ( const wxBrush& brush ) const
98{
99 return m_refData != brush.m_refData;
100}
101
102bool wxBrush::Ok() const
103{
104 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
105}
106
107int wxBrush::GetStyle() const
108{
109 if (m_refData == NULL)
110 {
111 wxFAIL_MSG( wxT("invalid brush") );
112 return 0;
113 }
114
115 return M_BRUSHDATA->m_style;
116}
117
118wxColour &wxBrush::GetColour() const
119{
120 if (m_refData == NULL)
121 {
122 wxFAIL_MSG( wxT("invalid brush") );
123 return wxNullColour;
124 }
125
126 return M_BRUSHDATA->m_colour;
127}
128
129wxBitmap *wxBrush::GetStipple() const
130{
131 if (m_refData == NULL)
132 {
133 wxFAIL_MSG( wxT("invalid brush") );
134 return &wxNullBitmap;
135 }
136
137 return &M_BRUSHDATA->m_stipple;
138}
139
140void wxBrush::SetColour( const wxColour& col )
141{
142 Unshare();
143 M_BRUSHDATA->m_colour = col;
144}
145
146void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
147{
148 Unshare();
149 M_BRUSHDATA->m_colour.Set( r, g, b );
150}
151
152void wxBrush::SetStyle( int style )
153{
154 Unshare();
155 M_BRUSHDATA->m_style = style;
156}
157
158void wxBrush::SetStipple( const wxBitmap& stipple )
159{
160 Unshare();
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}
171
172void wxBrush::Unshare()
173{
174 if (!m_refData)
175 {
176 m_refData = new wxBrushRefData();
177 }
178 else
179 {
180 wxBrushRefData* ref = new wxBrushRefData( *(wxBrushRefData*)m_refData );
181 UnRef();
182 m_refData = ref;
183 }
184}
185