1 package era.mi.gui.model.wires;
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.graphics.Color;
6 import era.mi.logic.types.Bit;
7 import era.mi.logic.wires.Wire;
8 import net.haspamelodica.swt.helper.gcs.GeneralGC;
9 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
15 private double[] path;
19 public GUIWire(Runnable redraw, Pin pin1, Pin pin2, Point... path)
21 this.path = new double[path.length * 2 + 4];
22 for (int srcI = 0, dstI = 2; srcI < path.length; srcI++, dstI += 2)
24 this.path[dstI + 0] = path[srcI].x;
25 this.path[dstI + 1] = path[srcI].y;
27 // TODO support moving pins
33 this.path[this.path.length - 2] = pos.x;
34 this.path[this.path.length - 1] = pos.y;
37 public void render(GeneralGC gc)
39 Color oldFG = gc.getForeground();
40 gc.setForeground(gc.getDevice().getSystemColor(getSWTColorConstantForWire(wire)));
41 gc.drawPolyline(path);
42 gc.setForeground(oldFG);
45 public void setLogicModelWire(Wire wire)
50 public static int getSWTColorConstantForWire(Wire wire)
52 if (wire != null && wire.length == 1)
53 return getSWTColorConstantForBit(wire.getValue());
55 return SWT.COLOR_BLACK;
58 public static int getSWTColorConstantForBit(Bit bit)
63 return SWT.COLOR_GREEN;
65 return SWT.COLOR_BLUE;
67 return SWT.COLOR_BLACK;
72 throw new IllegalArgumentException("Unknown enum constant: " + bit);