package com.example.fleche;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;

public class Fleche extends View{
    private Bitmap image_droite;
    private Bitmap image_gauche;
    public static final int DROITE = 0;
    public static final int GAUCHE = 1;
    private int currentShape = GAUCHE;

    public Fleche(Context context, AttributeSet attrs){
        super(context, attrs);

        image_droite = BitmapFactory.decodeResource(getResources(), R.drawable.fleche_droite);
        postInvalidate();

        image_gauche = BitmapFactory.decodeResource(getResources(), R.drawable.fleche_gauche);
        postInvalidate();
    }

    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();

        // Dessiner l'image si elle est chargée
        switch (currentShape) {
            case DROITE:
                if (image_droite != null) {
                    int imgWidth = image_droite.getWidth();
                    int imgHeight = image_droite.getHeight();
                    int imgX = (width - imgWidth) / 4;
                    int imgY = (height - imgHeight) / 4;
                    canvas.drawBitmap(image_droite, imgX, imgY, null);
                }
                break;
            case GAUCHE:
                if (image_gauche != null) {
                    int imgWidth = image_gauche.getWidth();
                    int imgHeight = image_gauche.getHeight();
                    int imgX = (width - imgWidth) / 4;
                    int imgY = (height - imgHeight) / 4;
                    canvas.drawBitmap(image_gauche, imgX, imgY, null);
                }
                break;
        }
    }
}
