mainform: fix the bug where choosing a small size from the menu (typically 1x) would cause unexpected black bars

This commit is contained in:
goyuken 2012-09-30 14:18:21 +00:00
parent 40d86d0a8b
commit 89cf8e75fe
1 changed files with 27 additions and 23 deletions

View File

@ -2687,33 +2687,37 @@ namespace BizHawk.MultiClient
public void FrameBufferResized() public void FrameBufferResized()
{ {
var video = Global.Emulator.VideoProvider; // run this entire thing exactly twice, since the first resize may adjust the menu stacking
int zoom = Global.Config.TargetZoomFactor; for (int i = 0; i < 2; i++)
var area = Screen.FromControl(this).WorkingArea;
int borderWidth = Size.Width - renderTarget.Size.Width;
int borderHeight = Size.Height - renderTarget.Size.Height;
// start at target zoom and work way down until we find acceptable zoom
for (; zoom >= 1; zoom--)
{ {
if ((((video.BufferWidth * zoom) + borderWidth) < area.Width) && (((video.BufferHeight * zoom) + borderHeight) < area.Height)) var video = Global.Emulator.VideoProvider;
break; int zoom = Global.Config.TargetZoomFactor;
} var area = Screen.FromControl(this).WorkingArea;
// Change size int borderWidth = Size.Width - renderTarget.Size.Width;
Size = new Size((video.BufferWidth * zoom) + borderWidth, (video.BufferHeight * zoom + borderHeight)); int borderHeight = Size.Height - renderTarget.Size.Height;
PerformLayout();
Global.RenderPanel.Resized = true;
// Is window off the screen at this size? // start at target zoom and work way down until we find acceptable zoom
if (area.Contains(Bounds) == false) for (; zoom >= 1; zoom--)
{ {
if (Bounds.Right > area.Right) // Window is off the right edge if ((((video.BufferWidth * zoom) + borderWidth) < area.Width) && (((video.BufferHeight * zoom) + borderHeight) < area.Height))
Location = new Point(area.Right - Size.Width, Location.Y); break;
}
if (Bounds.Bottom > area.Bottom) // Window is off the bottom edge // Change size
Location = new Point(Location.X, area.Bottom - Size.Height); Size = new Size((video.BufferWidth * zoom) + borderWidth, (video.BufferHeight * zoom + borderHeight));
PerformLayout();
Global.RenderPanel.Resized = true;
// Is window off the screen at this size?
if (area.Contains(Bounds) == false)
{
if (Bounds.Right > area.Right) // Window is off the right edge
Location = new Point(area.Right - Size.Width, Location.Y);
if (Bounds.Bottom > area.Bottom) // Window is off the bottom edge
Location = new Point(Location.X, area.Bottom - Size.Height);
}
} }
} }