using System;
using System.Collections.Generic;
using System.Text;
using Vortex.Drawing;
using System.Windows.Forms;
using Vortex.IO;

namespace Vortex {

	/// <summary>
	/// Contains information about game cursor: sprite for rendered cursor mode and system cursor 
	/// </summary>
	public class GameCursor {
		private static GameCursor _blankCursor;
		private static GameCursor _defaultCursor;

		private ISpriteSource _cursorSprite;
		private Cursor _systemCursor;

		/// <summary>
		/// Initializes a new instance of the <see cref="GameCursor"/> class.
		/// This cursor will always show system cursor from parameter
		/// </summary>
		/// <param name="systemCursor">The system cursor reference.</param>
		public GameCursor(Cursor systemCursor) {
			if (null == systemCursor) throw new ArgumentNullException("systemCursor");

			_systemCursor = systemCursor;
			_cursorSprite = null;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="GameCursor"/> class.
		/// This cursor will render sprite from specified source if drawed cursor mode is enabled; otherwise default system cursor will be used.
		/// </summary>
		/// <param name="cursorSprite">The cursor sprite source.</param>
		public GameCursor(ISpriteSource cursorSprite) : this(Cursors.Default, cursorSprite) {			
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="GameCursor"/> class.
		/// This cursor will render sprite from specified source id drawed cursor mode is enabled; otherwise specified system cursor will be shown.
		/// </summary>
		/// <param name="systemCursor">The system cursor.</param>
		/// <param name="cursorSprite">The cursor sprite source.</param>
		public GameCursor(Cursor systemCursor, ISpriteSource cursorSprite) {
			if (null == systemCursor) throw new ArgumentNullException("systemCursor");
			if (null == cursorSprite) throw new ArgumentNullException("cursorSprite");			

			_cursorSprite = cursorSprite;
			_systemCursor = systemCursor;
		}

		/// <summary>
		/// Gets the cursor sprite specified by this game cursor. May be null if custom drawn cursors are not supported.
		/// </summary>
		/// <value>The cursor sprite source.</value>
		public ISpriteSource CursorSprite {
			get { return _cursorSprite; }
		}

		/// <summary>
		/// Gets the system cursor associated with this game cursor. Never is null.
		/// </summary>
		/// <value>The system cursor.</value>
		public Cursor SystemCursor {
			get { return _systemCursor; }
		}

		/// <summary>
		/// Special game cursor which totally hides pointer
		/// </summary>
		public static GameCursor Blank {
			get {
				if (null == _blankCursor) {
					ResourceFileInfo resourceFile = new ResourceFileInfo("Vortex.blank.cur");
					using (System.IO.Stream cursorStream = resourceFile.OpenStream()) {
						Cursor cursor = new Cursor(cursorStream);
						_blankCursor = new GameCursor(cursor);
					}
				}
				return _blankCursor;
			}
		}

		/// <summary>
		/// Default game cursor. It represents system cursor selected by default with system settings
		/// </summary>
		public static GameCursor Default {
			get {
				if (null == _defaultCursor) {
					_defaultCursor = new GameCursor(Cursors.Default);
				}
				return _defaultCursor;
			}
		}
	}

}
