]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/dcbuffer.h
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"
17 #include "wx/window.h"
19 // ----------------------------------------------------------------------------
20 // Double buffering helper.
21 // ----------------------------------------------------------------------------
23 // Assumes the buffer bitmap covers the entire scrolled window,
24 // and prepares the window DC accordingly
25 #define wxBUFFER_VIRTUAL_AREA 0x01
27 // Assumes the buffer bitmap only covers the client area;
28 // does not prepare the window DC
29 #define wxBUFFER_CLIENT_AREA 0x02
31 class wxBufferedDC
: public wxMemoryDC
34 // Default ctor, must subsequently call Init for two stage construction.
35 wxBufferedDC() : m_dc( 0 ), m_style(0)
39 // Construct a wxBufferedDC using a user supplied buffer.
40 wxBufferedDC(wxDC
*dc
,
41 const wxBitmap
&buffer
= wxNullBitmap
,
42 int style
= wxBUFFER_CLIENT_AREA
)
50 // Construct a wxBufferedDC with an internal buffer of 'area'
51 // (where area is usually something like the size of the window
53 wxBufferedDC(wxDC
*dc
, const wxSize
&area
, int style
= wxBUFFER_CLIENT_AREA
)
55 m_buffer( area
.GetWidth(), area
.GetHeight() ),
62 // default copy ctor ok.
64 // The usually desired action in the dtor is to blit the buffer.
65 virtual ~wxBufferedDC()
70 // These reimplement the actions of the ctors for two stage creation, but
71 // are not used by the ctors themselves to save a few cpu cycles.
73 const wxBitmap
&buffer
=wxNullBitmap
,
74 int style
= wxBUFFER_CLIENT_AREA
)
76 wxASSERT_MSG( m_dc
== 0 && m_buffer
== wxNullBitmap
,
77 _T("wxBufferedDC already initialised") );
84 void Init(wxDC
*dc
, const wxSize
&area
, int style
= wxBUFFER_CLIENT_AREA
)
86 Init(dc
, wxBitmap(area
.GetWidth(), area
.GetHeight()), style
);
89 // Blits the buffer to the dc, and detaches the dc from the buffer (so it
90 // can be effectively used once only).
92 // Usually called in the dtor or by the dtor of derived classes if the
93 // BufferedDC must blit before the derived class (which may own the dc it's
94 // blitting to) is destroyed.
97 wxASSERT_MSG( m_dc
!= 0,
98 _T("No underlying DC associated with wxBufferedDC (anymore)") );
102 if (m_style
& wxBUFFER_CLIENT_AREA
)
103 GetDeviceOrigin(& x
, & y
);
106 m_buffer
.GetWidth(), m_buffer
.GetHeight(), this,
111 // Set and get the style
112 void SetStyle(int style
) { m_style
= style
; }
113 int GetStyle() const { return m_style
; }
116 // check that the bitmap is valid and use it
122 m_dc
->GetSize(&w
, &h
);
123 m_buffer
= wxBitmap(w
, h
);
126 SelectObject(m_buffer
);
129 // the underlying DC to which we copy everything drawn on this one in
132 // NB: Without the existence of a wxNullDC, this must be a pointer, else it
133 // could probably be a reference.
136 // the buffer (selected in this DC)
139 // the buffering style
142 DECLARE_NO_COPY_CLASS(wxBufferedDC
)
146 // ----------------------------------------------------------------------------
147 // Double buffered PaintDC.
148 // ----------------------------------------------------------------------------
150 // Creates a double buffered wxPaintDC, optionally allowing the
151 // user to specify their own buffer to use.
152 class wxBufferedPaintDC
: public wxBufferedDC
155 // If no bitmap is supplied by the user, a temporary one will be created.
156 wxBufferedPaintDC(wxWindow
*window
, const wxBitmap
& buffer
, int style
= wxBUFFER_CLIENT_AREA
)
159 // If we're buffering the virtual window, scale the paint DC as well
160 if (style
& wxBUFFER_VIRTUAL_AREA
)
161 window
->PrepareDC( m_paintdc
);
163 if( buffer
!= wxNullBitmap
)
164 Init(&m_paintdc
, buffer
, style
);
166 Init(&m_paintdc
, window
->GetClientSize(), style
);
169 // If no bitmap is supplied by the user, a temporary one will be created.
170 wxBufferedPaintDC(wxWindow
*window
, int style
= wxBUFFER_CLIENT_AREA
)
173 // If we're using the virtual window, scale the paint DC as well
174 if (style
& wxBUFFER_VIRTUAL_AREA
)
175 window
->PrepareDC( m_paintdc
);
177 Init(&m_paintdc
, window
->GetClientSize(), style
);
180 // default copy ctor ok.
182 virtual ~wxBufferedPaintDC()
184 // We must UnMask here, else by the time the base class
185 // does it, the PaintDC will have already been destroyed.
192 DECLARE_NO_COPY_CLASS(wxBufferedPaintDC
)
195 #endif // _WX_DCBUFFER_H_