using System;
using System.Threading;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace WorldOfPeacecraft
{
	public class SplashScreen : Form 
	{
		private string ImagesFolder = "textures/";
		private Image Logo;
		//private Music m = new Music();
		private Gui gui;
		private IBackend backend;

		public delegate void GuiHasLoadedEventHandler (SplashScreen screen, Gui gui);
		public event GuiHasLoadedEventHandler GuiHasLoaded;

		public SplashScreen (Gui gui, IBackend backend)
		{
			this.gui = gui;
			gui.MainForm = this;
			this.backend = backend;
			Thread t = new Thread (ThreadEntry);
			t.Start ();
			this.SetClientSizeCore (450, 150);
			this.FormBorderStyle = FormBorderStyle.None;
			this.CenterToScreen ();
			Logo = Image.FromFile (ImagesFolder + "splashscreen.png");
			//m.Playmusic ("splashscreen");
		}

		protected override void OnPaint (PaintEventArgs e)
		{
			Graphics g = e.Graphics;
			g.InterpolationMode = InterpolationMode.NearestNeighbor;
			g.DrawImage (Logo, 0, 0, 450, 150);
		}

		private void ThreadEntry(){
			Thread.Sleep(250);
			gui.LoadResources ();
			backend.Initialize ();
			if (GuiHasLoaded != null)
				GuiHasLoaded (this,gui);
		}
	}
}

