Video: Windowed fullscreen (+ auto-hide menu)

This commit is contained in:
Sour 2019-03-15 11:15:47 -04:00
parent 84d1439780
commit b09ca0c113
6 changed files with 222 additions and 73 deletions

View file

@ -24,6 +24,7 @@ namespace Mesen.GUI.Config
public UInt32 RewindBufferSize = 600;
public bool AlwaysOnTop = false;
public bool AutoHideMenu = false;
public bool ShowFps = false;
public bool ShowFrameCounter = false;

View file

@ -16,29 +16,105 @@ namespace Mesen.GUI.Emulation
private frmMain _frm;
private ctrlRenderer _renderer;
private Panel _panel;
private MenuStrip _menu;
private ctrlRecentGames _recentGames;
private bool _resizeForm;
private bool _fullscreenMode;
private FormWindowState _originalWindowState;
private Size _originalWindowMinimumSize;
public DisplayManager(frmMain frm, ctrlRenderer renderer, Panel panel)
public bool Fullscreen { get { return _fullscreenMode; } }
public DisplayManager(frmMain frm, ctrlRenderer renderer, Panel panel, MenuStrip menu, ctrlRecentGames recentGames)
{
_frm = frm;
_renderer = renderer;
_panel = panel;
_menu = menu;
_recentGames = recentGames;
_renderer.MouseClick += ctrlRenderer_MouseClick;
_renderer.Enter += ctrlRenderer_Enter;
_renderer.MouseMove += ctrlRenderer_MouseMove;
_panel.MouseMove += ctrlRenderer_MouseMove;
_recentGames.MouseMove += ctrlRenderer_MouseMove;
_panel.Click += panelRenderer_Click;
_frm.Resize += frmMain_Resize;
_menu.VisibleChanged += menu_VisibleChanged;
}
private void frmMain_Resize(object sender, EventArgs e)
{
SetScaleBasedOnWindowSize();
}
private void menu_VisibleChanged(object sender, EventArgs e)
{
if(!_menu.Visible) {
_renderer.Top += _menu.Height;
} else {
_renderer.Top -= _menu.Height;
}
}
public bool HideMenuStrip
{
get { return (_fullscreenMode && !ConfigManager.Config.Video.UseExclusiveFullscreen) || ConfigManager.Config.Preferences.AutoHideMenu; }
}
private void ctrlRenderer_MouseMove(object sender, MouseEventArgs e)
{
if(sender != _recentGames) {
//CursorManager.OnMouseMove((Control)sender);
}
if(this.HideMenuStrip && !_menu.ContainsFocus) {
if(sender == _renderer) {
_menu.Visible = _renderer.Top + e.Y < 30;
} else {
_menu.Visible = e.Y < 30;
}
}
}
private void ctrlRenderer_MouseClick(object sender, MouseEventArgs e)
{
if(this.HideMenuStrip) {
_menu.Visible = false;
}
//CursorManager.CaptureMouse();
}
private void panelRenderer_Click(object sender, EventArgs e)
{
if(this.HideMenuStrip) {
_menu.Visible = false;
}
//CursorManager.CaptureMouse();
_renderer.Focus();
}
private void ctrlRenderer_Enter(object sender, EventArgs e)
{
if(this.HideMenuStrip) {
_menu.Visible = false;
}
}
public void UpdateViewerSize()
{
if(HideMenuStrip) {
_menu.Visible = false;
}
ScreenSize screenSize = EmuApi.GetScreenSize(false);
if(_resizeForm && _frm.WindowState != FormWindowState.Maximized) {
_frm.Resize -= frmMain_Resize;
Size newSize = new Size(screenSize.Width, screenSize.Height);
_frm.ClientSize = new Size(newSize.Width, newSize.Height + _panel.Top);
_frm.ClientSize = new Size(newSize.Width, newSize.Height + (HideMenuStrip ? 0 : _panel.Top));
_frm.Resize += frmMain_Resize;
}
@ -54,9 +130,9 @@ namespace Mesen.GUI.Emulation
double verticalScale = (double)dimensions.Height / size.Height;
double horizontalScale = (double)dimensions.Width / size.Width;
double scale = Math.Min(verticalScale, horizontalScale);
/*if(_fullscreenMode && ConfigManager.Config.Video.FullscreenForceIntegerScale) {
if(_fullscreenMode && ConfigManager.Config.Video.FullscreenForceIntegerScale) {
scale = Math.Floor(scale);
}*/
}
SetScale(scale, false);
}
@ -83,7 +159,60 @@ namespace Mesen.GUI.Emulation
public void ToggleFullscreen()
{
SetFullscreenState(!_fullscreenMode);
}
private void SetFullscreenState(bool enabled)
{
if(_fullscreenMode == enabled) {
//Fullscreen mode already matches, no need to do anything
return;
}
bool saveState = !_fullscreenMode;
_fullscreenMode = enabled;
if(ConfigManager.Config.Video.UseExclusiveFullscreen) {
if(EmuRunner.IsRunning()) {
if(enabled) {
//StartExclusiveFullscreenMode();
} else {
//StopExclusiveFullscreenMode();
}
}
} else {
_frm.Resize -= frmMain_Resize;
if(enabled) {
StartFullscreenWindowMode(saveState);
} else {
StopFullscreenWindowMode();
}
_frm.Resize += frmMain_Resize;
UpdateViewerSize();
}
}
private void StartFullscreenWindowMode(bool saveState)
{
_menu.Visible = false;
if(saveState) {
_originalWindowState = _frm.WindowState;
_originalWindowMinimumSize = _frm.MinimumSize;
}
_frm.MinimumSize = new Size(0, 0);
_frm.WindowState = FormWindowState.Normal;
_frm.FormBorderStyle = FormBorderStyle.None;
_frm.WindowState = FormWindowState.Maximized;
SetScaleBasedOnWindowSize();
}
private void StopFullscreenWindowMode()
{
_menu.Visible = true;
_frm.WindowState = _originalWindowState;
_frm.MinimumSize = _originalWindowMinimumSize;
_frm.FormBorderStyle = FormBorderStyle.Sizable;
frmMain_Resize(null, EventArgs.Empty);
}
}
}

