From d04562880cfecf6fdaf5eab0e0da92cab8225e04 Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 19 Apr 2007 05:20:51 +0100 Subject: [PATCH] checkpoint --- src/edu/berkeley/slipway/gui/GuiCell.java | 37 +++++++---------------------- src/edu/berkeley/slipway/gui/GuiGate.java | 11 +++++++++ src/edu/berkeley/slipway/gui/P.java | 1 + src/edu/berkeley/slipway/gui/R.java | 15 ++++++++++++ 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/edu/berkeley/slipway/gui/GuiCell.java b/src/edu/berkeley/slipway/gui/GuiCell.java index 10992e9..ebd3044 100644 --- a/src/edu/berkeley/slipway/gui/GuiCell.java +++ b/src/edu/berkeley/slipway/gui/GuiCell.java @@ -50,11 +50,15 @@ public class GuiCell { 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; @@ -66,36 +70,19 @@ public class GuiCell { 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)); @@ -107,14 +94,8 @@ public class GuiCell { } } - 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)); diff --git a/src/edu/berkeley/slipway/gui/GuiGate.java b/src/edu/berkeley/slipway/gui/GuiGate.java index 56babc4..d3cab26 100644 --- a/src/edu/berkeley/slipway/gui/GuiGate.java +++ b/src/edu/berkeley/slipway/gui/GuiGate.java @@ -5,6 +5,7 @@ import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import java.awt.color.*; +import static com.atmel.fpslic.FpslicConstants.*; public class GuiGate { @@ -66,4 +67,14 @@ 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 diff --git a/src/edu/berkeley/slipway/gui/P.java b/src/edu/berkeley/slipway/gui/P.java index 79c986e..56b2304 100644 --- a/src/edu/berkeley/slipway/gui/P.java +++ b/src/edu/berkeley/slipway/gui/P.java @@ -40,4 +40,5 @@ public class P { return new P(dx+x, dy+y); } + } diff --git a/src/edu/berkeley/slipway/gui/R.java b/src/edu/berkeley/slipway/gui/R.java index 27ed3e7..fcc75c5 100644 --- a/src/edu/berkeley/slipway/gui/R.java +++ b/src/edu/berkeley/slipway/gui/R.java @@ -2,6 +2,7 @@ package edu.berkeley.slipway.gui; import com.atmel.fpslic.*; import java.awt.geom.*; +import static com.atmel.fpslic.FpslicConstants.*; public class R { @@ -44,4 +45,18 @@ 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 -- 1.7.10.4