#include <vector>
#include <string>

#include <Engine/GGEMain.h>
#include <Widgets/Main.h>
#include <algorithm>
#include <Utils/Random.h>
#include <Widgets/Basic/WidgetLayer.h>
#include <Widgets/WidgetRegistry.h>
#include <Resource/FontTheme.h>
#include <Widgets/FullscreenPanel.h>
#include <Widgets/Panel.h>
#include <Widgets/Tabpanel.h>

#include <Gorgon/Game/BitmapFont.h>
#include <Gorgon/Generic/DataArray.h>
#include <Gorgon/Widgets/WidgetRegistry.h>
#include <Gorgon/File.h>
#include <Gorgon/Game/FontTheme.h>
#include <Gorgon/Game/Pointer.h>
#include <Gorgon/Widgets/Checkbox.h>
#include <Gorgon/Widgets/Placeholder.h>
#include <Gorgon/Widgets/BorderData.h>
#include <Gorgon/Widgets/Rectangle.h>
#include <Gorgon/Widgets/Panel.h>
#include <Widgets/Organizers/LinearOrganizer.h>
#include <GGE/Widgets/Window.h>
#include <Widgets/Checkbox.h>
#include <Widgets/Dialogs/Message.h>
#include <Gorgon/Widgets/Tabpanel.h>
#include <Gorgon/Widgets/Textbox.h>
#include <Widgets/Textbox.h>
#include <Widgets/Listbox.h>
#include <Gorgon/Widgets/Listbox.h>
#include <Gorgon/Widgets/Slider.h>
#include <GGE/Widgets/Progressbar.h>
#include <Widgets/Slider.h>
#include <Gorgon/Widgets/Combobox.h>
#include <Widgets/Combobox.h>

using namespace gge;

