package fr.iutfbleau.wamster.dev45.tp05ex01_reticule;

import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class Evenement implements View.OnTouchListener{

    private Dessin dessin;
    private boolean mouvementEnCours;
    private float debutX;
    private float debutY;

    public Evenement(Dessin dessin){
        this.dessin = dessin;
        this.mouvementEnCours = false;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int action = event.getActionMasked();

        switch (action) {
            case MotionEvent.ACTION_DOWN:
                this.debutX = event.getX();
                this.debutY = event.getY();
                this.mouvementEnCours = true;
                break;

            case MotionEvent.ACTION_POINTER_DOWN:
                this.mouvementEnCours = false;
                break;

            case MotionEvent.ACTION_MOVE:
                if (this.mouvementEnCours){
                    float dx = event.getX()- this.debutX;
                    float dy = event.getY()- this.debutY;
                    this.debutX = event.getX();
                    this.debutY = event.getY();
                    this.dessin.addVecteur(dx, dy);
                }
                break;

            case MotionEvent.ACTION_UP:
                this.mouvementEnCours = false;
                break;
            case MotionEvent.ACTION_CANCEL:
                this.mouvementEnCours = false;
                break;
        }
        return true;
    }
}
