wxRuby Documentation Home

Wx::DragImage

This class is used when you wish to drag an object on the screen, and a simple cursor is not enough.

On Windows, the WIN32 API is used to achieve smooth dragging. On other platforms, GenericDragImage is used. Applications may also prefer to use GenericDragImage on Windows, too.

To use this class, when you wish to start dragging an image, create a DragImage object and store it somewhere you can access it as the drag progresses. Call BeginDrag to start, and EndDrag to stop the drag. To move the image, initially call Show and then Move. If you wish to update the screen contents during the drag (for example, highlight an item as in the dragimag sample), first call Hide, update the screen, call Move, and then call Show.

You can drag within one window, or you can use full-screen dragging 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 GenericDragImage and override DragImage#do_draw_image and DragImage#get_image_rect.

Please see samples/bigdemo/wxDragImage for an example.

Derived from

Object

Methods

DragImage.new

DragImage.new(Bitmap image,  Cursor cursor = NullCursor)

Constructs a drag image from a bitmap and optional cursor.

DragImage.new(Icon image,  Cursor cursor = NullCursor)

Constructs a drag image from an icon and optional cursor.

DragImage.new(String text,  Cursor cursor = NullCursor)

Constructs a drag image from a text string and optional cursor.

DragImage.new(TreeCtrl treeCtrl,  TreeItemId id)

Constructs a drag image from the text in the given tree control item, and optional cursor.

DragImage.new(ListCtrl treeCtrl,  Integer id)

Constructs a drag image from the text in the given tree control item, and optional cursor.

DragImage.new(Cursor cursor = NullCursor)

Constructs a drag image an optional cursor. This constructor is only available for GenericDragImage, and can be used when the application supplies DragImage#do_draw_image and DragImage#get_image_rect.

Parameters

DragImage#begin_drag

Boolean begin_drag(Point hotspot,  Window window, 
                   Boolean fullScreen = false, 
                   Rect rect = nil)

Start dragging the image, in a window or full screen.

Boolean begin_drag(Point hotspot,  Window window, 
                   Window boundingWindow)

Start dragging the image, using the first window to capture the mouse and the second to specify the bounding area. This form is equivalent to using the first form, but more convenient than working out the bounding rectangle explicitly.

You need to then call DragImage#show and DragImage#move to show the image on the screen.

Call DragImage#end_drag when the drag has finished.

Note that this call automatically calls CaptureMouse.

Parameters

DragImage#do_draw_image

Boolean do_draw_image(DC dc,  Point pos)

Draws the image on the device context with top-left corner at the given position.

This function is only available with GenericDragImage, to allow applications to draw their own image instead of using an actual bitmap. If you override this function, you must also override DragImage#get_image_rect.

DragImage#end_drag

Boolean end_drag()

Call this when the drag has finished.

Note that this call automatically calls ReleaseMouse.

DragImage#get_image_rect

Rect get_image_rect(Point 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 GenericDragImage only, and may be overridden (together with DragImage#do_draw_image) to provide a virtual drawing capability.

DragImage#hide

Boolean hide()

Hides the image. You may wish to call this before updating the window contents (perhaps highlighting an item). Then call DragImage#move and DragImage#show.

DragImage#move

Boolean move(Point pt)

Call this to move the image to a new position. The image will only be shown if DragImage#show has been called previously (for example at the start of the drag).

pt is the position in client coordinates (relative to the window specified in BeginDrag).

You can move the image either when the image is hidden or shown, but in general dragging will be smoother if you move the image when it is shown.

DragImage#show

Boolean show()

Shows the image. Call this at least once when dragging.

DragImage#update_backing_from_window

Boolean update_backing_from_window(DC windowDC,  MemoryDC destDC, 
                                   Rect sourceRect, 
                                   Rect destRect)

Override this if you wish to draw the window contents to the backing bitmap yourself. This can be desirable if you wish to avoid flicker by not having to redraw the updated window itself just before dragging, which can cause a flicker just as the drag starts. Instead, paint the drag image’s backing bitmap to show the appropriate graphic minus the objects to be dragged, and leave the window itself to be updated by the drag image. This can provide eerily smooth, flicker-free drag behaviour.

The default implementation copies the window contents to the backing bitmap. A new implementation will normally copy information from another source, such as from its own backing bitmap if it has one, or directly from internal data structures.

This function is available in GenericDragImage only.

[This page automatically generated from the Textile source at Wed Sep 09 02:21:06 +0100 2009]