Add STriangle

This commit is contained in:
2026-03-19 19:38:40 +01:00
parent b8ecf9859b
commit f424735a7b
9 changed files with 193 additions and 22 deletions

View File

@@ -3,9 +3,7 @@ package ovh.gasser.newshapes.ui;
import ovh.gasser.newshapes.ShapeVisitor;
import ovh.gasser.newshapes.attributes.ColorAttributes;
import ovh.gasser.newshapes.attributes.SelectionAttributes;
import ovh.gasser.newshapes.shapes.SCircle;
import ovh.gasser.newshapes.shapes.SCollection;
import ovh.gasser.newshapes.shapes.SRectangle;
import ovh.gasser.newshapes.shapes.*;
import ovh.gasser.newshapes.shapes.Shape;
import java.awt.*;
@@ -64,6 +62,32 @@ public class ShapeDraftman implements ShapeVisitor {
drawHandlerIfSelected(circle);
}
@Override
public void visitTriangle(STriangle tri) {
ColorAttributes colAttrs = (ColorAttributes) tri.getAttributes(ColorAttributes.ID);
var bounds = tri.getBounds();
var size = Math.min(bounds.width, bounds.height); // Should be the same because we only support equilateral triangles
if (colAttrs == null){
colAttrs = DEFAULT_COLOR_ATTRIBUTES;
}
if (colAttrs.filled) {
this.g2d.setColor(colAttrs.filledColor);
this.g2d.fillPolygon(
new int[]{ bounds.x, bounds.x + (size/2), bounds.x + size },
new int[]{ bounds.y + size, bounds.y, bounds.y + size },
3);
}
if (colAttrs.stroked) {
this.g2d.setColor(colAttrs.strokedColor);
this.g2d.drawPolygon(
new int[]{bounds.x, bounds.x + (size / 2), bounds.x + size},
new int[]{bounds.y + size, bounds.y, bounds.y + size},
3);
}
drawHandlerIfSelected(tri);
}
private void drawHandlerIfSelected(Shape s) {
SelectionAttributes selAttrs = (SelectionAttributes) s.getAttributes(SelectionAttributes.ID);
if ((selAttrs != null) && (selAttrs.selected)){