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
}
29 \helpref{wxCore
}{librarieslist
}
31 \wxheading{Predefined objects
}
44 wxMEDIUM
\_GREY\_BRUSH\\
45 wxLIGHT
\_GREY\_BRUSH\\
46 wxTRANSPARENT
\_BRUSH\\
52 On a monochrome display, wxWidgets shows
53 all brushes as white unless the colour is really black.
55 Do not initialize objects on the stack before the program commences,
56 since other required structures may not have been set up yet. Instead,
57 define global pointers to objects and create them in
\helpref{wxApp::OnInit
}{wxapponinit
} or
60 An application may wish to create brushes with different
61 characteristics dynamically, and there is the consequent danger that a
62 large number of duplicate brushes will be created. Therefore an
63 application may wish to get a pointer to a brush by using the global
64 list of brushes
{\bf wxTheBrushList
}, and calling the member function
65 \rtfsp{\bf FindOrCreateBrush
}.
67 This class uses
\helpref{reference counting and copy-on-write
}{trefcount
}
68 internally so that assignments between two instances of this class are very
69 cheap. You can therefore use actual objects instead of pointers without
70 efficiency problems. If an instance of this class is changed it will create
71 its own data internally so that other instances, which previously shared the
72 data using the reference counting, are not affected.
74 %TODO: an overview for wxBrush.
77 \helpref{wxBrushList
}{wxbrushlist
},
\helpref{wxDC
}{wxdc
},
\helpref{wxDC::SetBrush
}{wxdcsetbrush
}
79 \latexignore{\rtfignore{\wxheading{Members
}}}
82 \membersection{wxBrush::wxBrush
}\label{wxbrushctor
}
84 \func{}{wxBrush
}{\void}
86 Default constructor. The brush will be uninitialised, and
\helpref{wxBrush:IsOk
}{wxbrushisok
} will
89 \func{}{wxBrush
}{\param{const wxColour\&
}{ colour
},
\param{int
}{ style =
{\tt wxSOLID
}}}
91 Constructs a brush from a colour object and style.
93 \func{}{wxBrush
}{\param{const wxString\&
}{colourName
},
\param{int
}{ style
}}
95 Constructs a brush from a colour name and style.
97 \func{}{wxBrush
}{\param{const wxBitmap\&
}{stippleBitmap
}}
99 Constructs a stippled brush using a bitmap.
101 \func{}{wxBrush
}{\param{const wxBrush\&
}{ brush
}}
103 Copy constructor, uses
\helpref{reference counting
}{trefcount
}.
105 \wxheading{Parameters
}
107 \docparam{colour
}{Colour object.
}
109 \docparam{colourName
}{Colour name. The name will be looked up in the colour database.
}
111 \docparam{style
}{One of:
113 \begin{twocollist
}\itemsep=
0pt
114 \twocolitem{{\bf wxTRANSPARENT
}}{Transparent (no fill).
}
115 \twocolitem{{\bf wxSOLID
}}{Solid.
}
116 \twocolitem{{\bf wxSTIPPLE
}}{Uses a bitmap as a stipple.
}
117 \twocolitem{{\bf wxBDIAGONAL
\_HATCH}}{Backward diagonal hatch.
}
118 \twocolitem{{\bf wxCROSSDIAG
\_HATCH}}{Cross-diagonal hatch.
}
119 \twocolitem{{\bf wxFDIAGONAL
\_HATCH}}{Forward diagonal hatch.
}
120 \twocolitem{{\bf wxCROSS
\_HATCH}}{Cross hatch.
}
121 \twocolitem{{\bf wxHORIZONTAL
\_HATCH}}{Horizontal hatch.
}
122 \twocolitem{{\bf wxVERTICAL
\_HATCH}}{Vertical hatch.
}
125 \docparam{brush
}{Pointer or reference to a brush to copy.
}
127 \docparam{stippleBitmap
}{A bitmap to use for stippling.
}
131 If a stipple brush is created, the brush style will be set to wxSTIPPLE.
135 \helpref{wxBrushList
}{wxbrushlist
},
\helpref{wxColour
}{wxcolour
},
\helpref{wxColourDatabase
}{wxcolourdatabase
}
138 \membersection{wxBrush::
\destruct{wxBrush
}}\label{wxbrushdtor
}
140 \func{}{\destruct{wxBrush
}}{\void}
143 See
\helpref{reference-counted object destruction
}{refcountdestruct
} for more info.
147 Although all remaining brushes are deleted when the application exits,
148 the application should try to clean up all brushes itself. This is because
149 wxWidgets cannot know if a pointer to the brush object is stored in an
150 application data structure, and there is a risk of double deletion.
153 \membersection{wxBrush::GetColour
}\label{wxbrushgetcolour
}
155 \constfunc{wxColour\&
}{GetColour
}{\void}
157 Returns a reference to the brush colour.
161 \helpref{wxBrush::SetColour
}{wxbrushsetcolour
}
164 \membersection{wxBrush::GetStipple
}\label{wxbrushgetstipple
}
166 \constfunc{wxBitmap *
}{GetStipple
}{\void}
168 Gets a pointer to the stipple bitmap. If the brush does not have a wxSTIPPLE style,
169 this bitmap may be non-NULL but uninitialised (
\helpref{wxBitmap:IsOk
}{wxbitmapisok
} returns false).
173 \helpref{wxBrush::SetStipple
}{wxbrushsetstipple
}
176 \membersection{wxBrush::GetStyle
}\label{wxbrushgetstyle
}
178 \constfunc{int
}{GetStyle
}{\void}
180 Returns the brush style, one of:
182 \begin{twocollist
}\itemsep=
0pt
183 \twocolitem{{\bf wxTRANSPARENT
}}{Transparent (no fill).
}
184 \twocolitem{{\bf wxSOLID
}}{Solid.
}
185 \twocolitem{{\bf wxBDIAGONAL
\_HATCH}}{Backward diagonal hatch.
}
186 \twocolitem{{\bf wxCROSSDIAG
\_HATCH}}{Cross-diagonal hatch.
}
187 \twocolitem{{\bf wxFDIAGONAL
\_HATCH}}{Forward diagonal hatch.
}
188 \twocolitem{{\bf wxCROSS
\_HATCH}}{Cross hatch.
}
189 \twocolitem{{\bf wxHORIZONTAL
\_HATCH}}{Horizontal hatch.
}
190 \twocolitem{{\bf wxVERTICAL
\_HATCH}}{Vertical hatch.
}
191 \twocolitem{{\bf wxSTIPPLE
}}{Stippled using a bitmap.
}
192 \twocolitem{{\bf wxSTIPPLE
\_MASK\_OPAQUE}}{Stippled using a bitmap's mask.
}
197 \helpref{wxBrush::SetStyle
}{wxbrushsetstyle
},
\helpref{wxBrush::SetColour
}{wxbrushsetcolour
},
\rtfsp
198 \helpref{wxBrush::SetStipple
}{wxbrushsetstipple
}
201 \membersection{wxBrush::IsHatch
}\label{wxbrushishatch
}
203 \constfunc{bool
}{IsHatch
}{\void}
205 Returns true if the style of the brush is any of hatched fills.
209 \helpref{wxBrush::GetStyle
}{wxbrushgetstyle
}
212 \membersection{wxBrush::IsOk
}\label{wxbrushisok
}
214 \constfunc{bool
}{IsOk
}{\void}
216 Returns true if the brush is initialised. It will return false if the default
217 constructor has been used (for example, the brush is a member of a class, or
218 NULL has been assigned to it).
221 \membersection{wxBrush::SetColour
}\label{wxbrushsetcolour
}
223 \func{void
}{SetColour
}{\param{wxColour\&
}{colour
}}
225 Sets the brush colour using a reference to a colour object.
227 \func{void
}{SetColour
}{\param{const wxString\&
}{colourName
}}
229 Sets the brush colour using a colour name from the colour database.
231 \func{void
}{SetColour
}{\param{unsigned char
}{ red
},
\param{unsigned char
}{ green
},
\param{unsigned char
}{ blue
}}
233 Sets the brush colour using red, green and blue values.
237 \helpref{wxBrush::GetColour
}{wxbrushgetcolour
}
240 \membersection{wxBrush::SetStipple
}\label{wxbrushsetstipple
}
242 \func{void
}{SetStipple
}{\param{const wxBitmap\&
}{ bitmap
}}
244 Sets the stipple bitmap.
246 \wxheading{Parameters
}
248 \docparam{bitmap
}{The bitmap to use for stippling.
}
252 The style will be set to wxSTIPPLE, unless the bitmap has a mask associated
253 to it, in which case the style will be set to wxSTIPPLE
\_MASK\_OPAQUE.
255 If the wxSTIPPLE variant is used, the bitmap will be used to fill out the
256 area to be drawn. If the wxSTIPPLE
\_MASK\_OPAQUE is used, the current
257 text foreground and text background determine what colours are used for
258 displaying and the bits in the mask (which is a mono-bitmap actually)
259 determine where to draw what.
261 Note that under Windows
95, only
8x8 pixel large stipple bitmaps are
262 supported, Windows
98 and NT as well as GTK support arbitrary bitmaps.
266 \helpref{wxBitmap
}{wxbitmap
}
269 \membersection{wxBrush::SetStyle
}\label{wxbrushsetstyle
}
271 \func{void
}{SetStyle
}{\param{int
}{ style
}}
273 Sets the brush style.
275 \docparam{style
}{One of:
277 \begin{twocollist
}\itemsep=
0pt
278 \twocolitem{{\bf wxTRANSPARENT
}}{Transparent (no fill).
}
279 \twocolitem{{\bf wxSOLID
}}{Solid.
}
280 \twocolitem{{\bf wxBDIAGONAL
\_HATCH}}{Backward diagonal hatch.
}
281 \twocolitem{{\bf wxCROSSDIAG
\_HATCH}}{Cross-diagonal hatch.
}
282 \twocolitem{{\bf wxFDIAGONAL
\_HATCH}}{Forward diagonal hatch.
}
283 \twocolitem{{\bf wxCROSS
\_HATCH}}{Cross hatch.
}
284 \twocolitem{{\bf wxHORIZONTAL
\_HATCH}}{Horizontal hatch.
}
285 \twocolitem{{\bf wxVERTICAL
\_HATCH}}{Vertical hatch.
}
286 \twocolitem{{\bf wxSTIPPLE
}}{Stippled using a bitmap.
}
287 \twocolitem{{\bf wxSTIPPLE
\_MASK\_OPAQUE}}{Stippled using a bitmap's mask.
}
292 \helpref{wxBrush::GetStyle
}{wxbrushgetstyle
}
295 \membersection{wxBrush::operator $=$
}\label{wxbrushassignment
}
297 \func{wxBrush\&
}{operator $=$
}{\param{const wxBrush\&
}{brush
}}
299 Assignment operator, using
\helpref{reference counting
}{trefcount
}.
302 \membersection{wxBrush::operator $==$
}\label{wxbrushequals
}
304 \func{bool
}{operator $==$
}{\param{const wxBrush\&
}{brush
}}
307 See
\helpref{reference-counted object comparison
}{refcountequality
} for more info.
310 \membersection{wxBrush::operator $!=$
}\label{wxbrushnotequals
}
312 \func{bool
}{operator $!=$
}{\param{const wxBrush\&
}{brush
}}
315 See
\helpref{reference-counted object comparison
}{refcountequality
} for more info.
318 \section{\class{wxBrushList
}}\label{wxbrushlist
}
320 A brush list is a list containing all brushes which have been created.
322 \wxheading{Derived from
}
324 \helpref{wxList
}{wxlist
}\\
325 \helpref{wxObject
}{wxobject
}
327 \wxheading{Include files
}
333 \helpref{wxCore
}{librarieslist
}
337 There is only one instance of this class:
{\bf wxTheBrushList
}. Use
338 this object to search for a previously created brush of the desired
339 type and create it if not already found. In some windowing systems,
340 the brush may be a scarce resource, so it can pay to reuse old
341 resources if possible. When an application finishes, all brushes will
342 be deleted and their resources freed, eliminating the possibility of
343 `memory leaks'. However, it is best not to rely on this automatic
344 cleanup because it can lead to double deletion in some circumstances.
346 There are two mechanisms in recent versions of wxWidgets which make the
347 brush list less useful than it once was. Under Windows, scarce resources
348 are cleaned up internally if they are not being used. Also, a reference
349 counting mechanism applied to all GDI objects means that some sharing
350 of underlying resources is possible. You don't have to keep track of pointers,
351 working out when it is safe delete a brush, because the reference counting does
352 it for you. For example, you can set a brush in a device context, and then
353 immediately delete the brush you passed, because the brush is `copied'.
355 So you may find it easier to ignore the brush list, and instead create
356 and copy brushes as you see fit. If your Windows resource meter suggests
357 your application is using too many resources, you can resort to using
358 GDI lists to share objects explicitly.
360 The only compelling use for the brush list is for wxWidgets to keep
361 track of brushes in order to clean them up on exit. It is also kept for
362 backward compatibility with earlier versions of wxWidgets.
366 \helpref{wxBrush
}{wxbrush
}
368 \latexignore{\rtfignore{\wxheading{Members
}}}
371 \membersection{wxBrushList::wxBrushList
}\label{wxbrushlistconstr
}
373 \func{void
}{wxBrushList
}{\void}
375 Constructor. The application should not construct its own brush list:
376 use the object pointer
{\bf wxTheBrushList
}.
379 \membersection{wxBrushList::FindOrCreateBrush
}\label{wxbrushlistfindorcreatebrush
}
381 \func{wxBrush *
}{FindOrCreateBrush
}{\param{const wxColour\&
}{colour
},
\param{int
}{ style = wxSOLID
}}
383 Finds a brush with the specified attributes and returns it, else creates a new brush, adds it
384 to the brush list, and returns it.
386 \wxheading{Parameters
}
388 \docparam{colour
}{Colour object.
}
390 \docparam{style
}{Brush style. See
\helpref{wxBrush::SetStyle
}{wxbrushsetstyle
} for a list of styles.
}