2002-03-17 01:34:06 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/dcbuffer.h
|
|
|
|
// Purpose: wxBufferedDC class
|
|
|
|
// Author: Ron Lee <ron@debian.org>
|
2004-02-07 11:16:36 -05:00
|
|
|
// Modified by: Vadim Zeitlin (refactored, added bg preservation)
|
2002-03-17 01:34:06 -05:00
|
|
|
// Created: 16/03/02
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Ron Lee
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_DCBUFFER_H_
|
|
|
|
#define _WX_DCBUFFER_H_
|
|
|
|
|
2003-08-09 08:38:21 -04:00
|
|
|
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
2004-02-07 11:16:36 -05:00
|
|
|
#pragma interface "dcbuffer.h"
|
2002-03-17 01:34:06 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/dcmemory.h"
|
2003-07-21 14:57:04 -04:00
|
|
|
#include "wx/dcclient.h"
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// flags for wxBufferedDC ctor/Init()
|
|
|
|
enum
|
2002-03-17 01:34:06 -05:00
|
|
|
{
|
2004-02-07 11:16:36 -05:00
|
|
|
// this is more efficient and hence default
|
|
|
|
wxBUFFER_DC_OVERWRITE_BG = 0,
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// preserve the old background: more time consuming
|
|
|
|
wxBUFFER_DC_PRESERVE_BG = 1,
|
2002-03-17 01:34:06 -05:00
|
|
|
|
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// flags used by default
|
|
|
|
wxBUFFER_DC_DEFAULT = wxBUFFER_DC_PRESERVE_BG
|
|
|
|
};
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Double buffering helper.
|
|
|
|
// ----------------------------------------------------------------------------
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
class WXDLLIMPEXP_ADV wxBufferedDC : public wxMemoryDC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Default ctor, must subsequently call Init for two stage construction.
|
|
|
|
wxBufferedDC() : m_dc( 0 )
|
|
|
|
{
|
|
|
|
}
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// Construct a wxBufferedDC using a user supplied buffer.
|
|
|
|
wxBufferedDC(wxDC *dc, const wxBitmap &buffer);
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// Construct a wxBufferedDC with an internal buffer of 'area'
|
|
|
|
// (where area is usually something like the size of the window
|
|
|
|
// being buffered)
|
|
|
|
wxBufferedDC(wxDC *dc, const wxSize &area, int flags = wxBUFFER_DC_DEFAULT);
|
2002-03-17 01:34:06 -05:00
|
|
|
|
|
|
|
// default copy ctor ok.
|
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// The usually desired action in the dtor is to blit the buffer.
|
|
|
|
virtual ~wxBufferedDC() { if ( m_dc ) UnMask(); }
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// These reimplement the actions of the ctors for two stage creation, but
|
|
|
|
// are not used by the ctors themselves to save a few cpu cycles.
|
|
|
|
void Init(wxDC *dc, const wxBitmap &bitmap);
|
|
|
|
void Init(wxDC *dc, const wxSize &area, int flags = wxBUFFER_DC_DEFAULT);
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// Blits the buffer to the dc, and detaches the dc from the buffer (so it
|
|
|
|
// can be effectively used once only).
|
|
|
|
//
|
|
|
|
// Usually called in the dtor or by the dtor of derived classes if the
|
|
|
|
// BufferedDC must blit before the derived class (which may own the dc it's
|
|
|
|
// blitting to) is destroyed.
|
|
|
|
void UnMask();
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
private:
|
|
|
|
// check that the bitmap is valid and use it
|
|
|
|
void UseBuffer()
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( m_buffer.Ok(), _T("invalid bitmap in wxBufferedDC") );
|
|
|
|
|
|
|
|
SelectObject(m_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// preserve the background if necessary
|
|
|
|
void SaveBg(const wxSize& area, int flags)
|
|
|
|
{
|
|
|
|
if ( flags & wxBUFFER_DC_PRESERVE_BG )
|
|
|
|
{
|
|
|
|
Blit(0, 0, area.GetWidth(), area.GetHeight(), m_dc, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Without the existence of a wxNullDC, this must be
|
|
|
|
// a pointer, else it could probably be a reference.
|
|
|
|
wxDC *m_dc;
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
wxBitmap m_buffer;
|
2003-01-02 18:38:11 -05:00
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(wxBufferedDC)
|
2002-03-17 01:34:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Double buffered PaintDC.
|
|
|
|
// ----------------------------------------------------------------------------
|
2002-03-17 01:34:06 -05:00
|
|
|
|
|
|
|
// Creates a double buffered wxPaintDC, optionally allowing the
|
|
|
|
// user to specify their own buffer to use.
|
2003-08-01 21:04:55 -04:00
|
|
|
class WXDLLIMPEXP_ADV wxBufferedPaintDC : public wxBufferedDC
|
2002-03-17 01:34:06 -05:00
|
|
|
{
|
|
|
|
public:
|
2004-02-07 11:16:36 -05:00
|
|
|
// this ctor creates a bitmap of the size of the window for buffering
|
|
|
|
wxBufferedPaintDC(wxWindow *window, int flags = wxBUFFER_DC_DEFAULT)
|
2004-02-07 16:50:39 -05:00
|
|
|
: m_paintdc(window)
|
2004-02-07 11:16:36 -05:00
|
|
|
{
|
|
|
|
Prepare(window);
|
2004-02-07 16:50:39 -05:00
|
|
|
|
|
|
|
Init(&m_paintdc, window->GetClientSize(), flags);
|
2004-02-07 11:16:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// the bitmap must be valid here
|
|
|
|
wxBufferedPaintDC(wxWindow *window, const wxBitmap& buffer)
|
2004-02-07 16:50:39 -05:00
|
|
|
: m_paintdc(window)
|
2004-02-07 11:16:36 -05:00
|
|
|
{
|
|
|
|
Prepare(window);
|
2004-02-07 16:50:39 -05:00
|
|
|
|
|
|
|
Init(&m_paintdc, buffer);
|
2004-02-07 11:16:36 -05:00
|
|
|
}
|
2002-03-17 01:34:06 -05:00
|
|
|
|
|
|
|
// default copy ctor ok.
|
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
virtual ~wxBufferedPaintDC()
|
|
|
|
{
|
|
|
|
// We must UnMask here, else by the time the base class
|
|
|
|
// does it, the PaintDC will have already been destroyed.
|
|
|
|
UnMask();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// prepare the underlying DC
|
|
|
|
void Prepare(wxWindow *window)
|
|
|
|
{
|
|
|
|
window->PrepareDC(m_paintdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPaintDC m_paintdc;
|
2003-07-21 20:24:07 -04:00
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(wxBufferedPaintDC)
|
2002-03-17 01:34:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _WX_DCBUFFER_H_
|
|
|
|
|