// ---------------------------------------------------------
// Class: ImageDrawer
// ---------------------------------------------------------
// ImageDrawer is a class that stores the ArrayList of all 
// the image objects that will get drawn to the screen. 
// ---------------------------------------------------------

import java.util.*;
import processing.*;
import processing.core.*;

public class ImageDrawer {

  ArrayList images;
  PApplet papp;
  int w, h, translateX;

  // Constructor
  // -------------------
  public ImageDrawer(PApplet papp, int w, int h, int tx) {
    this.w = w;
    this.h = h;
    translateX = tx;
    this.papp = papp;
    images = new ArrayList(); 
  }

  // addImage
  // -------------------
  // adds the image from the passed in url as a new image object
  public void addImage(String imgurl) {
    
    // load the image as a PImage
    PImage pimg = new PImage();
    pimg = papp.loadImage(imgurl);
    if (pimg == null) {
      papp.println("=====> ADD IMAGE FAILED: IMG NULL");
      return;
    }
    
    if (pimg.width > 350)
    {
      papp.println("image too wide");
      return;
    }
    
    // get the x and y bounds so we can make sure the images
    // show up within the display space 
    int xbound = (w-pimg.width < 0) ? 0 : w-pimg.width;
    int ybound = (h-pimg.height < 0) ? 0 : h-pimg.height;
    
    // get a random x and y coordinate for this image
//    int xpos = (int) papp.random(xbound);
//    int ypos = (int) papp.random(ybound);
int xpos = (int) 0;
int ypos = (int) 0;
    papp.println("====> ADDING IMG: "+xpos+" "+ypos);
    
    // create an image object to store the PImage and its 
    // coordinates and add it to the arraylist
    ImageObject img = new ImageObject(pimg, xpos + translateX, ypos);
    images.add(img);
  }

  // getImageObj
  // -------------------
  // returns an image object at a specified index
  public ImageObject getImageObj(int index) {
    return (ImageObject)images.get(index);
  }

  // getImages
  // -------------------
  // returns all the image objects
  public ArrayList getImages() {
    return images;
  }
}
