package fr.iutfbleau.wamster.dev45.ex01gribouillage;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.view.View;
import android.graphics.Rect;

public class Dessin extends View {
    private Paint pinceau;
    private int bleu = 0xff0000ff;
    private int violet = 0xffff00ff;
    private int noire = 0xff000000;
    private Rect rectangle;

    private Bitmap bitmap;



    public Dessin(Context context, AttributeSet attrs){
        super(context, attrs);
        this.pinceau = new Paint();
        this.bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cercles);
    }
    @Override
    public void onDraw(Canvas canvas){
        super.onDraw(canvas);
        int width = canvas.getWidth();
        int height = canvas.getHeight();
        this.rectangle = new Rect(width/4, height/4, 2*width/4, 2*height/4);

        this.pinceau.setColor(this.bleu);
        canvas.drawRect(this.rectangle, this.pinceau);

        this.pinceau.setColor(this.violet);
        this.pinceau.setStyle(Paint.Style.STROKE);
        this.pinceau.setStrokeWidth(5.0f);
        canvas.drawCircle(3*width/4, height/8, width/8, this.pinceau);

        float hauteurText = 72f;
        this.pinceau.setColor(0xff000000);
        this.pinceau.setTextSize(hauteurText);
        this.pinceau.setFakeBoldText(true);
        this.pinceau.setStyle(Paint.Style.FILL);
        this.pinceau.setTextAlign(Paint.Align.CENTER);
        canvas.drawText("Ceci est un test", this.rectangle.exactCenterX(), (this.rectangle.exactCenterY()+hauteurText/4), this.pinceau);

        canvas.drawBitmap(bitmap,width/2,3*height/4,this.pinceau);
    }
}
