Created
September 14, 2015 22:07
-
-
Save GeePawHill/5bbe68bbfcf16cb19594 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
package org.geepawhill.whiteboard.action; | |
import javafx.geometry.Bounds; | |
import javafx.scene.Node; | |
import javafx.scene.layout.Pane; | |
import javafx.scene.paint.Color; | |
import javafx.scene.shape.Rectangle; | |
public class EnterBoundsBox implements Action | |
{ | |
private String selector; | |
private Rectangle box; | |
private double startX; | |
private double startY; | |
private double endX; | |
private double endY; | |
private Pane root; | |
public EnterBoundsBox(Pane root, String selector) | |
{ | |
this.root = root; | |
this.selector = selector; | |
box = new Rectangle(0, 0, 0, 0); | |
} | |
public void animate(double frac) | |
{ | |
box.setX(startX); | |
box.setY(startY); | |
box.setWidth((endX - startX) * frac); | |
box.setHeight((endY - startY) * frac); | |
} | |
public void beforeAnimation() | |
{ | |
box.setFill(Color.TRANSPARENT); | |
box.setStroke(Color.RED); | |
box.setOpacity(0.5); | |
box.setStrokeWidth(5d); | |
Node fromLast = root.lookup(selector); | |
if(fromLast==null) throw new RuntimeException("Can't find node: "+selector); | |
Bounds bounds = fromLast.getBoundsInParent(); | |
startX = bounds.getMinX() - 4; | |
startY = bounds.getMinY() - 4; | |
endX = bounds.getMaxX() + 4; | |
endY = bounds.getMaxY() + 4; | |
} | |
public double ms() | |
{ | |
return 1000d; | |
} | |
public ActorSet actors() | |
{ | |
return new ActorSet(box); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment