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