Video: Fullscreen window mode + auto-adjust video to window

This commit is contained in:
Souryo 2016-02-07 13:05:32 -05:00
parent 00201ebf46
commit 32b8206e74
13 changed files with 264 additions and 88 deletions

View file

@ -6,6 +6,7 @@
BaseVideoFilter::BaseVideoFilter()
{
_overscan = EmulationSettings::GetOverscanDimensions();
}
BaseVideoFilter::~BaseVideoFilter()

View file

@ -30,7 +30,8 @@ uint32_t EmulationSettings::_emulationSpeed = 100;
OverscanDimensions EmulationSettings::_overscan;
VideoFilterType EmulationSettings::_videoFilterType = VideoFilterType::None;
uint32_t EmulationSettings::_videoScale = 1;
double EmulationSettings::_videoScale = 1;
VideoAspectRatio EmulationSettings::_aspectRatio = VideoAspectRatio::Auto;
ConsoleType EmulationSettings::_consoleType = ConsoleType::Nes;
ExpansionPortDevice EmulationSettings::_expansionDevice = ExpansionPortDevice::None;

View file

@ -57,6 +57,15 @@ enum class VideoFilterType
HdPack = 999
};
enum class VideoAspectRatio
{
Auto = 0,
NTSC = 1,
PAL = 2,
Standard = 3,
Widescreen = 4
};
struct OverscanDimensions
{
uint32_t Left = 0;
@ -149,7 +158,8 @@ private:
static OverscanDimensions _overscan;
static VideoFilterType _videoFilterType;
static uint32_t _videoScale;
static double _videoScale;
static VideoAspectRatio _aspectRatio;
static ConsoleType _consoleType;
static ExpansionPortDevice _expansionDevice;
@ -237,10 +247,13 @@ public:
static void SetOverscanDimensions(uint8_t left, uint8_t right, uint8_t top, uint8_t bottom)
{
_overscan.Left = left;
_overscan.Right = right;
_overscan.Top = top;
_overscan.Bottom = bottom;
if(_overscan.Left != left || _overscan.Right != right || _overscan.Top != top || _overscan.Bottom != bottom) {
_overscan.Left = left;
_overscan.Right = right;
_overscan.Top = top;
_overscan.Bottom = bottom;
MessageManager::SendNotification(ConsoleNotificationType::ResolutionChanged);
}
}
static OverscanDimensions GetOverscanDimensions()
@ -273,13 +286,39 @@ public:
return _videoFilterType;
}
static void SetVideoScale(uint32_t scale)
static void SetVideoAspectRatio(VideoAspectRatio aspectRatio)
{
_videoScale = scale;
MessageManager::SendNotification(ConsoleNotificationType::ResolutionChanged);
if(_aspectRatio != aspectRatio) {
_aspectRatio = aspectRatio;
MessageManager::SendNotification(ConsoleNotificationType::ResolutionChanged);
}
}
static uint32_t GetVideoScale()
static VideoAspectRatio GetVideoAspectRatio()
{
return _aspectRatio;
}
static double GetAspectRatio()
{
switch(_aspectRatio) {
case VideoAspectRatio::NTSC: return 8.0 / 7.0;
case VideoAspectRatio::PAL: return 18.0 / 13.0;
case VideoAspectRatio::Standard: return 4.0 / 3.0;
case VideoAspectRatio::Widescreen: return 16.0 / 9.0;
}
return 0.0;
}
static void SetVideoScale(double scale)
{
if(_videoScale != scale) {
_videoScale = scale;
MessageManager::SendNotification(ConsoleNotificationType::ResolutionChanged);
}
}
static double GetVideoScale()
{
return _videoScale;
}

View file

@ -27,11 +27,15 @@ VideoDecoder::~VideoDecoder()
StopThread();
}
void VideoDecoder::GetScreenSize(ScreenSize &size)
void VideoDecoder::GetScreenSize(ScreenSize &size, bool ignoreScale)
{
if(_videoFilter) {
size.Width = _videoFilter->GetFrameInfo().Width * EmulationSettings::GetVideoScale();
size.Height = _videoFilter->GetFrameInfo().Height * EmulationSettings::GetVideoScale();
double aspectRatio = EmulationSettings::GetAspectRatio();
size.Width = (int32_t)(_videoFilter->GetFrameInfo().Width * (ignoreScale ? 1 : EmulationSettings::GetVideoScale()));
size.Height = (int32_t)(_videoFilter->GetFrameInfo().Height * (ignoreScale ? 1 : EmulationSettings::GetVideoScale()));
if(aspectRatio != 0.0) {
size.Width = (uint32_t)(size.Height * aspectRatio);
}
}
}

