void SetFormPosSize() { if (IsFullscreen || mpv.VideoSize.Width == 0) { return; } var wa = Screen.GetWorkingArea(this); int h = (int)(wa.Height * 0.6); int w = (int)(h * mpv.VideoSize.Width / (float)mpv.VideoSize.Height); Point middlePos = new Point(Left + Width / 2, Top + Height / 2); var r = new Native.RECT(new Rectangle(0, 0, w, h)); NativeHelp.AddWindowBorders(Handle, ref r); int l = middlePos.X - r.Width / 2; int t = middlePos.Y - r.Height / 2; if (l < 0) { l = 0; } if (t < 0) { t = 0; } if (l + r.Width > wa.Width) { l = wa.Width - r.Width; } if (t + r.Height > wa.Height) { t = wa.Height - r.Height; } Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, l, t, r.Width, r.Height, 4 /* SWP_NOZORDER */); }
void SetFormPositionAndSizeKeepHeight() { if (IsFullscreen || mp.VideoSize.Width == 0) { return; } Screen screen = Screen.FromControl(this); int height = ClientSize.Height; int width = Convert.ToInt32(height * mp.VideoSize.Width / (double)mp.VideoSize.Height); Point middlePos = new Point(Left + Width / 2, Top + Height / 2); var rect = new Native.RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height)); NativeHelp.AddWindowBorders(Handle, ref rect); int left = middlePos.X - rect.Width / 2; int top = middlePos.Y - rect.Height / 2; Screen[] screens = Screen.AllScreens; if (left < screens[0].Bounds.Left) { left = screens[0].Bounds.Left; } int maxLeft = screens[0].Bounds.Left + screens.Select((sc) => sc.Bounds.Width).Sum() - rect.Width - SystemInformation.CaptionHeight; if (left > maxLeft) { left = maxLeft; } Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */); }
void SetStartFormPositionAndSize() { if (IsFullscreen || mp.VideoSize.Width == 0) { return; } Screen screen = Screen.FromControl(this); int height = Convert.ToInt32(screen.Bounds.Height * 0.6); int width = Convert.ToInt32(height * mp.VideoSize.Width / (double)mp.VideoSize.Height); Point middlePos = new Point(Left + Width / 2, Top + Height / 2); var rect = new Native.RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height)); NativeHelp.AddWindowBorders(Handle, ref rect); int left = middlePos.X - rect.Width / 2; int top = middlePos.Y - rect.Height / 2; Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */); }
void SetFormPosAndSize() { if (WindowState == FormWindowState.Maximized) { return; } if (mp.Fullscreen) { CycleFullscreen(true); return; } Screen screen = Screen.FromControl(this); int autoFitHeight = Convert.ToInt32(screen.WorkingArea.Height * mp.Autofit); if (mp.VideoSize.Height == 0 || mp.VideoSize.Width == 0 || mp.VideoSize.Width / (float)mp.VideoSize.Height < App.MinimumAspectRatio) { mp.VideoSize = new Size((int)(autoFitHeight * (16 / 9.0)), autoFitHeight); } Size size = mp.VideoSize; int height = size.Height; if (App.RememberHeight) { if (WasInitialSizeSet) { height = ClientSize.Height; } else { height = autoFitHeight; WasInitialSizeSet = true; } } int width = Convert.ToInt32(height * size.Width / (double)size.Height); if (height > screen.WorkingArea.Height * 0.9) { height = Convert.ToInt32(screen.WorkingArea.Height * 0.9); width = Convert.ToInt32(height * size.Width / (double)size.Height); } if (width > screen.WorkingArea.Width * 0.9) { width = Convert.ToInt32(screen.WorkingArea.Width * 0.9); height = Convert.ToInt32(width * size.Height / (double)size.Width); } if (height < screen.WorkingArea.Height * mp.AutofitSmaller) { height = Convert.ToInt32(screen.WorkingArea.Height * mp.AutofitSmaller); width = Convert.ToInt32(height * size.Width / (double)size.Height); } if (height > screen.WorkingArea.Height * mp.AutofitLarger) { height = Convert.ToInt32(screen.WorkingArea.Height * mp.AutofitLarger); width = Convert.ToInt32(height * size.Width / (double)size.Height); } Point middlePos = new Point(Left + Width / 2, Top + Height / 2); var rect = new Native.RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height)); NativeHelp.AddWindowBorders(Handle, ref rect); int left = middlePos.X - rect.Width / 2; int top = middlePos.Y - rect.Height / 2; Screen[] screens = Screen.AllScreens; int minLeft = screens.Select(val => val.WorkingArea.X).Min(); int maxRight = screens.Select(val => val.WorkingArea.Right).Max(); int minTop = screens.Select(val => val.WorkingArea.Y).Min(); int maxBottom = screens.Select(val => val.WorkingArea.Bottom).Max(); if (left < minLeft) { left = minLeft; } if (left + rect.Width > maxRight) { left = maxRight - rect.Width; } if (top < minTop) { top = minTop; } if (top + rect.Height > maxBottom) { top = maxBottom - rect.Height; } Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */); }
void SetFormPosAndSize(double scale = 1, bool force = false) { if (!force) { if (WindowState != FormWindowState.Normal) { return; } if (core.Fullscreen) { CycleFullscreen(true); return; } } Screen screen = Screen.FromControl(this); int autoFitHeight = Convert.ToInt32(screen.WorkingArea.Height * core.Autofit); if (core.VideoSize.Height == 0 || core.VideoSize.Width == 0 || core.VideoSize.Width / (float)core.VideoSize.Height < App.MinimumAspectRatio) { core.VideoSize = new Size((int)(autoFitHeight * (16 / 9f)), autoFitHeight); } Size videoSize = core.VideoSize; int height = videoSize.Height; if (core.WasInitialSizeSet || scale != 1) { height = ClientSize.Height; } else { int savedHeight = RegistryHelp.GetInt(App.RegPath, "Height"); if (App.StartSize == "always" && savedHeight != 0) { height = savedHeight; } else if (App.StartSize != "video") { height = autoFitHeight; } core.WasInitialSizeSet = true; } height = Convert.ToInt32(height * scale); int width = height * videoSize.Width / videoSize.Height; int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height); int maxWidth = screen.WorkingArea.Width - (Width - ClientSize.Width); if (height < maxHeight * core.AutofitSmaller) { height = Convert.ToInt32(maxHeight * core.AutofitSmaller); width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); } if (height > maxHeight * core.AutofitLarger) { height = Convert.ToInt32(maxHeight * core.AutofitLarger); width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); } if (width > maxWidth) { width = maxWidth; height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width); } Point middlePos = new Point(Left + Width / 2, Top + Height / 2); var rect = new WinAPI.RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height)); NativeHelp.AddWindowBorders(Handle, ref rect); int left = middlePos.X - rect.Width / 2; int top = middlePos.Y - rect.Height / 2; Screen[] screens = Screen.AllScreens; int minLeft = screens.Select(val => val.WorkingArea.X).Min(); int maxRight = screens.Select(val => val.WorkingArea.Right).Max(); int minTop = screens.Select(val => val.WorkingArea.Y).Min(); int maxBottom = screens.Select(val => val.WorkingArea.Bottom).Max(); if (left < minLeft) { left = minLeft; } if (left + rect.Width > maxRight) { left = maxRight - rect.Width; } if (top < minTop) { top = minTop; } if (top + rect.Height > maxBottom) { top = maxBottom - rect.Height; } WinAPI.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */); }
void SetSize(Size size, Size videoSize, Screen screen, bool checkAutofitSmaller = true, bool checkAutofitLarger = true) { int height = size.Height; int width = size.Height * videoSize.Width / videoSize.Height; int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height); int maxWidth = screen.WorkingArea.Width - (Width - ClientSize.Width); if (checkAutofitSmaller && (height < maxHeight * core.AutofitSmaller)) { height = Convert.ToInt32(maxHeight * core.AutofitSmaller); width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); } float autofitLarger = checkAutofitLarger ? core.AutofitLarger : 1; if (height > maxHeight * autofitLarger) { height = Convert.ToInt32(maxHeight * autofitLarger); width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); } if (width > maxWidth) { width = maxWidth; height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width); } Point middlePos = new Point(Left + Width / 2, Top + Height / 2); var rect = new RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height)); NativeHelp.AddWindowBorders(Handle, ref rect); int left = middlePos.X - rect.Width / 2; int top = middlePos.Y - rect.Height / 2; Screen[] screens = Screen.AllScreens; int minLeft = screens.Select(val => val.WorkingArea.X).Min(); int maxRight = screens.Select(val => val.WorkingArea.Right).Max(); int minTop = screens.Select(val => val.WorkingArea.Y).Min(); int maxBottom = screens.Select(val => val.WorkingArea.Bottom).Max(); if (left < minLeft) { left = minLeft; } if (left + rect.Width > maxRight) { left = maxRight - rect.Width; } if (top < minTop) { top = minTop; } if (top + rect.Height > maxBottom) { top = maxBottom - rect.Height; } SetWindowPos(Handle, IntPtr.Zero, left, top, rect.Width, rect.Height, 4); }