#pragma once
#include <Resource/FontTheme.h>
#include "../Base.h"

namespace gorgon {


	class FontTheme;

	FontTheme *LoadFontTheme(Base *parent, File &file, std::istream &Data, int Size);

	class FontTheme : public gge::resource::FontTheme, public Base {
		friend FontTheme *LoadFontTheme(gorgon::Base *parent, File &file, std::istream &in, int Size);
	public:

		FontTheme() : gge::resource::FontTheme() 
		{ }


		using gge::resource::FontTheme::SetRenderer;
		virtual void SetRenderer(gge::Font::FontStyle style, gge::FontRenderer *renderer) {
			if(renderer!=NULL && !dynamic_cast<gorgon::Base*>(renderer))
				throw std::runtime_error("You may only add renderers derived from gorgon::Base");

			gge::resource::FontTheme::SetRenderer(style, renderer);
		}

		virtual void Save(std::ostream &out) {
			auto start=WriteObjectStart(out, *this);

			
			auto propstart=WriteSectionStart(out, gge::resource::GID::FontTheme_Props);

			WriteLink(NormalFont, out);
			WriteLink(BoldFont, out);
			WriteLink(ItalicFont, out);
			WriteLink(SmallFont, out);
			WriteLink(H1Font, out);
			WriteLink(H2Font, out);
			WriteLink(H3Font, out);

			WriteEnd(out, propstart);


			WriteEnd(out, start);
		}

		virtual GID::Type GetGID() const {
			return gge::resource::FontTheme::GetGID();
		}

		virtual void Prepare(gge::GGEMain &main, File &file) {
			Base::Prepare(main,file);

			if(NormalFont) return;

			NormalFont	= dynamic_cast<gge::FontRenderer*>(file.FindObject(guid_normal));
			BoldFont	= dynamic_cast<gge::FontRenderer*>(file.FindObject(guid_bold));
			ItalicFont	= dynamic_cast<gge::FontRenderer*>(file.FindObject(guid_italic));
			SmallFont	= dynamic_cast<gge::FontRenderer*>(file.FindObject(guid_small));
			H1Font		= dynamic_cast<gge::FontRenderer*>(file.FindObject(guid_h1));
			H2Font		= dynamic_cast<gge::FontRenderer*>(file.FindObject(guid_h2));
			H3Font		= dynamic_cast<gge::FontRenderer*>(file.FindObject(guid_h3));
		}

	};


}