package de.samdev.colorrunner.screens.menu.impl.elements;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;

import de.samdev.colorrunner.game.renderer.CRAssets;
import de.samdev.colorrunner.screens.menu.BaseMenuElement;

public class CRMenuRectangle extends BaseMenuElement {

    public interface ClickHandler {
        void onClick(float screenX, float screenY, CRMenuRectangle rect);
    }

    public final Rectangle Bounds;
    public final Color Color;
    public final ClickHandler Handler;
    public       Texture Tex;

    public CRMenuRectangle(float x, float y, float w, float h, Color c, Texture tx, ClickHandler clickHandler) {
        Bounds = new Rectangle(x, y, w, h);
        Color = c;
        Handler = clickHandler;
        Tex = tx;
    }

    @Override
    public void render(SpriteBatch batch) {


        if (Tex != null) {
            batch.setColor(com.badlogic.gdx.graphics.Color.WHITE);
            batch.draw(Tex, Bounds.x, Bounds.y, Bounds.width, Bounds.height);
        }
        else {
            batch.setColor(Color);
            batch.draw(CRAssets.TEX_BLANK, Bounds.x, Bounds.y, Bounds.width, Bounds.height);
        }

        batch.setColor(com.badlogic.gdx.graphics.Color.BLACK);

    }

    @Override
    public void update(float delta) {
        //Gdx.app.log("crmenurect", "> " + delta);
    }

    @Override
    public Rectangle getBounds() {
        return Bounds;
    }

    @Override
    public boolean clickTest(float x, float y) {
        if (this.Bounds.contains(x, y)) {
            this.Handler.onClick(x, y, this);
            return true;
        }
        return false;
    }
}
