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