private void drawBody(G g, R r) {
if (xgate == null && ygate == null) return;
+
+ int N = 7;
+ int TSIZE = 10;
+ double TSQR = TSIZE / Math.sqrt(2.0);
+
R body = r;
g.color(BODY_COLOR);
R xgater = null;
R ygater = null;
- int N = 7;
R gateArea = body.plus(12+N, 12+N, -(4+N), -(4+N));
if (xgate==null) ygater = gateArea;
else if (ygate==null) xgater = gateArea;
R xring = gateArea.plus(-4, -4, 4, 4);
R yring = gateArea.plus(-6, -6, 6, 6);
-
- int rot = 0;
- switch (fpslicCell.yi()) {
- case NORTH: rot = 2; break;
- case SOUTH: rot = 0; break;
- case WEST: rot = 3; break;
- case EAST: rot = 1; break;
- default: rot = 0;
- }
if (xgate != null) {
- xgate.rotation = rot;
+ xgate.rotation(fpslicCell.yi());
xgate.gateArea = gateArea;
xgate.r = xgater;
}
if (ygate != null) {
- ygate.rotation = rot;
+ ygate.rotation(fpslicCell.yi());
ygate.gateArea = gateArea;
ygate.r = ygater;
}
- int TSIZE = 10;
- double TSQR = TSIZE / Math.sqrt(2.0);
g.color(XGATE_COLOR);
- P p = null;
- switch (fpslicCell.xi()) {
- case SW: p = new P(r.minx(), r.miny()); break;
- case SE: p = new P(r.maxx(), r.miny()); break;
- case NW: p = new P(r.minx(), r.maxy()); break;
- case NE: p = new P(r.maxx(), r.maxy()); break;
- }
+ P p = r.corner(fpslicCell.xi());
if (p!=null) {
if (ygate != null) {
g.route(p, xring, ygate.getInput(1));
}
}
- p = null;
+ p = r.corner(fpslicCell.yi());
g.color(YGATE_COLOR);
- switch (fpslicCell.yi()) {
- case NORTH: p = new P(r.cx(), r.maxy()); break;
- case SOUTH: p = new P(r.cx(), r.miny()); break;
- case WEST: p = new P(r.minx(), r.cy()); break;
- case EAST: p = new P(r.maxx(), r.cy()); break;
- }
if (p!=null) {
if (ygate != null) {
g.route(p, yring, ygate.getInput(0));
import java.awt.geom.*;
import java.awt.event.*;
import java.awt.color.*;
+import static com.atmel.fpslic.FpslicConstants.*;
public class GuiGate {
r.miny() + r.height()/2).transform(at);
}
+ public void rotation(int dir) {
+ switch (dir) {
+ case NORTH: rotation = 2; break;
+ case SOUTH: rotation = 0; break;
+ case WEST: rotation = 3; break;
+ case EAST: rotation = 1; break;
+ default: rotation = 0;
+ }
+ }
+
}
\ No newline at end of file
import com.atmel.fpslic.*;
import java.awt.geom.*;
+import static com.atmel.fpslic.FpslicConstants.*;
public class R {
maxx()+maxxplus,
maxy()+maxyplus);
}
+
+ public P corner(int dir) {
+ switch (dir) {
+ case SW: return new P(minx(), miny());
+ case SE: return new P(maxx(), miny());
+ case NW: return new P(minx(), maxy());
+ case NE: return new P(maxx(), maxy());
+ case NORTH: return new P(cx(), maxy());
+ case SOUTH: return new P(cx(), miny());
+ case WEST: return new P(minx(), cy());
+ case EAST: return new P(maxx(), cy());
+ default: return null;
+ }
+ }
}
\ No newline at end of file