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