/*
 * GuiButton.h
 *
 *  Created on: 2009-07-11
 *      Author: wasyl
 */

#ifndef GUIBUTTON_H_
#define GUIBUTTON_H_

#include <allegro5/allegro.h>
#include <allegro5/a5_font.h>
#include <allegro5/kcm_audio.h>
#include "../prep/misc/Vector2D.h"
#include "../prep/ent/Entity.h"

class GuiButton : public Entity
{
public:
	enum State {DISABLED, NORMAL, HIGHLIGHTED};

protected:
	ALLEGRO_FONT *mFont;
	ALLEGRO_SAMPLE *mSndSelect;

	Rect mRect;
	bool mEnabled;
	std::string mText;
	bool mClicked;

	State mState;

	virtual void setState(State s) { mState = s; }

public:
	GuiButton(Rect r, std::string text, bool enabled);
	~GuiButton();

	int *indices()
	{
		static int ind[] = {ID("entt"), ID("rndr"), ID("dyna"), 0};
		return ind;
	}

	int order(int index)
	{
		if (index == ID("rndr"))
			return 99;
		else
			return (int)this;
	}

	void update(double dt);
	void render();

	void enable(bool enabled) { mEnabled = enabled; };
	bool enabled() { return mEnabled; }

	bool clicked() { bool ret = mClicked; mClicked = false; return ret; }
	void setText(std::string text) { mText = text; }
};

#endif /* GUIBUTTON_H_ */
