Fix to wxGenericDragImage inefficiency

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7615 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2000-06-20 19:35:11 +00:00
parent f7585687b2
commit 3a3377d7bf
5 changed files with 79 additions and 19 deletions

View File

@@ -22,6 +22,10 @@ either across the whole screen, or just restricted to one area
of the screen to save resources. If you want the user to drag between of the screen to save resources. If you want the user to drag between
two windows, then you will need to use full-screen dragging. two windows, then you will need to use full-screen dragging.
If you wish to draw the image yourself, use wxGenericDragImage and
override \helpref{wxDragImage::DoDrawImage}{wxdragimagedodrawimage} and
\helpref{wxDragImage::GetImageRect}{wxdragimagegetimagerect}.
Please see {\tt samples/dragimag} for an example. Please see {\tt samples/dragimag} for an example.
\wxheading{Derived from} \wxheading{Derived from}
@@ -72,6 +76,13 @@ Constructs a drag image from the text in the given tree control item, and option
\pythonnote{This constructor is called wxDragListItem in wxPython.} \pythonnote{This constructor is called wxDragListItem in wxPython.}
\func{}{wxDragImage}{\param{const wxCursor\& }{cursor = wxNullCursor},
\param{const wxPoint& }{hotspot = wxPoint(0, 0)}}
Constructs a drag image an optional cursor. This constructor is only available for
wxGenericDragImage, and can be used when the application
supplies \helpref{wxDragImage::DoDrawImage}{wxdragimagedodrawimage} and \helpref{wxDragImage::GetImageRect}{wxdragimagegetimagerect}.
\wxheading{Parameters} \wxheading{Parameters}
\docparam{image}{Icon or bitmap to be used as the drag image. The bitmap can \docparam{image}{Icon or bitmap to be used as the drag image. The bitmap can
@@ -101,7 +112,7 @@ Start dragging the image, using the first window to capture the mouse and the se
to specify the bounding area. This form is equivalent to using the first form, to specify the bounding area. This form is equivalent to using the first form,
but more convenient than working out the bounding rectangle explicitly. but more convenient than working out the bounding rectangle explicitly.
You need to then call \helpref{wxDragImage::Show}{wxdragimageshow} You need to then call \helpref{wxDragImage::Show}{wxdragimageshow}
and \helpref{wxDragImage::Move}{wxdragimagemove} to show the image on the screen. and \helpref{wxDragImage::Move}{wxdragimagemove} to show the image on the screen.
Call \helpref{wxDragImage::EndDrag}{wxdragimageenddrag} when the drag has finished. Call \helpref{wxDragImage::EndDrag}{wxdragimageenddrag} when the drag has finished.
@@ -128,6 +139,16 @@ bounds the dragging operation. Specifying this can make the operation more effic
by cutting down on the area under consideration, and it can also make a visual difference by cutting down on the area under consideration, and it can also make a visual difference
since the drag is clipped to this area.} since the drag is clipped to this area.}
\membersection{wxDragImage::DoDrawImage}\label{wxdragimagedodrawimage}
\func{virtual bool}{DoDrawImage}{\param{wxDC\&}{ dc}, \param{const wxPoint\&}{ pos}}
Draws the image on the device context with top-left corner at the given position.
This function is only available with wxGenericDragImage, to allow applications to
draw their own image instead of using an actual bitmap. If you override this function,
you must also override \helpref{wxDragImage::GetImageRect}{wxdragimagegetimagerect}.
\membersection{wxDragImage::EndDrag}\label{wxdragimageenddrag} \membersection{wxDragImage::EndDrag}\label{wxdragimageenddrag}
\func{bool}{EndDrag}{\void} \func{bool}{EndDrag}{\void}
@@ -136,19 +157,29 @@ Call this when the drag has finished.
Note that this call automatically calls ReleaseMouse. Note that this call automatically calls ReleaseMouse.
\membersection{wxDragImage::GetImageRect}\label{wxdragimagegetimagerect}
\constfunc{virtual wxRect}{GetImageRect}{\param{const wxPoint\&}{ pos}}
Returns the rectangle enclosing the image, assuming that the image is drawn with its
top-left corner at the given point.
This function is available in wxGenericDragImage only, and may be overridden (together with
\helpref{wxDragImage::DoDrawImage}{wxdragimagedodrawimage}) to provide a virtual drawing capability.
\membersection{wxDragImage::Hide}\label{wxdragimagehide} \membersection{wxDragImage::Hide}\label{wxdragimagehide}
\func{bool}{Hide}{\void} \func{bool}{Hide}{\void}
Hides the image. You may wish to call this before updating the window Hides the image. You may wish to call this before updating the window
contents (perhaps highlighting an item). Then call \helpref{wxDragImage::Move}{wxdragimagemove} contents (perhaps highlighting an item). Then call \helpref{wxDragImage::Move}{wxdragimagemove}
and \helpref{wxDragImage::Show}{wxdragimageshow}. and \helpref{wxDragImage::Show}{wxdragimageshow}.
\membersection{wxDragImage::Move}\label{wxdragimagemove} \membersection{wxDragImage::Move}\label{wxdragimagemove}
\func{bool}{Move}{\param{const wxPoint\& }{pt}} \func{bool}{Move}{\param{const wxPoint\& }{pt}}
Call this to move the image to a new position. The image will only be shown if Call this to move the image to a new position. The image will only be shown if
\helpref{wxDragImage::Show}{wxdragimageshow} has been called previously (for example \helpref{wxDragImage::Show}{wxdragimageshow} has been called previously (for example
at the start of the drag). at the start of the drag).

