2002-03-17 06:34:06 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/dcbuffer.h
|
|
|
|
// Purpose: wxBufferedDC class
|
|
|
|
// Author: Ron Lee <ron@debian.org>
|
2004-02-07 16:16:36 +00:00
|
|
|
// Modified by: Vadim Zeitlin (refactored, added bg preservation)
|
2002-03-17 06:34:06 +00:00
|
|
|
// Created: 16/03/02
|
|
|
|
// Copyright: (c) Ron Lee
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
2002-03-17 06:34:06 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_DCBUFFER_H_
|
|
|
|
#define _WX_DCBUFFER_H_
|
|
|
|
|
|
|
|
#include "wx/dcmemory.h"
|
2003-07-21 18:57:04 +00:00
|
|
|
#include "wx/dcclient.h"
|
2005-01-07 18:24:54 +00:00
|
|
|
#include "wx/window.h"
|
2002-03-17 06:34:06 +00:00
|
|
|
|
2006-10-09 16:39:34 +00:00
|
|
|
// Split platforms into two groups - those which have well-working
|
|
|
|
// double-buffering by default, and those which do not.
|
2014-08-24 01:50:11 +00:00
|
|
|
#if defined(__WXMAC__) || defined(__WXGTK20__) || defined(__WXDFB__) || defined(__WXQT__)
|
2006-10-09 16:39:34 +00:00
|
|
|
#define wxALWAYS_NATIVE_DOUBLE_BUFFER 1
|
|
|
|
#else
|
|
|
|
#define wxALWAYS_NATIVE_DOUBLE_BUFFER 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-02-07 16:16:36 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Double buffering helper.
|
|
|
|
// ----------------------------------------------------------------------------
|
2002-03-17 06:34:06 +00:00
|
|
|
|
2005-03-03 06:56:15 +00:00
|
|
|
// Assumes the buffer bitmap covers the entire scrolled window,
|
|
|
|
// and prepares the window DC accordingly
|
|
|
|
#define wxBUFFER_VIRTUAL_AREA 0x01
|
|
|
|
|
|
|
|
// Assumes the buffer bitmap only covers the client area;
|
|
|
|
// does not prepare the window DC
|
|
|
|
#define wxBUFFER_CLIENT_AREA 0x02
|
|
|
|
|
2007-03-10 18:09:38 +00:00
|
|
|
// Set when not using specific buffer bitmap. Note that this
|
|
|
|
// is private style and not returned by GetStyle.
|
|
|
|
#define wxBUFFER_USES_SHARED_BUFFER 0x04
|
|
|
|
|
2007-11-30 13:48:22 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxBufferedDC : public wxMemoryDC
|
2004-02-07 16:16:36 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Default ctor, must subsequently call Init for two stage construction.
|
2006-10-22 13:00:58 +00:00
|
|
|
wxBufferedDC()
|
|
|
|
: m_dc(NULL),
|
2006-11-01 02:07:36 +00:00
|
|
|
m_buffer(NULL),
|
2006-10-22 13:00:58 +00:00
|
|
|
m_style(0)
|
2004-02-07 16:16:36 +00:00
|
|
|
{
|
|
|
|
}
|
2002-03-17 06:34:06 +00:00
|
|
|
|
2004-02-07 16:16:36 +00:00
|
|
|
// Construct a wxBufferedDC using a user supplied buffer.
|
2005-03-08 00:38:53 +00:00
|
|
|
wxBufferedDC(wxDC *dc,
|
2006-11-01 02:07:36 +00:00
|
|
|
wxBitmap& buffer = wxNullBitmap,
|
2005-03-08 00:38:53 +00:00
|
|
|
int style = wxBUFFER_CLIENT_AREA)
|
2006-11-01 02:07:36 +00:00
|
|
|
: m_dc(NULL), m_buffer(NULL)
|
2004-02-19 06:23:01 +00:00
|
|
|
{
|
2006-10-22 13:04:28 +00:00
|
|
|
Init(dc, buffer, style);
|
2004-02-19 06:23:01 +00:00
|
|
|
}
|
2002-03-17 06:34:06 +00:00
|
|
|
|
2004-02-07 16:16:36 +00:00
|
|
|
// Construct a wxBufferedDC with an internal buffer of 'area'
|
|
|
|
// (where area is usually something like the size of the window
|
|
|
|
// being buffered)
|
2006-10-22 13:04:28 +00:00
|
|
|
wxBufferedDC(wxDC *dc, const wxSize& area, int style = wxBUFFER_CLIENT_AREA)
|
2006-11-01 02:07:36 +00:00
|
|
|
: m_dc(NULL), m_buffer(NULL)
|
2004-02-19 06:23:01 +00:00
|
|
|
{
|
2006-10-22 13:04:28 +00:00
|
|
|
Init(dc, area, style);
|
2004-02-19 06:23:01 +00:00
|
|
|
}
|
2002-03-17 06:34:06 +00:00
|
|
|
|
2004-02-07 16:16:36 +00:00
|
|
|
// The usually desired action in the dtor is to blit the buffer.
|
2004-02-19 06:23:01 +00:00
|
|
|
virtual ~wxBufferedDC()
|
|
|
|
{
|
2006-10-22 13:00:58 +00:00
|
|
|
if ( m_dc )
|
|
|
|
UnMask();
|
2004-02-19 06:23:01 +00:00
|
|
|
}
|
2002-03-17 06:34:06 +00:00
|
|
|
|
2006-10-22 13:04:28 +00:00
|
|
|
// These reimplement the actions of the ctors for two stage creation
|
2005-03-08 00:38:53 +00:00
|
|
|
void Init(wxDC *dc,
|
2006-11-01 02:07:36 +00:00
|
|
|
wxBitmap& buffer = wxNullBitmap,
|
2005-03-08 00:38:53 +00:00
|
|
|
int style = wxBUFFER_CLIENT_AREA)
|
2004-02-19 06:23:01 +00:00
|
|
|
{
|
2006-10-22 13:00:58 +00:00
|
|
|
InitCommon(dc, style);
|
|
|
|
|
2006-11-01 02:07:36 +00:00
|
|
|
m_buffer = &buffer;
|
2006-10-22 13:00:58 +00:00
|
|
|
|
2004-02-19 06:23:01 +00:00
|
|
|
UseBuffer();
|
|
|
|
}
|
|
|
|
|
2006-10-13 19:14:21 +00:00
|
|
|
void Init(wxDC *dc, const wxSize &area, int style = wxBUFFER_CLIENT_AREA)
|
2004-02-19 06:23:01 +00:00
|
|
|
{
|
2006-10-22 13:00:58 +00:00
|
|
|
InitCommon(dc, style);
|
|
|
|
|
2006-10-18 22:36:36 +00:00
|
|
|
UseBuffer(area.x, area.y);
|
2004-02-19 06:23:01 +00:00
|
|
|
}
|
2002-03-17 06:34:06 +00:00
|
|
|
|
2004-02-07 16:16:36 +00: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.
|
2007-03-10 18:09:38 +00:00
|
|
|
void UnMask();
|
2002-03-17 06:34:06 +00:00
|
|
|
|
2005-03-03 06:56:15 +00:00
|
|
|
// Set and get the style
|
|
|
|
void SetStyle(int style) { m_style = style; }
|
2007-03-10 18:09:38 +00:00
|
|
|
int GetStyle() const { return m_style & ~wxBUFFER_USES_SHARED_BUFFER; }
|
2005-03-03 06:56:15 +00:00
|
|
|
|
2004-02-07 16:16:36 +00:00
|
|
|
private:
|
2006-10-22 13:00:58 +00:00
|
|
|
// common part of Init()s
|
|
|
|
void InitCommon(wxDC *dc, int style)
|
|
|
|
{
|
2009-07-23 20:30:22 +00:00
|
|
|
wxASSERT_MSG( !m_dc, wxT("wxBufferedDC already initialised") );
|
2006-10-22 13:00:58 +00:00
|
|
|
|
|
|
|
m_dc = dc;
|
|
|
|
m_style = style;
|
|
|
|
}
|
|
|
|
|
2006-10-13 19:14:21 +00:00
|
|
|
// check that the bitmap is valid and use it
|
2006-10-18 22:36:36 +00:00
|
|
|
void UseBuffer(wxCoord w = -1, wxCoord h = -1);
|
2004-02-07 16:16:36 +00:00
|
|
|
|
2006-10-13 19:14:21 +00:00
|
|
|
// the underlying DC to which we copy everything drawn on this one in
|
|
|
|
// UnMask()
|
2004-02-08 18:54:04 +00:00
|
|
|
//
|
|
|
|
// NB: Without the existence of a wxNullDC, this must be a pointer, else it
|
|
|
|
// could probably be a reference.
|
2006-10-13 19:14:21 +00:00
|
|
|
wxDC *m_dc;
|
2002-03-17 06:34:06 +00:00
|
|
|
|
2006-10-23 22:06:01 +00:00
|
|
|
// the buffer (selected in this DC), initially invalid
|
2006-11-01 02:07:36 +00:00
|
|
|
wxBitmap *m_buffer;
|
2003-01-02 23:38:11 +00:00
|
|
|
|
2005-03-03 06:56:15 +00:00
|
|
|
// the buffering style
|
2006-10-13 19:14:21 +00:00
|
|
|
int m_style;
|
2005-03-03 06:56:15 +00:00
|
|
|
|
2012-06-08 19:26:19 +00:00
|
|
|
wxSize m_area;
|
2019-01-30 16:28:08 +00:00
|
|
|
|
2015-04-23 11:49:01 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxBufferedDC);
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxBufferedDC);
|
2002-03-17 06:34:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-02-07 16:16:36 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Double buffered PaintDC.
|
|
|
|
// ----------------------------------------------------------------------------
|
2002-03-17 06:34:06 +00:00
|
|
|
|
|
|
|
// Creates a double buffered wxPaintDC, optionally allowing the
|
|
|
|
// user to specify their own buffer to use.
|
2007-11-30 13:48:22 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxBufferedPaintDC : public wxBufferedDC
|
2002-03-17 06:34:06 +00:00
|
|
|
{
|
|
|
|
public:
|
2005-03-03 06:56:15 +00:00
|
|
|
// If no bitmap is supplied by the user, a temporary one will be created.
|
2006-11-01 02:07:36 +00:00
|
|
|
wxBufferedPaintDC(wxWindow *window, wxBitmap& buffer, int style = wxBUFFER_CLIENT_AREA)
|
2004-02-07 21:50:39 +00:00
|
|
|
: m_paintdc(window)
|
2004-02-07 16:16:36 +00:00
|
|
|
{
|
2019-01-13 14:45:06 +00:00
|
|
|
SetWindow(window);
|
|
|
|
|
2005-03-03 06:56:15 +00:00
|
|
|
// If we're buffering the virtual window, scale the paint DC as well
|
|
|
|
if (style & wxBUFFER_VIRTUAL_AREA)
|
|
|
|
window->PrepareDC( m_paintdc );
|
|
|
|
|
2006-10-30 19:26:48 +00:00
|
|
|
if( buffer.IsOk() )
|
2005-03-03 06:56:15 +00:00
|
|
|
Init(&m_paintdc, buffer, style);
|
2004-02-19 06:23:01 +00:00
|
|
|
else
|
2007-03-05 08:54:13 +00:00
|
|
|
Init(&m_paintdc, GetBufferedSize(window, style), style);
|
2005-03-03 06:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If no bitmap is supplied by the user, a temporary one will be created.
|
|
|
|
wxBufferedPaintDC(wxWindow *window, int style = wxBUFFER_CLIENT_AREA)
|
|
|
|
: m_paintdc(window)
|
|
|
|
{
|
2019-01-13 14:45:06 +00:00
|
|
|
SetWindow(window);
|
|
|
|
|
2005-03-03 06:56:15 +00:00
|
|
|
// If we're using the virtual window, scale the paint DC as well
|
|
|
|
if (style & wxBUFFER_VIRTUAL_AREA)
|
|
|
|
window->PrepareDC( m_paintdc );
|
|
|
|
|
2007-03-05 08:54:13 +00:00
|
|
|
Init(&m_paintdc, GetBufferedSize(window, style), style);
|
2004-02-07 16:16:36 +00:00
|
|
|
}
|
2002-03-17 06:34:06 +00:00
|
|
|
|
|
|
|
// default copy ctor ok.
|
|
|
|
|
2004-02-07 16:16:36 +00:00
|
|
|
virtual ~wxBufferedPaintDC()
|
|
|
|
{
|
|
|
|
// We must UnMask here, else by the time the base class
|
|
|
|
// does it, the PaintDC will have already been destroyed.
|
|
|
|
UnMask();
|
|
|
|
}
|
|
|
|
|
2007-03-05 08:54:13 +00:00
|
|
|
protected:
|
|
|
|
// return the size needed by the buffer: this depends on whether we're
|
|
|
|
// buffering just the currently shown part or the total (scrolled) window
|
|
|
|
static wxSize GetBufferedSize(wxWindow *window, int style)
|
|
|
|
{
|
|
|
|
return style & wxBUFFER_VIRTUAL_AREA ? window->GetVirtualSize()
|
|
|
|
: window->GetClientSize();
|
|
|
|
}
|
|
|
|
|
2004-02-07 16:16:36 +00:00
|
|
|
private:
|
|
|
|
wxPaintDC m_paintdc;
|
2003-07-22 00:24:07 +00:00
|
|
|
|
2015-04-23 11:49:01 +00:00
|
|
|
wxDECLARE_ABSTRACT_CLASS(wxBufferedPaintDC);
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxBufferedPaintDC);
|
2002-03-17 06:34:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-10-09 16:39:34 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// wxAutoBufferedPaintDC is a wxPaintDC in toolkits which have double-
|
|
|
|
// buffering by default. Otherwise it is a wxBufferedPaintDC. Thus,
|
|
|
|
// you can only expect it work with a simple constructor that
|
|
|
|
// accepts single wxWindow* argument.
|
|
|
|
//
|
|
|
|
#if wxALWAYS_NATIVE_DOUBLE_BUFFER
|
|
|
|
#define wxAutoBufferedPaintDCBase wxPaintDC
|
|
|
|
#else
|
|
|
|
#define wxAutoBufferedPaintDCBase wxBufferedPaintDC
|
|
|
|
#endif
|
|
|
|
|
2007-11-30 13:48:22 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxAutoBufferedPaintDC : public wxAutoBufferedPaintDCBase
|
2006-10-09 16:39:34 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
wxAutoBufferedPaintDC(wxWindow* win)
|
|
|
|
: wxAutoBufferedPaintDCBase(win)
|
|
|
|
{
|
2009-06-16 23:04:42 +00:00
|
|
|
wxASSERT_MSG( win->GetBackgroundStyle() == wxBG_STYLE_PAINT,
|
|
|
|
"You need to call SetBackgroundStyle(wxBG_STYLE_PAINT) in ctor, "
|
2009-03-21 23:36:37 +00:00
|
|
|
"and also, if needed, paint the background in wxEVT_PAINT handler."
|
|
|
|
);
|
2006-10-09 16:39:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~wxAutoBufferedPaintDC() { }
|
|
|
|
|
|
|
|
private:
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxAutoBufferedPaintDC);
|
2006-10-09 16:39:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-10-13 19:14:21 +00:00
|
|
|
// Check if the window is natively double buffered and will return a wxPaintDC
|
|
|
|
// if it is, a wxBufferedPaintDC otherwise. It is the caller's responsibility
|
|
|
|
// to delete the wxDC pointer when finished with it.
|
|
|
|
inline wxDC* wxAutoBufferedPaintDCFactory(wxWindow* window)
|
|
|
|
{
|
|
|
|
if ( window->IsDoubleBuffered() )
|
|
|
|
return new wxPaintDC(window);
|
|
|
|
else
|
|
|
|
return new wxBufferedPaintDC(window);
|
|
|
|
}
|
|
|
|
|
2006-10-09 16:39:34 +00:00
|
|
|
#endif // _WX_DCBUFFER_H_
|