2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dcbuffer.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxBufferedDC
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxBufferedDC
|
|
|
|
@wxheader{dcbuffer.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This class provides a simple way to avoid flicker: when drawing on it,
|
|
|
|
everything is in fact first drawn on an in-memory buffer (a
|
|
|
|
wxBitmap) and 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.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
When used like this, a valid @e dc must be specified in the constructor
|
|
|
|
while the @e buffer bitmap doesn't have to be explicitly provided, by
|
|
|
|
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,
|
2008-03-08 09:43:31 -05:00
|
|
|
wxBufferedDC can be used in the same way as any other device context.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
There is another possible use for wxBufferedDC is to use it to maintain a
|
|
|
|
backing store for the window contents. In this case, the associated @e dc
|
|
|
|
may be @NULL but a valid backing store bitmap should be specified.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Finally, please note that GTK+ 2.0 as well as OS X provide double buffering
|
2008-03-08 09:43:31 -05:00
|
|
|
themselves natively. You can either use wxWindow::IsDoubleBuffered
|
|
|
|
to determine whether you need to use buffering or not, or use
|
2008-03-08 08:52:38 -05:00
|
|
|
wxAutoBufferedPaintDC to avoid needless double
|
|
|
|
buffering on the systems which already do it automatically.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dc}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxDC, wxMemoryDC, wxBufferedPaintDC, wxAutoBufferedPaintDC
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxBufferedDC : public wxMemoryDC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//@{
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
If you use the first, default, constructor, you must call one of the
|
2008-03-08 08:52:38 -05:00
|
|
|
Init() methods later in order to use the object.
|
2008-03-08 09:43:31 -05:00
|
|
|
The other constructors initialize the object immediately and @c Init()
|
2008-03-08 08:52:38 -05:00
|
|
|
must not be called after using them.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param dc
|
2008-03-09 08:33:59 -04: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 09:43:31 -05:00
|
|
|
@param area
|
2008-03-09 08:33:59 -04:00
|
|
|
The size of the bitmap to be used for buffering (this bitmap is
|
|
|
|
created internally when it is not given explicitly).
|
2008-03-08 09:43:31 -05:00
|
|
|
@param buffer
|
2008-03-09 08:33:59 -04: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
|
2008-03-08 08:52:38 -05:00
|
|
|
bitmap
|
2008-03-09 08:33:59 -04:00
|
|
|
should have appropriate size, anything drawn outside of its bounds is
|
|
|
|
clipped.
|
|
|
|
@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 (in which case PrepareDC is automatically called
|
|
|
|
for the actual window
|
|
|
|
device context).
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxBufferedDC();
|
2008-03-09 08:33:59 -04:00
|
|
|
wxBufferedDC(wxDC* dc, const wxSize& area,
|
2008-03-08 09:43:31 -05:00
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2008-03-09 08:33:59 -04:00
|
|
|
wxBufferedDC(wxDC* dc, wxBitmap& buffer,
|
2008-03-08 09:43:31 -05:00
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Copies everything drawn on the DC so far to the underlying DC associated with
|
|
|
|
this object, if any.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
These functions initialize the object created using the default constructor.
|
|
|
|
Please see @ref ctor() "constructors documentation" for details.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
void Init(wxDC* dc, const wxSize& area,
|
2008-03-08 08:52:38 -05:00
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2008-03-09 08:33:59 -04:00
|
|
|
void Init(wxDC* dc, wxBitmap& buffer,
|
2008-03-08 09:43:31 -05:00
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxAutoBufferedPaintDC
|
|
|
|
@wxheader{dcbuffer.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This wxDC derivative can be used inside of an @c OnPaint() event handler to
|
|
|
|
achieve
|
|
|
|
double-buffered drawing. Just create an object of this class instead of
|
|
|
|
wxPaintDC
|
|
|
|
and make sure wxWindow::SetBackgroundStyle is called
|
|
|
|
with wxBG_STYLE_CUSTOM somewhere in the class initialization code, and that's
|
|
|
|
all you have
|
|
|
|
to do to (mostly) avoid flicker.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The difference between wxBufferedPaintDC and this class,
|
|
|
|
is the lightweigthness - on platforms which have native double-buffering,
|
|
|
|
wxAutoBufferedPaintDC is simply
|
|
|
|
a typedef of wxPaintDC. Otherwise, it is a typedef of wxBufferedPaintDC.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{dc}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxDC, wxBufferedPaintDC
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxAutoBufferedPaintDC : public wxBufferedPaintDC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor. Pass a pointer to the window on which you wish to paint.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
wxAutoBufferedPaintDC(wxWindow* window);
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxBufferedPaintDC
|
|
|
|
@wxheader{dcbuffer.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This is a subclass of wxBufferedDC which can be used
|
|
|
|
inside of an @c OnPaint() event handler. Just create an object of this class
|
|
|
|
instead
|
|
|
|
of wxPaintDC and make sure wxWindow::SetBackgroundStyle
|
|
|
|
is called with wxBG_STYLE_CUSTOM somewhere 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 wxScrolledWindow, you probably
|
|
|
|
do @b not want to call wxScrolledWindow::PrepareDC on it as it
|
|
|
|
already does this internally for the real underlying wxPaintDC.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{dc}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxDC, wxBufferedDC, wxAutoBufferedPaintDC
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxBufferedPaintDC : public wxBufferedDC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
As with @ref wxBufferedDC::ctor 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).
|
2008-03-09 08:33:59 -04:00
|
|
|
Pass wxBUFFER_CLIENT_AREA for the @a style parameter to indicate that just the
|
2008-03-08 08:52:38 -05:00
|
|
|
client area of
|
|
|
|
the window is buffered, or wxBUFFER_VIRTUAL_AREA to indicate that the buffer
|
|
|
|
bitmap
|
|
|
|
covers the virtual area (in which case PrepareDC is automatically called for
|
|
|
|
the actual window
|
|
|
|
device context).
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
wxBufferedPaintDC(wxWindow* window, wxBitmap& buffer,
|
2008-03-08 08:52:38 -05:00
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2008-03-09 08:33:59 -04:00
|
|
|
wxBufferedPaintDC(wxWindow* window,
|
2008-03-08 09:43:31 -05:00
|
|
|
int style = wxBUFFER_CLIENT_AREA);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Copies everything drawn on the DC so far to the window associated with this
|
|
|
|
object, using a wxPaintDC.
|
|
|
|
*/
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|