Fix start in window draws offscreen and wrong aspect ratio (1 Viewer)

visteon

Portal Pro
October 19, 2007
94
2
I know most people start MP full screen.

For those of us that dont its a pain that the window is often offscreen especially with the BlueTwo Wide Skin.

I have added this code in

MediaPortal.cs

This makes sure the window client area is the same aspect ratio as the skin and the window is on screen. I have tested on two systems with both BlueTwo skins and with / without resize to skin checked.

I hope a dev will pick this up, clean it up if required and add it to the code.

Best regards to all.:)

Paul

I have shown it between existing Log.Info calls to identify the section to be changed.

Log.Info("Main: Loading windowmanager");

if (splashScreen != null)
splashScreen.SetInformation("Initializing skin...");

Log.Info("Main: Resizing windowmanager");
using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")))
{
bool autosize = xmlreader.GetValueAsBool("general", "autosize", true);
if (!GUIGraphicsContext.Fullscreen)
{
int nHBorderAllowance = this.Width - this.ClientRectangle.Width;
int nVBorderAllowance = this.Height - this.ClientRectangle.Height;
float fAspectRatio = 1.0f;

if (GUIGraphicsContext.SkinSize.Height > 0)
{
fAspectRatio = (float)GUIGraphicsContext.SkinSize.Width / (float)GUIGraphicsContext.SkinSize.Height;
}

if (autosize)
{
// This will set the window size as large as possible up to the skin size, limited to the desktop size by windows ?
Size = new Size(GUIGraphicsContext.SkinSize.Width + nHBorderAllowance, GUIGraphicsContext.SkinSize.Height + nVBorderAllowance);
}
else
{
//Restore aspect ratio
Size = new Size((int)((float)(this.Height - nVBorderAllowance) * fAspectRatio) + nHBorderAllowance, this.Height);
}

if (this.Width > GUIGraphicsContext.currentScreen.WorkingArea.Width || this.Height > GUIGraphicsContext.currentScreen.WorkingArea.Height)
{
Log.Info("Main: Limiting Window Size : fAspectRatio = {0}", fAspectRatio);

//Try to fit width to working area then scale height to maintain aspect ratio
int nNewWidth = GUIGraphicsContext.currentScreen.WorkingArea.Width - nHBorderAllowance;
int nNewHeight = (int)((float)nNewWidth / fAspectRatio);

if (nNewHeight + nVBorderAllowance > GUIGraphicsContext.currentScreen.WorkingArea.Height)
{
// Height still too big
nNewHeight = GUIGraphicsContext.currentScreen.WorkingArea.Height - nVBorderAllowance;
nNewWidth = (int)((float)nNewHeight * fAspectRatio);
}
Size = new Size(nNewWidth + nHBorderAllowance, nNewHeight + nVBorderAllowance);
}
Log.Info("Main: Window Size : this.Width = {0} : Height = {1} : this.ClientRectangle.Width = {2} : Height = {3}", this.Width, this.Height, this.ClientRectangle.Width, this.ClientRectangle.Height);
//Position the window within the working area
if (this.Right > GUIGraphicsContext.currentScreen.WorkingArea.Right)
{
this.Left = GUIGraphicsContext.currentScreen.WorkingArea.Right - this.Width;
}
if (this.Left < GUIGraphicsContext.currentScreen.WorkingArea.Left)
{
this.Left = GUIGraphicsContext.currentScreen.WorkingArea.Left;
}
if (this.Bottom > GUIGraphicsContext.currentScreen.WorkingArea.Bottom)
{
this.Top = GUIGraphicsContext.currentScreen.WorkingArea.Bottom - this.Height;
}
if (this.Top < GUIGraphicsContext.currentScreen.WorkingArea.Top)
{
this.Top = GUIGraphicsContext.currentScreen.WorkingArea.Top;
}
}
else
{
GUIGraphicsContext.Load();
GUIWindowManager.OnResize();
}
}

Log.Info("Main: Initializing windowmanager");
 

Users who are viewing this thread

Top Bottom