]> git.saurik.com Git - wxWidgets.git/blame - interface/dcbuffer.h
More initial reviews of d* interface headers.
[wxWidgets.git] / interface / dcbuffer.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: dcbuffer.h
e54c96f1 3// Purpose: interface of wxBufferedDC
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxBufferedDC
11 @wxheader{dcbuffer.h}
7c913512 12
23324ae1 13 This class provides a simple way to avoid flicker: when drawing on it,
f09b5681
BP
14 everything is in fact first drawn on an in-memory buffer (a wxBitmap) and
15 then copied to the screen, using the associated wxDC, only once, when this
16 object is destroyed. wxBufferedDC itself is typically associated with
17 wxClientDC, if you want to use it in your @c EVT_PAINT handler, you should
18 look at wxBufferedPaintDC instead.
19
20 When used like this, a valid @e DC must be specified in the constructor
23324ae1 21 while the @e buffer bitmap doesn't have to be explicitly provided, by
f09b5681
BP
22 default this class will allocate the bitmap of required size itself.
23 However using a dedicated bitmap can speed up the redrawing process by
24 eliminating the repeated creation and destruction of a possibly big bitmap.
25 Otherwise, wxBufferedDC can be used in the same way as any other device
26 context.
7c913512 27
23324ae1 28 There is another possible use for wxBufferedDC is to use it to maintain a
f09b5681 29 backing store for the window contents. In this case, the associated @e DC
23324ae1 30 may be @NULL but a valid backing store bitmap should be specified.
7c913512 31
23324ae1 32 Finally, please note that GTK+ 2.0 as well as OS X provide double buffering
f09b5681
BP
33 themselves natively. You can either use wxWindow::IsDoubleBuffered() to
34 determine whether you need to use buffering or not, or use
35 wxAutoBufferedPaintDC to avoid needless double buffering on the systems
36 which already do it automatically.
7c913512 37
23324ae1
FM
38 @library{wxcore}
39 @category{dc}
7c913512 40
e54c96f1 41 @see wxDC, wxMemoryDC, wxBufferedPaintDC, wxAutoBufferedPaintDC
23324ae1
FM
42*/
43class wxBufferedDC : public wxMemoryDC
44{
45public:
f09b5681
BP
46 /**
47 Default constructor. You must call one of the Init() methods later in
48 order to use the device context.
49 */
50 wxBufferedDC();
51
23324ae1
FM
52 //@{
53 /**
f09b5681
BP
54 Creates a buffer for the provided @dc. Init() must not be called when
55 using this constructor.
3c4f71cc 56
7c913512 57 @param dc
f09b5681
BP
58 The underlying DC: everything drawn to this object will be flushed
59 to this DC when this object is destroyed. You may pass @NULL in
60 order to just initialize the buffer, and not flush it.
7c913512 61 @param area
4cc4bfaf
FM
62 The size of the bitmap to be used for buffering (this bitmap is
63 created internally when it is not given explicitly).
7c913512 64 @param buffer
f09b5681
BP
65 Explicitly provided bitmap to be used for buffering: this is the
66 most efficient solution as the bitmap doesn't have to be recreated
67 each time but it also requires more memory as the bitmap is never
68 freed. The bitmap should have appropriate size, anything drawn
69 outside of its bounds is clipped.
4cc4bfaf 70 @param style
f09b5681
BP
71 wxBUFFER_CLIENT_AREA to indicate that just the client area of the
72 window is buffered, or wxBUFFER_VIRTUAL_AREA to indicate that the
73 buffer bitmap covers the virtual area.
23324ae1 74 */
4cc4bfaf 75 wxBufferedDC(wxDC* dc, const wxSize& area,
7c913512 76 int style = wxBUFFER_CLIENT_AREA);
4cc4bfaf 77 wxBufferedDC(wxDC* dc, wxBitmap& buffer,
7c913512 78 int style = wxBUFFER_CLIENT_AREA);
23324ae1
FM
79 //@}
80
81 /**
f09b5681
BP
82 Copies everything drawn on the DC so far to the underlying DC
83 associated with this object, if any.
23324ae1 84 */
f09b5681 85 ~wxBufferedDC();
23324ae1
FM
86
87 //@{
88 /**
f09b5681
BP
89 Initializes the object created using the default constructor. Please
90 see the constructors for parameter details.
23324ae1 91 */
4cc4bfaf 92 void Init(wxDC* dc, const wxSize& area,
23324ae1 93 int style = wxBUFFER_CLIENT_AREA);
4cc4bfaf 94 void Init(wxDC* dc, wxBitmap& buffer,
7c913512 95 int style = wxBUFFER_CLIENT_AREA);
23324ae1
FM
96 //@}
97};
98
99
e54c96f1 100
23324ae1
FM
101/**
102 @class wxAutoBufferedPaintDC
103 @wxheader{dcbuffer.h}
7c913512 104
f09b5681
BP
105 This wxDC derivative can be used inside of an @c EVT_PAINT() event handler
106 to achieve double-buffered drawing. Just use this class instead of
107 wxPaintDC and make sure wxWindow::SetBackgroundStyle() is called with
108 wxBG_STYLE_CUSTOM somewhere in the class initialization code, and that's
109 all you have to do to (mostly) avoid flicker.
110
111 The difference between wxBufferedPaintDC and this class is that this class
112 won't double-buffer on platforms which have native double-buffering
113 already, avoiding any unneccessary buffering to avoid flicker.
7c913512 114
f09b5681
BP
115 wxAutoBufferedPaintDC is simply a typedef of wxPaintDC on platforms that
116 have native double-buffering, otherwise, it is a typedef of
117 wxBufferedPaintDC.
7c913512 118
23324ae1
FM
119 @library{wxbase}
120 @category{dc}
7c913512 121
f09b5681 122 @see wxDC, wxBufferedPaintDC, wxPaintDC
23324ae1
FM
123*/
124class wxAutoBufferedPaintDC : public wxBufferedPaintDC
125{
126public:
127 /**
128 Constructor. Pass a pointer to the window on which you wish to paint.
129 */
4cc4bfaf 130 wxAutoBufferedPaintDC(wxWindow* window);
23324ae1
FM
131};
132
133
e54c96f1 134
23324ae1
FM
135/**
136 @class wxBufferedPaintDC
137 @wxheader{dcbuffer.h}
7c913512 138
f09b5681
BP
139 This is a subclass of wxBufferedDC which can be used inside of an
140 @c EVT_PAINT() event handler to achieve double-buffered drawing. Just use
141 this class instead of wxPaintDC and make sure
142 wxWindow::SetBackgroundStyle() is called with wxBG_STYLE_CUSTOM somewhere
143 in the class initialization code, and that's all you have to do to (mostly)
144 avoid flicker. The only thing to watch out for is that if you are using
145 this class together with wxScrolled, you probably do @b not want to call
146 wxScrolled::PrepareDC() on it as it already does this internally for the
147 real underlying wxPaintDC.
7c913512 148
23324ae1
FM
149 @library{wxcore}
150 @category{dc}
7c913512 151
f09b5681 152 @see wxDC, wxBufferedDC, wxAutoBufferedPaintDC, wxPaintDC
23324ae1
FM
153*/
154class wxBufferedPaintDC : public wxBufferedDC
155{
156public:
157 //@{
158 /**
f09b5681
BP
159 As with wxBufferedDC, you may either provide the bitmap to be used for
160 buffering or let this object create one internally (in the latter case,
161 the size of the client part of the window is used).
162
163 Pass wxBUFFER_CLIENT_AREA for the @a style parameter to indicate that
164 just the client area of the window is buffered, or
165 wxBUFFER_VIRTUAL_AREA to indicate that the buffer bitmap covers the
166 virtual area.
23324ae1 167 */
4cc4bfaf 168 wxBufferedPaintDC(wxWindow* window, wxBitmap& buffer,
23324ae1 169 int style = wxBUFFER_CLIENT_AREA);
4cc4bfaf 170 wxBufferedPaintDC(wxWindow* window,
7c913512 171 int style = wxBUFFER_CLIENT_AREA);
23324ae1
FM
172 //@}
173
174 /**
f09b5681
BP
175 Copies everything drawn on the DC so far to the window associated with
176 this object, using a wxPaintDC.
23324ae1 177 */
f09b5681 178 ~wxBufferedPaintDC();
23324ae1 179};
e54c96f1 180