package fr.iutfbleau.pois;

import android.graphics.Point;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class ControleurTactile implements OnTouchListener {

    private final Rond composant;

    public ControleurTactile(Rond composant) {
        this.composant = composant;
    }

    @Override
    public boolean onTouch(View v, MotionEvent e) {
        int event = e.getActionMasked();
        int index = e.getActionIndex();
        int id = e.getPointerId(index);

        if (event == MotionEvent.ACTION_DOWN || event == MotionEvent.ACTION_POINTER_DOWN) {
            int couleur = this.composant.getCouleurSuivante();
            this.composant.ajouterPoint(id, new Doigt(e.getX(index), e.getY(index), couleur));
            this.composant.invalidate();
        }

        if (event == MotionEvent.ACTION_UP || event == MotionEvent.ACTION_POINTER_UP) {
            //this.composant.getCouleurs().addFirst(this.composant.getCoordCercles().get(id).getCouleur());
            this.composant.retirerPoint(id);
            this.composant.invalidate();
        }

        if (event == MotionEvent.ACTION_MOVE) {
            for (int i = 0; i < e.getPointerCount(); i++) {
                int secondId = e.getPointerId(i);
                this.composant.deplacerPoint(secondId, e.getX(i), e.getY(i));
                this.composant.invalidate();
            }

        }
        return true;
    }
}
