Last active
February 28, 2018 04:45
-
-
Save ahinchman1/b3301f17fac1ca41dbfda12a3b7c6160 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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