Video: Exclusive fullscreen mode support
This commit is contained in:
parent
b09ca0c113
commit
c66a63b0f3
10 changed files with 161 additions and 24 deletions
|
@ -93,7 +93,7 @@ struct VideoConfig
|
|||
|
||||
bool FullscreenForceIntegerScale = false;
|
||||
bool UseExclusiveFullscreen = false;
|
||||
int32_t ExclusiveFullscreenRefreshRate = 60;
|
||||
uint32_t ExclusiveFullscreenRefreshRate = 60;
|
||||
};
|
||||
|
||||
struct AudioConfig
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace Mesen.GUI.Config
|
|||
|
||||
[MarshalAs(UnmanagedType.I1)] public bool FullscreenForceIntegerScale = false;
|
||||
[MarshalAs(UnmanagedType.I1)] public bool UseExclusiveFullscreen = false;
|
||||
public Int32 ExclusiveFullscreenRefreshRate = 60;
|
||||
public UInt32 ExclusiveFullscreenRefreshRate = 60;
|
||||
|
||||
public void ApplyConfig()
|
||||
{
|
||||
|
|
|
@ -22,8 +22,10 @@ namespace Mesen.GUI.Emulation
|
|||
private bool _fullscreenMode;
|
||||
private FormWindowState _originalWindowState;
|
||||
private Size _originalWindowMinimumSize;
|
||||
private frmFullscreenRenderer _frmFullscreenRenderer = null;
|
||||
|
||||
public bool Fullscreen { get { return _fullscreenMode; } }
|
||||
public bool ExclusiveFullscreen { get { return _frmFullscreenRenderer != null; } }
|
||||
|
||||
public DisplayManager(frmMain frm, ctrlRenderer renderer, Panel panel, MenuStrip menu, ctrlRecentGames recentGames)
|
||||
{
|
||||
|
@ -162,7 +164,7 @@ namespace Mesen.GUI.Emulation
|
|||
SetFullscreenState(!_fullscreenMode);
|
||||
}
|
||||
|
||||
private void SetFullscreenState(bool enabled)
|
||||
public void SetFullscreenState(bool enabled)
|
||||
{
|
||||
if(_fullscreenMode == enabled) {
|
||||
//Fullscreen mode already matches, no need to do anything
|
||||
|
@ -173,12 +175,10 @@ namespace Mesen.GUI.Emulation
|
|||
_fullscreenMode = enabled;
|
||||
|
||||
if(ConfigManager.Config.Video.UseExclusiveFullscreen) {
|
||||
if(EmuRunner.IsRunning()) {
|
||||
if(enabled) {
|
||||
//StartExclusiveFullscreenMode();
|
||||
} else {
|
||||
//StopExclusiveFullscreenMode();
|
||||
}
|
||||
if(enabled && EmuRunner.IsRunning()) {
|
||||
StartExclusiveFullscreenMode();
|
||||
} else {
|
||||
StopExclusiveFullscreenMode();
|
||||
}
|
||||
} else {
|
||||
_frm.Resize -= frmMain_Resize;
|
||||
|
@ -214,5 +214,37 @@ namespace Mesen.GUI.Emulation
|
|||
_frm.FormBorderStyle = FormBorderStyle.Sizable;
|
||||
frmMain_Resize(null, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void StopExclusiveFullscreenMode()
|
||||
{
|
||||
if(_frmFullscreenRenderer != null) {
|
||||
_frmFullscreenRenderer.Close();
|
||||
}
|
||||
_fullscreenMode = false;
|
||||
}
|
||||
|
||||
private void StartExclusiveFullscreenMode()
|
||||
{
|
||||
Size screenSize = Screen.FromControl(_frm).Bounds.Size;
|
||||
_frmFullscreenRenderer = new frmFullscreenRenderer();
|
||||
_frmFullscreenRenderer.Shown += (object sender, EventArgs e) => {
|
||||
_renderer.Visible = false;
|
||||
SetScaleBasedOnScreenSize();
|
||||
EmuApi.SetFullscreenMode(true, _frmFullscreenRenderer.Handle, (UInt32)screenSize.Width, (UInt32)screenSize.Height);
|
||||
};
|
||||
_frmFullscreenRenderer.FormClosing += (object sender, FormClosingEventArgs e) => {
|
||||
EmuApi.SetFullscreenMode(false, _renderer.Handle, (UInt32)screenSize.Width, (UInt32)screenSize.Height);
|
||||
_frmFullscreenRenderer = null;
|
||||
_renderer.Visible = true;
|
||||
_fullscreenMode = false;
|
||||
frmMain_Resize(null, EventArgs.Empty);
|
||||
};
|
||||
|
||||
Screen currentScreen = Screen.FromHandle(_frm.Handle);
|
||||
_frmFullscreenRenderer.StartPosition = FormStartPosition.Manual;
|
||||
_frmFullscreenRenderer.Top = currentScreen.Bounds.Top;
|
||||
_frmFullscreenRenderer.Left = currentScreen.Bounds.Left;
|
||||
_frmFullscreenRenderer.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,14 +67,14 @@ namespace Mesen.GUI.Emulation
|
|||
}
|
||||
}
|
||||
|
||||
//TODO bool restoreFullscreen = _frmFullscreenRenderer != null;
|
||||
bool restoreFullscreen = _displayManager.ExclusiveFullscreen;
|
||||
|
||||
switch(shortcut) {
|
||||
case EmulatorShortcut.Pause: TogglePause(); break;
|
||||
case EmulatorShortcut.Reset: ResetEmu(); break;
|
||||
case EmulatorShortcut.PowerCycle: PowerCycleEmu(); break;
|
||||
case EmulatorShortcut.PowerOff: Task.Run(() => EmuApi.Stop()); break;
|
||||
case EmulatorShortcut.Exit: Application.OpenForms[0].Close(); break;
|
||||
case EmulatorShortcut.PowerOff: Task.Run(() => EmuApi.Stop()); restoreFullscreen = false; break;
|
||||
case EmulatorShortcut.Exit: Application.OpenForms[0].Close(); restoreFullscreen = false; break;
|
||||
|
||||
case EmulatorShortcut.ToggleAudio: ToggleAudio(); break;
|
||||
case EmulatorShortcut.ToggleFps: ToggleFps(); break;
|
||||
|
@ -84,7 +84,7 @@ namespace Mesen.GUI.Emulation
|
|||
case EmulatorShortcut.ToggleAlwaysOnTop: ToggleAlwaysOnTop(); break;
|
||||
case EmulatorShortcut.ToggleDebugInfo: ToggleDebugInfo(); break;
|
||||
case EmulatorShortcut.MaxSpeed: ToggleMaxSpeed(); break;
|
||||
case EmulatorShortcut.ToggleFullscreen: _displayManager.ToggleFullscreen(); break;
|
||||
case EmulatorShortcut.ToggleFullscreen: _displayManager.ToggleFullscreen(); restoreFullscreen = false; break;
|
||||
|
||||
case EmulatorShortcut.OpenFile: OpenFile(); break;
|
||||
case EmulatorShortcut.IncreaseSpeed: IncreaseEmulationSpeed(); break;
|
||||
|
@ -125,12 +125,10 @@ namespace Mesen.GUI.Emulation
|
|||
case EmulatorShortcut.LoadStateSlotAuto: SaveStateManager.LoadState(11); break;
|
||||
}
|
||||
|
||||
//TODO
|
||||
/*
|
||||
if(restoreFullscreen && _frmFullscreenRenderer == null && !_shuttingDown) {
|
||||
if(restoreFullscreen && !_displayManager.ExclusiveFullscreen) {
|
||||
//Need to restore fullscreen mode after showing a dialog
|
||||
this.SetFullscreenState(true);
|
||||
}*/
|
||||
_displayManager.SetFullscreenState(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenFile()
|
||||
|
|
13
UI/Forms/Config/frmVideoConfig.Designer.cs
generated
13
UI/Forms/Config/frmVideoConfig.Designer.cs
generated
|
@ -185,7 +185,7 @@
|
|||
this.chkUseExclusiveFullscreen.TabIndex = 24;
|
||||
this.chkUseExclusiveFullscreen.Text = "Use exclusive fullscreen mode";
|
||||
this.chkUseExclusiveFullscreen.UseVisualStyleBackColor = true;
|
||||
this.chkUseExclusiveFullscreen.Visible = false;
|
||||
this.chkUseExclusiveFullscreen.CheckedChanged += new System.EventHandler(this.chkUseExclusiveFullscreen_CheckedChanged);
|
||||
//
|
||||
// lblVideoScale
|
||||
//
|
||||
|
@ -373,11 +373,12 @@
|
|||
this.cboRefreshRate.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.cboRefreshRate.FormattingEnabled = true;
|
||||
this.cboRefreshRate.Items.AddRange(new object[] {
|
||||
"Auto",
|
||||
"NTSC (8:7)",
|
||||
"PAL (18:13)",
|
||||
"Standard (4:3)",
|
||||
"Widescreen (16:9)"});
|
||||
"50 Hz",
|
||||
"60 Hz",
|
||||
"100 Hz",
|
||||
"120 Hz",
|
||||
"200 Hz",
|
||||
"240 Hz"});
|
||||
this.cboRefreshRate.Location = new System.Drawing.Point(137, 3);
|
||||
this.cboRefreshRate.Name = "cboRefreshRate";
|
||||
this.cboRefreshRate.Size = new System.Drawing.Size(68, 21);
|
||||
|
|
|
@ -147,5 +147,10 @@ namespace Mesen.GUI.Forms.Config
|
|||
{
|
||||
UpdateOverscanImage(picOverscan, (int)nudOverscanTop.Value, (int)nudOverscanBottom.Value, (int)nudOverscanLeft.Value, (int)nudOverscanRight.Value);
|
||||
}
|
||||
|
||||
private void chkUseExclusiveFullscreen_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
flpRefreshRate.Visible = chkUseExclusiveFullscreen.Checked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
94
UI/Forms/frmFullscreenRenderer.cs
Normal file
94
UI/Forms/frmFullscreenRenderer.cs
Normal file
|
@ -0,0 +1,94 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Mesen.GUI.Forms
|
||||
{
|
||||
public class frmFullscreenRenderer : BaseInputForm
|
||||
{
|
||||
private const int LeftMouseButtonKeyCode = 0x200;
|
||||
private const int RightMouseButtonKeyCode = 0x201;
|
||||
private const int MiddleMouseButtonKeyCode = 0x202;
|
||||
private bool _closing = false;
|
||||
|
||||
public frmFullscreenRenderer()
|
||||
{
|
||||
this.BackColor = Color.Black;
|
||||
this.Text = "Mesen Fullscreen Window";
|
||||
this.FormBorderStyle = FormBorderStyle.None;
|
||||
this.WindowState = FormWindowState.Maximized;
|
||||
}
|
||||
|
||||
protected override void OnFormClosing(FormClosingEventArgs e)
|
||||
{
|
||||
_closing = true;
|
||||
base.OnFormClosing(e);
|
||||
}
|
||||
|
||||
protected override void OnDeactivate(EventArgs e)
|
||||
{
|
||||
base.OnDeactivate(e);
|
||||
|
||||
if(!_closing) {
|
||||
//Close fullscreen mode if window loses focus
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
//CursorManager.CaptureMouse();
|
||||
SetMouseButtonState(Control.MouseButtons);
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
SetMouseButtonState(Control.MouseButtons);
|
||||
}
|
||||
|
||||
private void SetMouseButtonState(MouseButtons pressedButtons)
|
||||
{
|
||||
InputApi.SetKeyState(LeftMouseButtonKeyCode, pressedButtons.HasFlag(MouseButtons.Left));
|
||||
InputApi.SetKeyState(RightMouseButtonKeyCode, pressedButtons.HasFlag(MouseButtons.Right));
|
||||
InputApi.SetKeyState(MiddleMouseButtonKeyCode, pressedButtons.HasFlag(MouseButtons.Middle));
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
|
||||
ScreenSize size = EmuApi.GetScreenSize(false);
|
||||
int leftMargin = (this.Width - size.Width) / 2;
|
||||
int topMargin = (this.Height - size.Height) / 2;
|
||||
|
||||
//CursorManager.OnMouseMove(this);
|
||||
|
||||
/*if(CursorManager.NeedMouseIcon) {
|
||||
this.Cursor = Cursors.Cross;
|
||||
}*/
|
||||
|
||||
double xPos = (double)(e.X - leftMargin) / size.Width;
|
||||
double yPos = (double)(e.Y - topMargin) / size.Height;
|
||||
|
||||
xPos = Math.Max(0.0, Math.Min(1.0, xPos));
|
||||
yPos = Math.Max(0.0, Math.Min(1.0, yPos));
|
||||
|
||||
InputApi.SetMousePosition(xPos, yPos);
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
|
||||
//CursorManager.OnMouseLeave();
|
||||
InputApi.SetMousePosition(-1, -1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -109,6 +109,9 @@ namespace Mesen.GUI.Forms
|
|||
ctrlRecentGames.Initialize();
|
||||
ctrlRecentGames.Visible = true;
|
||||
ResizeRecentGames();
|
||||
if(_displayManager.ExclusiveFullscreen) {
|
||||
_displayManager.SetFullscreenState(false);
|
||||
}
|
||||
}));
|
||||
break;
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ namespace Mesen.GUI
|
|||
);
|
||||
|
||||
[DllImport(DllPath)] public static extern void SetDisplayLanguage(Language lang);
|
||||
[DllImport(DllPath)] public static extern void SetFullscreenMode([MarshalAs(UnmanagedType.I1)]bool fullscreen, IntPtr windowHandle, UInt32 monitorWidth, UInt32 monitorHeight);
|
||||
|
||||
[DllImport(DllPath)] public static extern ScreenSize GetScreenSize([MarshalAs(UnmanagedType.I1)]bool ignoreScale);
|
||||
|
||||
|
|
|
@ -555,6 +555,9 @@
|
|||
<Compile Include="Forms\frmAbout.designer.cs">
|
||||
<DependentUpon>frmAbout.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\frmFullscreenRenderer.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\frmLogWindow.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
|
Loading…
Add table
Reference in a new issue