
import cs134lib.*;

import objectdraw.*;
import java.awt.*;
import java.applet.*;

/**
 * A Simple program to demonstrate using the Camera.
 * It will get a new Image from the camera every time
 * you press the red button.
 */
public class CameraController 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 FilledOval button;
  private VisibleImage image;
  private AudioClip click;
  private Camera camera;

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

    // create a new blank image 640x480
    image = new VisibleImage(Images.blankImage(IMAGE_WIDTH, IMAGE_HEIGHT), 
                             IMAGE_X, IMAGE_Y, IMAGE_WIDTH, IMAGE_HEIGHT, canvas);
    click = getAudio("click.wav");
    button = new FilledOval(BUTTON_LEFT, BUTTON_TOP, BUTTON_SIZE, BUTTON_SIZE, canvas);
    button.setColor(Color.red);

    camera = new Camera();
    camera.activate();
  }

  public void onMouseClick(Location point) {
    if (button.contains(point)) {
      click.play();
      image.setImage(camera.getImage());
    }
  }
}
