package harmonicTable;

import processing.core.PApplet;
import processing.core.PGraphics;

public class HexButton extends HarmonicTable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8460198731304739999L;
	PApplet parent;
	PGraphics buffer;
	int startX;
	int startY;
	int length;
	String note;
	int thisNoteNumber;
	
	public HexButton(Object p, int newStartX, int newStartY, int sideLength, int myNoteNumber){
		if (p instanceof PGraphics)
			buffer = (PGraphics) p;
		
		if (p instanceof PApplet)
			parent = (PApplet) p;
		
		startX = newStartX;
		startY = newStartY;
		length = sideLength;
		thisNoteNumber = myNoteNumber;
		String myNoteName = noteNumberArray[myNoteNumber];
		
		String temp[] = null;
		temp = myNoteName.split("/");
		if ((temp.length > 1) && (temp[1].contains("Bb") || temp[1].contains("Eb"))){
			note=temp[1].substring(0, temp[1].length()-1);
		} else {
			note=temp[0].substring(0, temp[0].length()-1);
		}
	}
	
	public void drawHex(boolean isPressed){
		/* Decide on fill value based on Note name
		 * if string contains # or b then the note should be black
		 * most other notes white
		 * G# dark blue, D light blue
		 * Maybe some gray alternates in there to match the C-thru
		 */
		
		if (isPressed){
			parent.fill(255);	
			if (note.contains("G#")) {
				parent.fill(255 - Gsharp);
			} else if (note.contains("D") && !note.contains("#")) {
				parent.fill(255 - D);
			} else if (note.contains("#")) {
				parent.fill(255 - blackKey);
			}
		} else{
			parent.fill(255);	
			if (note.contains("G#")) {
				parent.fill(Gsharp);
			} else if (note.contains("D") && !note.contains("#")) {
				parent.fill(D);
			} else if (note.contains("#") || note.contains("b")) {
				parent.fill(blackKey);
			}
		}
		
		//Got these from the parent class
		//Of Course...Make sure to set these in the parent class
		//float a = length/2;
		//float b = sin(radians(60))*length;
		//float c = length;
		
		parent.pushMatrix();
		parent.translate(startX, startY);
		//draw hex shape
		parent.beginShape();
			parent.vertex(0,b);
			parent.vertex(a,0);
			parent.vertex(a+c,0);
			parent.vertex(2*c,b);
			parent.vertex(a+c,2*b);
			parent.vertex(a+c,2*b);
			parent.vertex(a,2*b);
			parent.vertex(0,b);
		parent.endShape();
		drawNote(note);
		parent.popMatrix();
	}
	
	public void drawNote(String note){
		parent.fill(0);	
		if (note.contains("G#")) {
			parent.fill(255);
		} else if (note.contains("D") && !note.contains("#")) {
			parent.fill(0);
		} else if (note.contains("#") || note.contains("b")) {
			parent.fill(255);
		}
		parent.text(note, c, c);
	}
}

