From 2715d87179e1452a524f9820b9d3efe675060d5c Mon Sep 17 00:00:00 2001 From: Souryo Date: Sat, 6 Feb 2016 18:44:52 -0500 Subject: [PATCH] UI: Hide mouse cursor after 3 seconds if user doesn't move mouse --- GUI.NET/Controls/ctrlRenderer.Designer.cs | 10 +++++++++ GUI.NET/Controls/ctrlRenderer.cs | 25 +++++++++++++++++++++++ GUI.NET/Controls/ctrlRenderer.resx | 3 +++ 3 files changed, 38 insertions(+) diff --git a/GUI.NET/Controls/ctrlRenderer.Designer.cs b/GUI.NET/Controls/ctrlRenderer.Designer.cs index e5ec44ca..29d5718a 100644 --- a/GUI.NET/Controls/ctrlRenderer.Designer.cs +++ b/GUI.NET/Controls/ctrlRenderer.Designer.cs @@ -27,14 +27,22 @@ /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); + this.tmrMouse = new System.Windows.Forms.Timer(this.components); this.SuspendLayout(); // + // tmrMouse + // + this.tmrMouse.Interval = 3000; + this.tmrMouse.Tick += new System.EventHandler(this.tmrMouse_Tick); + // // ctrlRenderer // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Name = "ctrlRenderer"; this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ctrlRenderer_MouseDown); + this.MouseLeave += new System.EventHandler(this.ctrlRenderer_MouseLeave); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ctrlRenderer_MouseMove); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ctrlRenderer_MouseUp); this.ResumeLayout(false); @@ -42,5 +50,7 @@ } #endregion + + private System.Windows.Forms.Timer tmrMouse; } } diff --git a/GUI.NET/Controls/ctrlRenderer.cs b/GUI.NET/Controls/ctrlRenderer.cs index 18b75e66..4864832a 100644 --- a/GUI.NET/Controls/ctrlRenderer.cs +++ b/GUI.NET/Controls/ctrlRenderer.cs @@ -14,6 +14,7 @@ namespace Mesen.GUI.Controls public partial class ctrlRenderer : UserControl { private bool _rightButtonDown = false; + private bool _cursorHidden = false; public ctrlRenderer() { @@ -32,10 +33,19 @@ namespace Mesen.GUI.Controls private void ctrlRenderer_MouseMove(object sender, MouseEventArgs e) { + if(_cursorHidden) { + Cursor.Show(); + _cursorHidden = false; + } + tmrMouse.Stop(); + if(InteropEmu.HasZapper()) { this.Cursor = Cursors.Cross; } else { this.Cursor = Cursors.Default; + + //Only hide mouse if no zapper (otherwise this could be pretty annoying) + tmrMouse.Start(); } if(_rightButtonDown) { @@ -58,5 +68,20 @@ namespace Mesen.GUI.Controls _rightButtonDown = false; } } + + private void tmrMouse_Tick(object sender, EventArgs e) + { + _cursorHidden = true; + Cursor.Hide(); + } + + private void ctrlRenderer_MouseLeave(object sender, EventArgs e) + { + tmrMouse.Stop(); + if(_cursorHidden) { + _cursorHidden = false; + Cursor.Show(); + } + } } } diff --git a/GUI.NET/Controls/ctrlRenderer.resx b/GUI.NET/Controls/ctrlRenderer.resx index 1af7de15..765789c8 100644 --- a/GUI.NET/Controls/ctrlRenderer.resx +++ b/GUI.NET/Controls/ctrlRenderer.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file