]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/brush.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[wxWidgets.git] / src / gtk / brush.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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{
24 public:
25
26 wxBrushRefData();
27 wxBrushRefData( const wxBrushRefData& data );
28
29 int m_style;
30 wxBitmap m_stipple;
31 wxColour m_colour;
32};
33
34wxBrushRefData::wxBrushRefData()
35{
36 m_style = 0;
37}
38
39wxBrushRefData::wxBrushRefData( const wxBrushRefData& data )
40{
41 m_style = data.m_style;
42 m_stipple = data.m_stipple;
43 m_colour = data.m_colour;
44}
45
46//-----------------------------------------------------------------------------
47
48#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
49
50IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
51
52wxBrush::wxBrush()
53{
54 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
55}
56
57wxBrush::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 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
64}
65
66wxBrush::wxBrush( const wxBitmap &stippleBitmap )
67{
68 m_refData = new wxBrushRefData();
69 M_BRUSHDATA->m_style = wxSTIPPLE;
70 M_BRUSHDATA->m_colour = *wxBLACK;
71 M_BRUSHDATA->m_stipple = stippleBitmap;
72
73 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
74}
75
76wxBrush::wxBrush( const wxBrush &brush )
77{
78 Ref( brush );
79
80 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
81}
82
83wxBrush::~wxBrush()
84{
85 if (wxTheBrushList) wxTheBrushList->RemoveBrush( this );
86}
87
88wxBrush& wxBrush::operator = ( const wxBrush& brush )
89{
90 if (*this == brush) return (*this);
91 Ref( brush );
92 return *this;
93}
94
95bool wxBrush::operator == ( const wxBrush& brush )
96{
97 return m_refData == brush.m_refData;
98}
99
100bool wxBrush::operator != ( const wxBrush& brush )
101{
102 return m_refData != brush.m_refData;
103}
104
105bool wxBrush::Ok() const
106{
107 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
108}
109
110int wxBrush::GetStyle() const
111{
112 if (m_refData == NULL)
113 {
114 wxFAIL_MSG( wxT("invalid brush") );
115 return 0;
116 }
117
118 return M_BRUSHDATA->m_style;
119}
120
121wxColour &wxBrush::GetColour() const
122{
123 if (m_refData == NULL)
124 {
125 wxFAIL_MSG( wxT("invalid brush") );
126 return wxNullColour;
127 }
128
129 return M_BRUSHDATA->m_colour;
130}
131
132wxBitmap *wxBrush::GetStipple() const
133{
134 if (m_refData == NULL)
135 {
136 wxFAIL_MSG( wxT("invalid brush") );
137 return &wxNullBitmap;
138 }
139
140 return &M_BRUSHDATA->m_stipple;
141}
142
143void wxBrush::SetColour( const wxColour& col )
144{
145 Unshare();
146 M_BRUSHDATA->m_colour = col;
147}
148
149void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
150{
151 Unshare();
152 M_BRUSHDATA->m_colour.Set( r, g, b );
153}
154
155void wxBrush::SetStyle( int style )
156{
157 Unshare();
158 M_BRUSHDATA->m_style = style;
159}
160
161void wxBrush::SetStipple( const wxBitmap& stipple )
162{
163 Unshare();
164 M_BRUSHDATA->m_stipple = stipple;
165}
166
167void wxBrush::Unshare()
168{
169 if (!m_refData)
170 {
171 m_refData = new wxBrushRefData();
172 }
173 else
174 {
175 wxBrushRefData* ref = new wxBrushRefData( *(wxBrushRefData*)m_refData );
176 UnRef();
177 m_refData = ref;
178 }
179}
180