void import(const std::string &path) {
	gorgon::File file;
	file.SetFileType(gorgon::GID::File::Widget);

	gorgon::widgets::WidgetRegistry &wr=*new gorgon::widgets::WidgetRegistry;
	wr.SetCaption("Widget Registry");
	file.Root().Add(wr);




	//*** Info
	std::ifstream dimensionsfile(path+"/Spacing.txt");
	dimensionsfile>>wr.WidgetSpacing.x>>wr.WidgetSpacing.y;
	dimensionsfile>>wr.ShadowMargins.Left>>wr.ShadowMargins.Top>>wr.ShadowMargins.Right>>wr.ShadowMargins.Bottom;




	//*** Colors
	std::ifstream colorsfile(path+"/Colors.txt");
	colorsfile
		>>wr.Colors.Text
		>>wr.Colors.Forecolor
		>>wr.Colors.Background
		>>wr.Colors.Alternate
		>>wr.Colors.AlternateBackground
		>>wr.Colors.Highlight
		>>wr.Colors.Light
		>>wr.Colors.Dark
		>>wr.Colors.Saturated
		>>wr.Colors.Desaturated
		>>wr.Colors.Shadow
	;




	//*** FONTS
	gorgon::Folder &fontsfolder=*new gorgon::Folder;
	fontsfolder.SetCaption("Fonts");
	file.Root().Add(fontsfolder);

	gorgon::FontTheme &fonttheme=*new gorgon::FontTheme;
	gorgon::BitmapFont &font=*new gorgon::BitmapFont;
	gorgon::BitmapFont &boldfont=*new gorgon::BitmapFont;
	gorgon::BitmapFont &largefont=*new gorgon::BitmapFont;

	fonttheme.SetRenderer(gge::Font::Normal, &font);
	fonttheme.SetRenderer(gge::Font::Italic, &font);
	fonttheme.SetRenderer(gge::Font::Small, &font);
	fonttheme.SetRenderer(gge::Font::Bold, &boldfont);
	fonttheme.SetRenderer(gge::Font::H3, &boldfont);
	fonttheme.SetRenderer(gge::Font::H2, &largefont);
	fonttheme.SetRenderer(gge::Font::H1, &largefont);
	fonttheme.SetCaption("Theme");
	fontsfolder.Add(fonttheme);

	font.ImportDirectory(path + "/Font-normal");
	font.SetCaption("Normal");
	fontsfolder.Add(font);

	boldfont.ImportDirectory(path + "/Font-bold");
	boldfont.SetCaption("Bold");
	fontsfolder.Add(boldfont);

	largefont.ImportDirectory(path + "/Font-header");
	largefont.SetCaption("Large");
	fontsfolder.Add(largefont);

	wr.Fonts.Normal.Theme=&fonttheme;
	wr.Fonts.Normal.Color=wr.Colors.Text;
	wr.Fonts.Normal.Style=gge::Font::Normal;

	wr.Fonts.H1.Theme=&fonttheme;
	wr.Fonts.H1.Color=wr.Colors.Alternate;
	wr.Fonts.H1.Style=gge::Font::H1;

	wr.Fonts.H2.Theme=&fonttheme;
	wr.Fonts.H2.Color=wr.Colors.Text;
	wr.Fonts.H2.Style=gge::Font::H2;

	wr.Fonts.H3.Theme=&fonttheme;
	wr.Fonts.H3.Color=wr.Colors.Alternate;
	wr.Fonts.H3.Style=gge::Font::H3;

	wr.Fonts.Strong.Theme=&fonttheme;
	wr.Fonts.Strong.Color=wr.Colors.Text;
	wr.Fonts.Strong.Style=gge::Font::Bold;

	wr.Fonts.Emphasize.Theme=&fonttheme;
	wr.Fonts.Emphasize.Color=wr.Colors.Alternate;
	wr.Fonts.Emphasize.Style=gge::Font::Normal;

	wr.Fonts.Quote.Theme=&fonttheme;
	wr.Fonts.Quote.Color=wr.Colors.Text;
	wr.Fonts.Quote.Style=gge::Font::Normal;

	wr.Fonts.Info.Theme=&fonttheme;
	wr.Fonts.Info.Color=wr.Colors.Alternate;
	wr.Fonts.Info.Style=gge::Font::Normal;

	wr.Fonts.Small.Theme=&fonttheme;
	wr.Fonts.Small.Color=wr.Colors.Dark;
	wr.Fonts.Small.Style=gge::Font::Normal;

	wr.Fonts.Link.Theme=&fonttheme;
	wr.Fonts.Link.Color=wr.Colors.Text;
	wr.Fonts.Link.Style=gge::Font::Normal;

	wr.Fonts.Required.Theme=&fonttheme;
	wr.Fonts.Required.Color=wr.Colors.Alternate;
	wr.Fonts.Required.Style=gge::Font::Bold;

	wr.Fonts.Important.Theme=&fonttheme;
	wr.Fonts.Important.Color=wr.Colors.Alternate;
	wr.Fonts.Important.Style=gge::Font::Bold;

	wr.Fonts.Error.Theme=&fonttheme;
	wr.Fonts.Error.Color=wr.Colors.Text;
	wr.Fonts.Error.Style=gge::Font::Bold;

	wr.Fonts.Warning.Theme=&fonttheme;
	wr.Fonts.Warning.Color=wr.Colors.Text;
	wr.Fonts.Warning.Style=gge::Font::Normal;

	wr.Fonts.Success.Theme=&fonttheme;
	wr.Fonts.Success.Color=wr.Colors.Text;
	wr.Fonts.Success.Style=gge::Font::Bold;

	wr.Fonts.Tooltip.Theme=&fonttheme;
	wr.Fonts.Tooltip.Color=wr.Colors.Alternate;
	wr.Fonts.Tooltip.Style=gge::Font::Normal;

	wr.Fonts.Fixed.Theme=&fonttheme;
	wr.Fonts.Fixed.Color=wr.Colors.Text;
	wr.Fonts.Fixed.Style=gge::Font::Normal;

	wr.Fonts.Decorative.Theme=&fonttheme;
	wr.Fonts.Decorative.Color=wr.Colors.Alternate;
	wr.Fonts.Decorative.Style=gge::Font::Normal;





	//*** Pointers
	gorgon::Image &ptrimage=*new gorgon::Image;
	gorgon::Animation &ptranim=*new gorgon::Animation;
	gorgon::Pointer &pointer=*new gorgon::Pointer;
	ptrimage.ImportPNG(path+"/pointer.png");
	ptranim.Add(ptrimage);
	pointer.SetAnimation(ptranim);
	pointer.Type=gge::Pointer::Arrow;
	pointer.Hotspot=gge::utils::Point(0,0);
	wr.pointers->Add(pointer);





	//*** Labels
	gorgon::Folder &labelsfolder=*new gorgon::Folder;
	labelsfolder.SetCaption("Labels");
	file.Root().Add(labelsfolder);


	gorgon::widgets::Checkbox &labelnormal=*new gorgon::widgets::Checkbox;
	labelnormal.SetCaption("Normal");
	labelnormal.DefaultSize=utils::Size(100,22);
	labelsfolder.Add(labelnormal);
	wr.Labels.Label=&labelnormal;

	gorgon::widgets::CheckboxGroup &labelnormal_grp=*new gorgon::widgets::CheckboxGroup;
	labelnormal.Mapping[labelnormal_grp]=&labelnormal_grp;
	labelnormal.Subitems.Add(labelnormal_grp);

	gorgon::widgets::CheckboxElement &labelnormal_element=*new gorgon::widgets::CheckboxElement;
	labelnormal_element.Font=&wr.Fonts.Normal;
	labelnormal_grp.Normal=&labelnormal_element;
	labelnormal_grp.Subitems.Add(labelnormal_element);

	labelnormal_element.TextPlace=new gorgon::widgets::Placeholder;
	labelnormal_element.Subitems.Add(dynamic_cast<gorgon::Base*>(labelnormal_element.TextPlace));
	labelnormal_element.TextPlace->Align=Alignment::Middle_Left;
	labelnormal_element.TextPlace->SizingMode=labelnormal_element.TextPlace->MaximumAvailable;

	gorgon::widgets::BorderData &labelnormal_border=*new gorgon::widgets::BorderData;
	labelnormal_border.Padding=utils::Margins(1, 6);
	labelnormal_element.Border=&labelnormal_border;
	labelnormal_element.Subitems.Add(labelnormal_border);

	gorgon::widgets::CheckboxLine &labelnormal_line=*new gorgon::widgets::CheckboxLine;
	labelnormal_line.Contents.First=labelnormal.Icon;
	labelnormal_line.Contents.Second=labelnormal.Text;
	labelnormal_element.Lines[0]=&labelnormal_line;
	labelnormal_element.Subitems.Add(labelnormal_line);


	gorgon::widgets::Checkbox &labelhint=*new gorgon::widgets::Checkbox;
	labelhint.SetCaption("Hint");
	labelhint.DefaultSize=utils::Size(100,22);
	labelsfolder.Add(labelhint);
	wr.Labels.Hint=&labelhint;

	gorgon::widgets::CheckboxGroup &labelhint_grp=*new gorgon::widgets::CheckboxGroup;
	labelhint.Mapping[labelhint_grp]=&labelhint_grp;
	labelhint.Subitems.Add(labelhint_grp);

	gorgon::widgets::CheckboxElement &labelhint_element=*new gorgon::widgets::CheckboxElement;
	labelhint_element.Font=&wr.Fonts.Strong;
	labelhint_grp.Normal=&labelhint_element;
	labelhint_grp.Subitems.Add(labelhint_element);

	labelhint_element.TextPlace=new gorgon::widgets::Placeholder;
	labelhint_element.Subitems.Add(dynamic_cast<gorgon::Base*>(labelhint_element.TextPlace));
	labelhint_element.TextPlace->Align=Alignment::Middle_Right;
	labelhint_element.TextPlace->SizingMode=labelhint_element.TextPlace->MaximumAvailable;

	gorgon::widgets::BorderData &labelhint_border=*new gorgon::widgets::BorderData;
	labelhint_border.Padding=utils::Margins(1, 1);
	labelhint_element.Border=&labelhint_border;
	labelhint_element.Subitems.Add(labelhint_border);

	gorgon::widgets::CheckboxLine &labelhint_line=*new gorgon::widgets::CheckboxLine;
	labelhint_line.Contents.First=labelhint.Icon;
	labelhint_line.Contents.Second=labelhint.Text;
	labelhint_element.Lines[0]=&labelhint_line;
	labelhint_element.Subitems.Add(labelhint_line);


	gorgon::widgets::Checkbox &labelsubheading=*new gorgon::widgets::Checkbox;
	labelsubheading.SetCaption("Subheading");
	labelsubheading.DefaultSize=utils::Size(100,22);
	labelsfolder.Add(labelsubheading);
	wr.Labels.Subheading=&labelsubheading;

	gorgon::widgets::CheckboxGroup &labelsubheading_grp=*new gorgon::widgets::CheckboxGroup;
	labelsubheading.Mapping[labelsubheading_grp]=&labelsubheading_grp;
	labelsubheading.Subitems.Add(labelsubheading_grp);

	gorgon::widgets::CheckboxElement &labelsubheading_element=*new gorgon::widgets::CheckboxElement;
	labelsubheading_element.Font=new Font(wr.Fonts.Strong);
	labelsubheading_element.Font->Color=wr.Colors.Text;
	labelsubheading_grp.Normal=&labelsubheading_element;
	labelsubheading_grp.Subitems.Add(labelsubheading_element);

	labelsubheading_element.TextPlace=new gorgon::widgets::Placeholder;
	labelsubheading_element.Subitems.Add(dynamic_cast<gorgon::Base*>(labelsubheading_element.TextPlace));
	labelsubheading_element.TextPlace->Align=Alignment::Middle_Right;
	labelsubheading_element.TextPlace->SizingMode=labelsubheading_element.TextPlace->MaximumAvailable;

	gorgon::widgets::BorderData &labelsubheading_border=*new gorgon::widgets::BorderData;
	labelsubheading_border.Padding=utils::Margins(0, 0);
	labelsubheading_element.Border=&labelsubheading_border;
	labelsubheading_element.Subitems.Add(labelsubheading_border);

	gorgon::widgets::CheckboxLine &labelsubheading_line=*new gorgon::widgets::CheckboxLine;
	labelsubheading_line.Contents.First=labelsubheading.Icon;
	labelsubheading_line.Contents.Second=labelsubheading.Text;
	labelsubheading_element.Lines[0]=&labelsubheading_line;
	labelsubheading_element.Subitems.Add(labelsubheading_line);



	gorgon::widgets::Checkbox &labelbold=*new gorgon::widgets::Checkbox;
	labelbold.SetCaption("Title");
	labelbold.DefaultSize=utils::Size(100,22);
	labelsfolder.Add(labelbold);
	wr.Labels.Bold=&labelbold;

	gorgon::widgets::CheckboxGroup &labelbold_grp=*new gorgon::widgets::CheckboxGroup;
	labelbold.Mapping[labelbold_grp]=&labelbold_grp;
	labelbold.Subitems.Add(labelbold_grp);

	gorgon::widgets::CheckboxElement &labelbold_element=*new gorgon::widgets::CheckboxElement;
	labelbold_element.Font=&wr.Fonts.Important;
	labelbold_grp.Normal=&labelbold_element;
	labelbold_grp.Subitems.Add(labelbold_element);

	gorgon::widgets::BorderData &labelbold_border=*new gorgon::widgets::BorderData;
	labelbold_border.Padding=utils::Margins(1, 6);
	labelbold_element.Border=&labelbold_border;
	labelbold_element.Subitems.Add(labelbold_border);

	gorgon::widgets::CheckboxLine &labelbold_line=*new gorgon::widgets::CheckboxLine;
	labelbold_line.Contents.First=labelbold.Icon;
	labelbold_line.Contents.Second=labelbold.Text;
	labelbold_element.Lines[0]=&labelbold_line;
	labelbold_element.Subitems.Add(labelbold_line);


	gorgon::widgets::Checkbox &labeltitle=*new gorgon::widgets::Checkbox;
	labeltitle.SetCaption("Title");
	labeltitle.DefaultSize=utils::Size(100,22);
	labelsfolder.Add(labeltitle);
	wr.Labels.Title=&labeltitle;

	gorgon::widgets::CheckboxGroup &labeltitle_grp=*new gorgon::widgets::CheckboxGroup;
	labeltitle.Mapping[labeltitle_grp]=&labeltitle_grp;
	labeltitle.Subitems.Add(labeltitle_grp);

	gorgon::widgets::CheckboxElement &labeltitle_element=*new gorgon::widgets::CheckboxElement;
	labeltitle_element.Font=&wr.Fonts.H1;
	labeltitle_grp.Normal=&labeltitle_element;
	labeltitle_grp.Subitems.Add(labeltitle_element);

	gorgon::widgets::BorderData &labeltitle_border=*new gorgon::widgets::BorderData;
	labeltitle_border.Padding=utils::Margins(1, 6);
	labeltitle_element.Border=&labeltitle_border;
	labeltitle_element.Subitems.Add(labeltitle_border);

	gorgon::widgets::CheckboxLine &labeltitle_line=*new gorgon::widgets::CheckboxLine;
	labeltitle_line.Contents.First=labeltitle.Icon;
	labeltitle_line.Contents.Second=labeltitle.Text;
	labeltitle_element.Lines[0]=&labeltitle_line;
	labeltitle_element.Subitems.Add(labeltitle_line);




	//*** Buttons
	gorgon::Folder &buttonsfolder=*new gorgon::Folder;
	buttonsfolder.SetCaption("Buttons");
	file.Root().Add(buttonsfolder);

	std::ifstream button_dimensions(path+"/Button/Dimensions.txt");
	gorgon::widgets::Checkbox &button=*new gorgon::widgets::Checkbox;
	button.SetCaption("Button");
	button_dimensions>>button.DefaultSize.Width>>button.DefaultSize.Height;
	buttonsfolder.Add(button);
	wr.Buttons.Button=&button;

	gorgon::widgets::CheckboxGroup &button_grp=*new gorgon::widgets::CheckboxGroup;
	button.Mapping[button_grp]=&button_grp;
	button.Subitems.Add(button_grp);

	utils::Margins button_borderwidth;
	button_dimensions>>button_borderwidth.Left>>button_borderwidth.Top>>button_borderwidth.Right>>button_borderwidth.Bottom;

	gorgon::widgets::CheckboxElement &button_normal=*new gorgon::widgets::CheckboxElement;
	button_normal.Font=new Font(wr.Fonts.Strong);
	button_dimensions>>button_normal.Font->Color;
	button_grp.Normal=&button_normal;
	button_grp.Subitems.Add(button_normal);

	gorgon::widgets::BorderData &button_normal_border=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Button/normal");
	button_normal_border.BorderWidth=button_borderwidth;
	button_normal.Border=&button_normal_border;
	button_normal.Subitems.Add(button_normal_border);

	gorgon::widgets::CheckboxLine &button_line=*new gorgon::widgets::CheckboxLine;
	button_line.Contents.First=button.Icon;
	button_line.Contents.Second=button.Text;
	button_line.WidthMode=button.Auto;
	button_line.Align=Alignment::Middle_Center;
	button_normal.Lines[0]=&button_line;
	button_normal.Subitems.Add(button_line);

	gorgon::widgets::CheckboxElement &button_hover=*new gorgon::widgets::CheckboxElement;
	button_hover.Font=new Font(wr.Fonts.Strong);
	button_dimensions>>button_hover.Font->Color;
	button_grp.Hover=&button_hover;
	button_grp.Subitems.Add(button_hover);

	gorgon::widgets::CheckboxElement &button_down=*new gorgon::widgets::CheckboxElement;
	button_down.Font=new Font(wr.Fonts.Strong);
	button_dimensions>>button_down.Font->Color;
	button_grp.Down=&button_down;
	button_grp.Subitems.Add(button_down);

	gorgon::widgets::BorderData &button_down_border=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Button/down");
	button_down_border.BorderWidth=button_borderwidth;
	button_down.Border=&button_down_border;
	button_down.Subitems.Add(button_down_border);

	gorgon::widgets::CheckboxElement &button_disabled=*new gorgon::widgets::CheckboxElement;
	button_disabled.Font=new Font(wr.Fonts.Strong);
	button_dimensions>>button_disabled.Font->Color;
	button_grp.Disabled=&button_disabled;
	button_grp.Subitems.Add(button_disabled);

	gorgon::widgets::BorderData &button_disabled_border=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Button/disabled");
	button_disabled_border.BorderWidth=button_borderwidth;
	button_disabled.Border=&button_disabled_border;
	button_disabled.Subitems.Add(button_disabled_border);



	//*** Checkboxes
	gorgon::Folder &checkboxsfolder=*new gorgon::Folder;
	checkboxsfolder.SetCaption("Checkbox");
	file.Root().Add(checkboxsfolder);

	std::ifstream checkbox_dimensions(path+"/Checkbox/Dimensions.txt");
	gorgon::widgets::Checkbox &checkbox=*new gorgon::widgets::Checkbox;
	checkbox.SetCaption("Button");
	checkbox_dimensions>>checkbox.DefaultSize.Width>>checkbox.DefaultSize.Height;
	checkboxsfolder.Add(checkbox);
	wr.Checkboxes.Checkbox=&checkbox;

	gorgon::widgets::CheckboxGroup &checkbox_empty=*new gorgon::widgets::CheckboxGroup;
	checkbox.Mapping[checkbox_empty]=&checkbox_empty;
	checkbox.Subitems.Add(checkbox_empty);

	gorgon::widgets::CheckboxElement &checkbox_empty_normal=*new gorgon::widgets::CheckboxElement;
	checkbox_empty_normal.Font=&wr.Fonts.Normal;
	checkbox_empty.Normal=&checkbox_empty_normal;
	checkbox_empty.Subitems.Add(checkbox_empty_normal);

	gorgon::Image &checkbox_empty_symbol=*new gorgon::Image;
	checkbox_empty_symbol.ImportPNG(path+"/Checkbox/empty.png");
	checkbox_empty_normal.Symbol=&checkbox_empty_symbol;
	checkbox_empty_normal.Subitems.Add(checkbox_empty_symbol);

	gorgon::widgets::Placeholder &checkbox_textplace=*new gorgon::widgets::Placeholder;
	checkbox_textplace.SizingMode=checkbox_textplace.MaximumAvailable;
	checkbox_textplace.Align=Alignment::Middle_Left;
	checkbox_empty_normal.TextPlace=&checkbox_textplace;
	checkbox_empty_normal.Subitems.Add(checkbox_textplace);

	gorgon::widgets::CheckboxLine &checkbox_line=*new gorgon::widgets::CheckboxLine;
	checkbox_line.Contents.First=checkbox.Symbol;
	checkbox_line.Contents.Second=checkbox.Text;
	checkbox_empty_normal.Lines[0]=&checkbox_line;
	checkbox_empty_normal.Subitems.Add(checkbox_line);

	gorgon::widgets::CheckboxGroup &checkbox_checked=*new gorgon::widgets::CheckboxGroup;
	checkbox_checked.State.from=2;
	checkbox.Mapping[checkbox_checked]=&checkbox_checked;
	checkbox.Subitems.Add(checkbox_checked);

	gorgon::widgets::CheckboxElement &checkbox_checked_normal=*new gorgon::widgets::CheckboxElement;
	checkbox_checked_normal.Font=&wr.Fonts.Normal;
	checkbox_checked.Normal=&checkbox_checked_normal;
	checkbox_checked.Subitems.Add(checkbox_checked_normal);

	gorgon::Image &checkbox_checked_symbol=*new gorgon::Image;
	checkbox_checked_symbol.ImportPNG(path+"/Checkbox/checked.png");
	checkbox_checked_normal.Symbol=&checkbox_checked_symbol;
	checkbox_checked_normal.Subitems.Add(checkbox_checked_symbol);



	std::ifstream radio_dimensions(path+"/Radio/Dimensions.txt");
	gorgon::widgets::Checkbox &radio=*new gorgon::widgets::Checkbox;
	radio.SetCaption("Radio");
	radio_dimensions>>radio.DefaultSize.Width>>radio.DefaultSize.Height;
	checkboxsfolder.Add(radio);
	wr.Checkboxes.Radio=&radio;

	gorgon::widgets::CheckboxGroup &radio_empty=*new gorgon::widgets::CheckboxGroup;
	radio.Mapping[radio_empty]=&radio_empty;
	radio.Subitems.Add(radio_empty);

	gorgon::widgets::CheckboxElement &radio_empty_normal=*new gorgon::widgets::CheckboxElement;
	radio_empty_normal.Font=&wr.Fonts.Normal;
	radio_empty.Normal=&radio_empty_normal;
	radio_empty.Subitems.Add(radio_empty_normal);

	gorgon::Image &radio_empty_symbol=*new gorgon::Image;
	radio_empty_symbol.ImportPNG(path+"/Radio/empty.png");
	radio_empty_normal.Symbol=&radio_empty_symbol;
	radio_empty_normal.Subitems.Add(radio_empty_symbol);

	gorgon::widgets::Placeholder &radio_textplace=*new gorgon::widgets::Placeholder;
	radio_textplace.SizingMode=radio_textplace.MaximumAvailable;
	radio_textplace.Align=Alignment::Middle_Left;
	radio_empty_normal.TextPlace=&radio_textplace;
	radio_empty_normal.Subitems.Add(radio_textplace);

	gorgon::widgets::CheckboxLine &radio_line=*new gorgon::widgets::CheckboxLine;
	radio_line.Contents.First=radio.Symbol;
	radio_line.Contents.Second=radio.Text;
	radio_empty_normal.Lines[0]=&radio_line;
	radio_empty_normal.Subitems.Add(radio_line);

	gorgon::widgets::CheckboxGroup &radio_checked=*new gorgon::widgets::CheckboxGroup;
	radio_checked.State.from=2;
	radio.Mapping[radio_checked]=&radio_checked;
	radio.Subitems.Add(radio_checked);

	gorgon::widgets::CheckboxElement &radio_checked_normal=*new gorgon::widgets::CheckboxElement;
	radio_checked_normal.Font=&wr.Fonts.Normal;
	radio_checked.Normal=&radio_checked_normal;
	radio_checked.Subitems.Add(radio_checked_normal);

	gorgon::Image &radio_checked_symbol=*new gorgon::Image;
	radio_checked_symbol.ImportPNG(path+"/Radio/checked.png");
	radio_checked_normal.Symbol=&radio_checked_symbol;
	radio_checked_normal.Subitems.Add(radio_checked_symbol);


	std::ifstream tabbtn_dimensions(path+"/Tab/Dimensions.txt");
	gorgon::widgets::Checkbox &tabbtn=*new gorgon::widgets::Checkbox;
	tabbtn.SetCaption("Tab");
	tabbtn_dimensions>>tabbtn.DefaultSize.Width>>tabbtn.DefaultSize.Height;
	checkboxsfolder.Add(tabbtn);

	utils::Margins tabbtn_borderwidth;
	tabbtn_dimensions>>tabbtn_borderwidth.Left>>tabbtn_borderwidth.Top>>tabbtn_borderwidth.Right>>tabbtn_borderwidth.Bottom;

	gorgon::widgets::CheckboxGroup &tabbtn_empty=*new gorgon::widgets::CheckboxGroup;
	tabbtn.Mapping[tabbtn_empty]=&tabbtn_empty;
	tabbtn.Subitems.Add(tabbtn_empty);

	gorgon::widgets::CheckboxElement &tabbtn_empty_normal=*new gorgon::widgets::CheckboxElement;
	tabbtn_empty_normal.Font=&wr.Fonts.Normal;
	tabbtn_empty.Normal=&tabbtn_empty_normal;
	tabbtn_empty.Subitems.Add(tabbtn_empty_normal);

	gorgon::widgets::BorderData &tabbtn_empty_border=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Tab/empty");
	tabbtn_empty_border.BorderWidth=tabbtn_borderwidth;
	tabbtn_empty_normal.Border=&tabbtn_empty_border;
	tabbtn_empty_normal.Subitems.Add(tabbtn_empty_border);

	gorgon::widgets::Placeholder &tabbtn_textplace=*new gorgon::widgets::Placeholder;
	tabbtn_textplace.SizingMode=tabbtn_textplace.MaximumAvailable;
	tabbtn_textplace.Align=Alignment::Middle_Left;
	tabbtn_empty_normal.TextPlace=&tabbtn_textplace;
	tabbtn_empty_normal.Subitems.Add(tabbtn_textplace);

	gorgon::widgets::CheckboxLine &tabbtn_line=*new gorgon::widgets::CheckboxLine;
	tabbtn_line.Contents.First=tabbtn.Symbol;
	tabbtn_line.Contents.Second=tabbtn.Text;
	tabbtn_empty_normal.Lines[0]=&tabbtn_line;
	tabbtn_empty_normal.Subitems.Add(tabbtn_line);

	gorgon::widgets::CheckboxGroup &tabbtn_checked=*new gorgon::widgets::CheckboxGroup;
	tabbtn_checked.State.from=2;
	tabbtn.Mapping[tabbtn_checked]=&tabbtn_checked;
	tabbtn.Subitems.Add(tabbtn_checked);

	gorgon::widgets::CheckboxElement &tabbtn_checked_normal=*new gorgon::widgets::CheckboxElement;
	tabbtn_checked_normal.Font=new Font(wr.Fonts.Strong);
	tabbtn_dimensions>>tabbtn_checked_normal.Font->Color;
	tabbtn_checked.Normal=&tabbtn_checked_normal;
	tabbtn_checked.Subitems.Add(tabbtn_checked_normal);

	gorgon::widgets::BorderData &tabbtn_checked_border=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Tab/checked");
	tabbtn_checked_border.BorderWidth=tabbtn_borderwidth;
	tabbtn_checked_normal.Border=&tabbtn_checked_border;
	tabbtn_checked_normal.Subitems.Add(tabbtn_checked_border);



	//*** Textboxes
	gorgon::Folder &textboxsfolder=*new gorgon::Folder;
	textboxsfolder.SetCaption("Textboxes");
	file.Root().Add(textboxsfolder);

	std::ifstream textbox_dimensions(path+"/Textbox/Dimensions.txt");
	gorgon::widgets::Textbox &textbox=*new gorgon::widgets::Textbox;
	textbox.SetCaption("Textbox");
	textbox_dimensions>>textbox.DefaultSize.Width>>textbox.DefaultSize.Height;
	textboxsfolder.Add(textbox);
	wr.Textboxes.Textbox=&textbox;

	utils::Margins textbox_borderwidth;
	textbox_dimensions>>textbox_borderwidth.Left>>textbox_borderwidth.Top>>textbox_borderwidth.Right>>textbox_borderwidth.Bottom;

	gorgon::widgets::TextboxElement &textbox_normal=*new gorgon::widgets::TextboxElement;
	textbox_normal.Font=new Font(wr.Fonts.Normal);
	textbox_dimensions>>textbox_normal.Font->Color;
	textbox_normal.SelectedFont=new Font(wr.Fonts.Normal);
	textbox.Normal=&textbox_normal;
	textbox.Subitems.Add(textbox_normal);

	gorgon::widgets::BorderData &textbox_normal_border=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Textbox/normal");
	textbox_normal_border.BorderWidth=textbox_borderwidth;
	textbox_normal.OuterBorder=&textbox_normal_border;
	textbox_normal.Subitems.Add(textbox_normal_border);

	gorgon::widgets::TextboxElement &textbox_active=*new gorgon::widgets::TextboxElement;
	textbox.Focused=&textbox_active;
	textbox.Subitems.Add(textbox_active);

	gorgon::widgets::BorderData &textbox_active_border=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Textbox/active");
	textbox_active_border.BorderWidth=textbox_borderwidth;
	textbox_active.OuterBorder=&textbox_active_border;
	textbox_active.Subitems.Add(textbox_active_border);

	gorgon::Animation &textbox_caret=*new gorgon::Animation;
	gorgon::Image &textbox_caret1=*new gorgon::Image;
	textbox_caret1.ImportPNG(path+"/Textbox/caret-1.png");
	textbox_caret.Add(textbox_caret1, 200);
	gorgon::Image &textbox_caret2=*new gorgon::Image;
	textbox_caret2.ImportPNG(path+"/Textbox/caret-2.png");
	textbox_caret.Add(textbox_caret2, 500);
	textbox.Caret=&textbox_caret;
	textbox.Subitems.Add(textbox_caret);

	gorgon::widgets::BorderData &textbox_selection=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Textbox/selection");
	textbox_selection.SetCaption("Selection");
	textbox_selection.Padding=2;
	textbox_selection.Padding.Left=0;
	textbox_selection.AutoBorderWidth=false;
	textbox_selection.BorderWidth=1;
	textbox.Subitems.Add(textbox_selection);
	textbox.Selection=&textbox_selection;



	
	//*** Sliders
	gorgon::Folder &slidersfolder=*new gorgon::Folder;
	slidersfolder.SetCaption("Sliders");
	file.Root().Add(slidersfolder);

	std::ifstream slider_dimensions(path+"/Slider/Dimensions.txt");
	gorgon::widgets::Slider &slider=*new gorgon::widgets::Slider;
	slider_dimensions>>slider.DefaultSize.Width>>slider.DefaultSize.Height;
	slider.SetCaption("Slider");
	slidersfolder.Add(slider);
	wr.Sliders.Slider=&slider;

	gorgon::widgets::SliderGroup &slider_g_hor=*new gorgon::widgets::SliderGroup;
	slider_g_hor.Orientation=slider.Bottom;
	slider.Mapping[slider_g_hor]=&slider_g_hor;
	slider.Subitems.Add(slider_g_hor);

	gorgon::widgets::SliderElement &slider_hor=*new gorgon::widgets::SliderElement;
	slider_g_hor.Normal=&slider_hor;
	slider_g_hor.Subitems.Add(slider_hor);

	gorgon::Image &slider_hor_symbol=*new gorgon::Image;
	slider_hor_symbol.ImportPNG(path+"/Slider/symbol.png");
	slider_hor.Symbol=&slider_hor_symbol;
	slider_hor.Subitems.Add(slider_hor_symbol);

	gorgon::widgets::BorderData &slider_hor_ruler=gorgon::widgets::BorderData::CreateLineChainFrom(path+"/Slider/rule");
	slider_hor.Ruler=&slider_hor_ruler;
	slider_hor.Subitems.Add(slider_hor_ruler);


	std::ifstream scroll_dimensions(path+"/Scrollbar/Dimensions.txt");
	gorgon::widgets::Slider &scroll=*new gorgon::widgets::Slider;
	scroll_dimensions>>scroll.DefaultSize.Width>>scroll.DefaultSize.Height;
	scroll.SetCaption("Scrollbar");
	slidersfolder.Add(scroll);
	wr.Scrollbars.Scrollbar=&scroll;

	gorgon::widgets::SliderGroup &scroll_g_hor=*new gorgon::widgets::SliderGroup;
	scroll_g_hor.Orientation=scroll.Vertical;
	scroll.Mapping[scroll_g_hor]=&scroll_g_hor;
	scroll.Subitems.Add(scroll_g_hor);

	gorgon::widgets::SliderElement &scroll_hor=*new gorgon::widgets::SliderElement;
	scroll_g_hor.Normal=&scroll_hor;
	scroll_g_hor.Subitems.Add(scroll_hor);

	gorgon::Image &scroll_hor_symbol=*new gorgon::Image;
	scroll_hor_symbol.ImportPNG(path+"/Scrollbar/symbol.png");
	scroll_hor.Symbol=&scroll_hor_symbol;
	scroll_hor.Subitems.Add(scroll_hor_symbol);

	gorgon::widgets::BorderData &scroll_hor_ruler=gorgon::widgets::BorderData::CreateLineChainFrom(path+"/Scrollbar/rule", false, true);
	scroll_hor.Ruler=&scroll_hor_ruler;
	scroll_hor.Subitems.Add(scroll_hor_ruler);

	gorgon::widgets::Checkbox &scrollup_button=*new gorgon::widgets::Checkbox;
	scrollup_button.SetCaption("Scroll up button");
	scroll_dimensions>>scrollup_button.DefaultSize.Width>>scrollup_button.DefaultSize.Height;
	buttonsfolder.Add(scrollup_button);
	scroll_g_hor.UpButton=&scrollup_button;

	gorgon::widgets::CheckboxGroup &scrollup_button_grp=*new gorgon::widgets::CheckboxGroup;
	scrollup_button.Mapping[scrollup_button_grp]=&scrollup_button_grp;
	scrollup_button.Subitems.Add(scrollup_button_grp);

	gorgon::widgets::CheckboxElement &scrollup_button_normal=*new gorgon::widgets::CheckboxElement;
	scrollup_button_grp.Normal=&scrollup_button_normal;
	scrollup_button_grp.Subitems.Add(scrollup_button_normal);

	gorgon::widgets::BorderData &scrollup_button_border=gorgon::widgets::BorderData::CreateImageChainFrom(path+"/Scrollbar/upbtn.png");
	scrollup_button_normal.Subitems.Add(scrollup_button_border);

	gorgon::widgets::Checkbox &scrolldown_button=*new gorgon::widgets::Checkbox;
	scrolldown_button.SetCaption("Scroll down button");
	scroll_dimensions>>scrolldown_button.DefaultSize.Width>>scrolldown_button.DefaultSize.Height;
	buttonsfolder.Add(scrolldown_button);
	scroll_g_hor.DownButton=&scrolldown_button;

	gorgon::widgets::CheckboxGroup &scrolldown_button_grp=*new gorgon::widgets::CheckboxGroup;
	scrolldown_button.Mapping[scrolldown_button_grp]=&scrolldown_button_grp;
	scrolldown_button.Subitems.Add(scrolldown_button_grp);

	gorgon::widgets::CheckboxElement &scrolldown_button_normal=*new gorgon::widgets::CheckboxElement;
	scrolldown_button_grp.Normal=&scrolldown_button_normal;
	scrolldown_button_grp.Subitems.Add(scrolldown_button_normal);

	gorgon::widgets::BorderData &scrolldown_button_border=gorgon::widgets::BorderData::CreateImageChainFrom(path+"/Scrollbar/downbtn.png");
	scrolldown_button_normal.Subitems.Add(scrolldown_button_border);




	//*** Panels
	gorgon::Folder &panelsfolder=*new gorgon::Folder;
	panelsfolder.SetCaption("Panels");
	file.Root().Add(panelsfolder);

	std::ifstream panel_dimensions(path+"/Panel/Dimensions.txt");
	gorgon::widgets::Panel &panel=*new gorgon::widgets::Panel;
	panel.SetCaption("Panel");
	panel.Scroller=&scroll;
	panel_dimensions>>panel.DefaultSize.Width>>panel.DefaultSize.Height;
	panelsfolder.Add(panel);
	wr.Panels.Panel=&panel;

	gorgon::widgets::PanelElement &panel_element=*new gorgon::widgets::PanelElement;
	panel.Normal=&panel_element;
	panel.Subitems.Add(panel_element);

	gorgon::widgets::BorderData &panel_border=*new gorgon::widgets::BorderData;
	panel_element.OuterBorder=&panel_border;
	panel_element.Subitems.Add(panel_border);
	panel_border.AutoBorderWidth=false;
	panel_border.Padding=0;
	panel_dimensions>>panel_border.BorderWidth.Left>>panel_border.BorderWidth.Top>>panel_border.BorderWidth.Right>>panel_border.BorderWidth.Bottom;
	//panel_dimensions>>panel_border.Padding.Left>>panel_border.Padding.Top>>panel_border.Padding.Right>>panel_border.Padding.Bottom;

	gorgon::widgets::ResizableObject &panel_resiz=*new gorgon::widgets::ResizableObject;
	panel_border.SetProvider(panel_resiz);
	panel_border.Subitems.Add(panel_resiz);

	gorgon::widgets::Rectangle &panel_outer=*new gorgon::widgets::Rectangle;
	panel_outer.ImportPNGs(path+"/Panel/normal");
	panel_resiz.SetProvider(panel_outer);
	panel_resiz.Subitems.Add(panel_outer);


	std::ifstream window_dimensions(path+"/Window/Dimensions.txt");
	gorgon::widgets::Panel &window=*new gorgon::widgets::Panel;
	window.SetCaption("Window");
	window.Scroller=&scroll;
	window_dimensions>>window.DefaultSize.Width>>window.DefaultSize.Height;
	panelsfolder.Add(window);
	wr.Panels.Window=&window;

	gorgon::widgets::PanelElement &window_element=*new gorgon::widgets::PanelElement;
	window.Normal=&window_element;
	window.Subitems.Add(window_element);

	gorgon::widgets::BorderData &window_border=*new gorgon::widgets::BorderData;
	window_element.OuterBorder=&window_border;
	window_element.Subitems.Add(window_border);
	window_border.AutoBorderWidth=false;
	window_border.Padding=0;
	window_dimensions>>window_border.BorderWidth.Left>>window_border.BorderWidth.Top>>window_border.BorderWidth.Right>>window_border.BorderWidth.Bottom;
	//window_dimensions>>window_border.Padding.Left>>window_border.Padding.Top>>window_border.Padding.Right>>window_border.Padding.Bottom;

	gorgon::widgets::ResizableObject &window_resiz=*new gorgon::widgets::ResizableObject;
	window_border.SetProvider(window_resiz);
	window_border.Subitems.Add(window_resiz);

	gorgon::widgets::Rectangle &window_outer=*new gorgon::widgets::Rectangle;
	window_outer.ImportPNGs(path+"/Window/normal");
	window_resiz.SetProvider(window_outer);
	window_resiz.Subitems.Add(window_outer);

	gorgon::widgets::Checkbox &window_title=*new gorgon::widgets::Checkbox;
	window_title.SetCaption("Window title");
	window_title.DefaultSize=utils::Size(100,20);
	labelsfolder.Add(window_title);
	window.TitleLabel=&window_title;

	gorgon::widgets::CheckboxGroup &window_title_grp=*new gorgon::widgets::CheckboxGroup;
	window_title.Mapping[window_title_grp]=&window_title_grp;
	window_title.Subitems.Add(window_title_grp);

	gorgon::widgets::CheckboxElement &window_title_element=*new gorgon::widgets::CheckboxElement;
	window_title_element.Font=new gge::Font(wr.Fonts.Strong);
	window_dimensions>>window_title_element.Font->Color;
	window_title_grp.Normal=&window_title_element;
	window_title_grp.Subitems.Add(window_title_element);

	gorgon::widgets::BorderData &window_title_border=*new gorgon::widgets::BorderData;
	window_title_border.Padding=0;
	window_dimensions>>window_title_border.Padding.Left;
	window_dimensions>>window_title_border.Padding.Top;
	window_title_element.Border=&window_title_border;
	window_title_element.Subitems.Add(window_title_border);

	gorgon::widgets::CheckboxLine &window_title_line=*new gorgon::widgets::CheckboxLine;
	window_title_line.Contents.First=window_title.Icon;
	window_title_line.Contents.Second=window_title.Text;
	window_title_element.Lines[0]=&window_title_line;
	window_title_element.Subitems.Add(window_title_line);

	gorgon::widgets::Placeholder &window_title_textplace=*new gorgon::widgets::Placeholder;
	window_title_textplace.SizingMode=window_title_textplace.MaximumAvailable;
	window_title_textplace.Align=Alignment::Middle_Left;
	window_title_element.TextPlace=&window_title_textplace;
	window_title_element.Subitems.Add(window_title_textplace);

	gorgon::widgets::Checkbox &window_button=*new gorgon::widgets::Checkbox;
	window_button.SetCaption("Window button");
	window_dimensions>>window_button.DefaultSize.Width>>window_button.DefaultSize.Height;
	buttonsfolder.Add(window_button);
	window.TitleButton=&window_button;

	gorgon::widgets::CheckboxGroup &window_button_grp=*new gorgon::widgets::CheckboxGroup;
	window_button.Mapping[window_button_grp]=&window_button_grp;
	window_button.Subitems.Add(window_button_grp);

	gorgon::widgets::CheckboxElement &window_button_normal=*new gorgon::widgets::CheckboxElement;
	window_button_normal.Font=new gge::Font(wr.Fonts.Normal);
	window_dimensions>>window_button_normal.Font->Color;
	window_button_grp.Normal=&window_button_normal;
	window_button_grp.Subitems.Add(window_button_normal);

	gorgon::widgets::BorderData &window_button_border=gorgon::widgets::BorderData::CreateImageChainFrom(path+"/Window/button.png");
	window_button_border.Padding=0;
	window_button_border.BorderWidth=0;
	window_button_border.AutoBorderWidth=false;
	window_button_normal.Border=&window_button_border;
	window_button_normal.Subitems.Add(window_button_border);

	gorgon::widgets::Placeholder &window_button_iconplace=*new gorgon::widgets::Placeholder;
	window_button_normal.IconPlace=&window_button_iconplace;
	window_button_normal.IconPlace->Align=gge::Alignment::Middle_Center;
	window_button_normal.Subitems.Add(window_button_iconplace);

	gorgon::widgets::CheckboxLine &window_button_line=*new gorgon::widgets::CheckboxLine;
	window_button_line.Contents.First=window_button.Icon;
	window_button_line.Contents.Second=window_button.Text;
	window_button_line.WidthMode=window_button.Full;
	window_button_normal.Lines[0]=&window_button_line;
	window_button_normal.Subitems.Add(window_button_line);

	gorgon::widgets::CheckboxElement &window_button_down=*new gorgon::widgets::CheckboxElement;
	window_button_grp.Down=&window_button_down;
	window_button_grp.Subitems.Add(window_button_down);

	gorgon::widgets::BorderData &window_button_dborder=gorgon::widgets::BorderData::CreateImageChainFrom(path+"/Window/button-down.png");
	window_button_dborder.Padding=0;
	window_button_dborder.BorderWidth=0;
	window_button_dborder.AutoBorderWidth=false;
	window_button_down.Border=&window_button_dborder;
	window_button_down.Subitems.Add(window_button_dborder);

	gorgon::widgets::Placeholder &window_button_place=*new gorgon::widgets::Placeholder;
	window_dimensions>>window_button_place.Margins.Left>>window_button_place.Margins.Top>>window_button_place.Margins.Right>>window_button_place.Margins.Bottom;
	window_button_place.SizingMode=window_button_place.Free;
	window_button_place.Align=Alignment::Bottom_Right;
	window.TitleButtonPlace=&window_button_place;
	window.Subitems.Add(window_button_place);


	gorgon::widgets::Tabpanel &tab=*new gorgon::widgets::Tabpanel;
	tab.Radio=&tabbtn;
	panelsfolder.Add(tab);
	wr.Panels.Tabpanel=&tab;

	tab.Subitems.Add(dynamic_cast<gorgon::Base*>(tab.Placeholder));
	tab.Placeholder->Align=Alignment::Top_Left;
	tabbtn_dimensions>>tab.Placeholder->Margins.Left>>tab.Placeholder->Margins.Top>>tab.Placeholder->Margins.Right>>tab.Placeholder->Margins.Bottom;

	gorgon::widgets::Panel &tab_pnl=*new gorgon::widgets::Panel;
	tab_pnl.Scroller=&scroll;
	tab.Panel=&tab_pnl;
	tab.Subitems.Add(tab_pnl);

	gorgon::widgets::PanelElement &tab_pnl_element=*new gorgon::widgets::PanelElement;
	tab_pnl.Normal=&tab_pnl_element;
	tab_pnl.Subitems.Add(tab_pnl_element);

	gorgon::widgets::BorderData &tab_pnl_border=*new gorgon::widgets::BorderData;
	tab_pnl_border.Padding.Top=0;
	tab_pnl_element.OuterBorder=&tab_pnl_border;
	tab_pnl_element.Subitems.Add(tab_pnl_border);


	gorgon::widgets::Panel &fullscr=*new gorgon::widgets::Panel;
	fullscr.SetCaption("Fullscreen");
	panelsfolder.Add(fullscr);
	wr.Panels.Fullscreen=&fullscr;

	gorgon::widgets::PanelElement &fullscr_element=*new gorgon::widgets::PanelElement;
	fullscr.Normal=&fullscr_element;
	fullscr.Subitems.Add(fullscr_element);

	gorgon::widgets::BorderData &fullscr_border=gorgon::widgets::BorderData::CreateImageChainFrom(path+"/Panel/normal-c.png");
	fullscr_element.OuterBorder=&fullscr_border;
	dynamic_cast<gorgon::widgets::ResizableObject&>(fullscr_border.GetProvider()).SizeController=graphics::SizeController2D::TileFit;
	fullscr_element.Subitems.Add(fullscr_border);
	fullscr_border.AutoBorderWidth=false;
	fullscr_border.Padding=0;




	//*** Progressbars
	gorgon::Folder &progresssfolder=*new gorgon::Folder;
	progresssfolder.SetCaption("Progressbars");
	file.Root().Add(progresssfolder);

	std::ifstream progress_dimensions(path+"/Progressbar/Dimensions.txt");
	gorgon::widgets::Slider &progress=*new gorgon::widgets::Slider;
	progress_dimensions>>progress.DefaultSize.Width>>progress.DefaultSize.Height;
	progress.SetCaption("Progress");
	progresssfolder.Add(progress);
	wr.Progressbars.Progressbar=&progress;

	gorgon::widgets::SliderGroup &progress_g_hor=*new gorgon::widgets::SliderGroup;
	progress_g_hor.Orientation=progress.Horizontal;
	progress.Mapping[progress_g_hor]=&progress_g_hor;
	progress.Subitems.Add(progress_g_hor);

	gorgon::widgets::SliderElement &progress_hor=*new gorgon::widgets::SliderElement;
	progress_g_hor.Normal=&progress_hor;
	progress_g_hor.Subitems.Add(progress_hor);

	gorgon::widgets::BorderData &progress_hor_ruler=gorgon::widgets::BorderData::CreateLineChainFrom(path+"/Progressbar/rule");
	progress_hor_ruler.Margins=utils::Margins(2, 0);
	progress_hor.Ruler=&progress_hor_ruler;
	progress_hor.Subitems.Add(progress_hor_ruler);

	gorgon::widgets::BorderData &progress_hor_overlay=gorgon::widgets::BorderData::CreateLineChainFrom(path+"/Progressbar/overlay");
	progress_hor.Overlay=&progress_hor_overlay;
	progress_hor.Subitems.Add(progress_hor_overlay);

	gorgon::widgets::BorderData &progress_hor_indicator=gorgon::widgets::BorderData::CreateLineChainFrom(path+"/Progressbar/indicator");
	progress_hor.Indicator=&progress_hor_indicator;
	progress_hor.Subitems.Add(progress_hor_indicator);








	//*** Listbox
	gorgon::Folder &listboxsfolder=*new gorgon::Folder;
	listboxsfolder.SetCaption("Listboxes");
	file.Root().Add(listboxsfolder);

	std::ifstream list_dimensions(path+"/Listbox/Dimensions.txt");
	gorgon::widgets::Listbox &list=*new gorgon::widgets::Listbox;
	list_dimensions>>list.DefaultSize.Width>>list.DefaultSize.Height;
	list.SetCaption("Listbox");
	listboxsfolder.Add(list);
	wr.Listboxes.Listbox=&list;

	utils::Margins list_borderwidth;
	list_dimensions>>list_borderwidth.Left>>list_borderwidth.Top>>list_borderwidth.Right>>list_borderwidth.Bottom;

	gorgon::widgets::Panel &list_pnl=*new gorgon::widgets::Panel;
	list.Panel=&list_pnl;
	list.Subitems.Add(list_pnl);

	gorgon::widgets::PanelElement &list_pnl_element=*new gorgon::widgets::PanelElement;
	list_pnl.Normal=&list_pnl_element;
	list_pnl.Subitems.Add(list_pnl_element);
	list_pnl.Scroller=&scroll;

	gorgon::widgets::BorderData &list_pnl_border=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Listbox/listbox");
	list_pnl_border.BorderWidth=list_borderwidth;
	list_pnl_element.OuterBorder=&list_pnl_border;
	list_pnl_element.Subitems.Add(list_pnl_border);

	gorgon::widgets::Checkbox &list_item=*new gorgon::widgets::Checkbox;
	list_item.States=list_item.Dual;
	list_item.SetCaption("Item");
	list_item.DefaultSize=utils::Size(100,20);
	list.Subitems.Add(list_item);
	list.Item=&list_item;

	gorgon::widgets::CheckboxGroup &list_item_gnormal=*new gorgon::widgets::CheckboxGroup;
	list_item.Mapping[list_item_gnormal]=&list_item_gnormal;
	list_item.Subitems.Add(list_item_gnormal);

	gorgon::widgets::CheckboxElement &list_item_normal=*new gorgon::widgets::CheckboxElement;
	list_item_normal.Font=new Font(wr.Fonts.Normal);
	list_dimensions>>list_item_normal.Font->Color;
	list_item_gnormal.Normal=&list_item_normal;
	list_item_gnormal.Subitems.Add(list_item_normal);

	gorgon::widgets::BorderData &list_item_normal_border=*new gorgon::widgets::BorderData;
	list_item_normal_border.Padding=1;
	list_item_normal.Border=&list_item_normal_border;
	list_item_normal.Subitems.Add(list_item_normal_border);

	gorgon::widgets::CheckboxLine &list_item_line=*new gorgon::widgets::CheckboxLine;
	list_item_line.Contents.First=list_item.Icon;
	list_item_line.Contents.Second=list_item.Text;
	list_item_line.Height=25;
	list_item_normal.Lines[0]=&list_item_line;
	list_item_normal.Subitems.Add(list_item_line);


	gorgon::widgets::CheckboxGroup &list_item_gselected=*new gorgon::widgets::CheckboxGroup;
	list_item_gselected.State.from=2;
	list_item.Mapping[list_item_gselected]=&list_item_gselected;
	list_item.Subitems.Add(list_item_gselected);

	gorgon::widgets::CheckboxElement &list_item_selected=*new gorgon::widgets::CheckboxElement;
	list_item_selected.Font=new Font(wr.Fonts.Normal);
	list_item_gselected.Normal=&list_item_selected;
	list_item_gselected.Subitems.Add(list_item_selected);

	gorgon::widgets::BorderData &list_item_selected_border=gorgon::widgets::BorderData::CreateImageChainFrom(path+"/Listbox/selected.png");
	list_item_selected_border.Padding=1;
	list_item_selected.Border=&list_item_selected_border;
	list_item_selected.Subitems.Add(list_item_selected_border);



	//*** Combobox
	std::ifstream combo_dimensions(path+"/Combobox/Dimensions.txt");
	gorgon::widgets::Combobox &combo=*new gorgon::widgets::Combobox;
	combo_dimensions>>combo.DefaultSize.Width>>combo.DefaultSize.Height;
	combo.SetCaption("Combobox");
	listboxsfolder.Add(combo);
	wr.Others.Combobox=&combo;

	gorgon::widgets::Textbox &combo_textbox=*new gorgon::widgets::Textbox;
	combo_textbox.SetCaption("Combo textbox");
	combo.Textbox=&combo_textbox;
	textboxsfolder.Add(combo_textbox);

	utils::Margins combo_textbox_borderwidth;
	combo_dimensions>>combo_textbox_borderwidth.Left>>combo_textbox_borderwidth.Top>>combo_textbox_borderwidth.Right>>combo_textbox_borderwidth.Bottom;

	utils::Margins combo_textbox_margins;
	combo_dimensions>>combo_textbox_margins.Left>>combo_textbox_margins.Top>>combo_textbox_margins.Right>>combo_textbox_margins.Bottom;

	gorgon::widgets::TextboxElement &combo_textbox_normal=*new gorgon::widgets::TextboxElement;
	combo_textbox_normal.Font=new Font(wr.Fonts.Normal);
	combo_dimensions>>combo_textbox_normal.Font->Color;
	combo_textbox_normal.SelectedFont=new Font(wr.Fonts.Normal);
	combo_textbox.Normal=&combo_textbox_normal;
	combo_textbox.Subitems.Add(combo_textbox_normal);

	gorgon::widgets::BorderData &combo_textbox_normal_border=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Combobox/textnormal");
	combo_textbox_normal_border.BorderWidth=combo_textbox_borderwidth;
	combo_textbox_normal_border.Margins=combo_textbox_margins;
	combo_textbox_normal.OuterBorder=&combo_textbox_normal_border;
	combo_textbox_normal.Subitems.Add(combo_textbox_normal_border);

	gorgon::Animation &combo_textbox_caret=*new gorgon::Animation;
	gorgon::Image &combo_textbox_caret1=*new gorgon::Image;
	combo_textbox_caret1.ImportPNG(path+"/Textbox/caret-1.png");
	combo_textbox_caret.Add(combo_textbox_caret1, 200);
	gorgon::Image &combo_textbox_caret2=*new gorgon::Image;
	combo_textbox_caret2.ImportPNG(path+"/Textbox/caret-2.png");
	combo_textbox_caret.Add(combo_textbox_caret2, 500);
	combo_textbox.Caret=&combo_textbox_caret;
	combo_textbox.Subitems.Add(combo_textbox_caret);

	combo_textbox.Selection=textbox.Selection;


	gorgon::widgets::Checkbox &combo_dropbtn=*new gorgon::widgets::Checkbox;
	combo_dropbtn.SetCaption("Drop button");
	combo_dimensions>>combo_dropbtn.DefaultSize.Width>>combo_dropbtn.DefaultSize.Height;
	checkboxsfolder.Add(combo_dropbtn);
	combo.Dropbutton=&combo_dropbtn;

	gorgon::widgets::CheckboxGroup &combo_dropbtn_empty=*new gorgon::widgets::CheckboxGroup;
	combo_dropbtn.Mapping[combo_dropbtn_empty]=&combo_dropbtn_empty;
	combo_dropbtn.Subitems.Add(combo_dropbtn_empty);

	gorgon::widgets::CheckboxElement &combo_dropbtn_empty_normal=*new gorgon::widgets::CheckboxElement;
	combo_dropbtn_empty_normal.Font=&wr.Fonts.Normal;
	combo_dropbtn_empty.Normal=&combo_dropbtn_empty_normal;
	combo_dropbtn_empty.Subitems.Add(combo_dropbtn_empty_normal);

	gorgon::widgets::BorderData &combo_dropbtn_empty_border=gorgon::widgets::BorderData::CreateImageChainFrom(path+"/Combobox/dropbtn-normal.png");
	combo_dropbtn_empty_normal.Border=&combo_dropbtn_empty_border;
	combo_dropbtn_empty_normal.Subitems.Add(combo_dropbtn_empty_border);

	gorgon::widgets::CheckboxGroup &combo_dropbtn_checked=*new gorgon::widgets::CheckboxGroup;
	combo_dropbtn_checked.State.from=2;
	combo_dropbtn.Mapping[combo_dropbtn_checked]=&combo_dropbtn_checked;
	combo_dropbtn.Subitems.Add(combo_dropbtn_checked);

	gorgon::widgets::CheckboxElement &combo_dropbtn_checked_normal=*new gorgon::widgets::CheckboxElement;
	combo_dropbtn_checked_normal.Font=&wr.Fonts.Normal;
	combo_dropbtn_checked.Normal=&combo_dropbtn_checked_normal;
	combo_dropbtn_checked.Subitems.Add(combo_dropbtn_checked_normal);

	gorgon::widgets::BorderData &combo_dropbtn_checked_border=gorgon::widgets::BorderData::CreateImageChainFrom(path+"/Combobox/dropbtn-down.png");
	combo_dropbtn_checked_normal.Border=&combo_dropbtn_checked_border;
	combo_dropbtn_checked_normal.Subitems.Add(combo_dropbtn_checked_border);


	combo.Listbox=&list;






	//*** Borders
	gorgon::Folder &bordersfolder=*new gorgon::Folder;
	bordersfolder.SetCaption("Borders");
	file.Root().Add(bordersfolder);

	gorgon::widgets::BorderData &selection=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Borders/selection");
	selection.SetCaption("Selection");
	selection.Padding=0;
	selection.AutoBorderWidth=false;
	selection.BorderWidth=0;
	bordersfolder.Add(selection);
	wr.Borders.Selection=&selection;


	gorgon::widgets::BorderData &focus=gorgon::widgets::BorderData::CreateRectangleChainFrom(path+"/Borders/focus");
	focus.SetCaption("Focus");
	focus.Padding=1;
	focus.AutoBorderWidth=false;
	focus.BorderWidth=1;
	bordersfolder.Add(focus);
	wr.Borders.Focus=&focus;




	//*** Collection stuff
	os::filesystem::DirectoryIterator iconsdir(path+"/Icons");
	for(;iconsdir.IsValid();iconsdir.Next()) {
		if(os::filesystem::IsFileExists(path + "/Icons/" + *iconsdir)) {
			gorgon::Image &icon=*new gorgon::Image;
			icon.ImportPNG(path + "/Icons/" + *iconsdir);
			wr.AddIcon(iconsdir->substr(0,iconsdir->length()-4), icon);
		}
	}
	os::filesystem::DirectoryIterator picturesdir(path+"/Pictures");
	for(;picturesdir.IsValid();picturesdir.Next()) {
		if(os::filesystem::IsFileExists(path + "/Pictures/" + *picturesdir)) {
			gorgon::Image &picture=*new gorgon::Image;
			picture.ImportPNG(path + "/Pictures/" + *picturesdir);
			wr.AddPicture(picturesdir->substr(0,picturesdir->length()-4), picture);
		}
	}

	file.SaveFile(path + "/ui.wgt");
	file.SaveFile("ui.wgt");

	resource::File &loader=*new resource::File;
	widgets::RegisterLoaders(loader);
	loader.LoadFile(path + "/ui.wgt");
	//loader.Prepare();

	widgets::dialog::ShowMessage("The path "+path+" is imported successfully", "Import").SetIcon("success");
}

