Constructor

BlockDragSurfaceSvg

new BlockDragSurfaceSvg(container)

Class for a drag surface for the currently dragged block. This is a separate SVG that contains only the currently moving block, or nothing.

Parameter

container

Element

Containing element.

Value must not be null.

Methods

clearAndHide

clearAndHide(opt_newSurface)

Clear the group and hide the surface; move the blocks off onto the provided element. If the block is being deleted it doesn't need to go back to the original surface, since it would be removed immediately during dispose.

Parameter

opt_newSurface

Optional

Element

Surface the dragging blocks should be moved to, or null if the blocks should be removed from this surface without being moved to a different surface.

createDom

createDom()

Create the drag surface and inject it into the container.

getCurrentBlock

getCurrentBlock() returns (Element or undefined)

Get the current blocks on the drag surface, if any (primarily for BlockSvg.getRelativeToSurfaceXY).

Returns

(non-null Element or undefined) Drag surface block DOM element, or undefined if no blocks exist.

getGroup

getGroup() returns Element

Provide a reference to the drag group (primarily for BlockSvg.getRelativeToSurfaceXY).

Returns

Element Drag surface group element.

getSurfaceTranslation

getSurfaceTranslation() returns goog.math.Coordinate

Reports the surface translation in scaled workspace coordinates. Use this when finishing a drag to return blocks to the correct position.

Returns

non-null goog.math.Coordinate Current translation of the surface.

setBlocksAndShow

setBlocksAndShow(blocks)

Set the SVG blocks on the drag surface's group and show the surface. Only one block group should be on the drag surface at a time.

Parameter

blocks

Element

Block or group of blocks to place on the drag surface.

Value must not be null.

translateAndScaleGroup

translateAndScaleGroup(x, y, scale)

Translate and scale the entire drag surface group to the given position, to keep in sync with the workspace.

Parameter

x

number

X translation in workspace coordinates.

y

number

Y translation in workspace coordinates.

scale

number

Scale of the group.

translateSurface

translateSurface(x, y)

Translate the entire drag surface during a drag. We translate the drag surface instead of the blocks inside the surface so that the browser avoids repainting the SVG. Because of this, the drag coordinates must be adjusted by scale.

Parameter

x

number

X translation for the entire surface.

y

number

Y translation for the entire surface.