Skip to content

Commit

Permalink
Merge pull request #4752 from kwvanderlinde/bugfix/3692-line-cell-tem…
Browse files Browse the repository at this point in the history
…plate-fix

Fix rendering of line cell templates
  • Loading branch information
cwisniew authored Apr 16, 2024
2 parents 25ab0cd + 6de6d88 commit 8424030
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 265 deletions.
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

0 comments on commit 8424030

Please sign in to comment.