View File

@@ -691,7 +691,7 @@ Returns TRUE if the string is NULL (same as IsEmpty).
\constfunc{bool}{IsNumber}{\void} \constfunc{bool}{IsNumber}{\void}
Returns TRUE if the string is a number. Returns TRUE if the string is a positive or negative integer. Will return FALSE for decimals.
\membersection{wxString::IsSameAs}\label{wxstringissameas} \membersection{wxString::IsSameAs}\label{wxstringissameas}

View File

@@ -97,7 +97,11 @@ public:
// Ctors & dtor // Ctors & dtor
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
wxGenericDragImage(); wxGenericDragImage(const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
{
Init();
Create(cursor, hotspot);
}
wxGenericDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0)) wxGenericDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
{ {
Init(); Init();
@@ -136,6 +140,9 @@ public:
// Operations // Operations
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Create a drag image with a virtual image (need to override DoDrawImage, GetImageRect)
bool Create(const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
// Create a drag image from a bitmap and optional cursor // Create a drag image from a bitmap and optional cursor
bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0)); bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
@@ -178,10 +185,14 @@ public:
void Init(); void Init();
wxRect GetImageRect(const wxPoint& pos) const; // Override this if you are using a virtual image (drawing your own image)
virtual wxRect GetImageRect(const wxPoint& pos) const;
// Override this if you are using a virtual image (drawing your own image)
virtual bool DoDrawImage(wxDC& dc, const wxPoint& pos) const;
// Erase and redraw simultaneously if possible // Erase and redraw simultaneously if possible
bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos, bool eraseOld, bool drawNew); virtual bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos, bool eraseOld, bool drawNew);
protected: protected:
wxBitmap m_bitmap; wxBitmap m_bitmap;

View File

@@ -25,7 +25,7 @@
// Under Windows, change this to 1 // Under Windows, change this to 1
// to use wxGenericDragImage // to use wxGenericDragImage
#define wxUSE_GENERIC_DRAGIMAGE 0 #define wxUSE_GENERIC_DRAGIMAGE 1
#if wxUSE_GENERIC_DRAGIMAGE #if wxUSE_GENERIC_DRAGIMAGE
#include "wx/generic/dragimgg.h" #include "wx/generic/dragimgg.h"

View File

@@ -68,11 +68,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxGenericDragImage, wxObject)
// wxGenericDragImage ctors/dtor // wxGenericDragImage ctors/dtor
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxGenericDragImage::wxGenericDragImage()
{
Init();
}
wxGenericDragImage::~wxGenericDragImage() wxGenericDragImage::~wxGenericDragImage()
{ {
if (m_windowDC) if (m_windowDC)
@@ -97,6 +92,15 @@ void wxGenericDragImage::Init()
// Operations // Operations
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Create a drag image with a virtual image (need to override DoDrawImage, GetImageRect)
bool wxGenericDragImage::Create(const wxCursor& cursor, const wxPoint& hotspot)
{
m_cursor = cursor;
m_hotspot = hotspot;
return TRUE;
}
// Create a drag image from a bitmap and optional cursor // Create a drag image from a bitmap and optional cursor
bool wxGenericDragImage::Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& hotspot) bool wxGenericDragImage::Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& hotspot)
{ {
@@ -429,12 +433,8 @@ bool wxGenericDragImage::RedrawImage(const wxPoint& oldPos, const wxPoint& newPo
// If drawing, draw the image onto the mem DC // If drawing, draw the image onto the mem DC
if (drawNew) if (drawNew)
{ {
int x = newPos.x - fullRect.x; wxPoint pos(newPos.x - fullRect.x, newPos.y - fullRect.y) ;
int y = newPos.y - fullRect.y; DoDrawImage(memDCTemp, pos);
if (m_bitmap.Ok())
memDCTemp.DrawBitmap(m_bitmap, x, y, (m_bitmap.GetMask() != 0));
else if (m_icon.Ok())
memDCTemp.DrawIcon(m_icon, x, y);
} }
// Now blit to the window // Now blit to the window
@@ -447,6 +447,24 @@ bool wxGenericDragImage::RedrawImage(const wxPoint& oldPos, const wxPoint& newPo
return TRUE; return TRUE;
} }
// Override this if you are using a virtual image (drawing your own image)
bool wxGenericDragImage::DoDrawImage(wxDC& dc, const wxPoint& pos) const
{
if (m_bitmap.Ok())
{
dc.DrawBitmap(m_bitmap, pos.x, pos.y, (m_bitmap.GetMask() != 0));
return TRUE;
}
else if (m_icon.Ok())
{
dc.DrawIcon(m_icon, pos.x, pos.y);
return TRUE;
}
else
return FALSE;
}
// Override this if you are using a virtual image (drawing your own image)
wxRect wxGenericDragImage::GetImageRect(const wxPoint& pos) const wxRect wxGenericDragImage::GetImageRect(const wxPoint& pos) const
{ {
if (m_bitmap.Ok()) if (m_bitmap.Ok())