// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using MouseJumpUI.Models.Drawing; using MouseJumpUI.Models.Screen; namespace MouseJumpUI.Models.Layout; /// /// Represents a collection of values needed for calculating the MainForm layout. /// public sealed class LayoutConfig { public LayoutConfig( RectangleInfo virtualScreenBounds, List screens, PointInfo activatedLocation, int activatedScreenIndex, int activatedScreenNumber, SizeInfo maximumFormSize, PaddingInfo formPadding, PaddingInfo previewPadding) { // make sure the virtual screen entirely contains all of the individual screen bounds ArgumentNullException.ThrowIfNull(virtualScreenBounds); ArgumentNullException.ThrowIfNull(screens); if (screens.Any(screen => !virtualScreenBounds.Contains(screen.Bounds))) { throw new ArgumentException($"'{nameof(virtualScreenBounds)}' must contain all of the screens in '{nameof(screens)}'", nameof(virtualScreenBounds)); } this.VirtualScreenBounds = virtualScreenBounds; this.Screens = new(screens.ToList()); this.ActivatedLocation = activatedLocation; this.ActivatedScreenIndex = activatedScreenIndex; this.ActivatedScreenNumber = activatedScreenNumber; this.MaximumFormSize = maximumFormSize; this.FormPadding = formPadding; this.PreviewPadding = previewPadding; } /// /// Gets the coordinates of the entire virtual screen. /// /// /// The Virtual Screen is the bounding rectangle of all the monitors. /// https://learn.microsoft.com/en-us/windows/win32/gdi/the-virtual-screen /// public RectangleInfo VirtualScreenBounds { get; } /// /// Gets a collection containing the individual screens connected to the system. /// public ReadOnlyCollection Screens { get; } /// /// Gets the point where the cursor was located when the form was activated. /// /// /// The preview form will be centered on this location unless there are any /// constraints such as being too close to edge of a screen, in which case /// the form will be displayed centered as close as possible to this location. /// public PointInfo ActivatedLocation { get; } /// /// Gets the index of the screen the cursor was on when the form was activated. /// The value is an index into the ScreenBounds array and is 0-indexed as a result. /// public int ActivatedScreenIndex { get; } /// /// Gets the screen number the cursor was on when the form was activated. /// The value matches the screen numbering scheme in the "Display Settings" dialog /// and is 1-indexed as a result. /// public int ActivatedScreenNumber { get; } /// /// Gets the maximum size of the screen preview form. /// public SizeInfo MaximumFormSize { get; } /// /// Gets the padding border around the screen preview form. /// public PaddingInfo FormPadding { get; } /// /// Gets the padding border inside the screen preview image. /// public PaddingInfo PreviewPadding { get; } }