package projectzombie.menu.gui;

import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import projectzombie.model.Model;
import projectzombie.model.ModelGui;

public class GUIButtonModel implements GUIComponent
{
	public interface GUIButtonModelCallback {
		public void click(GUIButtonModel button);
	}
	
	private GUIButtonModelCallback callback;
	private ModelGui modelHover;
	private ModelGui model;
	
	private Vec2d pos = new Vec2d(0, 0);
	
	public GUIButtonModel(ModelGui model, ModelGui modelHover, GUIButtonModelCallback callback) {
		this.callback = callback;
		this.modelHover = modelHover;
		this.model = model;
	}
	
	public void setPos(Vec2d pos) {
		this.pos = pos;
	}

	@Override
	public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover)
	{
		Model model = (checkMouseHover(mousePos) && canHover) ? this.modelHover : this.model;
		
		model.setModel(Matrix4.multiply(Matrix4.translate(pos.x, pos.y, 0), matrix));
		model.render();
	}

	@Override
	public void update(Vec2d mousePos) {
		
	}

	@Override
	public boolean checkMouseHover(Vec2d mousePos) {
		return (mousePos.x > pos.x && mousePos.x < pos.x + model.getWidth() &&
				mousePos.y > pos.y && mousePos.y < pos.y + model.getHeight());
	}

	@Override
	public void onRightClick(Vec2d mousePos) {
	}

	@Override
	public void onMouseClick(Vec2d mousePos) {
		this.callback.click(this);
	}

	@Override
	public void onActivate() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onBack() {
	}
	
	@Override
	public void onScroll(Vec2d mousePos, double amount) {
	}

}