View file

@ -50,7 +50,7 @@ public:
uint32_t GetFrameCount();
void GetScreenSize(ScreenSize &size);
void GetScreenSize(ScreenSize &size, bool ignoreScale);
void DebugDecodeFrame(uint16_t* inputBuffer, uint32_t* outputBuffer, uint32_t length);

View file

@ -17,11 +17,10 @@ namespace Mesen.GUI.Config
public UInt32 OverscanRight = 0;
public UInt32 OverscanTop = 8;
public UInt32 OverscanBottom = 8;
public UInt32 VideoScale = 2;
public double VideoScale = 2;
public VideoFilterType VideoFilter = VideoFilterType.None;
public VideoAspectRatio AspectRatio = VideoAspectRatio.Auto;
public bool VerticalSync = true;
public bool FullscreenMode = false;
public bool UseHdPacks = false;
public Int32[] Palette = new Int32[0];
@ -43,6 +42,7 @@ namespace Mesen.GUI.Config
InteropEmu.SetVideoFilter(videoInfo.VideoFilter);
InteropEmu.SetVideoScale(videoInfo.VideoScale);
InteropEmu.SetVideoAspectRatio(videoInfo.AspectRatio);
if(videoInfo.Palette.Length == 64) {
InteropEmu.SetRgbPalette(videoInfo.Palette);

View file

@ -28,7 +28,6 @@
private void InitializeComponent()
{
this.tlpMain = new System.Windows.Forms.TableLayoutPanel();
this.chkFullscreenMode = new System.Windows.Forms.CheckBox();
this.lblVideoScale = new System.Windows.Forms.Label();
this.lblVideoFilter = new System.Windows.Forms.Label();
this.cboScale = new System.Windows.Forms.ComboBox();
@ -104,7 +103,6 @@
this.tlpMain.ColumnCount = 2;
this.tlpMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tlpMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tlpMain.Controls.Add(this.chkFullscreenMode, 0, 5);
this.tlpMain.Controls.Add(this.lblVideoScale, 0, 0);
this.tlpMain.Controls.Add(this.lblVideoFilter, 0, 1);
this.tlpMain.Controls.Add(this.cboScale, 1, 0);
@ -112,16 +110,15 @@
this.tlpMain.Controls.Add(this.chkVerticalSync, 0, 4);
this.tlpMain.Controls.Add(this.cboAspectRatio, 1, 2);
this.tlpMain.Controls.Add(this.lblDisplayRatio, 0, 2);
this.tlpMain.Controls.Add(this.flowLayoutPanel6, 1, 7);
this.tlpMain.Controls.Add(this.lblEmulationSpeed, 0, 7);
this.tlpMain.Controls.Add(this.chkShowFps, 0, 6);
this.tlpMain.Controls.Add(this.flowLayoutPanel6, 1, 6);
this.tlpMain.Controls.Add(this.lblEmulationSpeed, 0, 6);
this.tlpMain.Controls.Add(this.chkShowFps, 0, 5);
this.tlpMain.Controls.Add(this.flowLayoutPanel7, 0, 3);
this.tlpMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.tlpMain.Location = new System.Drawing.Point(3, 3);
this.tlpMain.Margin = new System.Windows.Forms.Padding(0);
this.tlpMain.Name = "tlpMain";
this.tlpMain.RowCount = 9;
this.tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
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());
@ -130,21 +127,10 @@
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.Size = new System.Drawing.Size(501, 256);
this.tlpMain.TabIndex = 1;
//
// chkFullscreenMode
//
this.chkFullscreenMode.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.chkFullscreenMode.AutoSize = true;
this.tlpMain.SetColumnSpan(this.chkFullscreenMode, 2);
this.chkFullscreenMode.Location = new System.Drawing.Point(3, 130);
this.chkFullscreenMode.Name = "chkFullscreenMode";
this.chkFullscreenMode.Size = new System.Drawing.Size(113, 17);
this.chkFullscreenMode.TabIndex = 18;
this.chkFullscreenMode.Text = "Fullscreen window";
this.chkFullscreenMode.UseVisualStyleBackColor = true;
//
// lblVideoScale
//
this.lblVideoScale.Anchor = System.Windows.Forms.AnchorStyles.Left;
@ -234,7 +220,7 @@
this.flowLayoutPanel6.Controls.Add(this.nudEmulationSpeed);
this.flowLayoutPanel6.Controls.Add(this.lblEmuSpeedHint);
this.flowLayoutPanel6.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel6.Location = new System.Drawing.Point(96, 173);
this.flowLayoutPanel6.Location = new System.Drawing.Point(96, 150);
this.flowLayoutPanel6.Margin = new System.Windows.Forms.Padding(0);
this.flowLayoutPanel6.Name = "flowLayoutPanel6";
this.flowLayoutPanel6.Size = new System.Drawing.Size(405, 26);
@ -266,7 +252,7 @@
//
this.lblEmulationSpeed.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.lblEmulationSpeed.AutoSize = true;
this.lblEmulationSpeed.Location = new System.Drawing.Point(3, 179);
this.lblEmulationSpeed.Location = new System.Drawing.Point(3, 156);
this.lblEmulationSpeed.Name = "lblEmulationSpeed";
this.lblEmulationSpeed.Size = new System.Drawing.Size(90, 13);
this.lblEmulationSpeed.TabIndex = 0;
@ -277,7 +263,7 @@
this.chkShowFps.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.chkShowFps.AutoSize = true;
this.tlpMain.SetColumnSpan(this.chkShowFps, 2);
this.chkShowFps.Location = new System.Drawing.Point(3, 153);
this.chkShowFps.Location = new System.Drawing.Point(3, 130);
this.chkShowFps.Name = "chkShowFps";
this.chkShowFps.Size = new System.Drawing.Size(76, 17);
this.chkShowFps.TabIndex = 9;
@ -669,7 +655,6 @@
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2;
private System.Windows.Forms.Label lblRight;
private System.Windows.Forms.NumericUpDown nudOverscanRight;
private System.Windows.Forms.CheckBox chkFullscreenMode;
private System.Windows.Forms.TabPage tpgPalette;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel7;
private System.Windows.Forms.CheckBox chkUseHdPacks;

View file

@ -26,7 +26,6 @@ namespace Mesen.GUI.Forms.Config
AddBinding("EmulationSpeed", nudEmulationSpeed);
AddBinding("ShowFPS", chkShowFps);
AddBinding("VerticalSync", chkVerticalSync);
AddBinding("FullscreenMode", chkFullscreenMode);
AddBinding("UseHdPacks", chkUseHdPacks);
AddBinding("VideoScale", cboScale);

View file

@ -1,4 +1,6 @@
namespace Mesen.GUI.Forms
using Mesen.GUI.Config;
namespace Mesen.GUI.Forms
{
partial class frmMain
{
@ -23,6 +25,10 @@
if(_debugger != null) {
_debugger.Close();
}
ConfigManager.Config.VideoInfo.VideoScale = _regularScale;
ConfigManager.ApplyChanges();
StopEmu();
InteropEmu.Release();
base.Dispose(disposing);
@ -72,10 +78,13 @@
this.mnuScale2x = new System.Windows.Forms.ToolStripMenuItem();
this.mnuScale3x = new System.Windows.Forms.ToolStripMenuItem();
this.mnuScale4x = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem13 = new System.Windows.Forms.ToolStripSeparator();
this.mnuScaleCustom = new System.Windows.Forms.ToolStripMenuItem();
this.mnuVideoFilter = new System.Windows.Forms.ToolStripMenuItem();
this.mnuNoneFilter = new System.Windows.Forms.ToolStripMenuItem();
this.mnuNtscFilter = new System.Windows.Forms.ToolStripMenuItem();
this.mnuShowFPS = new System.Windows.Forms.ToolStripMenuItem();
this.mnuFullscreen = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem10 = new System.Windows.Forms.ToolStripSeparator();
this.mnuAudioConfig = new System.Windows.Forms.ToolStripMenuItem();
this.mnuInput = new System.Windows.Forms.ToolStripMenuItem();
@ -127,7 +136,9 @@
this.mnuAbout = new System.Windows.Forms.ToolStripMenuItem();
this.menuTimer = new System.Windows.Forms.Timer(this.components);
this.ctrlRenderer = new Mesen.GUI.Controls.ctrlRenderer();
this.panelRenderer = new System.Windows.Forms.Panel();
this.menuStrip.SuspendLayout();
this.panelRenderer.SuspendLayout();
this.SuspendLayout();
//
// menuStrip
@ -140,9 +151,10 @@
this.mnuHelp});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(365, 24);
this.menuStrip.Size = new System.Drawing.Size(304, 24);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "menuStrip1";
this.menuStrip.VisibleChanged += new System.EventHandler(this.menuStrip_VisibleChanged);
//
// mnuFile
//
@ -286,6 +298,7 @@
this.mnuVideoScale,
this.mnuVideoFilter,
this.mnuShowFPS,
this.mnuFullscreen,
this.toolStripMenuItem10,
this.mnuAudioConfig,
this.mnuInput,
@ -391,7 +404,9 @@
this.mnuScale1x,
this.mnuScale2x,
this.mnuScale3x,
this.mnuScale4x});
this.mnuScale4x,
this.toolStripMenuItem13,
this.mnuScaleCustom});
this.mnuVideoScale.Image = global::Mesen.GUI.Properties.Resources.slideshow_full_screen;
this.mnuVideoScale.Name = "mnuVideoScale";
this.mnuVideoScale.Size = new System.Drawing.Size(163, 22);
@ -400,7 +415,7 @@
// mnuScale1x
//
this.mnuScale1x.Name = "mnuScale1x";
this.mnuScale1x.Size = new System.Drawing.Size(85, 22);
this.mnuScale1x.Size = new System.Drawing.Size(116, 22);
this.mnuScale1x.Tag = "1";
this.mnuScale1x.Text = "1x";
this.mnuScale1x.Click += new System.EventHandler(this.mnuScale_Click);
@ -408,7 +423,7 @@
// mnuScale2x
//
this.mnuScale2x.Name = "mnuScale2x";
this.mnuScale2x.Size = new System.Drawing.Size(85, 22);
this.mnuScale2x.Size = new System.Drawing.Size(116, 22);
this.mnuScale2x.Tag = "2";
this.mnuScale2x.Text = "2x";
this.mnuScale2x.Click += new System.EventHandler(this.mnuScale_Click);
@ -416,7 +431,7 @@
// mnuScale3x
//
this.mnuScale3x.Name = "mnuScale3x";
this.mnuScale3x.Size = new System.Drawing.Size(85, 22);
this.mnuScale3x.Size = new System.Drawing.Size(116, 22);
this.mnuScale3x.Tag = "3";
this.mnuScale3x.Text = "3x";
this.mnuScale3x.Click += new System.EventHandler(this.mnuScale_Click);
@ -424,11 +439,23 @@
// mnuScale4x
//
this.mnuScale4x.Name = "mnuScale4x";
this.mnuScale4x.Size = new System.Drawing.Size(85, 22);
this.mnuScale4x.Size = new System.Drawing.Size(116, 22);
this.mnuScale4x.Tag = "4";
this.mnuScale4x.Text = "4x";
this.mnuScale4x.Click += new System.EventHandler(this.mnuScale_Click);
//
// toolStripMenuItem13
//
this.toolStripMenuItem13.Name = "toolStripMenuItem13";
this.toolStripMenuItem13.Size = new System.Drawing.Size(113, 6);
//
// mnuScaleCustom
//
this.mnuScaleCustom.Name = "mnuScaleCustom";
this.mnuScaleCustom.Size = new System.Drawing.Size(116, 22);
this.mnuScaleCustom.Text = "Custom";
this.mnuScaleCustom.Click += new System.EventHandler(this.mnuScaleCustom_Click);
//
// mnuVideoFilter
//
this.mnuVideoFilter.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -461,6 +488,14 @@
this.mnuShowFPS.Text = "Show FPS";
this.mnuShowFPS.Click += new System.EventHandler(this.mnuShowFPS_Click);
//
// mnuFullscreen
//
this.mnuFullscreen.Name = "mnuFullscreen";
this.mnuFullscreen.ShortcutKeys = System.Windows.Forms.Keys.F11;
this.mnuFullscreen.Size = new System.Drawing.Size(163, 22);
this.mnuFullscreen.Text = "Fullscreen";
this.mnuFullscreen.Click += new System.EventHandler(this.mnuFullscreen_Click);
//
// toolStripMenuItem10
//
this.toolStripMenuItem10.Name = "toolStripMenuItem10";
@ -602,40 +637,40 @@
// mnuNetPlayPlayer1
//
this.mnuNetPlayPlayer1.Name = "mnuNetPlayPlayer1";
this.mnuNetPlayPlayer1.Size = new System.Drawing.Size(152, 22);
this.mnuNetPlayPlayer1.Size = new System.Drawing.Size(124, 22);
this.mnuNetPlayPlayer1.Text = "Player 1";
this.mnuNetPlayPlayer1.Click += new System.EventHandler(this.mnuNetPlayPlayer1_Click);
//
// mnuNetPlayPlayer2
//
this.mnuNetPlayPlayer2.Name = "mnuNetPlayPlayer2";
this.mnuNetPlayPlayer2.Size = new System.Drawing.Size(152, 22);
this.mnuNetPlayPlayer2.Size = new System.Drawing.Size(124, 22);
this.mnuNetPlayPlayer2.Text = "Player 2";
this.mnuNetPlayPlayer2.Click += new System.EventHandler(this.mnuNetPlayPlayer2_Click);
//
// mnuNetPlayPlayer3
//
this.mnuNetPlayPlayer3.Name = "mnuNetPlayPlayer3";
this.mnuNetPlayPlayer3.Size = new System.Drawing.Size(152, 22);
this.mnuNetPlayPlayer3.Size = new System.Drawing.Size(124, 22);
this.mnuNetPlayPlayer3.Text = "Player 3";
this.mnuNetPlayPlayer3.Click += new System.EventHandler(this.mnuNetPlayPlayer3_Click);
//
// mnuNetPlayPlayer4
//
this.mnuNetPlayPlayer4.Name = "mnuNetPlayPlayer4";
this.mnuNetPlayPlayer4.Size = new System.Drawing.Size(152, 22);
this.mnuNetPlayPlayer4.Size = new System.Drawing.Size(124, 22);
this.mnuNetPlayPlayer4.Text = "Player 4";
this.mnuNetPlayPlayer4.Click += new System.EventHandler(this.mnuNetPlayPlayer4_Click);
//
// toolStripMenuItem3
//
this.toolStripMenuItem3.Name = "toolStripMenuItem3";
this.toolStripMenuItem3.Size = new System.Drawing.Size(149, 6);
this.toolStripMenuItem3.Size = new System.Drawing.Size(121, 6);
//
// mnuNetPlaySpectator
//
this.mnuNetPlaySpectator.Name = "mnuNetPlaySpectator";
this.mnuNetPlaySpectator.Size = new System.Drawing.Size(152, 22);
this.mnuNetPlaySpectator.Size = new System.Drawing.Size(124, 22);
this.mnuNetPlaySpectator.Text = "Spectator";
this.mnuNetPlaySpectator.Click += new System.EventHandler(this.mnuNetPlaySpectator_Click);
//
@ -851,30 +886,43 @@
// ctrlRenderer
//
this.ctrlRenderer.BackColor = System.Drawing.Color.Black;
this.ctrlRenderer.Location = new System.Drawing.Point(0, 24);
this.ctrlRenderer.Location = new System.Drawing.Point(0, 0);
this.ctrlRenderer.Margin = new System.Windows.Forms.Padding(0);
this.ctrlRenderer.Name = "ctrlRenderer";
this.ctrlRenderer.Size = new System.Drawing.Size(263, 176);
this.ctrlRenderer.TabIndex = 1;
this.ctrlRenderer.Enter += new System.EventHandler(this.ctrlRenderer_Enter);
//
// panelRenderer
//
this.panelRenderer.BackColor = System.Drawing.Color.Black;
this.panelRenderer.Controls.Add(this.ctrlRenderer);
this.panelRenderer.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelRenderer.Location = new System.Drawing.Point(0, 24);
this.panelRenderer.Name = "panelRenderer";
this.panelRenderer.Size = new System.Drawing.Size(304, 218);
this.panelRenderer.TabIndex = 2;
this.panelRenderer.Click += new System.EventHandler(this.panelRenderer_Click);
//
// frmMain
//
this.AllowDrop = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(365, 272);
this.Controls.Add(this.ctrlRenderer);
this.BackColor = System.Drawing.Color.Maroon;
this.ClientSize = new System.Drawing.Size(304, 242);
this.Controls.Add(this.panelRenderer);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.MinimumSize = new System.Drawing.Size(320, 280);
this.Name = "frmMain";
this.Text = "Mesen";
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.frmMain_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.frmMain_DragEnter);
this.Resize += new System.EventHandler(this.frmMain_Resize);
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.panelRenderer.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -972,6 +1020,10 @@
private System.Windows.Forms.ToolStripMenuItem mnuNetPlayPlayer4;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3;
private System.Windows.Forms.ToolStripMenuItem mnuNetPlaySpectator;
private System.Windows.Forms.Panel panelRenderer;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem13;
private System.Windows.Forms.ToolStripMenuItem mnuScaleCustom;
private System.Windows.Forms.ToolStripMenuItem mnuFullscreen;
}
}