View file

@ -41,6 +41,7 @@
this.btnOpenMesenFolder = new System.Windows.Forms.Button();
this.btnResetSettings = new System.Windows.Forms.Button();
this.tpgShortcuts = new System.Windows.Forms.TabPage();
this.ctrlEmulatorShortcuts = new Mesen.GUI.Forms.Config.ctrlEmulatorShortcuts();
this.tpgFiles = new System.Windows.Forms.TabPage();
this.tableLayoutPanel6 = new System.Windows.Forms.TableLayoutPanel();
this.grpPathOverrides = new System.Windows.Forms.GroupBox();
@ -82,8 +83,8 @@
this.lblWindowSettings = new System.Windows.Forms.Label();
this.chkAlwaysOnTop = new System.Windows.Forms.CheckBox();
this.chkShowFps = new System.Windows.Forms.CheckBox();
this.ctrlEmulatorShortcuts = new Mesen.GUI.Forms.Config.ctrlEmulatorShortcuts();
this.chkShowDebugInfo = new System.Windows.Forms.CheckBox();
this.chkAutoHideMenu = new System.Windows.Forms.CheckBox();
this.tabMain.SuspendLayout();
this.tpgGeneral.SuspendLayout();
this.tlpMain.SuspendLayout();
@ -137,34 +138,25 @@
//
this.tlpMain.ColumnCount = 1;
this.tlpMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tlpMain.Controls.Add(this.chkAutoHideMenu, 0, 5);
this.tlpMain.Controls.Add(this.chkSingleInstance, 0, 2);
this.tlpMain.Controls.Add(this.chkAutomaticallyCheckForUpdates, 0, 1);
this.tlpMain.Controls.Add(this.flowLayoutPanel2, 0, 0);
this.tlpMain.Controls.Add(this.lblMiscSettings, 0, 3);
this.tlpMain.Controls.Add(this.chkAutoLoadPatches, 0, 4);
this.tlpMain.Controls.Add(this.tableLayoutPanel5, 0, 6);
this.tlpMain.Controls.Add(this.tableLayoutPanel5, 0, 7);
this.tlpMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.tlpMain.Location = new System.Drawing.Point(3, 3);
this.tlpMain.Name = "tlpMain";
this.tlpMain.RowCount = 7;
this.tlpMain.RowCount = 8;
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tlpMain.Size = new System.Drawing.Size(534, 383);
this.tlpMain.TabIndex = 1;
//
@ -290,6 +282,14 @@
this.tpgShortcuts.Text = "Shortcut Keys";
this.tpgShortcuts.UseVisualStyleBackColor = true;
//
// ctrlEmulatorShortcuts
//
this.ctrlEmulatorShortcuts.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlEmulatorShortcuts.Location = new System.Drawing.Point(3, 3);
this.ctrlEmulatorShortcuts.Name = "ctrlEmulatorShortcuts";
this.ctrlEmulatorShortcuts.Size = new System.Drawing.Size(534, 383);
this.ctrlEmulatorShortcuts.TabIndex = 0;
//
// tpgFiles
//
this.tpgFiles.Controls.Add(this.tableLayoutPanel6);
@ -847,14 +847,6 @@
this.chkShowFps.Text = "Show FPS";
this.chkShowFps.UseVisualStyleBackColor = true;
//
// ctrlEmulatorShortcuts
//
this.ctrlEmulatorShortcuts.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlEmulatorShortcuts.Location = new System.Drawing.Point(3, 3);
this.ctrlEmulatorShortcuts.Name = "ctrlEmulatorShortcuts";
this.ctrlEmulatorShortcuts.Size = new System.Drawing.Size(534, 383);
this.ctrlEmulatorShortcuts.TabIndex = 0;
//
// chkShowDebugInfo
//
this.chkShowDebugInfo.AutoSize = true;
@ -866,6 +858,17 @@
this.chkShowDebugInfo.Text = "Show debug information";
this.chkShowDebugInfo.UseVisualStyleBackColor = true;
//
// chkAutoHideMenu
//
this.chkAutoHideMenu.AutoSize = true;
this.chkAutoHideMenu.Location = new System.Drawing.Point(13, 118);
this.chkAutoHideMenu.Margin = new System.Windows.Forms.Padding(13, 3, 3, 3);
this.chkAutoHideMenu.Name = "chkAutoHideMenu";
this.chkAutoHideMenu.Size = new System.Drawing.Size(158, 17);
this.chkAutoHideMenu.TabIndex = 25;
this.chkAutoHideMenu.Text = "Automatically hide menu bar";
this.chkAutoHideMenu.UseVisualStyleBackColor = true;
//
// frmPreferences
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -967,5 +970,6 @@
private System.Windows.Forms.Button btnResetSettings;
private ctrlEmulatorShortcuts ctrlEmulatorShortcuts;
private System.Windows.Forms.CheckBox chkShowDebugInfo;
private System.Windows.Forms.CheckBox chkAutoHideMenu;
}
}

