Class: BlockDragger

Constructor

BlockDragger

new BlockDragger(block, workspace)

Class for a block dragger. It moves blocks around the workspace when they are being dragged by a mouse or touch.

Parameter

block

Blockly.BlockSvg

The block to drag.

Value must not be null.

workspace

Blockly.WorkspaceSvg

The workspace to drag on.

Value must not be null.

Implements
Blockly.IBlockDragger

Properties

draggedConnectionManager_

protected

non-null Blockly.InsertionMarkerManager

Object that keeps track of connections on dragged blocks.

draggingBlock_

protected

non-null Blockly.BlockSvg

The top block in the stack that is being dragged.

dragIconData_

protected

Array of non-null Object

A list of all of the icons (comment, warning, and mutator) that are on this block and its descendants. Moving an icon moves the bubble that extends from it if that bubble is open.

startXY_

protected

non-null Blockly.utils.Coordinate

The location of the top left corner of the dragging block at the beginning of the drag in workspace coordinates.

workspace_

protected

non-null Blockly.WorkspaceSvg

The workspace on which the block is being dragged.

wouldDeleteBlock_

protected

boolean

Whether the block would be deleted if dropped immediately.

Methods

disconnectBlock_

protected

disconnectBlock_(healStack, currentDragDeltaXY)

Disconnects the block and moves it to a new location.

Parameter

healStack

boolean

Whether or not to heal the stack after disconnecting.

currentDragDeltaXY

Blockly.utils.Coordinate

How far the pointer has moved from the position at mouse down, in pixel units.

Value must not be null.

dispose

package

dispose()

Sever all links from this object.

drag

public

drag(e, currentDragDeltaXY)

Execute a step of block dragging, based on the given event. Update the display accordingly.

Parameter

e

Event

The most recent move event.

Value must not be null.

currentDragDeltaXY

Blockly.utils.Coordinate

How far the pointer has moved from the position at the start of the drag, in pixel units.

Value must not be null.

Implements
Blockly.IBlockDragger#drag

dragIcons_

protected

dragIcons_(dxy)

Move all of the icons connected to this drag.

Parameter

dxy

Blockly.utils.Coordinate

How far to move the icons from their original positions, in workspace units.

Value must not be null.

endDrag

public

endDrag(e, currentDragDeltaXY)

Finish a block drag and put the block back on the workspace.

Parameter

e

Event

The mouseup/touchend event.

Value must not be null.

currentDragDeltaXY

Blockly.utils.Coordinate

How far the pointer has moved from the position at the start of the drag, in pixel units.

Value must not be null.

Implements
Blockly.IBlockDragger#endDrag

fireDragEndEvent_

protected

fireDragEndEvent_()

Fire a UI event at the end of a block drag.

fireDragStartEvent_

protected

fireDragStartEvent_()

Fire a UI event at the start of a block drag.

fireMoveEvent_

protected

fireMoveEvent_()

Fire a move event at the end of a block drag.

getInsertionMarkers

public

getInsertionMarkers() returns Array of non-null Blockly.BlockSvg

Get a list of the insertion markers that currently exist. Drags have 0, 1, or 2 insertion markers.

Implements
Blockly.IBlockDragger#getInsertionMarkers
Returns

non-null Array of non-null Blockly.BlockSvg A possibly empty list of insertion marker blocks.

getNewLocationAfterDrag_

protected

getNewLocationAfterDrag_(currentDragDeltaXY) returns Object

Calculates the drag delta and new location values after a block is dragged.

Parameter

currentDragDeltaXY

Blockly.utils.Coordinate

How far the pointer has moved from the start of the drag, in pixel units.

Value must not be null.

Returns

{delta: non-null Blockly.utils.Coordinate, newLocation: non-null Blockly.utils.Coordinate} New location after drag. delta is in workspace units. newLocation is the new coordinate where the block should end up.

maybeDeleteBlock_

protected

maybeDeleteBlock_() returns boolean

May delete the dragging block, if allowed. If this.wouldDeleteBlock_ is not true, the block will not be deleted. This should be called at the end of a block drag.

Returns

boolean True if the block was deleted.

pixelsToWorkspaceUnits_

protected

pixelsToWorkspaceUnits_(pixelCoord) returns Blockly.utils.Coordinate

Convert a coordinate object from pixels to workspace units, including a correction for mutator workspaces. This function does not consider differing origins. It simply scales the input's x and y values.

Parameter

pixelCoord

Blockly.utils.Coordinate

A coordinate with x and y values in CSS pixel units.

Value must not be null.

Returns

non-null Blockly.utils.Coordinate The input coordinate divided by the workspace scale.

shouldDisconnect_

protected

shouldDisconnect_(healStack) returns boolean

Whether or not we should disconnect the block when a drag is started.

Parameter

healStack

boolean

Whether or not to heal the stack after disconnecting.

Returns

boolean True to disconnect the block, false otherwise.

startDrag

public

startDrag(currentDragDeltaXY, healStack)

Start dragging a block. This includes moving it to the drag surface.

Parameter

currentDragDeltaXY

Blockly.utils.Coordinate

How far the pointer has moved from the position at mouse down, in pixel units.

Value must not be null.

healStack

boolean

Whether or not to heal the stack after disconnecting.

Implements
Blockly.IBlockDragger#startDrag

updateBlockAfterMove_

protected

updateBlockAfterMove_(delta)

Updates the necessary information to place a block at a certain location.

Parameter

delta

Blockly.utils.Coordinate

The change in location from where the block started the drag to where it ended the drag.

Value must not be null.

updateCursorDuringBlockDrag_

protected

updateCursorDuringBlockDrag_()

Update the cursor (and possibly the trash can lid) to reflect whether the dragging block would be deleted if released immediately.

updateToolboxStyle_

protected

updateToolboxStyle_(isEnd)

Adds or removes the style of the cursor for the toolbox. This is what changes the cursor to display an x when a deletable block is held over the toolbox.

Parameter

isEnd

boolean

True if we are at the end of a drag, false otherwise.