// Default ctor, must subsequently call Init for two stage construction.
wxBufferedDC()
: m_dc(NULL),
- m_buffer(NULL),
m_style(0)
{
}
wxBufferedDC(wxDC *dc,
const wxBitmap& buffer = wxNullBitmap,
int style = wxBUFFER_CLIENT_AREA)
- : m_dc(NULL),
- m_buffer(NULL)
+ : m_dc(NULL)
{
Init(dc, buffer, style);
}
// (where area is usually something like the size of the window
// being buffered)
wxBufferedDC(wxDC *dc, const wxSize& area, int style = wxBUFFER_CLIENT_AREA)
- : m_dc(NULL),
- m_buffer(NULL)
-
+ : m_dc(NULL)
{
Init(dc, area, style);
}
{
InitCommon(dc, style);
- m_buffer = &buffer;
+ m_buffer = buffer;
UseBuffer();
}
// blitting to) is destroyed.
void UnMask()
{
- wxCHECK_RET( m_dc, _T("No underlying DC in wxBufferedDC") );
+ wxCHECK_RET( m_dc, _T("no underlying wxDC?") );
+ wxASSERT_MSG( m_buffer.IsOk(), _T("invalid backing store") );
wxCoord x = 0,
y = 0;
if ( m_style & wxBUFFER_CLIENT_AREA )
GetDeviceOrigin(&x, &y);
- m_dc->Blit(0, 0, m_buffer->GetWidth(), m_buffer->GetHeight(),
+ m_dc->Blit(0, 0, m_buffer.GetWidth(), m_buffer.GetHeight(),
this, -x, -y );
m_dc = NULL;
}
// common part of Init()s
void InitCommon(wxDC *dc, int style)
{
- wxASSERT_MSG( !m_dc && !m_buffer, _T("wxBufferedDC already initialised") );
+ wxASSERT_MSG( !m_dc, _T("wxBufferedDC already initialised") );
wxCHECK_RET( dc, _T("can't associate NULL DC with wxBufferedDC") );
m_dc = dc;
// could probably be a reference.
wxDC *m_dc;
- // the buffer (selected in this DC)
- const wxBitmap *m_buffer;
+ // the buffer (selected in this DC), initially invalid
+ wxBitmap m_buffer;
// the buffering style
int m_style;
#include "wx/dcbuffer.h"
-
// ============================================================================
// implementation
// ============================================================================
-// ============================================================================
-// wxSharedDCBufferManager
-// Helper class to free shared buffer when the app exists.
-// ============================================================================
+// ----------------------------------------------------------------------------
+// wxSharedDCBufferManager: helper class maintaining backing store bitmap
+// ----------------------------------------------------------------------------
class wxSharedDCBufferManager
{
- friend class wxBufferedDC;
public:
-
wxSharedDCBufferManager() { }
~wxSharedDCBufferManager() { }
- wxBitmap* GetBuffer(int w, int h)
+ wxBitmap GetBuffer(int w, int h)
{
if ( !m_buffer.IsOk() ||
w > m_buffer.GetWidth() ||
m_buffer = wxBitmap(w, h);
}
- return &m_buffer;
+ return m_buffer;
}
private:
- wxBitmap m_buffer;
+ wxBitmap m_buffer;
};
static wxSharedDCBufferManager gs_sharedDCBufferManager;
void wxBufferedDC::UseBuffer(wxCoord w, wxCoord h)
{
- if ( !m_buffer )
+ if ( !m_buffer.IsOk() )
{
if ( w == -1 || h == -1 )
m_dc->GetSize(&w, &h);
m_buffer = gs_sharedDCBufferManager.GetBuffer(w, h);
}
- SelectObject(*m_buffer);
+ SelectObject(m_buffer);
}