-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectableMapObject.java
More file actions
49 lines (39 loc) · 1.96 KB
/
SelectableMapObject.java
File metadata and controls
49 lines (39 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package sample;
import com.sun.javafx.geom.Vec2d;
import javafx.geometry.Point2D;
/**
* Created by Jordan on 31/07/2017.
*/
public class SelectableMapObject extends MapObject{
protected ObjectProperty<Double> angle;
SelectableMapObject(String objectname, Point2D location, MainInterface mainInterface, Vec2d size, int depth){
super(objectname, location, mainInterface, size, depth);
this.selectable.Value = true;
angle = new ObjectProperty<Double>(0.0, "Angle", false);
Properties.add(this.angle);
}
public boolean isTouched(Point2D clickLocation){
Point2D canvasLocation = canvasLocation();
int east = (int) canvasLocation.getX();
int west = east + (int)(this.size.Value.x*this.getMainInterface().getZoomScale());
int north = (int) canvasLocation.getY();
int south = north + (int)(this.size.Value.y*this.getMainInterface().getZoomScale());
int clickX = (int) clickLocation.getX();
int clickY = (int) clickLocation.getY();
if(east <= clickX && clickX <= west && north <= clickY && clickY <= south){
return true;
}
return false;
}
public void move(double x, double y){
this.location.Value = this.location.Value.add(x/mainInterface.getZoomScale(), y/mainInterface.getZoomScale());
}
public void rotate(double x, double y){
System.out.println((x-this.canvasLocation().getX())+" "+(y-this.canvasLocation().getY()));
System.out.println(Math.toDegrees(Math.atan2(x-this.canvasLocation().getX(), y-this.canvasLocation().getY())));
this.angle.Value = -(Math.toDegrees(Math.atan2(x-this.canvasLocation().getX(), y-this.canvasLocation().getY())));
}
public MapObject createMapObject(MainInterface mainInterface){
return new SelectableMapObject("MapObject", mainInterface.getCanvasOffset(), mainInterface, new Vec2d(5,5), Layer.BACKGROUND);
}
}