View file

@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@ -26,7 +22,10 @@ namespace Mesen.GUI.Forms
private frmDebugger _debugger;
private string _romToLoad = null;
private string _currentGame = null;
private bool _customSize = false;
private bool _fullscreenMode = false;
private double _regularScale = ConfigManager.Config.VideoInfo.VideoScale;
public frmMain(string[] args)
{
if(args.Length > 0 && File.Exists(args[0])) {
@ -63,6 +62,8 @@ namespace Mesen.GUI.Forms
UpdateMenus();
UpdateRecentFiles();
UpdateViewerSize();
if(_romToLoad != null) {
LoadFile(this._romToLoad);
}
@ -172,19 +173,61 @@ namespace Mesen.GUI.Forms
UpdateScaleMenu(ConfigManager.Config.VideoInfo.VideoScale);
UpdateFilterMenu(ConfigManager.Config.VideoInfo.VideoFilter);
UpdateViewerSize();
UpdateViewerSize();
}
private void UpdateViewerSize()
{
InteropEmu.ScreenSize size = InteropEmu.GetScreenSize();
switch(ConfigManager.Config.VideoInfo.AspectRatio) {
case VideoAspectRatio.NTSC: size.Width = (int)(size.Height * 8 / 7.0); break;
case VideoAspectRatio.PAL: size.Width = (int)(size.Height * 18 / 13.0); break;
case VideoAspectRatio.Standard: size.Width = (int)(size.Height * 4 / 3.0); break;
case VideoAspectRatio.Widescreen: size.Width = (int)(size.Height * 16 / 9.0); break;
InteropEmu.ScreenSize size = InteropEmu.GetScreenSize(false);
if(!_customSize && this.WindowState != FormWindowState.Maximized) {
this.Resize -= frmMain_Resize;
this.ClientSize = new Size(size.Width, size.Height + menuStrip.Height);
this.Resize += frmMain_Resize;
}
ctrlRenderer.Size = new Size(size.Width, size.Height);
ctrlRenderer.Left = (panelRenderer.Width - ctrlRenderer.Width) / 2;
ctrlRenderer.Top = (panelRenderer.Height - ctrlRenderer.Height) / 2;
}
private void frmMain_Resize(object sender, EventArgs e)
{
if(this.WindowState != FormWindowState.Minimized) {
SetScaleBasedOnWindowSize();
}
}
private void SetScaleBasedOnWindowSize()
{
_customSize = true;
InteropEmu.ScreenSize size = InteropEmu.GetScreenSize(true);
double verticalScale = (double)panelRenderer.ClientSize.Height / size.Height;
double horizontalScale = (double)panelRenderer.ClientSize.Width / size.Width;
double scale = Math.Min(verticalScale, horizontalScale);
UpdateScaleMenu(scale);
VideoInfo.ApplyConfig();
}
private void SetFullscreenState(bool enabled)
{
this.Resize -= frmMain_Resize;
if(enabled) {
this.menuStrip.Visible = false;
this.WindowState = FormWindowState.Normal;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
SetScaleBasedOnWindowSize();
} else {
this.menuStrip.Visible = true;
this.WindowState = FormWindowState.Normal;
this.FormBorderStyle = FormBorderStyle.Sizable;
this.UpdateScaleMenu(_regularScale);
VideoInfo.ApplyConfig();
}
this.Resize += frmMain_Resize;
_fullscreenMode = enabled;
}
private void _notifListener_OnNotification(InteropEmu.NotificationEventArgs e)
@ -446,7 +489,7 @@ namespace Mesen.GUI.Forms
{
InteropEmu.Reset();
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(!this.menuStrip.Enabled) {
@ -454,6 +497,15 @@ namespace Mesen.GUI.Forms
return false;
}
if(_fullscreenMode && (keyData & Keys.Alt) == Keys.Alt) {
if(this.menuStrip.Visible && !this.menuStrip.ContainsFocus) {
this.menuStrip.Visible = false;
} else {
this.menuStrip.Visible = true;
this.menuStrip.Focus();
}
}
if(keyData == Keys.Escape && _emuThread != null && mnuPause.Enabled) {
PauseEmu();
return true;
@ -788,12 +840,13 @@ namespace Mesen.GUI.Forms
Process.Start(startInfo);
}
private void UpdateScaleMenu(UInt32 scale)
private void UpdateScaleMenu(double scale)
{
mnuScale1x.Checked = (scale == 1);
mnuScale2x.Checked = (scale == 2);
mnuScale3x.Checked = (scale == 3);
mnuScale4x.Checked = (scale == 4);
mnuScale1x.Checked = (scale == 1.0) && !_customSize;
mnuScale2x.Checked = (scale == 2.0) && !_customSize;
mnuScale3x.Checked = (scale == 3.0) && !_customSize;
mnuScale4x.Checked = (scale == 4.0) && !_customSize;
mnuScaleCustom.Checked = _customSize || !mnuScale1x.Checked && !mnuScale2x.Checked && !mnuScale3x.Checked && !mnuScale4x.Checked;
ConfigManager.Config.VideoInfo.VideoScale = scale;
ConfigManager.ApplyChanges();
@ -811,8 +864,9 @@ namespace Mesen.GUI.Forms
private void mnuScale_Click(object sender, EventArgs e)
{
UInt32 scale = UInt32.Parse((string)((ToolStripMenuItem)sender).Tag);
_customSize = false;
_regularScale = scale;
InteropEmu.SetVideoScale(scale);
UpdateScaleMenu(scale);
}
@ -820,12 +874,14 @@ namespace Mesen.GUI.Forms
{
InteropEmu.SetVideoFilter(VideoFilterType.None);
UpdateFilterMenu(VideoFilterType.None);
_customSize = false;
}
private void mnuNtscFilter_Click(object sender, EventArgs e)
{
InteropEmu.SetVideoFilter(VideoFilterType.NTSC);
UpdateFilterMenu(VideoFilterType.NTSC);
_customSize = false;
}
private void InitializeFdsDiskMenu()
@ -923,5 +979,38 @@ namespace Mesen.GUI.Forms
{
InteropEmu.NetPlaySelectController(0xFF);
}
private void mnuFullscreen_Click(object sender, EventArgs e)
{
SetFullscreenState(!_fullscreenMode);
mnuFullscreen.Checked = _fullscreenMode;
}
private void mnuScaleCustom_Click(object sender, EventArgs e)
{
SetScaleBasedOnWindowSize();
}
private void panelRenderer_Click(object sender, EventArgs e)
{
ctrlRenderer.Focus();
}
private void ctrlRenderer_Enter(object sender, EventArgs e)
{
if(_fullscreenMode) {
this.menuStrip.Visible = false;
}
}
private void menuStrip_VisibleChanged(object sender, EventArgs e)
{
IntPtr handle = this.Handle;
this.BeginInvoke((MethodInvoker)(() => {
if(_fullscreenMode && _customSize) {
SetScaleBasedOnWindowSize();
}
}));
}
}
}

View file

@ -98,12 +98,13 @@ namespace Mesen.GUI
[DllImport(DLLPath)] public static extern void SetNesModel(NesModel model);
[DllImport(DLLPath)] public static extern void SetEmulationSpeed(UInt32 emulationSpeed);
[DllImport(DLLPath)] public static extern void SetOverscanDimensions(UInt32 left, UInt32 right, UInt32 top, UInt32 bottom);
[DllImport(DLLPath)] public static extern void SetVideoScale(UInt32 scale);
[DllImport(DLLPath)] public static extern void SetVideoScale(double scale);
[DllImport(DLLPath)] public static extern void SetVideoAspectRatio(VideoAspectRatio aspectRatio);
[DllImport(DLLPath)] public static extern void SetVideoFilter(VideoFilterType filter);
[DllImport(DLLPath)] public static extern void SetRgbPalette(Int32[] palette);
[DllImport(DLLPath, EntryPoint="GetRgbPalette")] private static extern void GetRgbPaletteWrapper(IntPtr paletteBuffer);
[DllImport(DLLPath, EntryPoint="GetScreenSize")] private static extern void GetScreenSizeWrapper(out ScreenSize size);
[DllImport(DLLPath, EntryPoint="GetScreenSize")] private static extern void GetScreenSizeWrapper(out ScreenSize size, [MarshalAs(UnmanagedType.I1)]bool ignoreScale);
[DllImport(DLLPath, EntryPoint= "GetAudioDevices")] private static extern IntPtr GetAudioDevicesWrapper();
[DllImport(DLLPath)] public static extern void SetAudioDevice(string audioDevice);
@ -226,10 +227,10 @@ namespace Mesen.GUI
}
}
public static ScreenSize GetScreenSize()
public static ScreenSize GetScreenSize(bool ignoreScale)
{
ScreenSize size;
GetScreenSizeWrapper(out size);
GetScreenSizeWrapper(out size, ignoreScale);
return size;
}

