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