-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouse.java
More file actions
44 lines (40 loc) · 1.65 KB
/
Mouse.java
File metadata and controls
44 lines (40 loc) · 1.65 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
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
public class Mouse extends MouseAdapter {
//listens for mouse clicks and tests if near a node
@Override
public void mouseClicked(MouseEvent e) {
for (Node workingNode : Main.nodeList) {
if (Math.abs(e.getPoint().x - workingNode.getPrintPos().x) < workingNode.getWidth()/2 && Math.abs(e.getPoint().y - workingNode.getPrintPos().y) < workingNode.getWidth()/2) {
workingNode.clicked();
workingNode.setConnection();
return;
}
}
if (Main.nextGatePlacement != null) {
Main.nodeList.add(new Node(Node.getWorldPos(e.getPoint()), Main.nextGatePlacement));
Main.nextGatePlacement.copy();
Main.deletedNodeList.clear();
}
Main.lastNodeClicked = null;
Main.p.repaint();
}
//sets the scale of nodes and moves them accordingly about the world center for zooming effect
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getWheelRotation() == 1.0) {
Main.worldSpaceToScreenSpace.addScalers(1.1, 1.1);
for (Node workingNode : Main.nodeList) {
workingNode.scaleDimensions(1.1, 1.1);
}
}
if (e.getWheelRotation() == -1.0) {
Main.worldSpaceToScreenSpace.addScalers((1.0/1.1), (1.0/1.1));
for (Node workingNode : Main.nodeList) {
workingNode.scaleDimensions((1.0/1.1), (1.0/1.1));
}
}
Main.worldSpaceToScreenSpace.setWorld();
Main.p.repaint();
}
}