Skip to content

Instantly share code, notes, and snippets.

@ahinchman1
Last active February 28, 2018 04:45
Show Gist options
  • Save ahinchman1/b3301f17fac1ca41dbfda12a3b7c6160 to your computer and use it in GitHub Desktop.
Save ahinchman1/b3301f17fac1ca41dbfda12a3b7c6160 to your computer and use it in GitHub Desktop.
/**
* Grabs a tile and its properties to prepare for the animateDrag
* and drop events.
*
* @property MouseEvent evt
*/
private fun startDrag(evt : MouseEvent) {
val targetNode = evt.target as Node
val tileTarget = targetNode.findParentOfType(Tile::class)
val mousePt : Point2D = root.sceneToLocal( evt.sceneX, evt.sceneY )
moduleBoxItems
.filter {
it.contains(mousePt)
}
.apply {
// select tile from data grid
if (tileTarget is Tile && !workArea.contains(mousePt)) {
val title = tileTarget.titleProperty().value
tileBuilderController.hashmap[title]?.let {
inFlightTileProperties = it
}
inFlightTile = tileBuilderController.moduleTileBuilder(inFlightTileProperties)
inFlightTile.isVisible = false
root.children[1].add(inFlightTile)
isDragAndDrop = true
}
}
}
/**
* Renders a tile the user can drag to the desired grid location
*
* @property MouseEvent evt
*/
private fun animateDrag(evt : MouseEvent) {
val mousePt = root.sceneToLocal( evt.sceneX, evt.sceneY )
val targetNode = evt.target as Node
val tileTarget = targetNode.findParentOfType(Tile::class)
if (tileTarget != null) {
val tileTargetParent = tileTarget.parent
if( root.contains(mousePt) && (tileTargetParent !is GridPane) ) {
// animate a rectangle so that the user can follow
if( !inFlightTile.isVisible ) {
inFlightTile.isVisible = true
}
inFlightTile.toFront()
val widthOffset = inFlightTile.widthProperty().value/2
val heightOffset = inFlightTile.heightProperty().value/2
inFlightTile.relocate( mousePt.x - widthOffset, mousePt.y - heightOffset)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment