1 package edu.berkeley.slipway.gui;
3 import com.atmel.fpslic.*;
5 import java.awt.geom.*;
6 import java.awt.event.*;
7 import java.awt.color.*;
8 import static com.atmel.fpslic.FpslicConstants.*;
10 public class GuiGate {
12 private GeneralPath gp = new GeneralPath();
17 boolean disabled = false;
20 gp.moveTo(29.141f, 36.301f);
21 gp.lineTo(29.141f, 36.301f-7.161f);
22 gp.curveTo(27.71f, 11.24f, 23.413f, 9.45f, 14.82f, 0.5f);
23 gp.curveTo(6.229f, 9.45f, 1.932f, 11.24f, 0.5f, 29.141f);
24 gp.lineTo(0.5f, 29.141f+7.161f);
26 float y = 29.141f+7.161f;
27 gp.curveTo(5.729f+x, -1.789f+y, 6.444f+x, -2.686f+y, 14.32f+x, -3.58f+y);
28 gp.curveTo(22.697f, 33.616f, 23.413f, 34.512f, 29.141f, 36.301f);
29 double minx = gp.getBounds2D().getMinX();
30 double miny = gp.getBounds2D().getMinY();
31 gp.transform(AffineTransform.getTranslateInstance(-minx, -miny));
32 double width = gp.getBounds2D().getWidth();
33 double height = gp.getBounds2D().getHeight();
34 double factor = Math.max(width, height);
35 gp.transform(AffineTransform.getTranslateInstance(-width/2, -height/2));
36 gp.transform(AffineTransform.getScaleInstance(1.0/factor, -1.0/factor));
39 public void draw(G g, int color) {
42 g.g.translate(gateArea.cx(), gateArea.cy());
43 g.g.rotate((2 * Math.PI * rotation)/4);
44 g.g.translate(-1 * gateArea.cx(), -1 * gateArea.cy());
45 AffineTransform at = AffineTransform.getTranslateInstance(r.cx(), r.cy());
46 at.scale(r.getWidth(), r.getHeight());
48 g.g.fill(gp.createTransformedShape(at));
50 g.g.draw(gp.createTransformedShape(at));
54 public P getInput(int index) {
55 AffineTransform at = new AffineTransform();
56 at.translate(gateArea.cx(), gateArea.cy());
57 at.rotate((2 * Math.PI * rotation)/4);
58 at.translate(-1 * gateArea.cx(), -1 * gateArea.cy());
59 return new P(r.minx() + ((index + 1) * r.width()) / 4,
60 r.miny() - 3).transform(at);
63 public P getInputDest(int index) {
64 AffineTransform at = new AffineTransform();
65 at.translate(gateArea.cx(), gateArea.cy());
66 at.rotate((2 * Math.PI * rotation)/4);
67 at.translate(-1 * gateArea.cx(), -1 * gateArea.cy());
68 return new P(r.minx() + ((index + 1) * r.width()) / 4,
69 r.miny() + r.height()/2).transform(at);
72 public void rotation(int dir) {
74 case NORTH: rotation = 2; break;
75 case SOUTH: rotation = 0; break;
76 case WEST: rotation = 3; break;
77 case EAST: rotation = 1; break;
78 default: rotation = 0;
82 public void route(G g, P p, R ring, int input, int color) {
85 g.route(p, ring, getInput(input));
86 g.line(getInput(input), getInputDest(input));