Skip to content

Commit

Permalink
Borders: Fixed border paint to work for dashed empty rects
Browse files Browse the repository at this point in the history
  • Loading branch information
reportmill committed Aug 25, 2021
1 parent 9d5b662 commit c6ecc1e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/snap/gfx/Borders.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,23 @@ public void paint(Painter aPntr, Shape aShape)

// Handle Rect special: Paint border just inside rect (if thinner/shorter than border stroke, don't go negative)
if (aShape instanceof Rect) {

// Get shape rect inset by half stroke width to keep border inside bounds
Rect rect = (Rect) aShape;
double borderW = getWidth();
double insX = rect.width >= borderW ? borderW / 2 : rect.width / 2;
double insY = rect.height >= borderW ? borderW / 2 : rect.height / 2;
rect = rect.getInsetRect(insX, insY);
aPntr.draw(rect);

// If stroke is dashed, see if we need to draw as horizontal or vertical line to avoid dash overlaps
if (!Objects.equals(stroke.getDashArray(), Stroke.DASH_SOLID) && (rect.width < .001 || rect.height < .001)) {
if (rect.width < .001)
aPntr.drawLine(rect.x, rect.y, rect.x, rect.getMaxY());
aPntr.drawLine(rect.x, rect.y, rect.getMaxX(), rect.y);
}

// Otherwise just draw (stroke) rect
else aPntr.draw(rect);
}

// Handle arbitrary shape
Expand Down

0 comments on commit c6ecc1e

Please sign in to comment.