progress
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Eddy 2023-03-30 11:47:23 +02:00
parent bb5e2ff401
commit a99a53868b

View File

@ -3,6 +3,7 @@ import javafx.application.Application;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.event.Event; import javafx.event.Event;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.layout.Pane;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.Cursor; import javafx.scene.Cursor;
@ -12,6 +13,7 @@ import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon; import javafx.scene.shape.Polygon;
import javafx.scene.transform.Rotate; import javafx.scene.transform.Rotate;
import javafx.scene.transform.Scale;
import javafx.animation.RotateTransition; import javafx.animation.RotateTransition;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.Duration; import javafx.util.Duration;
@ -19,9 +21,21 @@ public class Piece extends Application{
double x; double x;
double y; double y;
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
Polygon piece1 = new Polygon(); Polygon piece1 = new Polygon();
Polygon piece2 = new Polygon();
Polygon piece3 = new Polygon();
Polygon piece4 = new Polygon();
Polygon piece5 = new Polygon();
Polygon piece6 = new Polygon();
Polygon piece7 = new Polygon();
piece1.getPoints().addAll(new Double [] { piece1.getPoints().addAll(new Double [] {
0.0,0.0, 0.0,0.0,
200.0,0.0, 200.0,0.0,
@ -30,12 +44,72 @@ public class Piece extends Application{
100.0,100.0, 100.0,100.0,
0.0,100.0}); 0.0,100.0});
Group root = new Group(); piece2.getPoints().addAll(new Double [] {
root.getChildren().addAll(piece1); 100.0,0.0,
Scene scene = new Scene(root,490,450,Color.WHEAT); 200.0,0.0,
primaryStage.setScene(scene); 200.0,300.0,
primaryStage.setTitle("piece 1"); 100.0,300.0,
primaryStage.show(); });
piece3.getPoints().addAll(new Double [] {
0.0,0.0,
200.0,0.0,
200.0,200.0,
0.0,200.0,
});
piece4.getPoints().addAll(new Double [] {
0.0,0.0,
200.0,0.0,
200.0,300.0,
0.0,300.0,
});
piece5.getPoints().addAll(new Double [] {
0.0,0.0,
100.0,0.0,
100.0,100.0,
0.0,100.0,
});
piece6.getPoints().addAll(new Double [] {
0.0,0.0,
200.0,0.0,
200.0,300.0,
100.0,300.0,
100.0,100.0,
0.0,100.0});
piece7.getPoints().addAll(new Double [] {
100.0,0.0,
200.0,0.0,
200.0,200.0,
100.0,200.0,
});
/*for(int i ; i<tab.lenght ; i++ ) {
for (int j , i<tab.widnth , j++) {
if (tab[0][0]==TRUE;) {
if(tab[
}
}
}*/
Group root = new Group();
root.getChildren().addAll(piece2,piece1,piece3,piece4,piece5,piece6,piece7/*,....,pieceN*/);
Scene scene = new Scene(root,690,650,Color.WHEAT);
root.getChildren().forEach(n -> makeDraggable((Polygon) n));
root.getChildren().forEach(n -> rotation((Polygon) n, scene));
primaryStage.setScene(scene);
primaryStage.setTitle("piece 1");
primaryStage.show();
@ -43,73 +117,107 @@ public class Piece extends Application{
piece1.setStroke(Color.BLACK); piece1.setStroke(Color.BLACK);
piece1.setStrokeWidth(3); piece1.setStrokeWidth(3);
piece2.setFill(Color.LIMEGREEN);
piece2.setStroke(Color.BLACK);
piece2.setStrokeWidth(3);
//Instantiating RotateTransition class to create the animation (rotation to the right) piece3.setFill(Color.LIMEGREEN);
piece3.setStroke(Color.BLACK);
piece3.setStrokeWidth(3);
piece4.setFill(Color.LIMEGREEN);
piece4.setStroke(Color.BLACK);
piece4.setStrokeWidth(3);
piece5.setFill(Color.LIMEGREEN);
piece5.setStroke(Color.BLACK);
piece5.setStrokeWidth(3);
piece6.setFill(Color.LIMEGREEN);
piece6.setStroke(Color.BLACK);
piece6.setStrokeWidth(3);
piece7.setFill(Color.LIMEGREEN);
piece7.setStroke(Color.BLACK);
piece7.setStrokeWidth(3);
}
//double click delayed bug to fix
public static void rotaterght (Node node) {
RotateTransition rotaterght = new RotateTransition(); RotateTransition rotaterght = new RotateTransition();
//setting attributes for the RotateTransition
rotaterght.setByAngle(90);
rotaterght.autoReverseProperty();
rotaterght.setDuration(Duration.millis(1000));
rotaterght.setNode(piece1);
rotaterght.setAxis(Rotate.Z_AXIS);
//Instantiating RotateTransition class to create the animation (rotation to the left)
RotateTransition rotatelft = new RotateTransition();
//setting attributes for the RotateTransition //setting attributes for the RotateTransition
rotatelft.setByAngle(-90);// minus to rotate to the left rotaterght.setByAngle(90);
rotatelft.autoReverseProperty(); rotaterght.autoReverseProperty();
rotatelft.setDuration(Duration.millis(1000)); rotaterght.setDuration(Duration.millis(1000));
rotatelft.setNode(piece1); rotaterght.setNode(node);
rotatelft.setAxis(Rotate.Z_AXIS); rotaterght.setAxis(Rotate.Z_AXIS);
rotaterght.play();}
//Mouse events handling public static void rotatelft (Node node) {
piece1.setOnMousePressed(new EventHandler<MouseEvent>() { //Instantiating RotateTransition class to create the animation (rotation to the left)
@Override public void handle(MouseEvent mouseEvent) { RotateTransition rotatelft = new RotateTransition();
// record a (x,y) distance for the drag and drop operation. //setting attributes for the RotateTransition
x = piece1.getLayoutX() - mouseEvent.getSceneX(); rotatelft.setByAngle(-90);// minus to rotate to the left
y = piece1.getLayoutY() - mouseEvent.getSceneY(); rotatelft.autoReverseProperty();
piece1.setCursor(Cursor.CLOSED_HAND); rotatelft.setDuration(Duration.millis(1000));
piece1.setFill(Color.AZURE); rotatelft.setNode(node);
} rotatelft.setAxis(Rotate.Z_AXIS);
}); rotatelft.play();}
piece1.setOnMouseReleased(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
piece1.setCursor(Cursor.HAND);
piece1.setFill(Color.LIMEGREEN);
}
});
piece1.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
piece1.setLayoutX(mouseEvent.getSceneX() + x);
piece1.setLayoutY(mouseEvent.getSceneY() + y);
}
});
piece1.setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
piece1.setCursor(Cursor.HAND);
}
});
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
public void rotation (Polygon node, Scene scene) {
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
public void handle(KeyEvent event) {// 'event' means corresponds to clicking on the clipboard public void handle(KeyEvent event) {// 'event' means corresponds to clicking on the clipboard
switch (event.getCode()) {// 'getCode' gets the code of the key pressed on the clipboard switch (event.getCode()) {// 'getCode' gets the code of the key pressed on the clipboard
case RIGHT: rotaterght.play(); break; case RIGHT: rotaterght(node); break;
case LEFT: rotatelft.play(); break; //args to set
case LEFT: rotatelft(node); break;
default: System.out.println("this case hasn't been taken in charge yet"); default: System.out.println("this case hasn't been taken in charge yet");
} }
} }
}); });
}
}
public void makeDraggable(Polygon node) {
node.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
// record a (x,y) distance for the drag and drop operation.
x = node.getLayoutX() - mouseEvent.getSceneX();
y = node.getLayoutY() - mouseEvent.getSceneY();
node.requestFocus();
node.setFocusTraversable(true);
node.focusedProperty();
node.focusVisibleProperty();
/*node.setFocused(true);*/
node.setCursor(Cursor.CLOSED_HAND);
node.setFill(Color.AZURE);
}
});
node.setOnMouseReleased(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
node.setCursor(Cursor.HAND);
node.setFill(Color.LIMEGREEN);
}
});
node.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
node.setLayoutX(mouseEvent.getSceneX() + x);
node.setLayoutY(mouseEvent.getSceneY() + y);
}
});
node.setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
node.setCursor(Cursor.HAND);
}
});
}
public static void main(String[] args) { public static void main(String[] args) {