]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/dcbuffer.h
1b5d728020bb0c062c7034d91b6e5f92e97bfcdb
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 #include "wx/dcmemory.h"
16 #include "wx/dcclient.h"
19 // ----------------------------------------------------------------------------
20 // Double buffering helper.
21 // ----------------------------------------------------------------------------
23 class wxBufferedDC
: public wxMemoryDC
26 // Default ctor, must subsequently call Init for two stage construction.
27 wxBufferedDC() : m_dc( 0 )
31 // Construct a wxBufferedDC using a user supplied buffer.
32 wxBufferedDC(wxDC
*dc
, const wxBitmap
&buffer
)
39 // Construct a wxBufferedDC with an internal buffer of 'area'
40 // (where area is usually something like the size of the window
42 wxBufferedDC(wxDC
*dc
, const wxSize
&area
)
44 m_buffer( area
.GetWidth(), area
.GetHeight() )
49 // default copy ctor ok.
51 // The usually desired action in the dtor is to blit the buffer.
52 virtual ~wxBufferedDC()
57 // These reimplement the actions of the ctors for two stage creation, but
58 // are not used by the ctors themselves to save a few cpu cycles.
59 void Init(wxDC
*dc
, const wxBitmap
&buffer
)
61 wxASSERT_MSG( m_dc
== 0 && m_buffer
== wxNullBitmap
,
62 _T("wxBufferedDC already initialised") );
68 void Init(wxDC
*dc
, const wxSize
&area
)
70 Init(dc
, wxBitmap(area
.GetWidth(), area
.GetHeight()));
73 // Blits the buffer to the dc, and detaches the dc from the buffer (so it
74 // can be effectively used once only).
76 // Usually called in the dtor or by the dtor of derived classes if the
77 // BufferedDC must blit before the derived class (which may own the dc it's
78 // blitting to) is destroyed.
81 wxASSERT_MSG( m_dc
!= 0,
82 _T("No underlying DC associated with wxBufferedDC (anymore)") );
85 m_buffer
.GetWidth(), m_buffer
.GetHeight(), this,
91 // check that the bitmap is valid and use it
94 wxASSERT_MSG( m_buffer
.Ok(), _T("invalid bitmap in wxBufferedDC") );
96 SelectObject(m_buffer
);
99 // the underlying DC to which we copy everything drawn on this one in
102 // NB: Without the existence of a wxNullDC, this must be a pointer, else it
103 // could probably be a reference.
106 // the buffer (selected in this DC)
109 DECLARE_NO_COPY_CLASS(wxBufferedDC
)
113 // ----------------------------------------------------------------------------
114 // Double buffered PaintDC.
115 // ----------------------------------------------------------------------------
117 // Creates a double buffered wxPaintDC, optionally allowing the
118 // user to specify their own buffer to use.
119 class wxBufferedPaintDC
: public wxBufferedDC
122 // If no bitmap is supplied by the user, a temporary one wil; be created.
123 wxBufferedPaintDC(wxWindow
*window
, const wxBitmap
& buffer
= wxNullBitmap
)
126 window
->PrepareDC( m_paintdc
);
128 if( buffer
!= wxNullBitmap
)
129 Init(&m_paintdc
, buffer
);
131 Init(&m_paintdc
, window
->GetClientSize());
134 // default copy ctor ok.
136 virtual ~wxBufferedPaintDC()
138 // We must UnMask here, else by the time the base class
139 // does it, the PaintDC will have already been destroyed.
146 DECLARE_NO_COPY_CLASS(wxBufferedPaintDC
)
149 #endif // _WX_DCBUFFER_H_