Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering of line cell templates #4752

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import javax.swing.SwingUtilities;
import net.rptools.maptool.client.ScreenPoint;
import net.rptools.maptool.client.swing.SwingUtil;
import net.rptools.maptool.client.tool.Tool;
import net.rptools.maptool.client.ui.zone.renderer.ZoneRenderer;
import net.rptools.maptool.model.ZonePoint;
import net.rptools.maptool.model.drawing.AbstractTemplate;
import net.rptools.maptool.model.drawing.AbstractTemplate.Quadrant;
import net.rptools.maptool.model.drawing.LineCellTemplate;
import net.rptools.maptool.model.drawing.Pen;

Expand Down Expand Up @@ -173,7 +171,6 @@ public void mousePressed(MouseEvent aE) {
protected void handleMouseMovement(MouseEvent e) {
// Setting anchor point?
LineCellTemplate lt = (LineCellTemplate) template;
ZonePoint pathVertex = lt.getPathVertex();
ZonePoint vertex = lt.getVertex();

if (!anchorSet) {
Expand All @@ -189,58 +186,21 @@ protected void handleMouseMovement(MouseEvent e) {
template.setRadius(getRadiusAtMouse(e));
controlOffset = null;

// The path vertex remains null until it is set the first time.
if (pathVertex == null) {
pathVertex = new ZonePoint(vertex.x, vertex.y);
lt.setPathVertex(pathVertex);
} // endif
if (setCellAtMouse(e, pathVertex)) lt.clearPath();

// Determine which of the extra squares are used on diagonals
double dx = pathVertex.x - vertex.x;
double dy = pathVertex.y - vertex.y;
if (dx != 0 && dy != 0) { // Ignore straight lines
boolean mouseSlopeGreater = false;
double m = Math.abs(dy / dx);
double edx = e.getX() - vertex.x;
double edy = e.getY() - vertex.y;
if (edx != 0 && edy != 0) { // Handle straight lines differently
double em = Math.abs(edy / edx);
mouseSlopeGreater = em > m;
} else if (edx == 0) {
mouseSlopeGreater = true;
} // endif
if (mouseSlopeGreater != lt.isMouseSlopeGreater()) {
lt.setMouseSlopeGreater(mouseSlopeGreater);
renderer.repaint();
} // endif
} // endif
ZonePoint pathVertex = getCellAtMouse(e);
lt.setPathVertex(pathVertex);
renderer.repaint();

// Let control move the path anchor
} else if (SwingUtil.isControlDown(e)) {
ZonePoint pathVertex = lt.getPathVertex();
handleControlOffset(e, pathVertex);
lt.setPathVertex(pathVertex);

// Set the final radius
} else {
template.setRadius(getRadiusAtMouse(e));
renderer.repaint();
controlOffset = null;
return;
} // endif

// Quadrant change?
if (pathVertex != null) {
ZonePoint mouse = new ScreenPoint(e.getX(), e.getY()).convertToZone(renderer);
int dx = mouse.x - vertex.x;
int dy = mouse.y - vertex.y;
AbstractTemplate.Quadrant quadrant =
(dx < 0)
? (dy < 0 ? Quadrant.NORTH_WEST : Quadrant.SOUTH_WEST)
: (dy < 0 ? Quadrant.NORTH_EAST : Quadrant.SOUTH_EAST);
if (quadrant != lt.getQuadrant()) {
lt.setQuadrant(quadrant);
renderer.repaint();
} // endif
} // endif
}
}
4 changes: 4 additions & 0 deletions src/main/java/net/rptools/maptool/model/CellPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public CellPoint(int x, int y, double distanceTraveled, double distanceTraveledW
this.distanceTraveledWithoutTerrain = distanceTraveledWithoutTerrain;
}

public CellPoint(CellPoint other) {
this(other.x, other.y);
}

@Override
public String toString() {
return "CellPoint" + super.toString();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/rptools/maptool/model/ZonePoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public ZonePoint(int x, int y) {
super(x, y);
}

public ZonePoint(ZonePoint other) {
this(other.x, other.y);
}

@Override
public String toString() {
return "ZonePoint" + super.toString();
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/net/rptools/maptool/model/drawing/Drawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ static Drawable fromDto(DrawableDto drawableDto) {
drawable.setRadius(dto.getRadius());
var vertex = dto.getVertex();
drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY()));
if (!dto.getQuadrant().isEmpty()) {
drawable.setQuadrant(AbstractTemplate.Quadrant.valueOf(dto.getQuadrant()));
}
drawable.setMouseSlopeGreater(dto.getMouseSlopeGreater());
var pathVertex = dto.getPathVertex();
drawable.setPathVertex(new ZonePoint(pathVertex.getX(), pathVertex.getY()));
if (dto.hasName()) {
Expand Down
Loading
Loading