]>
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 | { | |
1d57de48 | 30 | m_style = wxBRUSHSTYLE_INVALID; |
c89f5c02 | 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 | |
ac3688c0 FM |
66 | #if FUTURE_WXWIN_COMPATIBILITY_3_0 |
67 | wxBrush::wxBrush(const wxColour& col, int style) | |
68 | { | |
69 | m_refData = new wxBrushRefData; | |
70 | M_BRUSHDATA->m_style = (wxBrushStyle)style; | |
1d57de48 | 71 | M_BRUSHDATA->m_colour = col; |
ac3688c0 FM |
72 | } |
73 | #endif | |
74 | ||
c801d85f KB |
75 | wxBrush::wxBrush( const wxBitmap &stippleBitmap ) |
76 | { | |
58c837a4 | 77 | m_refData = new wxBrushRefData(); |
58c837a4 | 78 | M_BRUSHDATA->m_colour = *wxBLACK; |
7ecb8b06 | 79 | |
58c837a4 | 80 | M_BRUSHDATA->m_stipple = stippleBitmap; |
e1208c31 | 81 | |
de2d2cdc | 82 | if (M_BRUSHDATA->m_stipple.GetMask()) |
1d57de48 | 83 | M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE; |
7ecb8b06 | 84 | else |
1d57de48 | 85 | M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK; |
ff7b1510 | 86 | } |
c801d85f | 87 | |
8bbe427f | 88 | wxBrush::~wxBrush() |
c801d85f | 89 | { |
c89f5c02 | 90 | // m_refData unrefed in ~wxObject |
ff7b1510 | 91 | } |
c801d85f | 92 | |
8f884a0d | 93 | wxGDIRefData *wxBrush::CreateGDIRefData() const |
c801d85f | 94 | { |
c89f5c02 | 95 | return new wxBrushRefData; |
ff7b1510 | 96 | } |
c801d85f | 97 | |
8f884a0d | 98 | wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const |
c801d85f | 99 | { |
c89f5c02 | 100 | return new wxBrushRefData(*(wxBrushRefData *)data); |
ff7b1510 | 101 | } |
c801d85f | 102 | |
c89f5c02 | 103 | bool wxBrush::operator == ( const wxBrush& brush ) const |
c801d85f | 104 | { |
46562151 WS |
105 | if (m_refData == brush.m_refData) return true; |
106 | ||
107 | if (!m_refData || !brush.m_refData) return false; | |
108 | ||
c89f5c02 | 109 | return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData ); |
ff7b1510 | 110 | } |
c801d85f | 111 | |
3e6858cd | 112 | wxBrushStyle wxBrush::GetStyle() const |
c801d85f | 113 | { |
ac3688c0 | 114 | wxCHECK_MSG( Ok(), wxBRUSHSTYLE_INVALID, _T("invalid brush") ); |
e55ad60e | 115 | |
58c837a4 | 116 | return M_BRUSHDATA->m_style; |
ff7b1510 | 117 | } |
c801d85f | 118 | |
231b9591 | 119 | wxColour wxBrush::GetColour() const |
c801d85f | 120 | { |
ac3688c0 | 121 | wxCHECK_MSG( Ok(), wxNullColour, _T("invalid brush") ); |
8bbe427f | 122 | |
58c837a4 | 123 | return M_BRUSHDATA->m_colour; |
ff7b1510 | 124 | } |
c801d85f | 125 | |
8bbe427f | 126 | wxBitmap *wxBrush::GetStipple() const |
c801d85f | 127 | { |
ac3688c0 | 128 | wxCHECK_MSG( Ok(), NULL, _T("invalid brush") ); |
8bbe427f | 129 | |
58c837a4 | 130 | return &M_BRUSHDATA->m_stipple; |
ff7b1510 | 131 | } |
c801d85f | 132 | |
e55ad60e RR |
133 | void wxBrush::SetColour( const wxColour& col ) |
134 | { | |
c89f5c02 | 135 | AllocExclusive(); |
46562151 | 136 | |
58c837a4 | 137 | M_BRUSHDATA->m_colour = col; |
e55ad60e RR |
138 | } |
139 | ||
1a1498c0 | 140 | void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b ) |
e55ad60e | 141 | { |
c89f5c02 | 142 | AllocExclusive(); |
46562151 | 143 | |
58c837a4 | 144 | M_BRUSHDATA->m_colour.Set( r, g, b ); |
e55ad60e RR |
145 | } |
146 | ||
3e6858cd | 147 | void wxBrush::SetStyle( wxBrushStyle style ) |
e55ad60e | 148 | { |
c89f5c02 | 149 | AllocExclusive(); |
46562151 | 150 | |
58c837a4 | 151 | M_BRUSHDATA->m_style = style; |
e55ad60e RR |
152 | } |
153 | ||
154 | void wxBrush::SetStipple( const wxBitmap& stipple ) | |
155 | { | |
c89f5c02 | 156 | AllocExclusive(); |
46562151 | 157 | |
58c837a4 | 158 | M_BRUSHDATA->m_stipple = stipple; |
de2d2cdc | 159 | if (M_BRUSHDATA->m_stipple.GetMask()) |
1d57de48 | 160 | M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE; |
7ecb8b06 | 161 | else |
1d57de48 | 162 | M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK; |
e55ad60e | 163 | } |