/*
PolyGun

Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef POLYGUN_GUI_BUTTON_HPP
#define POLYGUN_GUI_BUTTON_HPP

#include "game/gui/component.hpp"
#include "game/gui/style_change_listener.hpp"

namespace polygun::engine {
	class Engine;
}

namespace polygun::renderer {
	class Texture;
}

namespace polygun::gui {
	struct ButtonProp {
		std::string m_caption;
		void (*m_callback)(void*);
		void* m_callback_data;
	};

	class Button final : public Component, public StyleChangeListener {
	public:
		Button(engine::Engine* engine, Constraint* x, Constraint* y, Constraint* width, Constraint* height, const std::string& id, const ButtonProp& prop);
		Button(engine::Engine* engine, Container* parent, xml::XMLNode* node);
		virtual ~Button() override;

		void set_caption(const std::string& caption);
		void set_callback(void (*callback)(void*), void* callback_data);

		virtual void set_inactive(bool inactive) override;
		virtual void render(renderer::GUIRenderer* renderer) override;
		virtual bool update(const window::Event& event) override;
		virtual void on_style_change() override;

	private:
		engine::Engine* m_engine;
		ButtonProp m_properties;
		renderer::Texture* m_caption_texture;
		bool m_pressed;
	};
}

#endif // POLYGUN_GUI_BUTTON_HPP
