/*!
	@file
	@author		Albert Semenov
	@date		10/2008
	@module
*/
#include "precompiled.h"
#include "DemoKeeper.h"
#include "Base/Main.h"
#include "UnitTest_List.h"
#include "UnitTest_MultiList.h"

namespace demo
{

	unittest::UnitTest_List * unittest_list = 0;
	unittest::UnitTest_MultiList * unittest_multilist = 0;

	void DemoKeeper::setupResources()
	{
		base::BaseManager::setupResources();
		addResourceLocation(getRootMedia() + "/Common/Wallpapers");
	}

	void DemoKeeper::createScene()
	{
        getGUI()->load("Wallpaper0.layout");

		const MyGUI::IntSize & view = MyGUI::Gui::getInstance().getViewSize();
		const MyGUI::IntSize size(100, 100);

		unittest_list = new unittest::UnitTest_List();
		unittest_multilist = new unittest::UnitTest_MultiList();

		getGUI()->eventFrameStart += MyGUI::newDelegate(this, &DemoKeeper::notifyFrameStarted);
	}

	void DemoKeeper::destroyScene()
	{
		getGUI()->eventFrameStart -= MyGUI::newDelegate(this, &DemoKeeper::notifyFrameStarted);

		if (unittest_multilist)
		{
			delete unittest_multilist;
			unittest_multilist = 0;
		}
		if (unittest_list)
		{
			delete unittest_list;
			unittest_list = 0;
		}
	}

	void DemoKeeper::notifyFrameStarted(float _time)
	{
		if (unittest_list) unittest_list->nextFrame();
		if (unittest_multilist) unittest_multilist->nextFrame();

#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
		::Sleep(10);
#endif
	}

} // namespace demo

MYGUI_APP(demo::DemoKeeper)
