hover fix
This commit is contained in:
parent
8a190cb755
commit
ce7a41c535
@ -34,6 +34,8 @@ public class CONFIG {
|
||||
|
||||
public static final Color PART_HOVER_COLOR = new Color(192, 192, 192, 128);
|
||||
|
||||
public static final Color HOVER_BORDER_COLOR = Color.BLACK;
|
||||
|
||||
public static final Color RASTER_COLOR = Color.gray;
|
||||
|
||||
public static final Color VOLTAGE_UNKNOWN_COLOR = Color.darkGray;
|
||||
@ -46,15 +48,17 @@ public class CONFIG {
|
||||
|
||||
public static final BasicStroke RASTER_STROKE = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, new float[]{5}, 0);
|
||||
|
||||
public static final BasicStroke NORMAL_STROKE = new BasicStroke(1);
|
||||
public static final BasicStroke JUNCTION_STROKE = new BasicStroke(1);
|
||||
|
||||
public static final BasicStroke HOVER_STROKE = new BasicStroke(2);
|
||||
|
||||
public static final BasicStroke SYMBOL_STROKE = new BasicStroke(3);
|
||||
|
||||
public static final BasicStroke WIRE_STROKE = new BasicStroke(5);
|
||||
|
||||
public static final BasicStroke WIRE_STROKE_BACK = new BasicStroke(WIRE_STROKE.getLineWidth() + 2);
|
||||
public static final BasicStroke WIRE_HOVER_STROKE = new BasicStroke(WIRE_STROKE.getLineWidth() + 2);
|
||||
|
||||
public static final BasicStroke WIRE_STROKE_BACK2 = new BasicStroke(WIRE_STROKE_BACK.getLineWidth() + 2);
|
||||
public static final BasicStroke WIRE_HOVER_STROKE_BACK = new BasicStroke(WIRE_HOVER_STROKE.getLineWidth() + 4);
|
||||
|
||||
public static final BasicStroke SWITCH_STROKE = new BasicStroke(15);
|
||||
|
||||
|
||||
@ -99,10 +99,14 @@ class CircuitPanelMouseAdapter extends MouseAdapter {
|
||||
private void findHover(final Point point) {
|
||||
partHover = circuit.findPart(point).orElse(null);
|
||||
junctionHover = partHover != null ? partHover.findJunction(point).orElse(null) : null;
|
||||
if (junctionHover == null) {
|
||||
wireHover = circuit.findWireByPoint(point).orElse(null);
|
||||
} else {
|
||||
if (junctionHover != null) {
|
||||
partHover = null;
|
||||
wireHover = null;
|
||||
return;
|
||||
}
|
||||
wireHover = circuit.findWireByPoint(point).orElse(null);
|
||||
if (wireHover != null) {
|
||||
partHover = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,13 +134,18 @@ class CircuitPanelMouseAdapter extends MouseAdapter {
|
||||
}
|
||||
|
||||
public void drawDrag(final Graphics2D g) {
|
||||
if (partHover != null) {
|
||||
final Point zero = partHover.translate(new Point());
|
||||
partHover.rect(g, zero.x, zero.y, RASTER, RASTER, HOVER_BORDER_COLOR, HOVER_STROKE, null);
|
||||
}
|
||||
if (junctionHover != null) {
|
||||
junctionHover.getOwner().circle(g, junctionHover.getAbsolute().x, junctionHover.getAbsolute().y, JUNCTION_RADIUS_HOVER, Color.BLACK, NORMAL_STROKE, junctionHover.getColor());
|
||||
junctionHover.getOwner().circle(g, junctionHover.getAbsolute().x, junctionHover.getAbsolute().y, JUNCTION_RADIUS_HOVER, HOVER_BORDER_COLOR, HOVER_STROKE, junctionHover.getColor());
|
||||
}
|
||||
if (wireHover != null) {
|
||||
wireHover.getA().getOwner().line(g, wireHover.getA().getAbsolute(), wireHover.getB().getAbsolute(), Color.black, WIRE_STROKE_BACK2);
|
||||
wireHover.getA().getOwner().line(g, wireHover.getA().getAbsolute(), wireHover.getB().getAbsolute(), wireHover.getA().getColor(), WIRE_STROKE_BACK);
|
||||
wireHover.getA().getOwner().line(g, wireHover.getA().getAbsolute(), wireHover.getB().getAbsolute(), HOVER_BORDER_COLOR, WIRE_HOVER_STROKE_BACK);
|
||||
wireHover.getA().getOwner().line(g, wireHover.getA().getAbsolute(), wireHover.getB().getAbsolute(), wireHover.getA().getColor(), WIRE_HOVER_STROKE);
|
||||
}
|
||||
|
||||
if (dragPosition != null) {
|
||||
if (partDrag != null) {
|
||||
g.setColor(PART_HOVER_COLOR);
|
||||
|
||||
@ -6,7 +6,7 @@ import lombok.NonNull;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import static de.ph87.electro.CONFIG.WIRE_STROKE_BACK2;
|
||||
import static de.ph87.electro.CONFIG.WIRE_HOVER_STROKE_BACK;
|
||||
|
||||
@Data
|
||||
public class Wire {
|
||||
@ -31,14 +31,14 @@ public class Wire {
|
||||
double dy = end.y - start.y;
|
||||
double length = dx * dx + dy * dy;
|
||||
if (length == 0) {
|
||||
return p.distance(start) <= WIRE_STROKE_BACK2.getLineWidth();
|
||||
return p.distance(start) <= WIRE_HOVER_STROKE_BACK.getLineWidth();
|
||||
}
|
||||
|
||||
double t = ((p.x - start.x) * dx + (p.y - start.y) * dy) / length;
|
||||
t = Math.max(0, Math.min(1, t));
|
||||
double closestX = start.x + t * dx;
|
||||
double closestY = start.y + t * dy;
|
||||
return p.distance(closestX, closestY) <= WIRE_STROKE_BACK2.getLineWidth();
|
||||
return p.distance(closestX, closestY) <= WIRE_HOVER_STROKE_BACK.getLineWidth();
|
||||
}
|
||||
|
||||
public Junction getOpposite(final Junction junction) {
|
||||
|
||||
@ -84,7 +84,7 @@ public class Junction {
|
||||
}
|
||||
|
||||
public void render(final Graphics2D g) {
|
||||
owner.circle(g, position.x, position.y, JUNCTION_RADIUS, Color.BLACK, NORMAL_STROKE, color);
|
||||
owner.circle(g, position.x, position.y, JUNCTION_RADIUS, Color.BLACK, JUNCTION_STROKE, color);
|
||||
}
|
||||
|
||||
public Point getAbsolute() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user