X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=LogicUI%2Fsrc%2Fera%2Fmi%2Fcomponents%2Fgui%2FGUIMux.java;h=509a8ccd0658315d84f1540529a9fa96fc281605;hb=26d5c3c4b6fa4d85f4aba3552a69da9c9c832d7f;hp=d5b7c48820103b0d163542cbe21e23dccec38f2f;hpb=7ba7a5160d1167f9d0510d811a2865a7d95b6952;p=Mograsim.git diff --git a/LogicUI/src/era/mi/components/gui/GUIMux.java b/LogicUI/src/era/mi/components/gui/GUIMux.java index d5b7c488..509a8ccd 100644 --- a/LogicUI/src/era/mi/components/gui/GUIMux.java +++ b/LogicUI/src/era/mi/components/gui/GUIMux.java @@ -1,28 +1,72 @@ package era.mi.components.gui; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + import era.mi.logic.components.Mux; import era.mi.logic.wires.WireArray; import net.haspamelodica.swt.helper.gcs.GeneralGC; +import net.haspamelodica.swt.helper.swtobjectwrappers.Point; public class GUIMux extends Mux implements BasicGUIComponent { - private final int inputCount; + private final double height; + private final List connectedWireArrays; + private final List wireArrayConnectionPoints; public GUIMux(int processTime, WireArray out, WireArray select, WireArray... inputs) { super(processTime, out, select, inputs); - this.inputCount = inputs.length; + + double height = inputs.length * 10; + if(height < 10) + height = 10; + this.height = height; + + List connectedWireArraysModifiable = new ArrayList<>(); + List wireArrayConnectionPointsModifiable = new ArrayList<>(); + + connectedWireArraysModifiable.add(out); + wireArrayConnectionPointsModifiable.add(new Point(20, 10 + height / 2)); + + connectedWireArraysModifiable.add(select); + wireArrayConnectionPointsModifiable.add(new Point(10, 5)); + + { + connectedWireArraysModifiable.addAll(Arrays.asList(inputs)); + double inputHeightIncrement = height / (inputs.length - 1); + double inputHeight = 10; + for(int i = 0; i < inputs.length; i ++, inputHeight += inputHeightIncrement) + wireArrayConnectionPointsModifiable.add(new Point(0, inputHeight)); + } + + this.connectedWireArrays = Collections.unmodifiableList(connectedWireArraysModifiable); + this.wireArrayConnectionPoints = Collections.unmodifiableList(wireArrayConnectionPointsModifiable); } @Override public void render(GeneralGC gc) { - double height = inputCount * 10; - if(height < 20) - height = 20; gc.drawPolygon(new double[] { 0, 0, 20, 10, 20, height + 10, 0, height + 20}); } + @Override + public int getConnectedWireArraysCount() + { + return connectedWireArrays.size(); + } + @Override + public WireArray getConnectedWireArray(int connectionIndex) + { + return connectedWireArrays.get(connectionIndex); + } + @Override + public Point getWireArrayConnectionPoint(int connectionI) + { + return wireArrayConnectionPoints.get(connectionI); + } } \ No newline at end of file