package fr.iutfbleau.dev45.wamster.tp05ex01_reticule;

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 Dessin extends View {
    private float rayon;
    private float x;
    private float y;
    private final Paint pinceau;
    public Dessin(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.pinceau = new Paint();
        this.pinceau.setStyle(Paint.Style.STROKE);
        this.pinceau.setStrokeWidth(20.0f);
        this.pinceau.setColor(0xfffc6600);
        this.rayon = 100f;
        this.x = -1;
        this.y = -1;
    }

    public void setCoordonnee(float x, float y){
        this.x = x;
        this.y =y;
        this.invalidate();
    }

    @Override
    public void onDraw(Canvas canvas){
        if (this.x < 0){
            this.x = getWidth()/2f;
        }
        if (this.y < 0){
            this.y = getHeight()/2f;
        }
        canvas.drawCircle(this.x, this.y, this.rayon, this.pinceau);
        Path trait1 = new Path();
        trait1.moveTo(this.x,this.y-(1.5f*this.rayon));
        trait1.lineTo(this.x, this.y+(1.5f*this.rayon));
        trait1.close();
        canvas.drawPath(trait1, this.pinceau);

        Path trait2 = new Path();
        trait2.moveTo(this.x-(1.5f*this.rayon),this.y);
        trait2.lineTo(this.x+(1.5f*this.rayon), this.y);
        trait2.close();
        canvas.drawPath(trait2, this.pinceau);
    }
}
