1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBufferedDC class
4 // Author: Ron Lee <ron@debian.org>
5 // Modified by: Vadim Zeitlin (refactored, added bg preservation)
8 // Copyright: (c) Ron Lee
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DCBUFFER_H_
13 #define _WX_DCBUFFER_H_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "dcbuffer.h"
19 #include "wx/dcmemory.h"
20 #include "wx/dcclient.h"
22 // flags for wxBufferedDC ctor/Init()
25 // this is more efficient and hence default
26 wxBUFFER_DC_OVERWRITE_BG
= 0,
28 // preserve the old background: more time consuming
29 wxBUFFER_DC_PRESERVE_BG
= 1,
32 // flags used by default
33 wxBUFFER_DC_DEFAULT
= wxBUFFER_DC_OVERWRITE_BG
36 // ----------------------------------------------------------------------------
37 // Double buffering helper.
38 // ----------------------------------------------------------------------------
40 class WXDLLIMPEXP_ADV wxBufferedDC
: public wxMemoryDC
43 // Default ctor, must subsequently call Init for two stage construction.
44 wxBufferedDC() : m_dc( 0 )
48 // Construct a wxBufferedDC using a user supplied buffer.
49 wxBufferedDC(wxDC
*dc
, const wxBitmap
&buffer
);
51 // Construct a wxBufferedDC with an internal buffer of 'area'
52 // (where area is usually something like the size of the window
54 wxBufferedDC(wxDC
*dc
, const wxSize
&area
, int flags
= wxBUFFER_DC_DEFAULT
);
56 // default copy ctor ok.
58 // The usually desired action in the dtor is to blit the buffer.
59 virtual ~wxBufferedDC() { if ( m_dc
) UnMask(); }
61 // These reimplement the actions of the ctors for two stage creation, but
62 // are not used by the ctors themselves to save a few cpu cycles.
63 void Init(wxDC
*dc
, const wxBitmap
&bitmap
);
64 void Init(wxDC
*dc
, const wxSize
&area
, int flags
= wxBUFFER_DC_DEFAULT
);
66 // Blits the buffer to the dc, and detaches the dc from the buffer (so it
67 // can be effectively used once only).
69 // Usually called in the dtor or by the dtor of derived classes if the
70 // BufferedDC must blit before the derived class (which may own the dc it's
71 // blitting to) is destroyed.
75 // check that the bitmap is valid and use it
78 wxASSERT_MSG( m_buffer
.Ok(), _T("invalid bitmap in wxBufferedDC") );
80 SelectObject(m_buffer
);
83 // preserve the background if necessary
84 void SaveBg(const wxSize
& area
, int flags
)
86 if ( flags
& wxBUFFER_DC_PRESERVE_BG
)
88 Blit(0, 0, area
.GetWidth(), area
.GetHeight(), m_dc
, 0, 0);
92 // the underlying DC to which we copy everything drawn on this one in
95 // NB: Without the existence of a wxNullDC, this must be a pointer, else it
96 // could probably be a reference.
99 // the buffer (selected in this DC)
102 DECLARE_NO_COPY_CLASS(wxBufferedDC
)
106 // ----------------------------------------------------------------------------
107 // Double buffered PaintDC.
108 // ----------------------------------------------------------------------------
110 // Creates a double buffered wxPaintDC, optionally allowing the
111 // user to specify their own buffer to use.
112 class WXDLLIMPEXP_ADV wxBufferedPaintDC
: public wxBufferedDC
115 // this ctor creates a bitmap of the size of the window for buffering
116 wxBufferedPaintDC(wxWindow
*window
, int flags
= wxBUFFER_DC_DEFAULT
)
119 Init(&m_paintdc
, window
->GetClientSize(), flags
);
124 // the bitmap must be valid here
125 wxBufferedPaintDC(wxWindow
*window
, const wxBitmap
& buffer
)
128 Init(&m_paintdc
, buffer
);
133 // default copy ctor ok.
135 virtual ~wxBufferedPaintDC()
137 // We must UnMask here, else by the time the base class
138 // does it, the PaintDC will have already been destroyed.
143 // prepare the underlying DC
144 void Prepare(wxWindow
*window
)
146 window
->PrepareDC(m_paintdc
);
151 DECLARE_NO_COPY_CLASS(wxBufferedPaintDC
)
154 #endif // _WX_DCBUFFER_H_