X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=LogicUI%2Fsrc%2FLogicUI.java;h=9d31c306a182bcb91a8ada7efb1e643c8bbf984d;hb=a923135e79725ab79434f5c53f3fdf63e990a8af;hp=97a5c75b1c16e8e50a3030ed3efcbcc5ddc1546f;hpb=70aaa694028a17acf0ac07ee6870659947ba28f0;p=Mograsim.git diff --git a/LogicUI/src/LogicUI.java b/LogicUI/src/LogicUI.java index 97a5c75b..9d31c306 100644 --- a/LogicUI/src/LogicUI.java +++ b/LogicUI/src/LogicUI.java @@ -6,15 +6,17 @@ import java.util.Set; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; import era.mi.components.gui.BasicGUIComponent; +import era.mi.components.gui.GUIAndGate; +import era.mi.components.gui.GUIManualSwitch; +import era.mi.components.gui.GUIMerger; import era.mi.components.gui.GUIMux; +import era.mi.components.gui.GUINotGate; +import era.mi.components.gui.GUISplitter; import era.mi.logic.Simulation; -import era.mi.logic.components.Merger; -import era.mi.logic.components.Splitter; -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; @@ -27,6 +29,7 @@ public class LogicUI { private final Display display; private final Shell shell; + private final ZoomableCanvas canvas; private final Set components; private final Map componentPositions; @@ -35,27 +38,31 @@ public class LogicUI display = new Display(); shell = new Shell(display); shell.setLayout(new FillLayout()); - ZoomableCanvas canvas = new ZoomableCanvas(shell, SWT.NONE); + canvas = new ZoomableCanvas(shell, SWT.NONE); components = new HashSet<>(); componentPositions = new HashMap<>(); initComponents(); canvas.addZoomedRenderer(gc -> components.forEach(component -> drawComponent(gc, component))); - new ZoomableCanvasUserInput(canvas).enableUserInput(); + ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(canvas); + userInput.buttonDrag = 3; + userInput.buttonZoom = 2; + userInput.enableUserInput(); new ZoomableCanvasOverlay(canvas, null).enableScale(); + canvas.addListener(SWT.MouseDown, this::mouseDown); } private void initComponents() { Simulation.TIMELINE.reset(); WireArray a = new WireArray(1, 1), b = new WireArray(1, 1), c = new WireArray(1, 10), d = new WireArray(2, 1), e = new WireArray(1, 1), f = new WireArray(1, 1), g = new WireArray(1, 1), h = new WireArray(2, 1), i = new WireArray(2, 1), j = new WireArray(1, 1), k = new WireArray(1, 1); - new AndGate(1, f, a, b); - new NotGate(1, f, g); - new Merger(h, c, g); + addComponent(new GUIManualSwitch(a), 160, 10); + addComponent(new GUIAndGate(1, f, a, b), 130, 10); + addComponent(new GUINotGate(1, f, g), 100, 10); + addComponent(new GUIMerger(h, c, g), 70, 10); 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); + addComponent(new GUISplitter(i, k, j), 40, 10); } private void addComponent(BasicGUIComponent component, double x, double y) { @@ -71,9 +78,24 @@ public class LogicUI { Point connectionPoint = component.getWireArrayConnectionPoint(i); if(connectionPoint != null) - tgc.fillOval(connectionPoint.x - 2, connectionPoint.y - 2, 4, 4); + tgc.fillOval(connectionPoint.x - 1, connectionPoint.y - 1, 2, 2); } } + private void mouseDown(Event e) + { + if(e.button == 1) + { + Point click = canvas.displayToWorldCoords(e.x, e.y); + for(BasicGUIComponent component : components) + if(component.getBounds().translate(componentPositions.get(component)).contains(click)) + { + if(component.clicked(click.x, click.y)) + canvas.redraw(); + break; + } + } + } + public void run() { shell.open();