X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=LogicUI%2Fsrc%2Fera%2Fmi%2Fgui%2Fcomponents%2FGUIMux.java;fp=LogicUI%2Fsrc%2Fera%2Fmi%2Fgui%2Fcomponents%2FGUIMux.java;h=0082a768521842abbac122f3e7545bc3cb8ae205;hb=d3a382377768fdb1434d5baebf73c9413e61e46f;hp=0000000000000000000000000000000000000000;hpb=0cfea6ef89dea8a797708ff685aa2ef9aefd85b9;p=Mograsim.git diff --git a/LogicUI/src/era/mi/gui/components/GUIMux.java b/LogicUI/src/era/mi/gui/components/GUIMux.java new file mode 100644 index 00000000..0082a768 --- /dev/null +++ b/LogicUI/src/era/mi/gui/components/GUIMux.java @@ -0,0 +1,79 @@ +package era.mi.gui.components; + +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; +import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; + +public class GUIMux extends Mux implements BasicGUIComponent +{ + 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); + + double height = inputs.length * 5; + 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 + 20) / inputs.length; + double inputHeight = inputHeightIncrement / 2; + 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 Rectangle getBounds() + { + return new Rectangle(0, 0, 20, height + 20); + } + @Override + public void render(GeneralGC gc) + { + 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