package fr.iutfbleau.wamster.dev45.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 addVecteur(float x, float y){
        this.x += x;
        this.y += y;
        this.invalidate();
    }
    public void setCoordonnee(float x, float y){
        this.x = x;
        this.y = y;
        this.invalidate();
    }
    public float getX(){
        return this.x;
    }
    public float getY(){
        return this.y;
    }

    @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);
        canvas.drawLine(this.x,this.y-(1.5f*this.rayon), this.x, this.y+(1.5f*this.rayon), this.pinceau);
        canvas.drawLine(this.x-(1.5f*this.rayon),this.y, this.x+(1.5f*this.rayon), this.y, this.pinceau);
    }
}