View file

@ -251,7 +251,8 @@ namespace InteropEmu {
DllExport void __stdcall SetNesModel(uint32_t model) { EmulationSettings::SetNesModel((NesModel)model); }
DllExport void __stdcall SetOverscanDimensions(uint32_t left, uint32_t right, uint32_t top, uint32_t bottom) { EmulationSettings::SetOverscanDimensions(left, right, top, bottom); }
DllExport void __stdcall SetEmulationSpeed(uint32_t emulationSpeed) { EmulationSettings::SetEmulationSpeed(emulationSpeed); }
DllExport void __stdcall SetVideoScale(uint32_t scale) { EmulationSettings::SetVideoScale(scale); }
DllExport void __stdcall SetVideoScale(double scale) { EmulationSettings::SetVideoScale(scale); }
DllExport void __stdcall SetVideoAspectRatio(VideoAspectRatio aspectRatio) { EmulationSettings::SetVideoAspectRatio(aspectRatio); }
DllExport void __stdcall SetVideoFilter(VideoFilterType filter) { EmulationSettings::SetVideoFilterType(filter); }
DllExport void __stdcall GetRgbPalette(uint32_t *paletteBuffer) { EmulationSettings::GetRgbPalette(paletteBuffer); }
DllExport void __stdcall SetRgbPalette(uint32_t *paletteBuffer) { EmulationSettings::SetRgbPalette(paletteBuffer); }
@ -264,7 +265,7 @@ namespace InteropEmu {
DllExport void __stdcall SetAudioDevice(char* audioDevice) { _soundManager->SetAudioDevice(audioDevice); }
DllExport void __stdcall GetScreenSize(ScreenSize &size) { VideoDecoder::GetInstance()->GetScreenSize(size); }
DllExport void __stdcall GetScreenSize(ScreenSize &size, bool ignoreScale) { VideoDecoder::GetInstance()->GetScreenSize(size, ignoreScale); }
//FDS functions
DllExport uint32_t __stdcall FdsGetSideCount() { return FDS::GetSideCount(); }

View file

@ -34,15 +34,19 @@ namespace NES
void Renderer::SetScreenSize(uint32_t width, uint32_t height)
{
uint32_t scale = EmulationSettings::GetVideoScale();
double scale = EmulationSettings::GetVideoScale();
if(_screenHeight != height*scale || _screenWidth != width*scale) {
ScreenSize screenSize;
VideoDecoder::GetInstance()->GetScreenSize(screenSize, false);
if(_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height || _nesFrameWidth != width) {
_nesFrameHeight = height;
_nesFrameWidth = width;
_newFrameBufferSize = width*height;
_screenHeight = height * scale;
_screenWidth = width * scale;
_screenHeight = screenSize.Height;
_screenWidth = screenSize.Width;
_screenBufferSize = _screenHeight*_screenWidth;
Reset();