int Application(std::vector<std::string> &args) {
	gge::os::IconHandle icon=0;
	gge::resource::Image iconimage;
	if(iconimage.ImportPNG("cup.png")==gge::resource::Image::NoError)
		icon=gge::os::IconFromImage(iconimage);

	//gge::Main.Setup("uiimport", 450,400);
	//gge::Main.InitializeAll("UI Importer", icon);

	widgets::InitializeApplication("uiimport", "UI Importer", 600, 400, icon);

	widgets::WidgetLayer filedrop;
	Main.Add(filedrop);

	filedrop.MouseCallback.SetLambda([&](input::mouse::Event::Type event, utils::Point location) -> bool {
		using namespace gge::input::mouse;
		if(event==Event::DragOver || event==Event::DragMove) {
			if(GetDraggedObject().TypeID()==FileListDragData::type) {
				return true;
			}
		}
		else if(event==Event::DragDrop) {
			if(GetDraggedObject().TypeID()==FileListDragData::type) {
				auto &data=dynamic_cast<FileListDragData&>(GetDraggedObject());
				for(auto it=data.data.begin();it!=data.data.end();++it) {
					if(gge::os::filesystem::IsDirectoryExists(*it)) {
						import(*it);
					}
				}

				return true;
			}
		}

		return false;
	}, input::mouse::Event::AllButOverCheck);

	widgets::Window wind;


	widgets::LinearOrganizer organizer;
	wind.SetOrganizer(organizer);
	wind.Title="This is a window";

	widgets::Button btn;
	btn.Text="Button";

	widgets::Button btn2;
	btn2.Text="Dis";
	btn2.Disable();

	widgets::Label help;
	help.Text="Drop a folder to begin import.\nRestart to see the result.";

	widgets::Checkbox checkthis;
	checkthis.Text="Is this GUI cool?";
	checkthis.Check();

	widgets::RadioGroup<int> options;
	widgets::RadioButton<int> option1("First option");
	widgets::RadioButton<int> option2("Second option");
	options.Add(option1);
	options.Add(option2);
	option2.Check();

	widgets::Textbox txt;
	txt.Text="This is a textbox";

	widgets::Combobox<std::string> dlist;
	os::filesystem::DirectoryIterator dir2(".");
	utils::AddCopy(dlist, dir2);
	dlist.Sort();

	auto nl=organizer.nextline;

	organizer
		<<"Drag meee."<<nl
		<<checkthis<<nl
		<<options
		<<"Text: "<<txt<<nl
		<<"Files: "<<dlist<<nl
		<<"Yees there is a bug."<<nl
		<<btn<<btn2<<nl
	;

	widgets::Panel pnl;
	pnl.Move(320,0);
	pnl.Resize(280, 300);
	pnl.SetContainer(widgets::TopLevel);
	pnl.Padding=0;

	widgets::Tabpanel tpnl;
	tpnl.SetContainer(pnl);
	tpnl.FillContainer();
	tpnl.Add("Test 1");
	tpnl.Add("Test 2");

	widgets::LinearOrganizer organizer2;
	tpnl("Test 1").SetOrganizer(organizer2);

	widgets::Listbox<> dlist2;
	os::filesystem::DirectoryIterator dir(".");
	utils::AddCopy(dlist2, dir);
	dlist2.Sort();

	widgets::Progressbar<int> progress;
	progress=50;

	widgets::Slider<int> sld;
	sld=50;

	organizer2
		<<help<<nl
		<<progress<<nl
		<<sld<<nl
		<<dlist2<<nl
	;

	organizer2.Reorganize();

	gge::Main.Run();

	wind.RemoveOrganizer();
	tpnl("Test 1").RemoveOrganizer();

	return 0;
}
