package com.example.gribouillage;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.view.View;

public class Gribouillage extends View {

    private final Paint bluePaint;
    private final Paint purplePaint;
    private final Paint textPaint;
    private final Rect rectangleBounds;
    private final String text;


    public Gribouillage(Context context) {
        super(context);

        // Initialize paints
        bluePaint = new Paint();
        bluePaint.setColor(Color.BLUE);
        bluePaint.setStyle(Paint.Style.FILL);

        purplePaint = new Paint();
        purplePaint.setColor(Color.MAGENTA);
        purplePaint.setStyle(Paint.Style.STROKE);
        purplePaint.setStrokeWidth(5);

        textPaint = new Paint();
        textPaint.setColor(Color.BLACK);
        textPaint.setTextSize(40);
        textPaint.setTypeface(Typeface.DEFAULT_BOLD);

        rectangleBounds = new Rect(100, 100, 500, 300);

        text = "Ceci est un test";
    }

    @Override
    protected void onDraw(Canvas c){
        super.onDraw(c);

        c.drawRect(rectangleBounds, bluePaint);

        int centerX = rectangleBounds.centerX();
        int centerY = rectangleBounds.centerY();
        int radius = Math.min(rectangleBounds.width(), rectangleBounds.height()) / 2;
        c.drawCircle(centerX, centerY, radius, purplePaint);

        float textWidth = textPaint.measureText(text);
        float x = rectangleBounds.centerX() - textWidth / 2;
        float y = rectangleBounds.centerY() - (textPaint.descent() + textPaint.ascent()) / 2;
        c.drawText(text, x, y, textPaint);
    }
}
