checkpoint
authoradam <adam@megacz.com>
Thu, 19 Apr 2007 04:20:51 +0000 (05:20 +0100)
committeradam <adam@megacz.com>
Thu, 19 Apr 2007 04:20:51 +0000 (05:20 +0100)
src/edu/berkeley/slipway/gui/GuiCell.java
src/edu/berkeley/slipway/gui/GuiGate.java
src/edu/berkeley/slipway/gui/P.java
src/edu/berkeley/slipway/gui/R.java

index 10992e9..ebd3044 100644 (file)
@@ -50,11 +50,15 @@ public class GuiCell {
 
     private void drawBody(G g, R r) {
         if (xgate == null && ygate == null) return;
 
     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;
         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 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);
 
         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) {
         if (xgate != null) {
-            xgate.rotation = rot;
+            xgate.rotation(fpslicCell.yi());
             xgate.gateArea = gateArea;
             xgate.r = xgater;
         }
         if (ygate != null) {
             xgate.gateArea = gateArea;
             xgate.r = xgater;
         }
         if (ygate != null) {
-            ygate.rotation = rot;
+            ygate.rotation(fpslicCell.yi());
             ygate.gateArea = gateArea;
             ygate.r = ygater;
         }
 
             ygate.gateArea = gateArea;
             ygate.r = ygater;
         }
 
-        int TSIZE   = 10;
-        double TSQR = TSIZE / Math.sqrt(2.0);
         g.color(XGATE_COLOR);
         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));
         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);
         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));
         if (p!=null) {
             if (ygate != null) {
                 g.route(p, yring, ygate.getInput(0));
index 56babc4..d3cab26 100644 (file)
@@ -5,6 +5,7 @@ import java.awt.*;
 import java.awt.geom.*;
 import java.awt.event.*;
 import java.awt.color.*;
 import java.awt.geom.*;
 import java.awt.event.*;
 import java.awt.color.*;
+import static com.atmel.fpslic.FpslicConstants.*;
 
 public class GuiGate {
 
 
 public class GuiGate {
 
@@ -66,4 +67,14 @@ public class GuiGate {
                      r.miny() + r.height()/2).transform(at);
     }
 
                      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
 }
\ No newline at end of file
index 79c986e..56b2304 100644 (file)
@@ -40,4 +40,5 @@ public class P {
         return new P(dx+x, dy+y);
     }
 
         return new P(dx+x, dy+y);
     }
 
+
 }
 }
index 27ed3e7..fcc75c5 100644 (file)
@@ -2,6 +2,7 @@ package edu.berkeley.slipway.gui;
 
 import com.atmel.fpslic.*;
 import java.awt.geom.*;
 
 import com.atmel.fpslic.*;
 import java.awt.geom.*;
+import static com.atmel.fpslic.FpslicConstants.*;
 
 public class R {
 
 
 public class R {
 
@@ -44,4 +45,18 @@ public class R {
                      maxx()+maxxplus,
                      maxy()+maxyplus);
     }
                      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
 }
\ No newline at end of file