import org.eclipse.swt.SWT;\r
import org.eclipse.swt.layout.FillLayout;\r
import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.Event;\r
import org.eclipse.swt.widgets.Shell;\r
\r
import era.mi.components.gui.BasicGUIComponent;\r
+import era.mi.components.gui.GUIAndGate;\r
+import era.mi.components.gui.GUIManualSwitch;\r
+import era.mi.components.gui.GUIMerger;\r
import era.mi.components.gui.GUIMux;\r
+import era.mi.components.gui.GUINotGate;\r
+import era.mi.components.gui.GUISplitter;\r
import era.mi.logic.Simulation;\r
-import era.mi.logic.components.Merger;\r
-import era.mi.logic.components.Splitter;\r
-import era.mi.logic.components.gates.AndGate;\r
-import era.mi.logic.components.gates.NotGate;\r
import era.mi.logic.wires.WireArray;\r
import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
import net.haspamelodica.swt.helper.gcs.TranslatedGC;\r
{\r
private final Display display;\r
private final Shell shell;\r
+ private final ZoomableCanvas canvas;\r
private final Set<BasicGUIComponent> components;\r
private final Map<BasicGUIComponent, Point> componentPositions;\r
\r
display = new Display();\r
shell = new Shell(display);\r
shell.setLayout(new FillLayout());\r
- ZoomableCanvas canvas = new ZoomableCanvas(shell, SWT.NONE);\r
+ canvas = new ZoomableCanvas(shell, SWT.NONE);\r
\r
components = new HashSet<>();\r
componentPositions = new HashMap<>();\r
initComponents();\r
\r
canvas.addZoomedRenderer(gc -> components.forEach(component -> drawComponent(gc, component)));\r
- new ZoomableCanvasUserInput(canvas).enableUserInput();\r
+ ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(canvas);\r
+ userInput.buttonDrag = 3;\r
+ userInput.buttonZoom = 2;\r
+ userInput.enableUserInput();\r
new ZoomableCanvasOverlay(canvas, null).enableScale();\r
+ canvas.addListener(SWT.MouseDown, this::mouseDown);\r
}\r
private void initComponents()\r
{\r
Simulation.TIMELINE.reset();\r
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),\r
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);\r
- new AndGate(1, f, a, b);\r
- new NotGate(1, f, g);\r
- new Merger(h, c, g);\r
+ addComponent(new GUIManualSwitch(a), 160, 10);\r
+ addComponent(new GUIAndGate(1, f, a, b), 130, 10);\r
+ addComponent(new GUINotGate(1, f, g), 100, 10);\r
+ addComponent(new GUIMerger(h, c, g), 70, 10);\r
addComponent(new GUIMux(1, i, e, h, d), 10, 10);\r
- addComponent(new GUIMux(1, a, new WireArray(10, 1), a, b, e, f), 100, 100);\r
- new Splitter(i, k, j);\r
+ addComponent(new GUISplitter(i, k, j), 40, 10);\r
}\r
private void addComponent(BasicGUIComponent component, double x, double y)\r
{\r
{\r
Point connectionPoint = component.getWireArrayConnectionPoint(i);\r
if(connectionPoint != null)\r
- tgc.fillOval(connectionPoint.x - 2, connectionPoint.y - 2, 4, 4);\r
+ tgc.fillOval(connectionPoint.x - 1, connectionPoint.y - 1, 2, 2);\r
}\r
}\r
+ private void mouseDown(Event e)\r
+ {\r
+ if(e.button == 1)\r
+ {\r
+ Point click = canvas.displayToWorldCoords(e.x, e.y);\r
+ for(BasicGUIComponent component : components)\r
+ if(component.getBounds().translate(componentPositions.get(component)).contains(click))\r
+ {\r
+ if(component.clicked(click.x, click.y))\r
+ canvas.redraw();\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
public void run()\r
{\r
shell.open();\r