/*
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_STYLE_HPP
#define POLYGUN_GUI_STYLE_HPP

#include <string>

#include "common/glm_ext.hpp"
#include "game/renderer/font.hpp"

namespace polygun::xml {
	class XMLNode;
}

namespace polygun::gui {
	class StyleChangeListener;

	class Style final {
	public:
		Style();
		~Style() = default;

		bool load_from_file(const std::string& path);
		void add_change_listener(StyleChangeListener* listener);
		void erase_change_listener(StyleChangeListener* listener);

		static Style& get() { return *s_instance; }
		static void create();
		static void cleanup();

	public:
		glm::vec4ub m_text_color;
		glm::vec4ub m_inactive_text_color;
		glm::vec4ub m_highlight_color;
		glm::vec4ub m_background_color;
		glm::vec4ub m_lower_background_color;
		renderer::Font m_font;
		unsigned m_extrusion_size;

	private:
		std::vector<StyleChangeListener*> m_change_listeners;
		static Style* s_instance;

	private:
		void load_text_style(xml::XMLNode* node);
		void load_misc(xml::XMLNode* node);
		void load_font(xml::XMLNode* node);
		void parse_color(const xml::XMLNode* node, glm::vec4ub& output);
	};

	glm::vec4ub add_to_color(const glm::vec4ub& target, const glm::vec4ub& val);
	glm::vec4ub subtract_from_color(const glm::vec4ub& target, const glm::vec4ub& val);
}

#endif // POLYGUN_GUI_STYLE_HPP
