
import cs134lib.*;
import objectdraw.*;
import java.awt.*;

/**
 * A video camera program that prevents the user from
 * creating more than one video camera at a time.
 */
public class VideoController extends WindowController {

  private static final int IMAGE_WIDTH = 640;

  private static final int IMAGE_HEIGHT = 480;
  private static final int IMAGE_X = 0;
  private static final int IMAGE_Y = 40;
  private static final int BUTTON_LEFT = 10;
  private static final int BUTTON_TOP = 10;
  private static final int BUTTON_SIZE = 20;
  
  
  private VideoCamera video;  // the current video camera, or null if none yet

  private FilledOval action;  // the button to click on
  
  private VisibleImage image;

  public void begin() {
    this.resize(IMAGE_WIDTH, IMAGE_Y + IMAGE_HEIGHT);

    // create a new blank image
    image = new VisibleImage(Images.blankImage(IMAGE_WIDTH, IMAGE_HEIGHT), 
      IMAGE_X, IMAGE_Y, IMAGE_WIDTH, IMAGE_HEIGHT, canvas);
      
    action = new FilledOval(BUTTON_LEFT, BUTTON_TOP, BUTTON_SIZE, BUTTON_SIZE, canvas);
    action.setColor(Color.red);
  }

  public void onMouseClick(Location point) {
    if (action.contains(point)) {
      
      // only create a new video camera if there hasn't been
      //  one created yet or the current camera is not filming
      if (video == null || !video.isFilming()) {
        video = new VideoCamera(image);
      } 
      
    } 
  }
}
