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:
@@ -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
|
||||
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.
|
||||
|
||||
\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.}
|
||||
|
||||
\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}
|
||||
|
||||
\docparam{image}{Icon or bitmap to be used as the drag image. The bitmap can
|
||||
@@ -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
|
||||
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}
|
||||
|
||||
\func{bool}{EndDrag}{\void}
|
||||
@@ -136,6 +157,16 @@ Call this when the drag has finished.
|
||||
|
||||
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}
|
||||
|
||||
\func{bool}{Hide}{\void}
|
||||
|
@@ -691,7 +691,7 @@ Returns TRUE if the string is NULL (same as IsEmpty).
|
||||
|
||||
\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}
|
||||
|
||||
|
@@ -97,7 +97,11 @@ public:
|
||||
// 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))
|
||||
{
|
||||
Init();
|
||||
@@ -136,6 +140,9 @@ public:
|
||||
// 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
|
||||
bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
|
||||
|
||||
@@ -178,10 +185,14 @@ public:
|
||||
|
||||
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
|
||||
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:
|
||||
wxBitmap m_bitmap;
|
||||
|
@@ -25,7 +25,7 @@
|
||||
// Under Windows, change this to 1
|
||||
// to use wxGenericDragImage
|
||||
|
||||
#define wxUSE_GENERIC_DRAGIMAGE 0
|
||||
#define wxUSE_GENERIC_DRAGIMAGE 1
|
||||
|
||||
#if wxUSE_GENERIC_DRAGIMAGE
|
||||
#include "wx/generic/dragimgg.h"
|
||||
|
@@ -68,11 +68,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxGenericDragImage, wxObject)
|
||||
// wxGenericDragImage ctors/dtor
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxGenericDragImage::wxGenericDragImage()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
wxGenericDragImage::~wxGenericDragImage()
|
||||
{
|
||||
if (m_windowDC)
|
||||
@@ -97,6 +92,15 @@ void wxGenericDragImage::Init()
|
||||
// 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
|
||||
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 (drawNew)
|
||||
{
|
||||
int x = newPos.x - fullRect.x;
|
||||
int y = newPos.y - fullRect.y;
|
||||
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);
|
||||
wxPoint pos(newPos.x - fullRect.x, newPos.y - fullRect.y) ;
|
||||
DoDrawImage(memDCTemp, pos);
|
||||
}
|
||||
|
||||
// Now blit to the window
|
||||
@@ -447,6 +447,24 @@ bool wxGenericDragImage::RedrawImage(const wxPoint& oldPos, const wxPoint& newPo
|
||||
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
|
||||
{
|
||||
if (m_bitmap.Ok())
|
||||
|
Reference in New Issue
Block a user