#pragma once

#include <Widgets/Definitions.h>
#include <Widgets/Basic/ResizableObjectResource.h>
#include "../Base.h"
#include "../File.h"
#include "../Game/Animation.h"

namespace gorgon { namespace widgets {

	class ResizableObject;

	ResizableObject *LoadResizableObject(Base *parent, File &file, std::istream &in, int Size);

	class ResizableObject : public gge::widgets::ResizableObjectResource, public Base {
		friend ResizableObject *LoadResizableObject(gorgon::Base *parent, File &file, std::istream &in, int Size);
	public:

		ResizableObject() {
			
		}

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


			auto propstart=WriteSectionStart(out, gge::widgets::GID::ResizableObj_Props);

			WriteLink(object, out);
			WriteTo(out, (int)SizeController.Align);
			WriteTo(out, (int)SizeController.HorizontalTiling);
			WriteTo(out, (int)SizeController.VerticalTiling);

			WriteEnd(out, propstart);

			WriteNames(out, *this, gge::widgets::GID::ResizableObj_Names, gge::widgets::GID::ResizableObj_Name);
			WriteSubItems(out, *this);


			WriteEnd(out, start);
		}

		virtual GID::Type GetGID() const {
			return gge::widgets::ResizableObjectResource::GetGID();
		}

		virtual void SetProvider(gge::resource::ResizableObjectProvider &object)  {
			if(!dynamic_cast<gorgon::Base*>(&object))
				throw std::runtime_error("You may only add line resources derived from gorgon::Base");


			gge::widgets::ResizableObjectResource::SetProvider(object);
		}

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

			if(!object)
				object		= dynamic_cast<gge::resource::ResizableObjectProvider*>(file.Root().FindObject(target));
		}

		using gorgon::Base::Subitems;
	};	


}}
