From 4f98329f3309ba3f646ab062ae334ecb5c6f992d Mon Sep 17 00:00:00 2001 From: Sour Date: Thu, 24 Oct 2019 18:09:35 -0400 Subject: [PATCH] UI: Allow recent game selection screen to display 4 or 9 titles based on window size --- UI/Controls/ctrlRecentGame.Designer.cs | 119 ++++++++++++++ UI/Controls/ctrlRecentGame.cs | 77 ++++++++++ UI/Controls/ctrlRecentGame.resx | 120 +++++++++++++++ UI/Controls/ctrlRecentGames.Designer.cs | 88 ++++------- UI/Controls/ctrlRecentGames.cs | 196 +++++++++++++++--------- UI/Forms/frmMain.cs | 2 +- UI/UI.csproj | 9 ++ 7 files changed, 477 insertions(+), 134 deletions(-) create mode 100644 UI/Controls/ctrlRecentGame.Designer.cs create mode 100644 UI/Controls/ctrlRecentGame.cs create mode 100644 UI/Controls/ctrlRecentGame.resx diff --git a/UI/Controls/ctrlRecentGame.Designer.cs b/UI/Controls/ctrlRecentGame.Designer.cs new file mode 100644 index 0000000..7076468 --- /dev/null +++ b/UI/Controls/ctrlRecentGame.Designer.cs @@ -0,0 +1,119 @@ +namespace Mesen.GUI.Controls +{ + partial class ctrlRecentGame + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if(disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.lblGameName = new System.Windows.Forms.Label(); + this.lblSaveDate = new System.Windows.Forms.Label(); + this.picPreviousState = new Mesen.GUI.Controls.GamePreviewBox(); + this.tableLayoutPanel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.picPreviousState)).BeginInit(); + this.SuspendLayout(); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 1; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.Controls.Add(this.picPreviousState, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.lblGameName, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.lblSaveDate, 0, 2); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 3; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.Size = new System.Drawing.Size(158, 93); + this.tableLayoutPanel1.TabIndex = 0; + // + // lblGameName + // + this.lblGameName.AutoEllipsis = true; + this.lblGameName.BackColor = System.Drawing.Color.Transparent; + this.lblGameName.Dock = System.Windows.Forms.DockStyle.Fill; + this.lblGameName.ForeColor = System.Drawing.Color.White; + this.lblGameName.Location = new System.Drawing.Point(3, 64); + this.lblGameName.Name = "lblGameName"; + this.lblGameName.Size = new System.Drawing.Size(152, 16); + this.lblGameName.TabIndex = 12; + this.lblGameName.Text = "Game Name"; + this.lblGameName.TextAlign = System.Drawing.ContentAlignment.TopCenter; + // + // lblSaveDate + // + this.lblSaveDate.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.lblSaveDate.AutoSize = true; + this.lblSaveDate.BackColor = System.Drawing.Color.Transparent; + this.lblSaveDate.ForeColor = System.Drawing.Color.White; + this.lblSaveDate.Location = new System.Drawing.Point(64, 80); + this.lblSaveDate.Name = "lblSaveDate"; + this.lblSaveDate.Size = new System.Drawing.Size(30, 13); + this.lblSaveDate.TabIndex = 13; + this.lblSaveDate.Text = "Date"; + // + // picPreviousState + // + this.picPreviousState.BackColor = System.Drawing.Color.Black; + this.picPreviousState.Cursor = System.Windows.Forms.Cursors.Hand; + this.picPreviousState.Dock = System.Windows.Forms.DockStyle.Fill; + this.picPreviousState.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; + this.picPreviousState.Location = new System.Drawing.Point(0, 0); + this.picPreviousState.Margin = new System.Windows.Forms.Padding(0); + this.picPreviousState.Name = "picPreviousState"; + this.picPreviousState.Size = new System.Drawing.Size(158, 64); + this.picPreviousState.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.picPreviousState.TabIndex = 11; + this.picPreviousState.TabStop = false; + this.picPreviousState.Visible = false; + this.picPreviousState.Click += new System.EventHandler(this.picPreviousState_Click); + // + // ctrlRecentGame + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Black; + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "ctrlRecentGame"; + this.Size = new System.Drawing.Size(158, 93); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.picPreviousState)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private GamePreviewBox picPreviousState; + private System.Windows.Forms.Label lblGameName; + private System.Windows.Forms.Label lblSaveDate; + } +} diff --git a/UI/Controls/ctrlRecentGame.cs b/UI/Controls/ctrlRecentGame.cs new file mode 100644 index 0000000..50fc42d --- /dev/null +++ b/UI/Controls/ctrlRecentGame.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.IO; +using System.IO.Compression; +using Mesen.GUI.Emulation; + +namespace Mesen.GUI.Controls +{ + public partial class ctrlRecentGame : UserControl + { + private RecentGameInfo _recentGame; + + public ctrlRecentGame() + { + InitializeComponent(); + } + + public RecentGameInfo RecentGame + { + get { return _recentGame; } + set + { + if(_recentGame == value) { + return; + } + + _recentGame = value; + + lblSaveDate.Visible = false; + + if(value == null) { + picPreviousState.Visible = false; + lblGameName.Visible = false; + return; + } + + lblGameName.Text = Path.GetFileNameWithoutExtension(_recentGame.RomName); + lblSaveDate.Text = _recentGame.Timestamp.ToString(); + + try { + ZipArchive zip = new ZipArchive(new MemoryStream(File.ReadAllBytes(_recentGame.FileName))); + ZipArchiveEntry entry = zip.GetEntry("Screenshot.png"); + if(entry != null) { + using(Stream stream = entry.Open()) { + picPreviousState.Image = Image.FromStream(stream); + } + } else { + picPreviousState.Image = null; + } + } catch { + picPreviousState.Image = null; + } + + lblGameName.Visible = true; + lblSaveDate.Visible = true; + picPreviousState.Visible = true; + } + } + + public bool Highlight + { + set { picPreviousState.Highlight = value; } + } + + private void picPreviousState_Click(object sender, EventArgs e) + { + EmuRunner.LoadRecentGame(_recentGame.FileName); + } + } +} diff --git a/UI/Controls/ctrlRecentGame.resx b/UI/Controls/ctrlRecentGame.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/UI/Controls/ctrlRecentGame.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/UI/Controls/ctrlRecentGames.Designer.cs b/UI/Controls/ctrlRecentGames.Designer.cs index 719f1b6..9a75819 100644 --- a/UI/Controls/ctrlRecentGames.Designer.cs +++ b/UI/Controls/ctrlRecentGames.Designer.cs @@ -29,14 +29,11 @@ { this.components = new System.ComponentModel.Container(); this.tlpPreviousState = new Mesen.GUI.Controls.DBTableLayoutPanel(); - this.picPreviousState = new Mesen.GUI.Controls.GamePreviewBox(); - this.lblGameName = new System.Windows.Forms.Label(); - this.lblSaveDate = new System.Windows.Forms.Label(); this.picNextGame = new System.Windows.Forms.PictureBox(); this.picPrevGame = new System.Windows.Forms.PictureBox(); this.tmrInput = new System.Windows.Forms.Timer(this.components); + this.tlpGrid = new DBTableLayoutPanel(); this.tlpPreviousState.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.picPreviousState)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.picNextGame)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.picPrevGame)).BeginInit(); this.SuspendLayout(); @@ -48,65 +45,21 @@ this.tlpPreviousState.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tlpPreviousState.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tlpPreviousState.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); - this.tlpPreviousState.Controls.Add(this.picPreviousState, 1, 1); - this.tlpPreviousState.Controls.Add(this.lblGameName, 1, 2); - this.tlpPreviousState.Controls.Add(this.lblSaveDate, 1, 3); + this.tlpPreviousState.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tlpPreviousState.Controls.Add(this.picNextGame, 2, 1); this.tlpPreviousState.Controls.Add(this.picPrevGame, 0, 1); + this.tlpPreviousState.Controls.Add(this.tlpGrid, 1, 1); this.tlpPreviousState.Dock = System.Windows.Forms.DockStyle.Fill; this.tlpPreviousState.Location = new System.Drawing.Point(0, 0); this.tlpPreviousState.Name = "tlpPreviousState"; - this.tlpPreviousState.RowCount = 6; + this.tlpPreviousState.RowCount = 3; this.tlpPreviousState.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 10F)); - this.tlpPreviousState.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tlpPreviousState.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tlpPreviousState.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tlpPreviousState.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 5F)); this.tlpPreviousState.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tlpPreviousState.Size = new System.Drawing.Size(272, 107); + this.tlpPreviousState.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tlpPreviousState.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tlpPreviousState.Size = new System.Drawing.Size(272, 236); this.tlpPreviousState.TabIndex = 9; // - // picPreviousState - // - this.picPreviousState.Anchor = System.Windows.Forms.AnchorStyles.Top; - this.picPreviousState.BackColor = System.Drawing.Color.Black; - this.picPreviousState.Cursor = System.Windows.Forms.Cursors.Hand; - this.picPreviousState.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; - this.picPreviousState.Location = new System.Drawing.Point(115, 10); - this.picPreviousState.Margin = new System.Windows.Forms.Padding(0); - this.picPreviousState.Name = "picPreviousState"; - this.picPreviousState.Size = new System.Drawing.Size(42, 42); - this.picPreviousState.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.picPreviousState.TabIndex = 7; - this.picPreviousState.TabStop = false; - this.picPreviousState.Visible = false; - this.picPreviousState.Click += new System.EventHandler(this.picPreviousState_Click); - // - // lblGameName - // - this.lblGameName.AutoEllipsis = true; - this.lblGameName.BackColor = System.Drawing.Color.Transparent; - this.lblGameName.Dock = System.Windows.Forms.DockStyle.Fill; - this.lblGameName.ForeColor = System.Drawing.Color.White; - this.lblGameName.Location = new System.Drawing.Point(36, 62); - this.lblGameName.Name = "lblGameName"; - this.lblGameName.Size = new System.Drawing.Size(200, 16); - this.lblGameName.TabIndex = 9; - this.lblGameName.Text = "Game Name"; - this.lblGameName.TextAlign = System.Drawing.ContentAlignment.TopCenter; - // - // lblSaveDate - // - this.lblSaveDate.Anchor = System.Windows.Forms.AnchorStyles.Top; - this.lblSaveDate.AutoSize = true; - this.lblSaveDate.BackColor = System.Drawing.Color.Transparent; - this.lblSaveDate.ForeColor = System.Drawing.Color.White; - this.lblSaveDate.Location = new System.Drawing.Point(121, 78); - this.lblSaveDate.Name = "lblSaveDate"; - this.lblSaveDate.Size = new System.Drawing.Size(30, 13); - this.lblSaveDate.TabIndex = 10; - this.lblSaveDate.Text = "Date"; - // // picNextGame // this.picNextGame.Cursor = System.Windows.Forms.Cursors.Hand; @@ -114,7 +67,7 @@ this.picNextGame.Image = global::Mesen.GUI.Properties.Resources.MediaPlay; this.picNextGame.Location = new System.Drawing.Point(242, 13); this.picNextGame.Name = "picNextGame"; - this.picNextGame.Size = new System.Drawing.Size(27, 46); + this.picNextGame.Size = new System.Drawing.Size(27, 200); this.picNextGame.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; this.picNextGame.TabIndex = 11; this.picNextGame.TabStop = false; @@ -127,7 +80,7 @@ this.picPrevGame.Image = global::Mesen.GUI.Properties.Resources.MediaPlay; this.picPrevGame.Location = new System.Drawing.Point(3, 13); this.picPrevGame.Name = "picPrevGame"; - this.picPrevGame.Size = new System.Drawing.Size(27, 46); + this.picPrevGame.Size = new System.Drawing.Size(27, 200); this.picPrevGame.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; this.picPrevGame.TabIndex = 12; this.picPrevGame.TabStop = false; @@ -138,6 +91,21 @@ this.tmrInput.Interval = 50; this.tmrInput.Tick += new System.EventHandler(this.tmrInput_Tick); // + // tlpGrid + // + this.tlpGrid.ColumnCount = 2; + this.tlpGrid.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tlpGrid.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tlpGrid.Dock = System.Windows.Forms.DockStyle.Fill; + this.tlpGrid.Location = new System.Drawing.Point(33, 10); + this.tlpGrid.Margin = new System.Windows.Forms.Padding(0, 0, 0, 0); + this.tlpGrid.Name = "tlpGrid"; + this.tlpGrid.RowCount = 2; + this.tlpGrid.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tlpGrid.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tlpGrid.Size = new System.Drawing.Size(206, 206); + this.tlpGrid.TabIndex = 13; + // // ctrlRecentGames // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -145,10 +113,8 @@ this.BackColor = System.Drawing.Color.Transparent; this.Controls.Add(this.tlpPreviousState); this.Name = "ctrlRecentGames"; - this.Size = new System.Drawing.Size(272, 107); + this.Size = new System.Drawing.Size(272, 236); this.tlpPreviousState.ResumeLayout(false); - this.tlpPreviousState.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.picPreviousState)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.picNextGame)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.picPrevGame)).EndInit(); this.ResumeLayout(false); @@ -158,11 +124,9 @@ #endregion private DBTableLayoutPanel tlpPreviousState; - private GamePreviewBox picPreviousState; - private System.Windows.Forms.Label lblGameName; - private System.Windows.Forms.Label lblSaveDate; private System.Windows.Forms.PictureBox picNextGame; private System.Windows.Forms.PictureBox picPrevGame; private System.Windows.Forms.Timer tmrInput; + private DBTableLayoutPanel tlpGrid; } } diff --git a/UI/Controls/ctrlRecentGames.cs b/UI/Controls/ctrlRecentGames.cs index 4a3faf0..f1f768a 100644 --- a/UI/Controls/ctrlRecentGames.cs +++ b/UI/Controls/ctrlRecentGames.cs @@ -19,6 +19,9 @@ namespace Mesen.GUI.Controls { public partial class ctrlRecentGames : BaseControl { + private int _elementsPerRow = 0; + private int _elementsPerPage = 0; + public delegate void RecentGameLoadedHandler(RecentGameInfo gameInfo); public new event MouseEventHandler MouseMove @@ -36,7 +39,7 @@ namespace Mesen.GUI.Controls private bool _initialized = false; private int _currentIndex = 0; private List _recentGames = new List(); - private PrivateFontCollection _fonts = new PrivateFontCollection(); + private List _controls = new List(); public ctrlRecentGames() { @@ -47,13 +50,51 @@ namespace Mesen.GUI.Controls DoubleBuffered = true; - _fonts.AddFontFile(Path.Combine(ConfigManager.HomeFolder, "Resources", "PixelFont.ttf")); - lblGameName.Font = new Font(_fonts.Families[0], 10); - lblSaveDate.Font = new Font(_fonts.Families[0], 10); - picPrevGame.Image.RotateFlip(RotateFlipType.RotateNoneFlipX); } + private void InitGrid() + { + int elementsPerRow = 1; + if(ClientSize.Width > 850 && ClientSize.Height > 850) { + elementsPerRow = 3; + } else if(ClientSize.Width > 450 && ClientSize.Height > 450) { + elementsPerRow = 2; + } + + if(_recentGames.Count <= 1) { + elementsPerRow = 1; + } else if(_recentGames.Count <= 4) { + elementsPerRow = Math.Min(2, elementsPerRow); + } + + if(_elementsPerRow == elementsPerRow) { + return; + } + + _elementsPerRow = elementsPerRow; + _elementsPerPage = elementsPerRow * elementsPerRow; + + _controls = new List(); + tlpGrid.ColumnCount = _elementsPerRow; + tlpGrid.RowCount = _elementsPerRow; + tlpGrid.ColumnStyles.Clear(); + tlpGrid.RowStyles.Clear(); + tlpGrid.Controls.Clear(); + for(int j = 0; j < _elementsPerRow; j++) { + tlpGrid.RowStyles.Add(new RowStyle(SizeType.Percent, 100F / _elementsPerRow)); + for(int i = 0; i < _elementsPerRow; i++) { + tlpGrid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F / _elementsPerRow)); + ctrlRecentGame ctrl = new ctrlRecentGame(); + ctrl.Dock = DockStyle.Fill; + ctrl.Margin = new Padding(2); + tlpGrid.Controls.Add(ctrl, i, j); + _controls.Add(ctrl); + } + } + UpdateGameInfo(); + } + public new bool Visible { get { return base.Visible; } @@ -68,7 +109,7 @@ namespace Mesen.GUI.Controls //We just re-enabled the screen, initialize it Initialize(); } - + InitGrid(); base.Visible = value; tmrInput.Enabled = value; } @@ -82,6 +123,8 @@ namespace Mesen.GUI.Controls public void Initialize() { + InitGrid(); + _initialized = true; _recentGames = new List(); _currentIndex = 0; @@ -107,8 +150,8 @@ namespace Mesen.GUI.Controls _recentGames = _recentGames.OrderBy((info) => info.Timestamp).Reverse().ToList(); - if(_recentGames.Count > 5) { - _recentGames.RemoveRange(5, _recentGames.Count - 5); + if(_recentGames.Count > 20) { + _recentGames.RemoveRange(36, _recentGames.Count - 36); } if(_recentGames.Count == 0) { @@ -119,33 +162,19 @@ namespace Mesen.GUI.Controls tmrInput.Enabled = true; } - picPreviousState.Visible = _recentGames.Count > 0; - picPrevGame.Visible = _recentGames.Count > 1; - picNextGame.Visible = _recentGames.Count > 1; + picPrevGame.Visible = true; + picNextGame.Visible = true; } public void UpdateGameInfo() { - if(_currentIndex < _recentGames.Count) { - lblGameName.Text = Path.GetFileNameWithoutExtension(_recentGames[_currentIndex].RomName); - lblSaveDate.Text = _recentGames[_currentIndex].Timestamp.ToString(); + int count = _recentGames.Count; + int pageStart = _currentIndex / _elementsPerPage * _elementsPerPage; - try { - ZipArchive zip = new ZipArchive(new MemoryStream(File.ReadAllBytes(_recentGames[_currentIndex].FileName))); - ZipArchiveEntry entry = zip.GetEntry("Screenshot.png"); - if(entry != null) { - using(Stream stream = entry.Open()) { - picPreviousState.Image = Image.FromStream(stream); - } - } else { - picPreviousState.Image = null; - } - } catch { - picPreviousState.Image = null; - } - UpdateSize(); + for(int i = 0; i < _elementsPerPage; i++) { + _controls[i].RecentGame = count > pageStart + i ? _recentGames[pageStart+i] : null; + _controls[i].Highlight = (_currentIndex % _elementsPerPage) == i; } - picPreviousState.Visible = _recentGames.Count > 0; } float _xFactor = 1; @@ -157,22 +186,6 @@ namespace Mesen.GUI.Controls base.ScaleControl(factor, specified); } - private void UpdateSize() - { - tlpPreviousState.Visible = false; - Size maxSize = new Size(this.Size.Width - (int)(120 * _xFactor), this.Size.Height - (int)(50 * _yFactor)); - - if(picPreviousState.Image != null) { - double xRatio = (double)picPreviousState.Image.Width / maxSize.Width; - double yRatio = (double)picPreviousState.Image.Height / maxSize.Height; - double ratio = Math.Max(xRatio, yRatio); - - Size newSize = new Size((int)(picPreviousState.Image.Width / ratio), (int)(picPreviousState.Image.Height / ratio)); - picPreviousState.Size = newSize; - } - tlpPreviousState.Visible = true; - } - protected override void OnResize(EventArgs e) { if(Program.IsMono) { @@ -183,48 +196,40 @@ namespace Mesen.GUI.Controls picPrevGame.Dock = DockStyle.Fill; } - if(picPreviousState.Image != null) { - UpdateSize(); - } + InitGrid(); base.OnResize(e); } - - private void picPreviousState_Click(object sender, EventArgs e) - { - LoadSelectedGame(); - } private void picNextGame_MouseDown(object sender, MouseEventArgs e) { - GoToNextGame(); + GoToNextPage(); } private void picPrevGame_MouseDown(object sender, MouseEventArgs e) { - GoToPreviousGame(); + GoToPreviousPage(); } - private void GoToPreviousGame() + private void GoToPreviousPage() { - if(_currentIndex == 0) { - _currentIndex = _recentGames.Count - 1; + if(_currentIndex < _elementsPerPage) { + _currentIndex = _recentGames.Count - _elementsPerPage; } else { - _currentIndex--; + _currentIndex -= _elementsPerPage; } UpdateGameInfo(); } - private void GoToNextGame() + private void GoToNextPage() { - _currentIndex = (_currentIndex + 1) % _recentGames.Count; + if(_currentIndex + _elementsPerPage < _recentGames.Count) { + _currentIndex += _elementsPerPage; + } else { + _currentIndex = 0; + } UpdateGameInfo(); } - private void LoadSelectedGame() - { - EmuRunner.LoadRecentGame(_recentGames[_currentIndex].FileName); - } - private bool _waitForRelease = false; private void tmrInput_Tick(object sender, EventArgs e) { @@ -244,13 +249,51 @@ namespace Mesen.GUI.Controls foreach(KeyMapping mapping in mappings) { if(mapping.Left == keyCode) { _waitForRelease = true; - GoToPreviousGame(); + if(_currentIndex == 0) { + _currentIndex = _recentGames.Count - 1; + } else { + _currentIndex--; + } + UpdateGameInfo(); } else if(mapping.Right == keyCode) { _waitForRelease = true; - GoToNextGame(); - } else if(mapping.A == keyCode || mapping.B == keyCode) { + _currentIndex = (_currentIndex + 1) % _recentGames.Count; + UpdateGameInfo(); + } else if(mapping.Down == keyCode) { _waitForRelease = true; - LoadSelectedGame(); + if(_currentIndex + _elementsPerRow < _recentGames.Count) { + _currentIndex += _elementsPerRow; + } else { + _currentIndex = 0; + } + UpdateGameInfo(); + } else if(mapping.Up == keyCode) { + _waitForRelease = true; + if(_currentIndex < _elementsPerRow) { + _currentIndex = _recentGames.Count - _elementsPerRow; + } else { + _currentIndex -= _elementsPerRow; + } + UpdateGameInfo(); + } else if(mapping.L == keyCode) { + _waitForRelease = true; + if(_currentIndex < _elementsPerPage) { + _currentIndex = _recentGames.Count - _elementsPerPage; + } else { + _currentIndex -= _elementsPerPage; + } + UpdateGameInfo(); + } else if(mapping.R == keyCode) { + _waitForRelease = true; + if(_currentIndex + _elementsPerPage < _recentGames.Count) { + _currentIndex += _elementsPerPage; + } else { + _currentIndex = 0; ; + } + UpdateGameInfo(); + } else if(mapping.A == keyCode || mapping.B == keyCode || mapping.X == keyCode || mapping.Y == keyCode || mapping.Select == keyCode || mapping.Start == keyCode) { + _waitForRelease = true; + EmuRunner.LoadRecentGame(_recentGames[_currentIndex].FileName); } } } @@ -273,6 +316,7 @@ namespace Mesen.GUI.Controls { public System.Drawing.Drawing2D.InterpolationMode InterpolationMode { get; set; } private bool _hovered = false; + private bool _highlight = false; public GamePreviewBox() { @@ -280,6 +324,16 @@ namespace Mesen.GUI.Controls InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default; } + public bool Highlight + { + get { return _highlight; } + set + { + _highlight = value; + this.Invalidate(); + } + } + protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); @@ -299,7 +353,7 @@ namespace Mesen.GUI.Controls pe.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; base.OnPaint(pe); - using(Pen pen = new Pen(_hovered ? Color.LightBlue : Color.Gray, 2)) { + using(Pen pen = new Pen(_hovered ? Color.LightBlue : (_highlight ? Color.Orange : Color.Gray), 2)) { pe.Graphics.DrawRectangle(pen, 1, 1, this.Width - 2, this.Height - 2); } } diff --git a/UI/Forms/frmMain.cs b/UI/Forms/frmMain.cs index bec9a1b..4fb4c96 100644 --- a/UI/Forms/frmMain.cs +++ b/UI/Forms/frmMain.cs @@ -432,7 +432,7 @@ namespace Mesen.GUI.Forms private void ResizeRecentGames() { - ctrlRecentGames.Height = this.ClientSize.Height - ctrlRecentGames.Top - 80; + ctrlRecentGames.Height = this.ClientSize.Height - ctrlRecentGames.Top - 5; } private void frmMain_Resize(object sender, EventArgs e) diff --git a/UI/UI.csproj b/UI/UI.csproj index 0f015dd..ca4d220 100644 --- a/UI/UI.csproj +++ b/UI/UI.csproj @@ -230,6 +230,12 @@ Component + + UserControl + + + ctrlRecentGame.cs + UserControl @@ -920,6 +926,9 @@ ctrlPathSelection.cs + + ctrlRecentGame.cs + ctrlRecentGames.cs