]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/brush.cpp
introduce wxBrushStyle enum and replace 'int style' occurrences in wxBrush code with...
[wxWidgets.git] / src / gtk / brush.cpp
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 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #include "wx/brush.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/bitmap.h"
17 #include "wx/colour.h"
18 #endif
19
20 //-----------------------------------------------------------------------------
21 // wxBrush
22 //-----------------------------------------------------------------------------
23
24 class wxBrushRefData: public wxGDIRefData
25 {
26 public:
27 wxBrushRefData(const wxColour& colour = wxNullColour, wxBrushStyle style = wxBRUSHSTYLE_SOLID)
28 {
29 m_style = style;
30 m_colour = colour;
31 }
32
33 wxBrushRefData( const wxBrushRefData& data )
34 : wxGDIRefData()
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(colour, style);
62 }
63
64 wxBrush::wxBrush( const wxBitmap &stippleBitmap )
65 {
66 wxBrushStyle style = wxBRUSHSTYLE_STIPPLE;
67 if (stippleBitmap.GetMask())
68 style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
69
70 m_refData = new wxBrushRefData(*wxBLACK, style);
71 M_BRUSHDATA->m_stipple = stippleBitmap;
72 }
73
74 wxBrush::~wxBrush()
75 {
76 // m_refData unrefed in ~wxObject
77 }
78
79 wxGDIRefData *wxBrush::CreateGDIRefData() const
80 {
81 return new wxBrushRefData;
82 }
83
84 wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
85 {
86 return new wxBrushRefData(*(wxBrushRefData *)data);
87 }
88
89 bool wxBrush::operator==(const wxBrush& brush) const
90 {
91 if (m_refData == brush.m_refData) return true;
92
93 if (!m_refData || !brush.m_refData) return false;
94
95 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
96 }
97
98 wxBrushStyle wxBrush::GetStyle() const
99 {
100 if (m_refData == NULL)
101 {
102 wxFAIL_MSG( wxT("invalid brush") );
103 return wxBRUSHSTYLE_MAX;
104 }
105
106 return M_BRUSHDATA->m_style;
107 }
108
109 wxColour &wxBrush::GetColour() const
110 {
111 if (m_refData == NULL)
112 {
113 wxFAIL_MSG( wxT("invalid brush") );
114 return wxNullColour;
115 }
116
117 return M_BRUSHDATA->m_colour;
118 }
119
120 wxBitmap *wxBrush::GetStipple() const
121 {
122 if (m_refData == NULL)
123 {
124 wxFAIL_MSG( wxT("invalid brush") );
125 return &wxNullBitmap;
126 }
127
128 return &M_BRUSHDATA->m_stipple;
129 }
130
131 void wxBrush::SetColour( const wxColour& col )
132 {
133 AllocExclusive();
134
135 M_BRUSHDATA->m_colour = col;
136 }
137
138 void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
139 {
140 AllocExclusive();
141
142 M_BRUSHDATA->m_colour.Set( r, g, b );
143 }
144
145 void wxBrush::SetStyle( wxBrushStyle style )
146 {
147 AllocExclusive();
148
149 M_BRUSHDATA->m_style = style;
150 }
151
152 void wxBrush::SetStipple( const wxBitmap& stipple )
153 {
154 AllocExclusive();
155
156 M_BRUSHDATA->m_stipple = stipple;
157 if (M_BRUSHDATA->m_stipple.GetMask())
158 {
159 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
160 }
161 else
162 {
163 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE;
164 }
165 }