
import objectdraw.*;

import java.awt.*;

/*
 * Drag a shirt around window, with a logo
 */
public class FancyShirtController extends WindowController {

    // starting location of t-shirt
    private static final int ITEM_LEFT = 75;
    private static final int ITEM_TOP = 50;

    // T-shirts on the screen
    private FancyTShirt shirt;

    // Previously noted position of mouse cursor
    private Location lastPoint;

    // Whether user is actually dragging a shirt
    private boolean dragging;

    public void begin() {
        shirt = new FancyTShirt(ITEM_LEFT, ITEM_TOP, canvas);
        shirt.setColor(Color.blue);
    }

    // If mouse is dragged, move the selected shirt with it
    // If didn't press mouse on a shirt, do nothing
    public void onMouseClick(Location point) {
        if (shirt.contains(point)) {
            shirt.toggleLogo();
        }
    }

    // Whenever mouse is depressed, note its location
    // and which (if any) shirt the mouse is on.
    public void onMousePress(Location point) {
        lastPoint = point;
        dragging = shirt.contains(point);
    }

    // If mouse is dragged, move the selected shirt with it
    // If didn't press mouse on a shirt, do nothing
    public void onMouseDrag(Location point) {
        if (dragging) {
            shirt.move(point.getX() - lastPoint.getX(),
                       point.getY() - lastPoint.getY());
            lastPoint = point;
        }
    }
    
    public void onMouseExit(Location point) {
        shirt.reset();
    }
}
