package fr.iutfbleau.dessin;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

public class Triangle extends View {

    private float x1;
    private float y1;
    private float x2;
    private float y2;
    private final Paint peinture;
    private Path triangle;

    public Triangle(Context c, AttributeSet s) {
        super(c, s);
        this.x1 = 0;
        this.y1 = 0;
        this.x2 = 0;
        this.y2 = 0;
        this.peinture = new Paint();
        this.peinture.setStrokeWidth(25f);
        this.peinture.setColor(0xffff0000);
        this.peinture.setStyle(Paint.Style.STROKE);
        this.triangle = new Path();
    }

    @Override
    protected void onDraw(Canvas c) {
        super.onDraw(c);
        c.drawPath(this.triangle, this.peinture);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        this.x1 = 0;
        this.y1 = 0;
        this.x2 = w;
        this.y2 = h;
        this.triangle.moveTo(x2/2, y1+25);
        this.triangle.lineTo(x2-25, y2);
        this.triangle.lineTo(x1+25, y2);
        this.triangle.close();
    }
}

