Skip to content
Snippets Groups Projects
Commit 2e670c2c authored by CHAHINE Rami's avatar CHAHINE Rami
Browse files

.

parent 0e769f3c
No related branches found
No related tags found
No related merge requests found
package TP7.state;
import TP7.shape.Shape;
public class StateMoveShape implements DrawerState{
private Shape selectedShape;
private double previousX, previousY;
@Override
public void mousePressed(DrawerContext context, double x, double y) {
selectedShape = context.getDrawer().shapeContains(x,y);
System.out.println("selectedShape : " + selectedShape);
if(selectedShape != null) {
previousX = x;
previousY = y;
}
}
@Override
public void mouseReleased(DrawerContext context, double x, double y) {
selectedShape = null;
}
@Override
public void mouseMoved(DrawerContext context, double x, double y) {
if(selectedShape != null) {
double deltaX = x - previousX;
double deltaY = y - previousY;
selectedShape.translate(deltaX, deltaY);
previousX = x;
previousY = y;
context.getDrawer().repaint();
}
}
@Override
public void paint(DrawerContext context) {
}
}
package TP7.state;
import TP7.shape.Rectangle;
public class StateRectangle0 implements DrawerState{
public StateRectangle0() { }
@Override
public void mousePressed(DrawerContext context, double x, double y) {
Rectangle rectangle = new Rectangle(x, y,0,0);
rectangle.setFinished(false);
context.getDrawer().addShape(rectangle);
context.setState(new StateRectangle1(rectangle));
}
@Override
public void mouseReleased(DrawerContext context, double x, double y) {
}
@Override
public void mouseMoved(DrawerContext context, double x, double y) {
}
@Override
public void paint(DrawerContext context) {
}
}
package TP7.state;
import TP7.shape.Rectangle;
public class StateRectangle1 implements DrawerState {
private Rectangle rectangle;
private double startX, startY;
public StateRectangle1(Rectangle rectangle) {
this.rectangle = rectangle;
this.startX = rectangle.getX();
this.startY = rectangle.getY();
}
@Override
public void mousePressed(DrawerContext context, double x, double y) {}
@Override
public void mouseReleased(DrawerContext context, double x, double y) {
rectangle.setFinished(true);
context.paint(context.getDrawer().getGraphicsContext2D());
context.setState(new StateRectangle0());
}
@Override
public void mouseMoved(DrawerContext context, double x, double y) {
double width = x - startX;
double height = y - startY;
rectangle.setDimensions(startX,startY,width,height);
context.paint(context.getDrawer().getGraphicsContext2D());
}
@Override
public void paint(DrawerContext context) {
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment