package fr.iutfbleau.reticule;

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

public class ControleurReticule implements OnTouchListener {

    private final Reticule reticule;
    private Point position;

    public ControleurReticule(Reticule reticule) {
        this.reticule = reticule;
    }

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

        if (event == MotionEvent.ACTION_DOWN) {
            this.position = new Point((int) e.getX(), (int) e.getY());
        }

        if (event == MotionEvent.ACTION_MOVE) {
            float coordReticuleX = this.reticule.getX();
            float coordReticuleY = this.reticule.getY();
            this.reticule.deplacerReticule((int) coordReticuleX + ((int) e.getX() - this.position.x), (int) coordReticuleY + ((int) e.getY() - this.position.y));
            this.position = new Point((int) e.getX(), (int) e.getY());
            this.reticule.invalidate();
        }
        return true;
    }

}
