package com.example.choix;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

public class Choix extends View{
    public static final int SHAPE_CROIX = 0;
    public static final int SHAPE_CARRE = 1;
    public static final int SHAPE_ROND = 2;
    public static final int SHAPE_TRIANGLE = 3;

    private int currentShape = SHAPE_CROIX;
    private Paint paint;

    public Choix(Context context, AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(20);
    }

    public void setShape(int shape) {
        this.currentShape = shape;
        invalidate(); // Redessine la vue
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = getWidth();
        int height = getHeight();
        int midX = width / 3;
        int midY = height / 3;
        int size = Math.min(width, height) / 4;

        switch (currentShape) {
            case SHAPE_CROIX:
                canvas.drawLine(midX - size, midY - size, midX + size, midY + size, paint);
                canvas.drawLine(midX - size, midY + size, midX + size, midY - size, paint);
                break;
            case SHAPE_CARRE:
                canvas.drawRect(midX - size, midY - size, midX + size, midY + size, paint);
                break;
            case SHAPE_ROND:
                canvas.drawCircle(midX, midY, size, paint);
                break;
            case SHAPE_TRIANGLE:
                Path path = new Path();
                path.moveTo(midX, midY - size);
                path.lineTo(midX - size, midY + size);
                path.lineTo(midX + size, midY + size);
                path.close();
                canvas.drawPath(path, paint);
                break;
        }
    }
}
