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