package net.voxelindustry.brokkgui.shape;

import net.voxelindustry.brokkgui.internal.IGuiRenderer;
import net.voxelindustry.brokkgui.paint.Color;
import net.voxelindustry.brokkgui.paint.Texture;

import java.util.function.Supplier;

public class LineShape implements ShapeDefinition
{
    private Supplier<Float> lineWidthSupplier;

    public LineShape(Supplier<Float> lineWidthSupplier)
    {
        this.lineWidthSupplier = lineWidthSupplier;
    }

    @Override
    public void drawColored(GuiShape shape, IGuiRenderer renderer, float startX, float startY, Color color,
                            float zLevel)
    {
        renderer.getHelper().drawColoredLine(renderer, startX, startY,
                startX + shape.getWidth(), startY + shape.getHeight(),
                lineWidthSupplier.get(), zLevel, color);
    }

    @Override
    public void drawColoredEmpty(GuiShape shape, IGuiRenderer renderer, float startX, float startY, float lineWidth,
                                 Color color, float zLevel)
    {
        renderer.getHelper().drawColoredLine(renderer, startX, startY,
                startX + shape.getWidth(), startY + shape.getHeight(),
                lineWidthSupplier.get(), zLevel, color);
    }

    @Override
    public void drawTextured(GuiShape shape, IGuiRenderer renderer, float startX, float startY, Texture texture,
                             float zLevel)
    {
        // TODO : Add helper for drawing textured lines
    }

    @Override
    public boolean isMouseInside(GuiShape shape, int mouseX, int mouseY)
    {
        // TODO : Impl a check for non-axis-aligned boxes
        return false;
    }
}

@@ -1571,84 +1571,882 @@
     
-// TODO : Impl a check for non-axis-aligned boxes%0A        return false
+if(!Rectangle.SHAPE.isMouseInside(shape, mouseX, mouseY)) // Bad behavior expected with very high line width%0A            return false;                                         // and at line's extremities%0A%0A        /*%0A            Let AM = (mouseX - startX, mouseY - startY) a vec2%0A            Let AB = (shapeWidth, shapeHeight) a vec2%0A            dist(M, AB) = %7Cdet(AB,AM)%7C / %7C%7CAB%7C%7C%0A        */%0A%0A        // Vector from segment beginning to mouse position%0A        float AMx = mouseX - (shape.getxPos() + shape.getxTranslate());%0A        float AMy = mouseY - (shape.getyPos() + shape.getyTranslate());%0A%0A        float ABx = shape.getWidth();%0A        float ABy = shape.getHeight();%0A%0A        // Remember : det(A,B) = Ax * By - Ay * Bx%0A%0A        double dist = Math.abs(AMx * ABy - AMy * ABx) / Math.sqrt(ABx * ABx + ABy * ABy);%0A%0A        return dist %3C lineWidthSupplier.get() / 4d
 ;%0A    %7D%0A
 %7D%0A
@@ -2443,10 +2443,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Implement LineShape#isMouseInside (#15)