View file

@ -35,6 +35,7 @@ namespace Mesen.GUI.Forms.Config
AddBinding(nameof(PreferencesConfig.AssociateMssFiles), chkMssFormat);
AddBinding(nameof(PreferencesConfig.AlwaysOnTop), chkAlwaysOnTop);
AddBinding(nameof(PreferencesConfig.AutoHideMenu), chkAutoHideMenu);
AddBinding(nameof(PreferencesConfig.ShowTitleBarInfo), chkDisplayTitleBarInfo);
AddBinding(nameof(PreferencesConfig.DisableOsd), chkDisableOsd);

View file

@ -71,11 +71,6 @@
this.tableLayoutPanel8 = new System.Windows.Forms.TableLayoutPanel();
this.cboFilter = new System.Windows.Forms.ComboBox();
this.lblVideoFilter = new System.Windows.Forms.Label();
this.ctxPicturePresets = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuPresetComposite = new System.Windows.Forms.ToolStripMenuItem();
this.mnuPresetSVideo = new System.Windows.Forms.ToolStripMenuItem();
this.mnuPresetRgb = new System.Windows.Forms.ToolStripMenuItem();
this.mnuPresetMonochrome = new System.Windows.Forms.ToolStripMenuItem();
this.tpgOverscan = new System.Windows.Forms.TabPage();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.picOverscan = new System.Windows.Forms.PictureBox();
@ -91,6 +86,11 @@
this.tableLayoutPanel14 = new System.Windows.Forms.TableLayoutPanel();
this.nudOverscanLeft = new Mesen.GUI.Controls.MesenNumericUpDown();
this.lblLeft = new System.Windows.Forms.Label();
this.ctxPicturePresets = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuPresetComposite = new System.Windows.Forms.ToolStripMenuItem();
this.mnuPresetSVideo = new System.Windows.Forms.ToolStripMenuItem();
this.mnuPresetRgb = new System.Windows.Forms.ToolStripMenuItem();
this.mnuPresetMonochrome = new System.Windows.Forms.ToolStripMenuItem();
this.tabMain.SuspendLayout();
this.tpgGeneral.SuspendLayout();
this.tlpMain.SuspendLayout();
@ -105,7 +105,6 @@
this.tableLayoutPanel4.SuspendLayout();
this.grpScanlines.SuspendLayout();
this.tableLayoutPanel8.SuspendLayout();
this.ctxPicturePresets.SuspendLayout();
this.tpgOverscan.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picOverscan)).BeginInit();
@ -113,6 +112,7 @@
this.tableLayoutPanel12.SuspendLayout();
this.tableLayoutPanel13.SuspendLayout();
this.tableLayoutPanel14.SuspendLayout();
this.ctxPicturePresets.SuspendLayout();
this.SuspendLayout();
//
// baseConfigPanel
@ -332,7 +332,6 @@
this.chkFullscreenForceIntegerScale.TabIndex = 23;
this.chkFullscreenForceIntegerScale.Text = "Use integer scale values when entering fullscreen mode";
this.chkFullscreenForceIntegerScale.UseVisualStyleBackColor = true;
this.chkFullscreenForceIntegerScale.Visible = false;
//
// chkIntegerFpsMode
//
@ -776,44 +775,6 @@
this.lblVideoFilter.TabIndex = 13;
this.lblVideoFilter.Text = "Filter:";
//
// ctxPicturePresets
//
this.ctxPicturePresets.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuPresetComposite,
this.mnuPresetSVideo,
this.mnuPresetRgb,
this.mnuPresetMonochrome});
this.ctxPicturePresets.Name = "contextPicturePresets";
this.ctxPicturePresets.Size = new System.Drawing.Size(148, 92);
//
// mnuPresetComposite
//
this.mnuPresetComposite.Name = "mnuPresetComposite";
this.mnuPresetComposite.Size = new System.Drawing.Size(147, 22);
this.mnuPresetComposite.Text = "Composite";
this.mnuPresetComposite.Click += new System.EventHandler(this.mnuPresetComposite_Click);
//
// mnuPresetSVideo
//
this.mnuPresetSVideo.Name = "mnuPresetSVideo";
this.mnuPresetSVideo.Size = new System.Drawing.Size(147, 22);
this.mnuPresetSVideo.Text = "S-Video";
this.mnuPresetSVideo.Click += new System.EventHandler(this.mnuPresetSVideo_Click);
//
// mnuPresetRgb
//
this.mnuPresetRgb.Name = "mnuPresetRgb";
this.mnuPresetRgb.Size = new System.Drawing.Size(147, 22);
this.mnuPresetRgb.Text = "RGB";
this.mnuPresetRgb.Click += new System.EventHandler(this.mnuPresetRgb_Click);
//
// mnuPresetMonochrome
//
this.mnuPresetMonochrome.Name = "mnuPresetMonochrome";
this.mnuPresetMonochrome.Size = new System.Drawing.Size(147, 22);
this.mnuPresetMonochrome.Text = "Monochrome";
this.mnuPresetMonochrome.Click += new System.EventHandler(this.mnuPresetMonochrome_Click);
//
// tpgOverscan
//
this.tpgOverscan.Controls.Add(this.tableLayoutPanel1);
@ -1102,6 +1063,44 @@
this.lblLeft.Text = "Left";
this.lblLeft.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// ctxPicturePresets
//
this.ctxPicturePresets.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuPresetComposite,
this.mnuPresetSVideo,
this.mnuPresetRgb,
this.mnuPresetMonochrome});
this.ctxPicturePresets.Name = "contextPicturePresets";
this.ctxPicturePresets.Size = new System.Drawing.Size(148, 92);
//
// mnuPresetComposite
//
this.mnuPresetComposite.Name = "mnuPresetComposite";
this.mnuPresetComposite.Size = new System.Drawing.Size(147, 22);
this.mnuPresetComposite.Text = "Composite";
this.mnuPresetComposite.Click += new System.EventHandler(this.mnuPresetComposite_Click);
//
// mnuPresetSVideo
//
this.mnuPresetSVideo.Name = "mnuPresetSVideo";
this.mnuPresetSVideo.Size = new System.Drawing.Size(147, 22);
this.mnuPresetSVideo.Text = "S-Video";
this.mnuPresetSVideo.Click += new System.EventHandler(this.mnuPresetSVideo_Click);
//
// mnuPresetRgb
//
this.mnuPresetRgb.Name = "mnuPresetRgb";
this.mnuPresetRgb.Size = new System.Drawing.Size(147, 22);
this.mnuPresetRgb.Text = "RGB";
this.mnuPresetRgb.Click += new System.EventHandler(this.mnuPresetRgb_Click);
//
// mnuPresetMonochrome
//
this.mnuPresetMonochrome.Name = "mnuPresetMonochrome";
this.mnuPresetMonochrome.Size = new System.Drawing.Size(147, 22);
this.mnuPresetMonochrome.Text = "Monochrome";
this.mnuPresetMonochrome.Click += new System.EventHandler(this.mnuPresetMonochrome_Click);
//
// frmVideoConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -1137,7 +1136,6 @@
this.grpScanlines.ResumeLayout(false);
this.tableLayoutPanel8.ResumeLayout(false);
this.tableLayoutPanel8.PerformLayout();
this.ctxPicturePresets.ResumeLayout(false);
this.tpgOverscan.ResumeLayout(false);
this.tableLayoutPanel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.picOverscan)).EndInit();
@ -1149,6 +1147,7 @@
this.tableLayoutPanel13.PerformLayout();
this.tableLayoutPanel14.ResumeLayout(false);
this.tableLayoutPanel14.PerformLayout();
this.ctxPicturePresets.ResumeLayout(false);
this.ResumeLayout(false);
}

