Skip to content

Commit e80f9ff

Browse files
authored
Merge pull request TeachingTechnologistBeth#33 from EdNutting/master
Straight Paths
2 parents 91ed4e1 + 03c80a0 commit e80f9ff

19 files changed

Lines changed: 468 additions & 34 deletions

src/com/modsim/gui/view/ViewUtil.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import com.modsim.modules.parts.Port;
1313
import com.modsim.simulator.*;
1414
import com.modsim.tools.*;
15-
import com.modsim.util.BezierPath;
15+
import com.modsim.util.Path;
1616
import com.modsim.util.Vec2;
1717

1818
/**
@@ -34,7 +34,7 @@ public class ViewUtil implements MouseListener, MouseMotionListener, MouseWheelL
3434
*/
3535
public static Link worldSpace_linkAt(Vec2 pt) {
3636
for (Link link : Main.sim.getLinks()) {
37-
BezierPath.PointInfo info = link.path.approxClosestPoint(pt, 6);
37+
Path.PointInfo info = link.path.approxClosestPoint(pt, 6);
3838

3939
if (info.dist < 15.0) {
4040
return link;
@@ -267,12 +267,12 @@ public void mousePressed(MouseEvent e) {
267267
boolean handled = false;
268268
if (targ != null && targ.getType() == PickableEntity.MODULE) {
269269
BaseModule m = (BaseModule) targ;
270-
handled = m.lbDown(e.getX(), e.getY());
270+
handled = m.lbDown(e.getX(), e.getY(), e.isShiftDown());
271271
}
272272

273273
if (!handled) {
274274
if (tool != null) {
275-
Main.ui.view.curTool = tool.lbDown(e.getX(), e.getY());
275+
Main.ui.view.curTool = tool.lbDown(e.getX(), e.getY(), e.isShiftDown());
276276
}
277277
else {
278278
Port p = screenSpace_portAt(e.getX(), e.getY());
@@ -282,7 +282,7 @@ public void mousePressed(MouseEvent e) {
282282
//Link behaviour
283283
if (p != null) {
284284
tool = new MakeLinkTool();
285-
Main.ui.view.curTool = tool.lbDown(e.getX(), e.getY());
285+
Main.ui.view.curTool = tool.lbDown(e.getX(), e.getY(), e.isShiftDown());
286286
}
287287
else {
288288
// Link edit if we haven't hit a module
@@ -299,7 +299,7 @@ public void mousePressed(MouseEvent e) {
299299

300300
// Finally, try selection behaviour
301301
tool = new SelectTool();
302-
Main.ui.view.curTool = tool.lbDown(e.getX(), e.getY());
302+
Main.ui.view.curTool = tool.lbDown(e.getX(), e.getY(), e.isShiftDown());
303303
}
304304
}
305305
}

src/com/modsim/modules/BaseModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ public void delete() {
560560
* @param iy Y coord in view space
561561
* @return Whether the input was handled
562562
*/
563-
public boolean lbDown(int ix, int iy) {
563+
public boolean lbDown(int ix, int iy, boolean isShiftDown) {
564564
if (!enabled) return false;
565565

566566
// Coords in object space
@@ -573,7 +573,7 @@ public boolean lbDown(int ix, int iy) {
573573

574574
synchronized (parts) {
575575
for (VisiblePart p : parts) {
576-
if (p.lbDown(dx, dy)) {
576+
if (p.lbDown(dx, dy, isShiftDown)) {
577577
return true;
578578
}
579579
}

src/com/modsim/modules/Link.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import com.modsim.Main;
1111
import com.modsim.res.Colors;
1212
import com.modsim.operations.DeleteOperation;
13+
import com.modsim.util.Path;
1314
import com.modsim.util.BezierPath;
15+
import com.modsim.util.StraightPath;
1416
import com.modsim.util.BinData;
1517

1618
/**
@@ -22,7 +24,7 @@ public class Link {
2224

2325
public Port src;
2426
public Port targ;
25-
public BezierPath path;
27+
public Path path;
2628

2729
public boolean highlight = false;
2830

@@ -47,7 +49,7 @@ public int getLinkID() {
4749
* @param path A bezier path to display for the link
4850
* @return New link, or null if link was invalid
4951
*/
50-
public static Link createLink(Port source, Port target, BezierPath path) {
52+
public static Link createLink(Port source, Port target, Path path) {
5153
// Check error conditions first
5254

5355
if (source == null || target == null) {

src/com/modsim/modules/parts/PushBtn.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void init() {
4242
}
4343

4444
@Override
45-
public boolean lbDown(int xPt, int yPt) {
45+
public boolean lbDown(int xPt, int yPt, boolean isShiftDown) {
4646
if (xPt > x-w/2 && xPt < x+w/2 && yPt > y-h/2 && yPt < y+h/2) {
4747
// Clicked
4848
setEnabled(true);

src/com/modsim/modules/parts/Switch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void setColour(LEDColour col) {
3636
}
3737

3838
@Override
39-
public boolean lbDown(int xPt, int yPt) {
39+
public boolean lbDown(int xPt, int yPt, boolean isShiftDown) {
4040
if (xPt > x-w/2 && xPt < x+w/2 && yPt > y-h/2 && yPt < y+h/2) {
4141
// Clicked
4242
toggleEnabled();

src/com/modsim/modules/parts/VisiblePart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public enum RefreshMode {
2020
public BaseModule owner;
2121

2222
// Interaction
23-
public boolean lbDown(int x, int y) {return false;}
23+
public boolean lbDown(int x, int y, boolean isShiftDown) {return false;}
2424
public boolean lbUp(int x, int y) {return false;}
2525

2626
// Display

src/com/modsim/tools/BaseTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public abstract class BaseTool {
1818
public BaseTool rbDown(int x, int y) {return this;}
1919
public BaseTool rbUp(int x, int y) {return this;}
2020

21-
public BaseTool lbDown(int x, int y) {return this;}
21+
public BaseTool lbDown(int x, int y, boolean isShiftDown) {return this;}
2222
public BaseTool lbUp(int x, int y) {return this;}
2323
public BaseTool mouseMove(int x, int y) {return this;}
2424
public BaseTool mouseDrag(int x, int y) {return this;}

src/com/modsim/tools/EditLinkTool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.modsim.operations.CreateOperation;
77
import com.modsim.operations.MoveOperation;
88
import com.modsim.res.Colors;
9-
import com.modsim.util.BezierPath.PointInfo;
9+
import com.modsim.util.Path.PointInfo;
1010
import com.modsim.util.CtrlPt;
1111
import com.modsim.util.Vec2;
1212

@@ -77,7 +77,7 @@ public BaseTool rbDown(int x, int y) {
7777
}
7878

7979
@Override
80-
public BaseTool lbDown(int x, int y) {
80+
public BaseTool lbDown(int x, int y, boolean isShiftDown) {
8181
// Try picking nearest control point
8282
Vec2 worldPoint = ViewUtil.screenToWorld(new Vec2(x, y));
8383
CtrlPt pickCtrl = link.path.closestCtrlPt(worldPoint);

src/com/modsim/tools/MakeLinkTool.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public class MakeLinkTool extends BaseTool {
2323

2424
public Vec2 start = new Vec2();
2525
public Vec2 current = new Vec2();
26-
public BezierPath curve;
26+
public Path curve;
2727

2828
public boolean working = false;
2929

3030
@Override
31-
public BaseTool lbDown(int x, int y) {
31+
public BaseTool lbDown(int x, int y, boolean isShiftDown) {
3232
// Get the clicked port, start linking from here
3333
if (!working) {
34-
if (!startLink(x, y)) {
34+
if (!startLink(x, y, isShiftDown)) {
3535
return null;
3636
}
3737
}
@@ -93,14 +93,18 @@ public void paintWorld(Graphics2D g) {
9393
* @param y Y position to check
9494
* @return True if successful
9595
*/
96-
public boolean startLink(int x, int y) {
96+
public boolean startLink(int x, int y, boolean isShiftDown) {
9797
source = ViewUtil.screenSpace_portAt(x, y);
9898
if (source != null) {
9999
Main.selection.clear();
100100

101101
working = true;
102102
start = new Vec2(x, y);
103-
curve = new BezierPath();
103+
if (isShiftDown) {
104+
curve = new BezierPath();
105+
} else {
106+
curve = new StraightPath();
107+
}
104108

105109
curve.setEnd(source.getDisplayPosW());
106110
curve.setStart(source);

src/com/modsim/tools/PlaceTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public BaseTool mouseMove(int x, int y) {
7272
}
7373

7474
@Override
75-
public BaseTool lbDown(int x, int y) {
75+
public BaseTool lbDown(int x, int y, boolean isShiftDown) {
7676
// Make sure the positions are up to date
7777
mouseMove(x, y);
7878

0 commit comments

Comments
 (0)