2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dcbuffer.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxBufferedDC
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-09-18 04:38:01 +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
|
|
|
|
|
|
|
|
// Set when not using specific buffer bitmap. Note that this
|
|
|
|
// is private style and not returned by GetStyle.
|
|
|
|
#define wxBUFFER_USES_SHARED_BUFFER 0x04
|
|
|
|
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxBufferedDC
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
This class provides a simple way to avoid flicker: when drawing on it,
|
2011-04-03 20:31:32 +00:00
|
|
|
everything is in fact first drawn on an in-memory buffer (a wxBitmap) and
|
2008-04-17 07:06:20 +00:00
|
|
|
then copied to the screen, using the associated wxDC, only once, when this
|
|
|
|
object is destroyed. wxBufferedDC itself is typically associated with
|
|
|
|
wxClientDC, if you want to use it in your @c EVT_PAINT handler, you should
|
|
|
|
look at wxBufferedPaintDC instead.
|
|
|
|
|
|
|
|
When used like this, a valid @e DC must be specified in the constructor
|
2008-03-08 13:52:38 +00:00
|
|
|
while the @e buffer bitmap doesn't have to be explicitly provided, by
|
2008-04-17 07:06:20 +00:00
|
|
|
default this class will allocate the bitmap of required size itself.
|
|
|
|
However using a dedicated bitmap can speed up the redrawing process by
|
|
|
|
eliminating the repeated creation and destruction of a possibly big bitmap.
|
|
|
|
Otherwise, wxBufferedDC can be used in the same way as any other device
|
|
|
|
context.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
There is another possible use for wxBufferedDC is to use it to maintain a
|
2008-04-17 07:06:20 +00:00
|
|
|
backing store for the window contents. In this case, the associated @e DC
|
2008-03-08 13:52:38 +00:00
|
|
|
may be @NULL but a valid backing store bitmap should be specified.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Finally, please note that GTK+ 2.0 as well as OS X provide double buffering
|
2008-04-17 07:06:20 +00:00
|
|
|
themselves natively. You can either use wxWindow::IsDoubleBuffered() to
|
|
|
|
determine whether you need to use buffering or not, or use
|
|
|
|
wxAutoBufferedPaintDC to avoid needless double buffering on the systems
|
|
|
|
which already do it automatically.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dc}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxDC, wxMemoryDC, wxBufferedPaintDC, wxAutoBufferedPaintDC
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxBufferedDC : public wxMemoryDC
|
|
|
|
{
|
|
|
|
public:
|
2008-04-17 07:06:20 +00:00
|
|
|
/**
|
|
|
|
Default constructor. You must call one of the Init() methods later in
|
|
|
|
order to use the device context.
|
|
|
|
*/
|
|
|
|
wxBufferedDC();
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
2008-08-27 04:20:07 +00:00
|
|
|
Creates a buffer for the provided @a dc. Init() must not be called when
|
2008-04-17 07:06:20 +00:00
|
|
|
using this constructor.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param dc
|
2008-04-17 07:06:20 +00:00
|
|
|
The underlying DC: everything drawn to this object will be flushed
|
|
|
|
to this DC when this object is destroyed. You may pass @NULL in
|
|
|
|
order to just initialize the buffer, and not flush it.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param area
|
2008-03-09 12:33:59 +00:00
|
|
|
The size of the bitmap to be used for buffering (this bitmap is
|
|
|
|
created internally when it is not given explicitly).
|
2008-08-27 04:20:07 +00:00
|
|
|
@param style
|
|
|
|
wxBUFFER_CLIENT_AREA to indicate that just the client area of the
|
|
|
|
window is buffered, or wxBUFFER_VIRTUAL_AREA to indicate that the
|
|
|
|
buffer bitmap covers the virtual area.
|
|
|
|
*/
|
|
|
|
wxBufferedDC(wxDC* dc, const wxSize& area,
|
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2008-09-21 23:13:49 +00:00
|
|
|
|
2008-08-27 04:20:07 +00:00
|
|
|
/**
|
|
|
|
Creates a buffer for the provided dc. Init() must not be called when
|
|
|
|
using this constructor.
|
|
|
|
|
|
|
|
@param dc
|
|
|
|
The underlying DC: everything drawn to this object will be flushed
|
|
|
|
to this DC when this object is destroyed. You may pass @NULL in
|
|
|
|
order to just initialize the buffer, and not flush it.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param buffer
|
2008-04-17 07:06:20 +00:00
|
|
|
Explicitly provided bitmap to be used for buffering: this is the
|
|
|
|
most efficient solution as the bitmap doesn't have to be recreated
|
|
|
|
each time but it also requires more memory as the bitmap is never
|
|
|
|
freed. The bitmap should have appropriate size, anything drawn
|
|
|
|
outside of its bounds is clipped.
|
2008-03-09 12:33:59 +00:00
|
|
|
@param style
|
2008-04-17 07:06:20 +00:00
|
|
|
wxBUFFER_CLIENT_AREA to indicate that just the client area of the
|
|
|
|
window is buffered, or wxBUFFER_VIRTUAL_AREA to indicate that the
|
|
|
|
buffer bitmap covers the virtual area.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2009-01-10 23:44:44 +00:00
|
|
|
wxBufferedDC(wxDC* dc, wxBitmap& buffer = wxNullBitmap,
|
2008-03-08 14:43:31 +00:00
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-17 07:06:20 +00:00
|
|
|
Copies everything drawn on the DC so far to the underlying DC
|
|
|
|
associated with this object, if any.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-21 23:13:49 +00:00
|
|
|
virtual ~wxBufferedDC();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-04-17 07:06:20 +00:00
|
|
|
Initializes the object created using the default constructor. Please
|
|
|
|
see the constructors for parameter details.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void Init(wxDC* dc, const wxSize& area,
|
2008-03-08 13:52:38 +00:00
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2009-01-10 23:44:44 +00:00
|
|
|
void Init(wxDC* dc, wxBitmap& buffer = wxNullBitmap,
|
2008-03-08 14:43:31 +00:00
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
2012-12-22 08:00:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Blits the buffer to the dc, and detaches the dc from the buffer (so it
|
|
|
|
can be effectively used once only).
|
|
|
|
|
|
|
|
Usually only called in the destructor or by the destructor 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();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the style.
|
|
|
|
*/
|
|
|
|
void SetStyle(int style);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get the style.
|
|
|
|
*/
|
|
|
|
int GetStyle() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxAutoBufferedPaintDC
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-17 07:06:20 +00:00
|
|
|
This wxDC derivative can be used inside of an @c EVT_PAINT() event handler
|
|
|
|
to achieve double-buffered drawing. Just use this class instead of
|
|
|
|
wxPaintDC and make sure wxWindow::SetBackgroundStyle() is called with
|
2011-09-18 04:38:01 +00:00
|
|
|
wxBG_STYLE_PAINT somewhere in the class initialization code, and that's
|
2008-04-17 07:06:20 +00:00
|
|
|
all you have to do to (mostly) avoid flicker.
|
|
|
|
|
|
|
|
The difference between wxBufferedPaintDC and this class is that this class
|
|
|
|
won't double-buffer on platforms which have native double-buffering
|
2011-04-03 20:31:32 +00:00
|
|
|
already, avoiding any unnecessary buffering to avoid flicker.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-17 07:06:20 +00:00
|
|
|
wxAutoBufferedPaintDC is simply a typedef of wxPaintDC on platforms that
|
|
|
|
have native double-buffering, otherwise, it is a typedef of
|
|
|
|
wxBufferedPaintDC.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2012-10-15 01:17:21 +00:00
|
|
|
@library{wxcore}
|
2008-03-08 13:52:38 +00:00
|
|
|
@category{dc}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-17 07:06:20 +00:00
|
|
|
@see wxDC, wxBufferedPaintDC, wxPaintDC
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxAutoBufferedPaintDC : public wxBufferedPaintDC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor. Pass a pointer to the window on which you wish to paint.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxAutoBufferedPaintDC(wxWindow* window);
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-07-19 06:46:44 +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.
|
|
|
|
*/
|
|
|
|
wxDC* wxAutoBufferedPaintDCFactory(wxWindow* window);
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxBufferedPaintDC
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-17 07:06:20 +00:00
|
|
|
This is a subclass of wxBufferedDC which can be used inside of an
|
|
|
|
@c EVT_PAINT() event handler to achieve double-buffered drawing. Just use
|
|
|
|
this class instead of wxPaintDC and make sure
|
2011-09-18 04:38:01 +00:00
|
|
|
wxWindow::SetBackgroundStyle() is called with wxBG_STYLE_PAINT somewhere
|
2008-04-17 07:06:20 +00:00
|
|
|
in the class initialization code, and that's all you have to do to (mostly)
|
|
|
|
avoid flicker. The only thing to watch out for is that if you are using
|
|
|
|
this class together with wxScrolled, you probably do @b not want to call
|
|
|
|
wxScrolled::PrepareDC() on it as it already does this internally for the
|
|
|
|
real underlying wxPaintDC.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dc}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-17 07:06:20 +00:00
|
|
|
@see wxDC, wxBufferedDC, wxAutoBufferedPaintDC, wxPaintDC
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxBufferedPaintDC : public wxBufferedDC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//@{
|
|
|
|
/**
|
2008-04-17 07:06:20 +00:00
|
|
|
As with wxBufferedDC, you may either provide the bitmap to be used for
|
|
|
|
buffering or let this object create one internally (in the latter case,
|
|
|
|
the size of the client part of the window is used).
|
|
|
|
|
|
|
|
Pass wxBUFFER_CLIENT_AREA for the @a style parameter to indicate that
|
|
|
|
just the client area of the window is buffered, or
|
|
|
|
wxBUFFER_VIRTUAL_AREA to indicate that the buffer bitmap covers the
|
|
|
|
virtual area.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxBufferedPaintDC(wxWindow* window, wxBitmap& buffer,
|
2008-03-08 13:52:38 +00:00
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2008-03-09 12:33:59 +00:00
|
|
|
wxBufferedPaintDC(wxWindow* window,
|
2008-03-08 14:43:31 +00:00
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
2008-04-17 07:06:20 +00:00
|
|
|
Copies everything drawn on the DC so far to the window associated with
|
|
|
|
this object, using a wxPaintDC.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-21 23:13:49 +00:00
|
|
|
virtual ~wxBufferedPaintDC();
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|