X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.editor%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Feditor%2Fhandles%2FWireHandle.java;h=199df99c22571e7053ec02defef7dc2086676522;hb=6e1902e006401ddea190178595bf6ae6357e74ad;hp=0e6c455557a8aa6e67b89344718dfc9e45701149;hpb=cc6e329dc014542eb743833ef865b9d59047abbb;p=Mograsim.git diff --git a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java index 0e6c4555..199df99c 100644 --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java @@ -24,7 +24,7 @@ public class WireHandle extends Handle parent.addPathChangedListener(c -> updateBounds()); updateBounds(); } - + @Override void destroy() { @@ -38,18 +38,18 @@ public class WireHandle extends Handle moveTo(r.x, r.y); setSize(r.width, r.height); } - + @Override public void render(GeneralGC gc) { - if(selected) + if (selected) { gc.setLineWidth(WIDTH); gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_YELLOW)); gc.drawPolyline(parent.getEffectivePath()); } } - + @Override public void onSelect() { @@ -63,42 +63,43 @@ public class WireHandle extends Handle selected = false; callRedrawListeners(); } - + @Override public void reqDelete() { parent.destroy(); } - + @Override public boolean contains(double x, double y) { return click(parent, x, y).isPresent(); } - + @Override public boolean click(double x, double y, int stateMask, EditorState state) { Optional op = click(parent, x, y); - if(op.isEmpty()) + if (op.isEmpty()) return false; WireClickData data = op.get(); return state.clickedHandle(new WireHandleClickInfo(this, data.segment, data.pos, stateMask)); } - + public static class WireHandleClickInfo extends HandleClickInfo { public final int segment; public final Point posOnWire; + WireHandleClickInfo(WireHandle clicked, int segment, Point posOnWire, int stateMask) { super(clicked, stateMask); this.segment = segment; this.posOnWire = posOnWire; } - + } - + private static Optional click(GUIWire w, double x, double y) { Rectangle modifiedBounds = w.getBounds(); @@ -111,8 +112,8 @@ public class WireHandle extends Handle double[] effectivePath = w.getEffectivePath(); for (int i = 3; i < effectivePath.length; i += 2) { - double a1 = effectivePath[i - 3], a2 = effectivePath[i - 2], b1 = effectivePath[i - 1], - b2 = effectivePath[i], r1 = b2 - a2, r2 = a1 - b1; + double a1 = effectivePath[i - 3], a2 = effectivePath[i - 2], b1 = effectivePath[i - 1], b2 = effectivePath[i], r1 = b2 - a2, + r2 = a1 - b1; double f = ((x - a1) * r2 + (a2 - y) * r1) / (-r2 * r2 - r1 * r1); if (f >= 0 && f <= 1) @@ -145,7 +146,7 @@ public class WireHandle extends Handle */ public final int segment; } - + @Override public HandleType getType() {