Class: BlockDragSurfaceSvg

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.

Property

SVG_

non-null SVGElement

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

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

Returns

nullable Element Drag surface block DOM element, or null if no blocks exist.

getGroup

getGroup() returns SVGElement

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

Returns

nullable SVGElement Drag surface group element.

getSurfaceTranslation

getSurfaceTranslation() returns Blockly.utils.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 Blockly.utils.Coordinate Current translation of the surface.

getSvgRoot

getSvgRoot() returns SVGElement

Returns the SVG drag surface.

Returns

nullable SVGElement The SVG drag surface.

getWsTranslation

getWsTranslation() returns Blockly.utils.Coordinate

Gets the translation of the child block surface This surface is in charge of keeping track of how much the workspace has moved.

Returns

non-null Blockly.utils.Coordinate The amount the workspace has been moved.

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

SVGElement

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 pixel coordinates.

y

number

Y translation in pixel coordinates.

scale

number

Scale of the group.

translateBy

translateBy(deltaX, deltaY)

Translates the entire surface by a relative offset.

Parameter

deltaX

number

Horizontal offset in pixel units.

deltaY

number

Vertical offset in pixel units.

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.