UI: Hide mouse no matter where it is inside the window when playing
This commit is contained in:
parent
d05d66507c
commit
fcd09ebdd9
7 changed files with 115 additions and 76 deletions
9
GUI.NET/Controls/ctrlRenderer.Designer.cs
generated
9
GUI.NET/Controls/ctrlRenderer.Designer.cs
generated
|
@ -27,15 +27,8 @@
|
|||
/// </summary>
|
||||
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);
|
||||
|
@ -48,7 +41,5 @@
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Timer tmrMouse;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,34 +17,11 @@ namespace Mesen.GUI.Controls
|
|||
private const int RightMouseButtonKeyCode = 0x201;
|
||||
private const int MiddleMouseButtonKeyCode = 0x202;
|
||||
|
||||
private bool _cursorHidden = false;
|
||||
|
||||
public ctrlRenderer()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public bool NeedMouseIcon
|
||||
{
|
||||
get { return InteropEmu.GetExpansionDevice() == InteropEmu.ExpansionPortDevice.OekaKidsTablet || InteropEmu.HasZapper(); }
|
||||
}
|
||||
|
||||
private void ShowMouse()
|
||||
{
|
||||
if(_cursorHidden) {
|
||||
Cursor.Show();
|
||||
_cursorHidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void HideMouse()
|
||||
{
|
||||
if(!_cursorHidden) {
|
||||
Cursor.Hide();
|
||||
_cursorHidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
|
@ -66,21 +43,10 @@ namespace Mesen.GUI.Controls
|
|||
|
||||
private void ctrlRenderer_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if(!InteropEmu.IsRunning() || InteropEmu.IsPaused() || !InteropEmu.HasArkanoidPaddle()) {
|
||||
ShowMouse();
|
||||
} else if(InteropEmu.HasArkanoidPaddle() && !this.NeedMouseIcon) {
|
||||
HideMouse();
|
||||
}
|
||||
CursorManager.OnMouseMove(this);
|
||||
|
||||
tmrMouse.Stop();
|
||||
|
||||
if(this.NeedMouseIcon) {
|
||||
if(CursorManager.NeedMouseIcon) {
|
||||
this.Cursor = Cursors.Cross;
|
||||
} else {
|
||||
this.Cursor = Cursors.Default;
|
||||
|
||||
//Only hide mouse if no zapper (otherwise this could be pretty annoying)
|
||||
tmrMouse.Start();
|
||||
}
|
||||
|
||||
double xPos = (double)e.X / this.Width;
|
||||
|
@ -92,15 +58,9 @@ namespace Mesen.GUI.Controls
|
|||
InteropEmu.SetMousePosition(xPos, yPos);
|
||||
}
|
||||
|
||||
private void tmrMouse_Tick(object sender, EventArgs e)
|
||||
{
|
||||
HideMouse();
|
||||
}
|
||||
|
||||
private void ctrlRenderer_MouseLeave(object sender, EventArgs e)
|
||||
{
|
||||
tmrMouse.Stop();
|
||||
ShowMouse();
|
||||
CursorManager.OnMouseLeave();
|
||||
InteropEmu.SetMousePosition(-1, -1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,4 @@
|
|||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="tmrMouse.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
80
GUI.NET/CursorManager.cs
Normal file
80
GUI.NET/CursorManager.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
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 Mesen.GUI.Config;
|
||||
|
||||
namespace Mesen.GUI
|
||||
{
|
||||
public class CursorManager
|
||||
{
|
||||
private static bool _cursorHidden = false;
|
||||
private static Timer _tmrMouse = new Timer();
|
||||
|
||||
static CursorManager()
|
||||
{
|
||||
_tmrMouse.Interval = 3000;
|
||||
_tmrMouse.Tick += tmrMouse_Tick;
|
||||
}
|
||||
|
||||
private static void tmrMouse_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if(InteropEmu.IsRunning() && !InteropEmu.IsPaused()) {
|
||||
HideMouse();
|
||||
} else {
|
||||
ShowMouse();
|
||||
_tmrMouse.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowMouse()
|
||||
{
|
||||
if(_cursorHidden) {
|
||||
Cursor.Show();
|
||||
_cursorHidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void HideMouse()
|
||||
{
|
||||
if(!_cursorHidden) {
|
||||
Cursor.Hide();
|
||||
_cursorHidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool NeedMouseIcon
|
||||
{
|
||||
get { return InteropEmu.GetExpansionDevice() == InteropEmu.ExpansionPortDevice.OekaKidsTablet || InteropEmu.HasZapper(); }
|
||||
}
|
||||
|
||||
public static void OnMouseMove(Control ctrl)
|
||||
{
|
||||
if(!InteropEmu.IsRunning() || InteropEmu.IsPaused() || !InteropEmu.HasArkanoidPaddle()) {
|
||||
ShowMouse();
|
||||
} else if(InteropEmu.HasArkanoidPaddle() && !CursorManager.NeedMouseIcon) {
|
||||
HideMouse();
|
||||
}
|
||||
|
||||
_tmrMouse.Stop();
|
||||
|
||||
if(!CursorManager.NeedMouseIcon) {
|
||||
ctrl.Cursor = Cursors.Default;
|
||||
|
||||
//Only hide mouse if no zapper (otherwise this could be pretty annoying)
|
||||
_tmrMouse.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public static void OnMouseLeave()
|
||||
{
|
||||
_tmrMouse.Stop();
|
||||
ShowMouse();
|
||||
}
|
||||
}
|
||||
}
|
41
GUI.NET/Forms/frmMain.Designer.cs
generated
41
GUI.NET/Forms/frmMain.Designer.cs
generated
|
@ -211,6 +211,7 @@ namespace Mesen.GUI.Forms
|
|||
this.panelRenderer.TabIndex = 2;
|
||||
this.panelRenderer.Click += new System.EventHandler(this.panelRenderer_Click);
|
||||
this.panelRenderer.DoubleClick += new System.EventHandler(this.ctrlRenderer_DoubleClick);
|
||||
this.panelRenderer.MouseLeave += new System.EventHandler(this.panelRenderer_MouseLeave);
|
||||
this.panelRenderer.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ctrlRenderer_MouseMove);
|
||||
//
|
||||
// ctrlLoading
|
||||
|
@ -265,8 +266,8 @@ namespace Mesen.GUI.Forms
|
|||
this.ctrlRecentGames.Size = new System.Drawing.Size(430, 309);
|
||||
this.ctrlRecentGames.TabIndex = 7;
|
||||
this.ctrlRecentGames.Visible = false;
|
||||
this.ctrlRecentGames.DoubleClick += new System.EventHandler(this.ctrlRenderer_DoubleClick);
|
||||
this.ctrlRecentGames.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ctrlRenderer_MouseMove);
|
||||
this.ctrlRecentGames.DoubleClick += new System.EventHandler(this.ctrlRenderer_DoubleClick);
|
||||
//
|
||||
// ctrlNsfPlayer
|
||||
//
|
||||
|
@ -327,50 +328,50 @@ namespace Mesen.GUI.Forms
|
|||
this.mnuOpen.Image = global::Mesen.GUI.Properties.Resources.FolderOpen;
|
||||
this.mnuOpen.Name = "mnuOpen";
|
||||
this.mnuOpen.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
|
||||
this.mnuOpen.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuOpen.Size = new System.Drawing.Size(146, 22);
|
||||
this.mnuOpen.Text = "Open";
|
||||
this.mnuOpen.Click += new System.EventHandler(this.mnuOpen_Click);
|
||||
//
|
||||
// toolStripMenuItem4
|
||||
//
|
||||
this.toolStripMenuItem4.Name = "toolStripMenuItem4";
|
||||
this.toolStripMenuItem4.Size = new System.Drawing.Size(149, 6);
|
||||
this.toolStripMenuItem4.Size = new System.Drawing.Size(143, 6);
|
||||
//
|
||||
// mnuSaveState
|
||||
//
|
||||
this.mnuSaveState.Name = "mnuSaveState";
|
||||
this.mnuSaveState.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuSaveState.Size = new System.Drawing.Size(146, 22);
|
||||
this.mnuSaveState.Text = "Save State";
|
||||
this.mnuSaveState.DropDownOpening += new System.EventHandler(this.mnuSaveState_DropDownOpening);
|
||||
//
|
||||
// mnuLoadState
|
||||
//
|
||||
this.mnuLoadState.Name = "mnuLoadState";
|
||||
this.mnuLoadState.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuLoadState.Size = new System.Drawing.Size(146, 22);
|
||||
this.mnuLoadState.Text = "Load State";
|
||||
this.mnuLoadState.DropDownOpening += new System.EventHandler(this.mnuLoadState_DropDownOpening);
|
||||
//
|
||||
// toolStripMenuItem7
|
||||
//
|
||||
this.toolStripMenuItem7.Name = "toolStripMenuItem7";
|
||||
this.toolStripMenuItem7.Size = new System.Drawing.Size(149, 6);
|
||||
this.toolStripMenuItem7.Size = new System.Drawing.Size(143, 6);
|
||||
//
|
||||
// mnuRecentFiles
|
||||
//
|
||||
this.mnuRecentFiles.Name = "mnuRecentFiles";
|
||||
this.mnuRecentFiles.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuRecentFiles.Size = new System.Drawing.Size(146, 22);
|
||||
this.mnuRecentFiles.Text = "Recent Files";
|
||||
//
|
||||
// toolStripMenuItem6
|
||||
//
|
||||
this.toolStripMenuItem6.Name = "toolStripMenuItem6";
|
||||
this.toolStripMenuItem6.Size = new System.Drawing.Size(149, 6);
|
||||
this.toolStripMenuItem6.Size = new System.Drawing.Size(143, 6);
|
||||
//
|
||||
// mnuExit
|
||||
//
|
||||
this.mnuExit.Image = global::Mesen.GUI.Properties.Resources.Exit;
|
||||
this.mnuExit.Name = "mnuExit";
|
||||
this.mnuExit.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuExit.Size = new System.Drawing.Size(146, 22);
|
||||
this.mnuExit.Text = "Exit";
|
||||
this.mnuExit.Click += new System.EventHandler(this.mnuExit_Click);
|
||||
//
|
||||
|
@ -532,7 +533,7 @@ namespace Mesen.GUI.Forms
|
|||
this.mnuShowFPS});
|
||||
this.mnuEmulationSpeed.Image = global::Mesen.GUI.Properties.Resources.Speed;
|
||||
this.mnuEmulationSpeed.Name = "mnuEmulationSpeed";
|
||||
this.mnuEmulationSpeed.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuEmulationSpeed.Size = new System.Drawing.Size(135, 22);
|
||||
this.mnuEmulationSpeed.Text = "Speed";
|
||||
this.mnuEmulationSpeed.DropDownOpening += new System.EventHandler(this.mnuEmulationSpeed_DropDownOpening);
|
||||
//
|
||||
|
@ -634,7 +635,7 @@ namespace Mesen.GUI.Forms
|
|||
this.mnuFullscreen});
|
||||
this.mnuVideoScale.Image = global::Mesen.GUI.Properties.Resources.Fullscreen;
|
||||
this.mnuVideoScale.Name = "mnuVideoScale";
|
||||
this.mnuVideoScale.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuVideoScale.Size = new System.Drawing.Size(135, 22);
|
||||
this.mnuVideoScale.Text = "Video Size";
|
||||
//
|
||||
// mnuScale1x
|
||||
|
@ -750,7 +751,7 @@ namespace Mesen.GUI.Forms
|
|||
this.mnuBilinearInterpolation});
|
||||
this.mnuVideoFilter.Image = global::Mesen.GUI.Properties.Resources.VideoFilter;
|
||||
this.mnuVideoFilter.Name = "mnuVideoFilter";
|
||||
this.mnuVideoFilter.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuVideoFilter.Size = new System.Drawing.Size(135, 22);
|
||||
this.mnuVideoFilter.Text = "Video Filter";
|
||||
//
|
||||
// mnuNoneFilter
|
||||
|
@ -980,7 +981,7 @@ namespace Mesen.GUI.Forms
|
|||
this.mnuRegionDendy});
|
||||
this.mnuRegion.Image = global::Mesen.GUI.Properties.Resources.Globe;
|
||||
this.mnuRegion.Name = "mnuRegion";
|
||||
this.mnuRegion.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuRegion.Size = new System.Drawing.Size(135, 22);
|
||||
this.mnuRegion.Text = "Region";
|
||||
//
|
||||
// mnuRegionAuto
|
||||
|
@ -1014,13 +1015,13 @@ namespace Mesen.GUI.Forms
|
|||
// toolStripMenuItem10
|
||||
//
|
||||
this.toolStripMenuItem10.Name = "toolStripMenuItem10";
|
||||
this.toolStripMenuItem10.Size = new System.Drawing.Size(149, 6);
|
||||
this.toolStripMenuItem10.Size = new System.Drawing.Size(132, 6);
|
||||
//
|
||||
// mnuAudioConfig
|
||||
//
|
||||
this.mnuAudioConfig.Image = global::Mesen.GUI.Properties.Resources.Audio;
|
||||
this.mnuAudioConfig.Name = "mnuAudioConfig";
|
||||
this.mnuAudioConfig.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuAudioConfig.Size = new System.Drawing.Size(135, 22);
|
||||
this.mnuAudioConfig.Text = "Audio";
|
||||
this.mnuAudioConfig.Click += new System.EventHandler(this.mnuAudioConfig_Click);
|
||||
//
|
||||
|
@ -1028,7 +1029,7 @@ namespace Mesen.GUI.Forms
|
|||
//
|
||||
this.mnuInput.Image = global::Mesen.GUI.Properties.Resources.Controller;
|
||||
this.mnuInput.Name = "mnuInput";
|
||||
this.mnuInput.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuInput.Size = new System.Drawing.Size(135, 22);
|
||||
this.mnuInput.Text = "Input";
|
||||
this.mnuInput.Click += new System.EventHandler(this.mnuInput_Click);
|
||||
//
|
||||
|
@ -1036,7 +1037,7 @@ namespace Mesen.GUI.Forms
|
|||
//
|
||||
this.mnuVideoConfig.Image = global::Mesen.GUI.Properties.Resources.Video;
|
||||
this.mnuVideoConfig.Name = "mnuVideoConfig";
|
||||
this.mnuVideoConfig.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuVideoConfig.Size = new System.Drawing.Size(135, 22);
|
||||
this.mnuVideoConfig.Text = "Video";
|
||||
this.mnuVideoConfig.Click += new System.EventHandler(this.mnuVideoConfig_Click);
|
||||
//
|
||||
|
@ -1044,20 +1045,20 @@ namespace Mesen.GUI.Forms
|
|||
//
|
||||
this.mnuEmulationConfig.Image = global::Mesen.GUI.Properties.Resources.DipSwitches;
|
||||
this.mnuEmulationConfig.Name = "mnuEmulationConfig";
|
||||
this.mnuEmulationConfig.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuEmulationConfig.Size = new System.Drawing.Size(135, 22);
|
||||
this.mnuEmulationConfig.Text = "Emulation";
|
||||
this.mnuEmulationConfig.Click += new System.EventHandler(this.mnuEmulationConfig_Click);
|
||||
//
|
||||
// toolStripMenuItem11
|
||||
//
|
||||
this.toolStripMenuItem11.Name = "toolStripMenuItem11";
|
||||
this.toolStripMenuItem11.Size = new System.Drawing.Size(149, 6);
|
||||
this.toolStripMenuItem11.Size = new System.Drawing.Size(132, 6);
|
||||
//
|
||||
// mnuPreferences
|
||||
//
|
||||
this.mnuPreferences.Image = global::Mesen.GUI.Properties.Resources.Cog;
|
||||
this.mnuPreferences.Name = "mnuPreferences";
|
||||
this.mnuPreferences.Size = new System.Drawing.Size(152, 22);
|
||||
this.mnuPreferences.Size = new System.Drawing.Size(135, 22);
|
||||
this.mnuPreferences.Text = "Preferences";
|
||||
this.mnuPreferences.Click += new System.EventHandler(this.mnuPreferences_Click);
|
||||
//
|
||||
|
|
|
@ -426,6 +426,10 @@ namespace Mesen.GUI.Forms
|
|||
|
||||
private void ctrlRenderer_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if(sender != this.ctrlRecentGames) {
|
||||
CursorManager.OnMouseMove((Control)sender);
|
||||
}
|
||||
|
||||
if(this.HideMenuStrip && !this.menuStrip.ContainsFocus) {
|
||||
if(sender == ctrlRenderer) {
|
||||
this.menuStrip.Visible = ctrlRenderer.Top + e.Y < 30;
|
||||
|
@ -1615,7 +1619,7 @@ namespace Mesen.GUI.Forms
|
|||
|
||||
private void ctrlRenderer_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
if(!ctrlRenderer.NeedMouseIcon && !InteropEmu.HasArkanoidPaddle()) {
|
||||
if(!CursorManager.NeedMouseIcon && !InteropEmu.HasArkanoidPaddle()) {
|
||||
//Disable double clicking (used to switch to fullscreen mode) when using zapper/arkanoid controller
|
||||
SetFullscreenState(!_fullscreenMode);
|
||||
}
|
||||
|
@ -1835,5 +1839,10 @@ namespace Mesen.GUI.Forms
|
|||
frm.ShowDialog(sender, this);
|
||||
}
|
||||
}
|
||||
|
||||
private void panelRenderer_MouseLeave(object sender, EventArgs e)
|
||||
{
|
||||
CursorManager.OnMouseLeave();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -253,6 +253,7 @@
|
|||
<Compile Include="Controls\ctrlRecentGames.Designer.cs">
|
||||
<DependentUpon>ctrlRecentGames.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="CursorManager.cs" />
|
||||
<Compile Include="Controls\ctrlRiskyOption.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
|
|
Loading…
Add table
Reference in a new issue