View file

@ -56,7 +56,7 @@ namespace Mesen.GUI.Forms
ConfigManager.Config.InitializeDefaults();
ConfigManager.Config.ApplyConfig();
_displayManager = new DisplayManager(this, ctrlRenderer, pnlRenderer);
_displayManager = new DisplayManager(this, ctrlRenderer, pnlRenderer, mnuMain, ctrlRecentGames);
_displayManager.UpdateViewerSize();
_shortcuts = new ShortcutHandler(_displayManager);
@ -126,6 +126,19 @@ namespace Mesen.GUI.Forms
}
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(_displayManager.HideMenuStrip && (keyData & Keys.Alt) == Keys.Alt) {
if(mnuMain.Visible && !mnuMain.ContainsFocus) {
mnuMain.Visible = false;
} else {
mnuMain.Visible = true;
mnuMain.Focus();
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
private void BindShortcuts()
{
Func<bool> notClient = () => { return true; }; //TODO
@ -376,6 +389,8 @@ namespace Mesen.GUI.Forms
mnuScale4x.Checked = (scale == 4.0);
mnuScale5x.Checked = (scale == 5.0);
mnuScale6x.Checked = (scale == 6.0);
mnuFullscreen.Checked = _displayManager.Fullscreen;
}
private void mnuEmulationSpeed_DropDownOpening(object sender, EventArgs e)