1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 %% Copyright: (c) wxWidgets
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxBrush
}}\label{wxbrush
}
14 A brush is a drawing tool for filling in areas. It is used for painting
15 the background of rectangles, ellipses, etc. It has a colour and a
18 \wxheading{Derived from
}
20 \helpref{wxGDIObject
}{wxgdiobject
}\\
21 \helpref{wxObject
}{wxobject
}
23 \wxheading{Include files
}
27 \wxheading{Predefined objects
}
40 wxMEDIUM
\_GREY\_BRUSH\\
41 wxLIGHT
\_GREY\_BRUSH\\
42 wxTRANSPARENT
\_BRUSH\\
48 On a monochrome display, wxWidgets shows
49 all brushes as white unless the colour is really black.
51 Do not initialize objects on the stack before the program commences,
52 since other required structures may not have been set up yet. Instead,
53 define global pointers to objects and create them in
\helpref{wxApp::OnInit
}{wxapponinit
} or
56 An application may wish to create brushes with different
57 characteristics dynamically, and there is the consequent danger that a
58 large number of duplicate brushes will be created. Therefore an
59 application may wish to get a pointer to a brush by using the global
60 list of brushes
{\bf wxTheBrushList
}, and calling the member function
61 \rtfsp{\bf FindOrCreateBrush
}.
63 This class uses
\helpref{reference counting and copy-on-write
}{trefcount
}
64 internally so that assignments between two instances of this class are very
65 cheap. You can therefore use actual objects instead of pointers without
66 efficiency problems. If an instance of this class is changed it will create
67 its own data internally so that other instances, which previously shared the
68 data using the reference counting, are not affected.
70 %TODO: an overview for wxBrush.
73 \helpref{wxBrushList
}{wxbrushlist
},
\helpref{wxDC
}{wxdc
},
\helpref{wxDC::SetBrush
}{wxdcsetbrush
}
75 \latexignore{\rtfignore{\wxheading{Members
}}}
78 \membersection{wxBrush::wxBrush
}\label{wxbrushctor
}
80 \func{}{wxBrush
}{\void}
82 Default constructor. The brush will be uninitialised, and
\helpref{wxBrush:IsOk
}{wxbrushisok
} will
85 \func{}{wxBrush
}{\param{const wxColour\&
}{ colour
},
\param{int
}{ style =
{\tt wxSOLID
}}}
87 Constructs a brush from a colour object and style.
89 \func{}{wxBrush
}{\param{const wxString\&
}{colourName
},
\param{int
}{ style
}}
91 Constructs a brush from a colour name and style.
93 \func{}{wxBrush
}{\param{const wxBitmap\&
}{stippleBitmap
}}
95 Constructs a stippled brush using a bitmap.
97 \func{}{wxBrush
}{\param{const wxBrush\&
}{ brush
}}
99 Copy constructor, uses
\helpref{reference counting
}{trefcount
}.
101 \wxheading{Parameters
}
103 \docparam{colour
}{Colour object.
}
105 \docparam{colourName
}{Colour name. The name will be looked up in the colour database.
}
107 \docparam{style
}{One of:
109 \begin{twocollist
}\itemsep=
0pt
110 \twocolitem{{\bf wxTRANSPARENT
}}{Transparent (no fill).
}
111 \twocolitem{{\bf wxSOLID
}}{Solid.
}
112 \twocolitem{{\bf wxSTIPPLE
}}{Uses a bitmap as a stipple.
}
113 \twocolitem{{\bf wxBDIAGONAL
\_HATCH}}{Backward diagonal hatch.
}
114 \twocolitem{{\bf wxCROSSDIAG
\_HATCH}}{Cross-diagonal hatch.
}
115 \twocolitem{{\bf wxFDIAGONAL
\_HATCH}}{Forward diagonal hatch.
}
116 \twocolitem{{\bf wxCROSS
\_HATCH}}{Cross hatch.
}
117 \twocolitem{{\bf wxHORIZONTAL
\_HATCH}}{Horizontal hatch.
}
118 \twocolitem{{\bf wxVERTICAL
\_HATCH}}{Vertical hatch.
}
121 \docparam{brush
}{Pointer or reference to a brush to copy.
}
123 \docparam{stippleBitmap
}{A bitmap to use for stippling.
}
127 If a stipple brush is created, the brush style will be set to wxSTIPPLE.
131 \helpref{wxBrushList
}{wxbrushlist
},
\helpref{wxColour
}{wxcolour
},
\helpref{wxColourDatabase
}{wxcolourdatabase
}
134 \membersection{wxBrush::
\destruct{wxBrush
}}\label{wxbrushdtor
}
136 \func{}{\destruct{wxBrush
}}{\void}
139 See
\helpref{reference-counted object destruction
}{refcountdestruct
} for more info.
143 Although all remaining brushes are deleted when the application exits,
144 the application should try to clean up all brushes itself. This is because
145 wxWidgets cannot know if a pointer to the brush object is stored in an
146 application data structure, and there is a risk of double deletion.
149 \membersection{wxBrush::GetColour
}\label{wxbrushgetcolour
}
151 \constfunc{wxColour\&
}{GetColour
}{\void}
153 Returns a reference to the brush colour.
157 \helpref{wxBrush::SetColour
}{wxbrushsetcolour
}
160 \membersection{wxBrush::GetStipple
}\label{wxbrushgetstipple
}
162 \constfunc{wxBitmap *
}{GetStipple
}{\void}
164 Gets a pointer to the stipple bitmap. If the brush does not have a wxSTIPPLE style,
165 this bitmap may be non-NULL but uninitialised (
\helpref{wxBitmap:IsOk
}{wxbitmapisok
} returns false).
169 \helpref{wxBrush::SetStipple
}{wxbrushsetstipple
}
172 \membersection{wxBrush::GetStyle
}\label{wxbrushgetstyle
}
174 \constfunc{int
}{GetStyle
}{\void}
176 Returns the brush style, one of:
178 \begin{twocollist
}\itemsep=
0pt
179 \twocolitem{{\bf wxTRANSPARENT
}}{Transparent (no fill).
}
180 \twocolitem{{\bf wxSOLID
}}{Solid.
}
181 \twocolitem{{\bf wxBDIAGONAL
\_HATCH}}{Backward diagonal hatch.
}
182 \twocolitem{{\bf wxCROSSDIAG
\_HATCH}}{Cross-diagonal hatch.
}
183 \twocolitem{{\bf wxFDIAGONAL
\_HATCH}}{Forward diagonal hatch.
}
184 \twocolitem{{\bf wxCROSS
\_HATCH}}{Cross hatch.
}
185 \twocolitem{{\bf wxHORIZONTAL
\_HATCH}}{Horizontal hatch.
}
186 \twocolitem{{\bf wxVERTICAL
\_HATCH}}{Vertical hatch.
}
187 \twocolitem{{\bf wxSTIPPLE
}}{Stippled using a bitmap.
}
188 \twocolitem{{\bf wxSTIPPLE
\_MASK\_OPAQUE}}{Stippled using a bitmap's mask.
}
193 \helpref{wxBrush::SetStyle
}{wxbrushsetstyle
},
\helpref{wxBrush::SetColour
}{wxbrushsetcolour
},
\rtfsp
194 \helpref{wxBrush::SetStipple
}{wxbrushsetstipple
}
197 \membersection{wxBrush::IsHatch
}\label{wxbrushishatch
}
199 \constfunc{bool
}{IsHatch
}{\void}
201 Returns true if the style of the brush is any of hatched fills.
205 \helpref{wxBrush::GetStyle
}{wxbrushgetstyle
}
208 \membersection{wxBrush::IsOk
}\label{wxbrushisok
}
210 \constfunc{bool
}{IsOk
}{\void}
212 Returns true if the brush is initialised. It will return false if the default
213 constructor has been used (for example, the brush is a member of a class, or
214 NULL has been assigned to it).
217 \membersection{wxBrush::SetColour
}\label{wxbrushsetcolour
}
219 \func{void
}{SetColour
}{\param{wxColour\&
}{colour
}}
221 Sets the brush colour using a reference to a colour object.
223 \func{void
}{SetColour
}{\param{const wxString\&
}{colourName
}}
225 Sets the brush colour using a colour name from the colour database.
227 \func{void
}{SetColour
}{\param{unsigned char
}{ red
},
\param{unsigned char
}{ green
},
\param{unsigned char
}{ blue
}}
229 Sets the brush colour using red, green and blue values.
233 \helpref{wxBrush::GetColour
}{wxbrushgetcolour
}
236 \membersection{wxBrush::SetStipple
}\label{wxbrushsetstipple
}
238 \func{void
}{SetStipple
}{\param{const wxBitmap\&
}{ bitmap
}}
240 Sets the stipple bitmap.
242 \wxheading{Parameters
}
244 \docparam{bitmap
}{The bitmap to use for stippling.
}
248 The style will be set to wxSTIPPLE, unless the bitmap has a mask associated
249 to it, in which case the style will be set to wxSTIPPLE
\_MASK\_OPAQUE.
251 If the wxSTIPPLE variant is used, the bitmap will be used to fill out the
252 area to be drawn. If the wxSTIPPLE
\_MASK\_OPAQUE is used, the current
253 text foreground and text background determine what colours are used for
254 displaying and the bits in the mask (which is a mono-bitmap actually)
255 determine where to draw what.
257 Note that under Windows
95, only
8x8 pixel large stipple bitmaps are
258 supported, Windows
98 and NT as well as GTK support arbitrary bitmaps.
262 \helpref{wxBitmap
}{wxbitmap
}
265 \membersection{wxBrush::SetStyle
}\label{wxbrushsetstyle
}
267 \func{void
}{SetStyle
}{\param{int
}{ style
}}
269 Sets the brush style.
271 \docparam{style
}{One of:
273 \begin{twocollist
}\itemsep=
0pt
274 \twocolitem{{\bf wxTRANSPARENT
}}{Transparent (no fill).
}
275 \twocolitem{{\bf wxSOLID
}}{Solid.
}
276 \twocolitem{{\bf wxBDIAGONAL
\_HATCH}}{Backward diagonal hatch.
}
277 \twocolitem{{\bf wxCROSSDIAG
\_HATCH}}{Cross-diagonal hatch.
}
278 \twocolitem{{\bf wxFDIAGONAL
\_HATCH}}{Forward diagonal hatch.
}
279 \twocolitem{{\bf wxCROSS
\_HATCH}}{Cross hatch.
}
280 \twocolitem{{\bf wxHORIZONTAL
\_HATCH}}{Horizontal hatch.
}
281 \twocolitem{{\bf wxVERTICAL
\_HATCH}}{Vertical hatch.
}
282 \twocolitem{{\bf wxSTIPPLE
}}{Stippled using a bitmap.
}
283 \twocolitem{{\bf wxSTIPPLE
\_MASK\_OPAQUE}}{Stippled using a bitmap's mask.
}
288 \helpref{wxBrush::GetStyle
}{wxbrushgetstyle
}
291 \membersection{wxBrush::operator $=$
}\label{wxbrushassignment
}
293 \func{wxBrush\&
}{operator $=$
}{\param{const wxBrush\&
}{brush
}}
295 Assignment operator, using
\helpref{reference counting
}{trefcount
}.
298 \membersection{wxBrush::operator $==$
}\label{wxbrushequals
}
300 \func{bool
}{operator $==$
}{\param{const wxBrush\&
}{brush
}}
303 See
\helpref{reference-counted object comparison
}{refcountequality
} for more info.
306 \membersection{wxBrush::operator $!=$
}\label{wxbrushnotequals
}
308 \func{bool
}{operator $!=$
}{\param{const wxBrush\&
}{brush
}}
311 See
\helpref{reference-counted object comparison
}{refcountequality
} for more info.
314 \section{\class{wxBrushList
}}\label{wxbrushlist
}
316 A brush list is a list containing all brushes which have been created.
318 \wxheading{Derived from
}
320 \helpref{wxList
}{wxlist
}\\
321 \helpref{wxObject
}{wxobject
}
323 \wxheading{Include files
}
329 There is only one instance of this class:
{\bf wxTheBrushList
}. Use
330 this object to search for a previously created brush of the desired
331 type and create it if not already found. In some windowing systems,
332 the brush may be a scarce resource, so it can pay to reuse old
333 resources if possible. When an application finishes, all brushes will
334 be deleted and their resources freed, eliminating the possibility of
335 `memory leaks'. However, it is best not to rely on this automatic
336 cleanup because it can lead to double deletion in some circumstances.
338 There are two mechanisms in recent versions of wxWidgets which make the
339 brush list less useful than it once was. Under Windows, scarce resources
340 are cleaned up internally if they are not being used. Also, a reference
341 counting mechanism applied to all GDI objects means that some sharing
342 of underlying resources is possible. You don't have to keep track of pointers,
343 working out when it is safe delete a brush, because the reference counting does
344 it for you. For example, you can set a brush in a device context, and then
345 immediately delete the brush you passed, because the brush is `copied'.
347 So you may find it easier to ignore the brush list, and instead create
348 and copy brushes as you see fit. If your Windows resource meter suggests
349 your application is using too many resources, you can resort to using
350 GDI lists to share objects explicitly.
352 The only compelling use for the brush list is for wxWidgets to keep
353 track of brushes in order to clean them up on exit. It is also kept for
354 backward compatibility with earlier versions of wxWidgets.
358 \helpref{wxBrush
}{wxbrush
}
360 \latexignore{\rtfignore{\wxheading{Members
}}}
363 \membersection{wxBrushList::wxBrushList
}\label{wxbrushlistconstr
}
365 \func{void
}{wxBrushList
}{\void}
367 Constructor. The application should not construct its own brush list:
368 use the object pointer
{\bf wxTheBrushList
}.
371 \membersection{wxBrushList::FindOrCreateBrush
}\label{wxbrushlistfindorcreatebrush
}
373 \func{wxBrush *
}{FindOrCreateBrush
}{\param{const wxColour\&
}{colour
},
\param{int
}{ style = wxSOLID
}}
375 Finds a brush with the specified attributes and returns it, else creates a new brush, adds it
376 to the brush list, and returns it.
378 \wxheading{Parameters
}
380 \docparam{colour
}{Colour object.
}
382 \docparam{style
}{Brush style. See
\helpref{wxBrush::SetStyle
}{wxbrushsetstyle
} for a list of styles.
}