package net.beadsproject.touch.surface;
import net.beadsproject.touch.SurfacePlayer;
import net.beadsproject.touch.event.Event;
import net.beadsproject.touch.event.EventListener;
import net.beadsproject.touch.perform.PerformNode;
import processing.core.PApplet;


/**
 * Surface contains a set of regions which send out events such as Enter and Exit.
 * Different surfaces have different region boundaries.
 * 
 * @author ben
 */
public abstract class Surface {	
	EventListener eventListener = null;	
	public void setEventListener(EventListener e)
	{
		eventListener = e;
	}
	
	public void event(Event e)
	{
		if (eventListener!=null)
			eventListener.receiveEvent(e);
	}
	
	// events that a surface can receive 
	// the coordinates are in world space
	/**
	 * A player clicked (rapid press and release) on the surface. 
	 */
	public void playerClicked(SurfacePlayer sp, float x, float y){}
	/**
	 * A player pressed into the surface.
	 */	
	public void playerPressed(SurfacePlayer sp, float x, float y){}
	/**
	 * A player released form the surface.
	 */
	public void playerReleased(SurfacePlayer sp, float x, float y){}
	/**
	 * A player who is pressed has moved location.
	 */
	public void playerMoved(SurfacePlayer sp, float fromX, float fromY, float toX, float toY){}	
		
	// different mouse events that the surface can receive
	public void mouseMoved(float fromX, float fromY, float toX, float toY){}
	public void mousePressed(float x, float y){}
	public void mouseReleased(float x, float y){}
	
	/**
	 * draw this surface into a processing applet
	 * @param app
	 */
	public abstract void draw(PApplet app);
	
	static public int[] backgroundColour = {255,255,255};
	static public int[] regionColour = {100,100,100};
	static public int[] highlightColour = {240,240,200};
	static public int[] borderColour = {255,255,255};
	
	static public void setUniqueFill(PApplet app, PerformNode pn)
	{
		float v = pn.uniqueValue();		
		float c1[] = {255,255,0};
		float c2[] = {0,0,255};
		float c[] = {c1[0]*v + (1-v)*c2[0], c1[1]*v + (1-v)*c2[1], c1[2]*v + (1-v)*c2[2]};
		app.fill(c[0],c[1],c[2]);		
	}
}
