]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
3cbab641 | 2 | // Name: src/gtk1/brush.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
f96aa4d9 | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
c801d85f | 13 | #include "wx/brush.h" |
7cf41a5d WS |
14 | |
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/colour.h" | |
17 | #endif | |
c801d85f | 18 | |
20e05ffb | 19 | #include <gdk/gdk.h> |
83624f79 | 20 | |
c801d85f KB |
21 | //----------------------------------------------------------------------------- |
22 | // wxBrush | |
23 | //----------------------------------------------------------------------------- | |
24 | ||
8f884a0d | 25 | class wxBrushRefData: public wxGDIRefData |
c801d85f | 26 | { |
58c837a4 | 27 | public: |
c89f5c02 RR |
28 | wxBrushRefData() |
29 | { | |
30 | m_style = 0; | |
31 | } | |
46562151 | 32 | |
c89f5c02 | 33 | wxBrushRefData( const wxBrushRefData& data ) |
8f884a0d | 34 | : wxGDIRefData() |
c89f5c02 RR |
35 | { |
36 | m_style = data.m_style; | |
37 | m_stipple = data.m_stipple; | |
38 | m_colour = data.m_colour; | |
39 | } | |
46562151 | 40 | |
c89f5c02 RR |
41 | bool operator == (const wxBrushRefData& data) const |
42 | { | |
43 | return (m_style == data.m_style && | |
a3ab1c18 | 44 | m_stipple.IsSameAs(data.m_stipple) && |
c89f5c02 RR |
45 | m_colour == data.m_colour); |
46 | } | |
46562151 | 47 | |
3e6858cd FM |
48 | wxBrushStyle m_style; |
49 | wxColour m_colour; | |
50 | wxBitmap m_stipple; | |
c801d85f KB |
51 | }; |
52 | ||
c801d85f KB |
53 | //----------------------------------------------------------------------------- |
54 | ||
55 | #define M_BRUSHDATA ((wxBrushRefData *)m_refData) | |
56 | ||
57 | IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject) | |
58 | ||
3e6858cd | 59 | wxBrush::wxBrush( const wxColour &colour, wxBrushStyle style ) |
c801d85f | 60 | { |
58c837a4 RR |
61 | m_refData = new wxBrushRefData(); |
62 | M_BRUSHDATA->m_style = style; | |
63 | M_BRUSHDATA->m_colour = colour; | |
ff7b1510 | 64 | } |
c801d85f | 65 | |
c801d85f KB |
66 | wxBrush::wxBrush( const wxBitmap &stippleBitmap ) |
67 | { | |
58c837a4 | 68 | m_refData = new wxBrushRefData(); |
58c837a4 | 69 | M_BRUSHDATA->m_colour = *wxBLACK; |
7ecb8b06 | 70 | |
58c837a4 | 71 | M_BRUSHDATA->m_stipple = stippleBitmap; |
e1208c31 | 72 | |
de2d2cdc | 73 | if (M_BRUSHDATA->m_stipple.GetMask()) |
7ecb8b06 VZ |
74 | M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; |
75 | else | |
76 | M_BRUSHDATA->m_style = wxSTIPPLE; | |
ff7b1510 | 77 | } |
c801d85f | 78 | |
8bbe427f | 79 | wxBrush::~wxBrush() |
c801d85f | 80 | { |
c89f5c02 | 81 | // m_refData unrefed in ~wxObject |
ff7b1510 | 82 | } |
c801d85f | 83 | |
8f884a0d | 84 | wxGDIRefData *wxBrush::CreateGDIRefData() const |
c801d85f | 85 | { |
c89f5c02 | 86 | return new wxBrushRefData; |
ff7b1510 | 87 | } |
c801d85f | 88 | |
8f884a0d | 89 | wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const |
c801d85f | 90 | { |
c89f5c02 | 91 | return new wxBrushRefData(*(wxBrushRefData *)data); |
ff7b1510 | 92 | } |
c801d85f | 93 | |
c89f5c02 | 94 | bool wxBrush::operator == ( const wxBrush& brush ) const |
c801d85f | 95 | { |
46562151 WS |
96 | if (m_refData == brush.m_refData) return true; |
97 | ||
98 | if (!m_refData || !brush.m_refData) return false; | |
99 | ||
c89f5c02 | 100 | return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData ); |
ff7b1510 | 101 | } |
c801d85f | 102 | |
3e6858cd | 103 | wxBrushStyle wxBrush::GetStyle() const |
c801d85f | 104 | { |
58c837a4 RR |
105 | if (m_refData == NULL) |
106 | { | |
107 | wxFAIL_MSG( wxT("invalid brush") ); | |
108 | return 0; | |
109 | } | |
e55ad60e | 110 | |
58c837a4 | 111 | return M_BRUSHDATA->m_style; |
ff7b1510 | 112 | } |
c801d85f | 113 | |
8bbe427f | 114 | wxColour &wxBrush::GetColour() const |
c801d85f | 115 | { |
58c837a4 RR |
116 | if (m_refData == NULL) |
117 | { | |
118 | wxFAIL_MSG( wxT("invalid brush") ); | |
119 | return wxNullColour; | |
120 | } | |
8bbe427f | 121 | |
58c837a4 | 122 | return M_BRUSHDATA->m_colour; |
ff7b1510 | 123 | } |
c801d85f | 124 | |
8bbe427f | 125 | wxBitmap *wxBrush::GetStipple() const |
c801d85f | 126 | { |
58c837a4 RR |
127 | if (m_refData == NULL) |
128 | { | |
129 | wxFAIL_MSG( wxT("invalid brush") ); | |
130 | return &wxNullBitmap; | |
131 | } | |
8bbe427f | 132 | |
58c837a4 | 133 | return &M_BRUSHDATA->m_stipple; |
ff7b1510 | 134 | } |
c801d85f | 135 | |
e55ad60e RR |
136 | void wxBrush::SetColour( const wxColour& col ) |
137 | { | |
c89f5c02 | 138 | AllocExclusive(); |
46562151 | 139 | |
58c837a4 | 140 | M_BRUSHDATA->m_colour = col; |
e55ad60e RR |
141 | } |
142 | ||
1a1498c0 | 143 | void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b ) |
e55ad60e | 144 | { |
c89f5c02 | 145 | AllocExclusive(); |
46562151 | 146 | |
58c837a4 | 147 | M_BRUSHDATA->m_colour.Set( r, g, b ); |
e55ad60e RR |
148 | } |
149 | ||
3e6858cd | 150 | void wxBrush::SetStyle( wxBrushStyle style ) |
e55ad60e | 151 | { |
c89f5c02 | 152 | AllocExclusive(); |
46562151 | 153 | |
58c837a4 | 154 | M_BRUSHDATA->m_style = style; |
e55ad60e RR |
155 | } |
156 | ||
157 | void wxBrush::SetStipple( const wxBitmap& stipple ) | |
158 | { | |
c89f5c02 | 159 | AllocExclusive(); |
46562151 | 160 | |
58c837a4 | 161 | M_BRUSHDATA->m_stipple = stipple; |
de2d2cdc VZ |
162 | if (M_BRUSHDATA->m_stipple.GetMask()) |
163 | { | |
7ecb8b06 VZ |
164 | M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; |
165 | } | |
166 | else | |
167 | { | |
168 | M_BRUSHDATA->m_style = wxSTIPPLE; | |
169 | } | |
e55ad60e | 170 | } |