Documentation

dragrect

Drag rectangles with mouse

Syntax

[finalrect] = dragrect(initialrect)
[finalrect] = dragrect(initialrect,stepsize)

Description

[finalrect] = dragrect(initialrect)tracks one or more rectangles anywhere on the screen. The n-by-4 matrixinitialrectdefines the rectangles. Each row ofinitialrectmust contain the initial rectangle position as [left bottom width height]values.dragrectreturns the final position of the rectangles infinalrect

[finalrect] = dragrect(initialrect,stepsize)moves the rectangles in increments ofstepsize。左下角corner of the first rectangle is constrained to a grid of size equal tostepsizestarting at the lower left corner of the figure, and all other rectangles maintain their original offset from the first rectangle.

[finalrect] = dragrect(...)returns the final positions of the rectangles when the mouse button is released. The default step size is1

Examples

Drag a rectangle with dimensions of 50-by-100pixels

waitforbuttonpress point1 = get(gcf,'CurrentPoint') % button down detected rect = [point1(1,1) point1(1,2) 50 100] [r2] = dragrect(rect)

More About

collapse all

Pixels

Distances in pixels are independent of your system resolution on Windows®and Macintosh systems:

  • On Windows systems, a pixel is 1/96th of an inch.

  • On Macintosh systems, a pixel is 1/72nd of an inch.

On Linux®systems, the size of a pixel is determined by your system resolution.

Tips

dragrectreturns immediately if a mouse button is not currently pressed. Usedragrectin aButtonDownFcn, or from the command line in conjunction withwaitforbuttonpress, to ensure that the mouse button is down whendragrectis called.dragrectreturns when you release the mouse button.

If the drag ends over a figure window, the positions of the rectangles are returned in that figure's coordinate system. If the drag ends over a part of the screen not contained within a figure window, the rectangles are returned in the coordinate system of the figure over which the drag began.

    Note:You cannot use normalized figure units withdragrect

Introduced before R2006a

Was this topic helpful?