]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dcbuffer.h
WinCE compilation fix
[wxWidgets.git] / include / wx / dcbuffer.h
CommitLineData
67e2efca
RL
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/dcbuffer.h
3// Purpose: wxBufferedDC class
4// Author: Ron Lee <ron@debian.org>
1cc8c8b7 5// Modified by: Vadim Zeitlin (refactored, added bg preservation)
67e2efca
RL
6// Created: 16/03/02
7// RCS-ID: $Id$
8// Copyright: (c) Ron Lee
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_DCBUFFER_H_
13#define _WX_DCBUFFER_H_
14
67e2efca 15#include "wx/dcmemory.h"
aeb500e6 16#include "wx/dcclient.h"
67e2efca 17
67e2efca 18
1cc8c8b7
VZ
19// ----------------------------------------------------------------------------
20// Double buffering helper.
21// ----------------------------------------------------------------------------
67e2efca 22
c0b15381 23class wxBufferedDC : public wxMemoryDC
1cc8c8b7
VZ
24{
25public:
26 // Default ctor, must subsequently call Init for two stage construction.
27 wxBufferedDC() : m_dc( 0 )
28 {
29 }
67e2efca 30
1cc8c8b7 31 // Construct a wxBufferedDC using a user supplied buffer.
dbd22c6a
RL
32 wxBufferedDC(wxDC *dc, const wxBitmap &buffer)
33 : m_dc( dc ),
34 m_buffer( buffer )
35 {
36 UseBuffer();
37 }
67e2efca 38
1cc8c8b7
VZ
39 // Construct a wxBufferedDC with an internal buffer of 'area'
40 // (where area is usually something like the size of the window
41 // being buffered)
dbd22c6a
RL
42 wxBufferedDC(wxDC *dc, const wxSize &area)
43 : m_dc( dc ),
44 m_buffer( area.GetWidth(), area.GetHeight() )
45 {
46 UseBuffer();
47 }
67e2efca
RL
48
49 // default copy ctor ok.
50
1cc8c8b7 51 // The usually desired action in the dtor is to blit the buffer.
dbd22c6a
RL
52 virtual ~wxBufferedDC()
53 {
54 if ( m_dc ) UnMask();
55 }
67e2efca 56
1cc8c8b7
VZ
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.
dbd22c6a
RL
59 void Init(wxDC *dc, const wxBitmap &buffer)
60 {
61 wxASSERT_MSG( m_dc == 0 && m_buffer == wxNullBitmap,
62 _T("wxBufferedDC already initialised") );
63 m_dc = dc;
64 m_buffer = buffer;
65 UseBuffer();
66 }
67
68 void Init(wxDC *dc, const wxSize &area)
69 {
70 Init(dc, wxBitmap(area.GetWidth(), area.GetHeight()));
71 }
67e2efca 72
1cc8c8b7
VZ
73 // Blits the buffer to the dc, and detaches the dc from the buffer (so it
74 // can be effectively used once only).
75 //
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.
dbd22c6a
RL
79 void UnMask()
80 {
81 wxASSERT_MSG( m_dc != 0,
82 _T("No underlying DC associated with wxBufferedDC (anymore)") );
83
7775e41f 84 m_dc->Blit( 0, 0,
dbd22c6a 85 m_buffer.GetWidth(), m_buffer.GetHeight(), this,
7775e41f 86 0, 0 );
dbd22c6a
RL
87 m_dc = NULL;
88 }
67e2efca 89
1cc8c8b7
VZ
90private:
91 // check that the bitmap is valid and use it
92 void UseBuffer()
93 {
94 wxASSERT_MSG( m_buffer.Ok(), _T("invalid bitmap in wxBufferedDC") );
95
96 SelectObject(m_buffer);
97 }
98
74f4dabb
VZ
99 // the underlying DC to which we copy everything drawn on this one in
100 // UnMask()
101 //
102 // NB: Without the existence of a wxNullDC, this must be a pointer, else it
103 // could probably be a reference.
104 wxDC *m_dc;
67e2efca 105
74f4dabb
VZ
106 // the buffer (selected in this DC)
107 wxBitmap m_buffer;
22f3361e
VZ
108
109 DECLARE_NO_COPY_CLASS(wxBufferedDC)
67e2efca
RL
110};
111
112
1cc8c8b7
VZ
113// ----------------------------------------------------------------------------
114// Double buffered PaintDC.
115// ----------------------------------------------------------------------------
67e2efca
RL
116
117// Creates a double buffered wxPaintDC, optionally allowing the
118// user to specify their own buffer to use.
c0b15381 119class wxBufferedPaintDC : public wxBufferedDC
67e2efca 120{
67e2efca 121public:
dbd22c6a
RL
122 // If no bitmap is supplied by the user, a temporary one wil; be created.
123 wxBufferedPaintDC(wxWindow *window, const wxBitmap& buffer = wxNullBitmap)
a66f2f42 124 : m_paintdc(window)
1cc8c8b7 125 {
7775e41f
RD
126 window->PrepareDC( m_paintdc );
127
dbd22c6a
RL
128 if( buffer != wxNullBitmap )
129 Init(&m_paintdc, buffer);
130 else
131 Init(&m_paintdc, window->GetClientSize());
1cc8c8b7 132 }
67e2efca
RL
133
134 // default copy ctor ok.
135
1cc8c8b7
VZ
136 virtual ~wxBufferedPaintDC()
137 {
138 // We must UnMask here, else by the time the base class
139 // does it, the PaintDC will have already been destroyed.
140 UnMask();
141 }
142
143private:
1cc8c8b7 144 wxPaintDC m_paintdc;
fc7a2a60
VZ
145
146 DECLARE_NO_COPY_CLASS(wxBufferedPaintDC)
67e2efca
RL
147};
148
67e2efca
RL
149#endif // _WX_DCBUFFER_H_
150