package com.example.jmastermind.Geometrics;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;

public class Circle extends View {
    private Paint picasso;
    private int color;

    /**
     * Les cercles du jeu "programmiser" en Java
     * @param context Le context
     * @param attrs Les attributs (notamment id)
     * */
    public Circle(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.color = Color.GRAY;
        this.picasso = new Paint();
    }
    /**
     * Recuperer la couleur du cercle
     * @return La couleur du cercle en int
     * */
    public int getColor() {
        return this.color;
    }
    /**
     * Changer la couleur d'un cercle
     * @param c La nouvelle couleur
     * */
    public void setColor(int c) {
        this.color = c;
        this.invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int centerX = getWidth() / 2;
        int centerY = getHeight() / 2;
        int radius = Math.min(centerX, centerY);

        this.picasso.setColor(this.color);
        this.picasso.setStyle(Paint.Style.FILL);
        canvas.drawCircle(centerX, centerY, radius-2, this.picasso);

        int corail = Color.rgb(255, 127, 80);
        this.picasso.setColor(corail);
        this.picasso.setStyle(Paint.Style.STROKE);
        this.picasso.setStrokeWidth(4f);
        canvas.drawCircle(centerX, centerY, radius-3, this.picasso);
    }
}
