import era.mi.logic.components.gates.AndGate;
import era.mi.logic.components.gates.NotGate;
import era.mi.logic.wires.WireArray;
+import net.haspamelodica.swt.helper.gcs.GeneralGC;
import net.haspamelodica.swt.helper.gcs.TranslatedGC;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
import net.haspamelodica.swt.helper.zoomablecanvas.ZoomableCanvas;
componentPositions = new HashMap<>();
initComponents();
- canvas.addZoomedRenderer(gc -> components.forEach(
- component -> component.render(new TranslatedGC(gc, componentPositions.get(component)))));
+ canvas.addZoomedRenderer(gc -> components.forEach(component -> drawComponent(gc, component)));
new ZoomableCanvasUserInput(canvas).enableUserInput();
new ZoomableCanvasOverlay(canvas, null).enableScale();
}
new NotGate(1, f, g);
new Merger(h, c, g);
addComponent(new GUIMux(1, i, e, h, d), 10, 10);
+ addComponent(new GUIMux(1, a, new WireArray(10, 1), a, b, e, f), 100, 100);
new Splitter(i, k, j);
}
private void addComponent(BasicGUIComponent component, double x, double y)
components.add(component);
componentPositions.put(component, new Point(x, y));
}
+ private void drawComponent(GeneralGC gc, BasicGUIComponent component)
+ {
+ TranslatedGC tgc = new TranslatedGC(gc, componentPositions.get(component));
+ component.render(tgc);
+ tgc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
+ for(int i = 0; i < component.getConnectedWireArraysCount(); i ++)
+ {
+ Point connectionPoint = component.getWireArrayConnectionPoint(i);
+ if(connectionPoint != null)
+ tgc.fillOval(connectionPoint.x - 2, connectionPoint.y - 2, 4, 4);
+ }
+ }
public void run()
{
shell.open();
package era.mi.components.gui;
+import java.util.List;
+
+import era.mi.logic.wires.WireArray;
import net.haspamelodica.swt.helper.gcs.GeneralGC;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
public interface BasicGUIComponent
{
public void render(GeneralGC gc);
+
+ public int getConnectedWireArraysCount();
+ public WireArray getConnectedWireArray(int connectionIndex);
+ public Point getWireArrayConnectionPoint(int connectionIndex);
}
\ No newline at end of file
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<WireArray> connectedWireArrays;
+ private final List<Point> 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<WireArray> connectedWireArraysModifiable = new ArrayList<>();
+ List<Point> 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