using System;

namespace SharpQuake
{
	internal class VideoMenu : MenuBase
	{
		public override void KeyEvent(int key)
		{
			if (key == 27)
			{
				snd.LocalSound("misc/menu1.wav");
				MenuBase.OptionsMenu.Show();
			}
		}

		public override void Draw()
		{
			glpic_t glpic_t = Drawer.CachePic("gfx/vidmodes.lmp");
			menu.DrawPic((320 - glpic_t.width) / 2, 4, glpic_t);
			this._WModes = 0;
			int num = vid.Modes.Length;
			int num2 = 1;
			while (num2 < num && this._WModes < 27)
			{
				mode_t mode_t = vid.Modes[num2];
				int wmodes = this._WModes;
				this._ModeDescs[wmodes].modenum = num2;
				this._ModeDescs[wmodes].desc = string.Format("{0}x{1}x{2}", mode_t.width, mode_t.height, mode_t.bpp);
				this._ModeDescs[wmodes].iscur = false;
				if (num2 == vid.ModeNum)
				{
					this._ModeDescs[wmodes].iscur = true;
				}
				this._WModes++;
				num2++;
			}
			if (this._WModes > 0)
			{
				menu.Print(16, 36, "Fullscreen Modes (WIDTHxHEIGHTxBPP)");
				int num3 = 8;
				int num4 = 52;
				for (int i = 0; i < this._WModes; i++)
				{
					if (this._ModeDescs[i].iscur)
					{
						menu.PrintWhite(num3, num4, this._ModeDescs[i].desc);
					}
					else
					{
						menu.Print(num3, num4, this._ModeDescs[i].desc);
					}
					num3 += 104;
					if (i % 3 == 2)
					{
						num3 = 8;
						num4 += 8;
					}
				}
			}
			menu.Print(24, 140, "Video modes must be set from the");
			menu.Print(24, 148, "command line with -width <width>");
			menu.Print(24, 156, "and -bpp <bits-per-pixel>");
			menu.Print(24, 172, "Select windowed mode with -window");
		}

		private const int MAX_COLUMN_SIZE = 9;

		private const int MODE_AREA_HEIGHT = 11;

		private const int MAX_MODEDESCS = 27;

		private int _WModes;

		private VideoMenu.modedesc_t[] _ModeDescs = new VideoMenu.modedesc_t[27];

		private struct modedesc_t
		{
			public int modenum;

			public string desc;

			public bool iscur;
		}
	}
}
