From b63c1f9c4e61031de4576c0723357c1eb55e56b8 Mon Sep 17 00:00:00 2001 From: Souryo Date: Thu, 22 Dec 2016 23:08:34 -0500 Subject: [PATCH] UI: Improve/simplify resizing logic --- Core/BaseVideoFilter.cpp | 2 -- Core/EmulationSettings.h | 8 ++++---- Core/VideoDecoder.cpp | 10 +++++++++- Core/VideoDecoder.h | 5 +++++ GUI.NET/Forms/frmMain.cs | 36 ++++++++++++------------------------ GUI.NET/InteropEmu.cs | 1 + 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Core/BaseVideoFilter.cpp b/Core/BaseVideoFilter.cpp index 27d6513a..bf177506 100644 --- a/Core/BaseVideoFilter.cpp +++ b/Core/BaseVideoFilter.cpp @@ -32,8 +32,6 @@ void BaseVideoFilter::UpdateBufferSize() _bufferSize = newBufferSize; _outputBuffer = new uint8_t[newBufferSize]; _frameLock.Release(); - - MessageManager::SendNotification(ConsoleNotificationType::ResolutionChanged); } } diff --git a/Core/EmulationSettings.h b/Core/EmulationSettings.h index 4eff9d91..8480ba89 100644 --- a/Core/EmulationSettings.h +++ b/Core/EmulationSettings.h @@ -635,7 +635,6 @@ public: _overscan.Right = right; _overscan.Top = top; _overscan.Bottom = bottom; - MessageManager::SendNotification(ConsoleNotificationType::ResolutionChanged); } } @@ -666,7 +665,10 @@ public: static void SetVideoFilterType(VideoFilterType videoFilterType) { - _videoFilterType = videoFilterType; + if(_videoFilterType != videoFilterType) { + _videoScale = videoFilterType == VideoFilterType::None ? 2.0 : 1.0; + _videoFilterType = videoFilterType; + } } static VideoFilterType GetVideoFilterType() @@ -688,7 +690,6 @@ public: { if(_aspectRatio != aspectRatio) { _aspectRatio = aspectRatio; - MessageManager::SendNotification(ConsoleNotificationType::ResolutionChanged); } } @@ -753,7 +754,6 @@ public: { if(_videoScale != scale) { _videoScale = scale; - MessageManager::SendNotification(ConsoleNotificationType::ResolutionChanged); } } diff --git a/Core/VideoDecoder.cpp b/Core/VideoDecoder.cpp index 19bce8c9..8f495b33 100644 --- a/Core/VideoDecoder.cpp +++ b/Core/VideoDecoder.cpp @@ -41,6 +41,7 @@ void VideoDecoder::GetScreenSize(ScreenSize &size, bool ignoreScale) if(aspectRatio != 0.0) { size.Width = (uint32_t)(frameInfo.OriginalHeight * scale * aspectRatio * ((double)frameInfo.Width / frameInfo.OriginalWidth)); } + size.Scale = scale; } } @@ -90,9 +91,16 @@ void VideoDecoder::DecodeFrame() } _videoFilter->SendFrame(_ppuOutputBuffer); + FrameInfo frameInfo = _videoFilter->GetFrameInfo(); + if(_previousScale != EmulationSettings::GetVideoScale() || frameInfo.Height != _previousFrameInfo.Height || frameInfo.Width != _previousFrameInfo.Width) { + MessageManager::SendNotification(ConsoleNotificationType::ResolutionChanged); + } + _previousScale = EmulationSettings::GetVideoScale(); + _previousFrameInfo = frameInfo; + _frameChanged = false; - VideoRenderer::GetInstance()->UpdateFrame(_videoFilter->GetOutputBuffer(), _videoFilter->GetFrameInfo().Width, _videoFilter->GetFrameInfo().Height); + VideoRenderer::GetInstance()->UpdateFrame(_videoFilter->GetOutputBuffer(), frameInfo.Width, frameInfo.Height); } void VideoDecoder::DebugDecodeFrame(uint16_t* inputBuffer, uint32_t* outputBuffer, uint32_t length) diff --git a/Core/VideoDecoder.h b/Core/VideoDecoder.h index 4b521a06..6088b9ec 100644 --- a/Core/VideoDecoder.h +++ b/Core/VideoDecoder.h @@ -7,6 +7,7 @@ using std::thread; #include "../Utilities/AutoResetEvent.h" #include "EmulationSettings.h" #include "HdNesPack.h" +#include "FrameInfo.h" class BaseVideoFilter; class IRenderingDevice; @@ -15,6 +16,7 @@ struct ScreenSize { int32_t Width; int32_t Height; + double Scale; }; class VideoDecoder @@ -33,6 +35,9 @@ private: atomic _stopFlag; uint32_t _frameCount = 0; + FrameInfo _previousFrameInfo = {}; + double _previousScale = 0; + VideoFilterType _videoFilterType = VideoFilterType::None; unique_ptr _videoFilter; diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index bc7aab47..1c5dc260 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -34,7 +34,6 @@ namespace Mesen.GUI.Forms private FormWindowState _originalWindowState; private bool _fullscreenMode = false; private double _regularScale = ConfigManager.Config.VideoInfo.VideoScale; - private bool _needScaleUpdate = false; private bool _isNsfPlayerMode = false; private object _loadRomLock = new object(); private int _romLoadCounter = 0; @@ -295,17 +294,6 @@ namespace Mesen.GUI.Forms private void UpdateVideoSettings() { - if(_needScaleUpdate) { - //Reset scale to 1 when filter is changed - if(this.WindowState == FormWindowState.Maximized || mnuNoneFilter.Checked) { - SetScaleBasedOnWindowSize(); - } else { - SetScale(1); - } - _regularScale = 1; - _needScaleUpdate = false; - } - mnuShowFPS.Checked = ConfigManager.Config.VideoInfo.ShowFPS; mnuBilinearInterpolation.Checked = ConfigManager.Config.VideoInfo.UseBilinearInterpolation; UpdateScaleMenu(ConfigManager.Config.VideoInfo.VideoScale); @@ -324,11 +312,13 @@ namespace Mesen.GUI.Forms } else { if(!_customSize && this.WindowState != FormWindowState.Maximized) { Size sizeGap = this.Size - this.ClientSize; + + _regularScale = size.Scale; + UpdateScaleMenu(size.Scale); + this.Resize -= frmMain_Resize; this.ClientSize = new Size(Math.Max(this.MinimumSize.Width - sizeGap.Width, size.Width), Math.Max(this.MinimumSize.Height - sizeGap.Height, size.Height + menuStrip.Height)); this.Resize += frmMain_Resize; - } else { - SetScaleBasedOnWindowSize(); } ctrlRenderer.Size = new Size(size.Width, size.Height); @@ -374,7 +364,6 @@ namespace Mesen.GUI.Forms this.SetScale(_regularScale); this.UpdateScaleMenu(_regularScale); VideoInfo.ApplyConfig(); - UpdateViewerSize(); } this.Resize += frmMain_Resize; @@ -431,7 +420,7 @@ namespace Mesen.GUI.Forms case InteropEmu.ConsoleNotificationType.ResolutionChanged: this.BeginInvoke((MethodInvoker)(() => { - UpdateVideoSettings(); + UpdateViewerSize(); })); break; @@ -1196,10 +1185,9 @@ namespace Mesen.GUI.Forms private void SetVideoFilter(VideoFilterType type) { + _customSize = false; InteropEmu.SetVideoFilter(type); UpdateFilterMenu(type); - - _needScaleUpdate = true; } private void mnuNoneFilter_Click(object sender, EventArgs e) @@ -1430,12 +1418,12 @@ namespace Mesen.GUI.Forms private void menuStrip_VisibleChanged(object sender, EventArgs e) { - IntPtr handle = this.Handle; - this.BeginInvoke((MethodInvoker)(() => { - if(_fullscreenMode && _customSize) { - SetScaleBasedOnWindowSize(); - } - })); + if(_fullscreenMode) { + IntPtr handle = this.Handle; + this.BeginInvoke((MethodInvoker)(() => { + this.ctrlRenderer.Top = this.menuStrip.Visible ? -menuStrip.Height : 0; + })); + } } private void mnuAbout_Click(object sender, EventArgs e) diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index 1371bb67..3d08f114 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -563,6 +563,7 @@ namespace Mesen.GUI { public Int32 Width; public Int32 Height; + public double Scale; } public enum InputDisplayPosition