]>
Commit | Line | Data |
---|---|---|
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 | ||
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
1cc8c8b7 | 16 | #pragma interface "dcbuffer.h" |
67e2efca RL |
17 | #endif |
18 | ||
19 | #include "wx/dcmemory.h" | |
aeb500e6 | 20 | #include "wx/dcclient.h" |
67e2efca | 21 | |
1cc8c8b7 VZ |
22 | // flags for wxBufferedDC ctor/Init() |
23 | enum | |
67e2efca | 24 | { |
1cc8c8b7 VZ |
25 | // this is more efficient and hence default |
26 | wxBUFFER_DC_OVERWRITE_BG = 0, | |
67e2efca | 27 | |
1cc8c8b7 VZ |
28 | // preserve the old background: more time consuming |
29 | wxBUFFER_DC_PRESERVE_BG = 1, | |
67e2efca | 30 | |
67e2efca | 31 | |
1cc8c8b7 VZ |
32 | // flags used by default |
33 | wxBUFFER_DC_DEFAULT = wxBUFFER_DC_PRESERVE_BG | |
34 | }; | |
67e2efca | 35 | |
1cc8c8b7 VZ |
36 | // ---------------------------------------------------------------------------- |
37 | // Double buffering helper. | |
38 | // ---------------------------------------------------------------------------- | |
67e2efca | 39 | |
1cc8c8b7 VZ |
40 | class WXDLLIMPEXP_ADV wxBufferedDC : public wxMemoryDC |
41 | { | |
42 | public: | |
43 | // Default ctor, must subsequently call Init for two stage construction. | |
44 | wxBufferedDC() : m_dc( 0 ) | |
45 | { | |
46 | } | |
67e2efca | 47 | |
1cc8c8b7 VZ |
48 | // Construct a wxBufferedDC using a user supplied buffer. |
49 | wxBufferedDC(wxDC *dc, const wxBitmap &buffer); | |
67e2efca | 50 | |
1cc8c8b7 VZ |
51 | // Construct a wxBufferedDC with an internal buffer of 'area' |
52 | // (where area is usually something like the size of the window | |
53 | // being buffered) | |
54 | wxBufferedDC(wxDC *dc, const wxSize &area, int flags = wxBUFFER_DC_DEFAULT); | |
67e2efca RL |
55 | |
56 | // default copy ctor ok. | |
57 | ||
1cc8c8b7 VZ |
58 | // The usually desired action in the dtor is to blit the buffer. |
59 | virtual ~wxBufferedDC() { if ( m_dc ) UnMask(); } | |
67e2efca | 60 | |
1cc8c8b7 VZ |
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); | |
67e2efca | 65 | |
1cc8c8b7 VZ |
66 | // Blits the buffer to the dc, and detaches the dc from the buffer (so it |
67 | // can be effectively used once only). | |
68 | // | |
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. | |
72 | void UnMask(); | |
67e2efca | 73 | |
1cc8c8b7 VZ |
74 | private: |
75 | // check that the bitmap is valid and use it | |
76 | void UseBuffer() | |
77 | { | |
78 | wxASSERT_MSG( m_buffer.Ok(), _T("invalid bitmap in wxBufferedDC") ); | |
79 | ||
80 | SelectObject(m_buffer); | |
81 | } | |
82 | ||
83 | // preserve the background if necessary | |
84 | void SaveBg(const wxSize& area, int flags) | |
85 | { | |
86 | if ( flags & wxBUFFER_DC_PRESERVE_BG ) | |
87 | { | |
88 | Blit(0, 0, area.GetWidth(), area.GetHeight(), m_dc, 0, 0); | |
89 | } | |
90 | } | |
91 | ||
92 | // Without the existence of a wxNullDC, this must be | |
93 | // a pointer, else it could probably be a reference. | |
94 | wxDC *m_dc; | |
67e2efca | 95 | |
1cc8c8b7 | 96 | wxBitmap m_buffer; |
22f3361e VZ |
97 | |
98 | DECLARE_NO_COPY_CLASS(wxBufferedDC) | |
67e2efca RL |
99 | }; |
100 | ||
101 | ||
1cc8c8b7 VZ |
102 | // ---------------------------------------------------------------------------- |
103 | // Double buffered PaintDC. | |
104 | // ---------------------------------------------------------------------------- | |
67e2efca RL |
105 | |
106 | // Creates a double buffered wxPaintDC, optionally allowing the | |
107 | // user to specify their own buffer to use. | |
12f190b0 | 108 | class WXDLLIMPEXP_ADV wxBufferedPaintDC : public wxBufferedDC |
67e2efca | 109 | { |
67e2efca | 110 | public: |
1cc8c8b7 VZ |
111 | // this ctor creates a bitmap of the size of the window for buffering |
112 | wxBufferedPaintDC(wxWindow *window, int flags = wxBUFFER_DC_DEFAULT) | |
a66f2f42 | 113 | : m_paintdc(window) |
1cc8c8b7 VZ |
114 | { |
115 | Prepare(window); | |
a66f2f42 VZ |
116 | |
117 | Init(&m_paintdc, window->GetClientSize(), flags); | |
1cc8c8b7 VZ |
118 | } |
119 | ||
120 | // the bitmap must be valid here | |
121 | wxBufferedPaintDC(wxWindow *window, const wxBitmap& buffer) | |
a66f2f42 | 122 | : m_paintdc(window) |
1cc8c8b7 VZ |
123 | { |
124 | Prepare(window); | |
a66f2f42 VZ |
125 | |
126 | Init(&m_paintdc, buffer); | |
1cc8c8b7 | 127 | } |
67e2efca RL |
128 | |
129 | // default copy ctor ok. | |
130 | ||
1cc8c8b7 VZ |
131 | virtual ~wxBufferedPaintDC() |
132 | { | |
133 | // We must UnMask here, else by the time the base class | |
134 | // does it, the PaintDC will have already been destroyed. | |
135 | UnMask(); | |
136 | } | |
137 | ||
138 | private: | |
139 | // prepare the underlying DC | |
140 | void Prepare(wxWindow *window) | |
141 | { | |
142 | window->PrepareDC(m_paintdc); | |
143 | } | |
144 | ||
145 | wxPaintDC m_paintdc; | |
fc7a2a60 VZ |
146 | |
147 | DECLARE_NO_COPY_CLASS(wxBufferedPaintDC) | |
67e2efca RL |
148 | }; |
149 | ||
67e2efca RL |
150 | #endif // _WX_DCBUFFER_H_ |
151 |