diff --git a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/PaddingInfo.cs b/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/PaddingInfo.cs deleted file mode 100644 index 9437bf0531e9..000000000000 --- a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/PaddingInfo.cs +++ /dev/null @@ -1,60 +0,0 @@ -// 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.Windows.Forms; - -namespace MouseJumpUI.Models.Drawing; - -/// -/// Immutable version of a System.Windows.Forms.Padding object with some extra utility methods. -/// -public sealed class PaddingInfo -{ - public PaddingInfo(decimal all) - : this(all, all, all, all) - { - } - - public PaddingInfo(decimal left, decimal top, decimal right, decimal bottom) - { - this.Left = left; - this.Top = top; - this.Right = right; - this.Bottom = bottom; - } - - public decimal Left - { - get; - } - - public decimal Top - { - get; - } - - public decimal Right - { - get; - } - - public decimal Bottom - { - get; - } - - public decimal Horizontal => this.Left + this.Right; - - public decimal Vertical => this.Top + this.Bottom; - - public override string ToString() - { - return "{" + - $"{nameof(this.Left)}={this.Left}," + - $"{nameof(this.Top)}={this.Top}," + - $"{nameof(this.Right)}={this.Right}," + - $"{nameof(this.Bottom)}={this.Bottom}" + - "}"; - } -} diff --git a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/PointInfo.cs b/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/PointInfo.cs deleted file mode 100644 index 40e452a378dc..000000000000 --- a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/PointInfo.cs +++ /dev/null @@ -1,53 +0,0 @@ -// 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.Drawing; - -namespace MouseJumpUI.Models.Drawing; - -/// -/// Immutable version of a System.Drawing.Point object with some extra utility methods. -/// -public sealed class PointInfo -{ - public PointInfo(decimal x, decimal y) - { - this.X = x; - this.Y = y; - } - - public PointInfo(Point point) - : this(point.X, point.Y) - { - } - - public decimal X - { - get; - } - - public decimal Y - { - get; - } - - public SizeInfo ToSize() - { - return new((int)this.X, (int)this.Y); - } - - public PointInfo Scale(decimal scalingFactor) => new(this.X * scalingFactor, this.Y * scalingFactor); - - public PointInfo Offset(PointInfo amount) => new(this.X + amount.X, this.Y + amount.Y); - - public Point ToPoint() => new((int)this.X, (int)this.Y); - - public override string ToString() - { - return "{" + - $"{nameof(this.X)}={this.X}," + - $"{nameof(this.Y)}={this.Y}" + - "}"; - } -} diff --git a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/RectangleInfo.cs b/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/RectangleInfo.cs deleted file mode 100644 index af46b8547080..000000000000 --- a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/RectangleInfo.cs +++ /dev/null @@ -1,131 +0,0 @@ -// 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.Drawing; - -namespace MouseJumpUI.Models.Drawing; - -/// -/// Immutable version of a System.Drawing.Rectangle object with some extra utility methods. -/// -public sealed class RectangleInfo -{ - public RectangleInfo(decimal x, decimal y, decimal width, decimal height) - { - this.X = x; - this.Y = y; - this.Width = width; - this.Height = height; - } - - public RectangleInfo(Rectangle rectangle) - : this(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height) - { - } - - public RectangleInfo(Point location, SizeInfo size) - : this(location.X, location.Y, size.Width, size.Height) - { - } - - public RectangleInfo(SizeInfo size) - : this(0, 0, size.Width, size.Height) - { - } - - public decimal X - { - get; - } - - public decimal Y - { - get; - } - - public decimal Width - { - get; - } - - public decimal Height - { - get; - } - - public decimal Left => this.X; - - public decimal Top => this.Y; - - public decimal Right => this.X + this.Width; - - public decimal Bottom => this.Y + this.Height; - - public SizeInfo Size => new(this.Width, this.Height); - - public PointInfo Location => new(this.X, this.Y); - - public decimal Area => this.Width * this.Height; - - /// - /// Adapted from https://github.com/dotnet/runtime - /// See https://github.com/dotnet/runtime/blob/dfd618dc648ba9b11dd0f8034f78113d69f223cd/src/libraries/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs - /// - public bool Contains(RectangleInfo rect) => - (this.X <= rect.X) && (rect.X + rect.Width <= this.X + this.Width) && - (this.Y <= rect.Y) && (rect.Y + rect.Height <= this.Y + this.Height); - - public RectangleInfo Enlarge(PaddingInfo padding) => new( - this.X + padding.Left, - this.Y + padding.Top, - this.Width + padding.Horizontal, - this.Height + padding.Vertical); - - public RectangleInfo Offset(SizeInfo amount) => this.Offset(amount.Width, amount.Height); - - public RectangleInfo Offset(decimal dx, decimal dy) => new(this.X + dx, this.Y + dy, this.Width, this.Height); - - public RectangleInfo Scale(decimal scalingFactor) => new( - this.X * scalingFactor, - this.Y * scalingFactor, - this.Width * scalingFactor, - this.Height * scalingFactor); - - public RectangleInfo Center(PointInfo point) => new( - x: point.X - (this.Width / 2), - y: point.Y - (this.Height / 2), - width: this.Width, - height: this.Height); - - public PointInfo Midpoint => new( - x: this.X + (this.Width / 2), - y: this.Y + (this.Height / 2)); - - public RectangleInfo Clamp(RectangleInfo outer) - { - if ((this.Width > outer.Width) || (this.Height > outer.Height)) - { - throw new ArgumentException($"Value cannot be larger than {nameof(outer)}."); - } - - return new( - x: Math.Clamp(this.X, outer.X, outer.Right - this.Width), - y: Math.Clamp(this.Y, outer.Y, outer.Bottom - this.Height), - width: this.Width, - height: this.Height); - } - - public Rectangle ToRectangle() => new((int)this.X, (int)this.Y, (int)this.Width, (int)this.Height); - - public override string ToString() - { - return "{" + - $"{nameof(this.Left)}={this.Left}," + - $"{nameof(this.Top)}={this.Top}," + - $"{nameof(this.Width)}={this.Width}," + - $"{nameof(this.Height)}={this.Height}" + - "}"; - } -} diff --git a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/SizeInfo.cs b/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/SizeInfo.cs deleted file mode 100644 index a91febc23cfa..000000000000 --- a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/SizeInfo.cs +++ /dev/null @@ -1,87 +0,0 @@ -// 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.Drawing; - -namespace MouseJumpUI.Models.Drawing; - -/// -/// Immutable version of a System.Drawing.Size object with some extra utility methods. -/// -public sealed class SizeInfo -{ - public SizeInfo(decimal width, decimal height) - { - this.Width = width; - this.Height = height; - } - - public SizeInfo(Size size) - : this(size.Width, size.Height) - { - } - - public decimal Width - { - get; - } - - public decimal Height - { - get; - } - - public SizeInfo Negate() => new(-this.Width, -this.Height); - - public SizeInfo Shrink(PaddingInfo padding) => new(this.Width - padding.Horizontal, this.Height - padding.Vertical); - - public SizeInfo Intersect(SizeInfo size) => new( - Math.Min(this.Width, size.Width), - Math.Min(this.Height, size.Height)); - - public RectangleInfo PlaceAt(decimal x, decimal y) => new(x, y, this.Width, this.Height); - - public SizeInfo ScaleToFit(SizeInfo bounds) - { - var widthRatio = bounds.Width / this.Width; - var heightRatio = bounds.Height / this.Height; - return widthRatio.CompareTo(heightRatio) switch - { - < 0 => new(bounds.Width, this.Height * widthRatio), - 0 => bounds, - > 0 => new(this.Width * heightRatio, bounds.Height), - }; - } - - /// - /// Get the scaling ratio to scale obj by so that it fits inside the specified bounds - /// without distorting the aspect ratio. - /// - public decimal ScaleToFitRatio(SizeInfo bounds) - { - if (bounds.Width == 0 || bounds.Height == 0) - { - throw new ArgumentException($"{nameof(bounds.Width)} or {nameof(bounds.Height)} cannot be zero", nameof(bounds)); - } - - var widthRatio = bounds.Width / this.Width; - var heightRatio = bounds.Height / this.Height; - var scalingRatio = Math.Min(widthRatio, heightRatio); - - return scalingRatio; - } - - public Size ToSize() => new((int)this.Width, (int)this.Height); - - public Point ToPoint() => new((int)this.Width, (int)this.Height); - - public override string ToString() - { - return "{" + - $"{nameof(this.Width)}={this.Width}," + - $"{nameof(this.Height)}={this.Height}" + - "}"; - } -} diff --git a/src/modules/MouseUtils/MouseJumpUI/Models/Layout/LayoutConfig.cs b/src/modules/MouseUtils/MouseJumpUI/Models/Layout/LayoutConfig.cs deleted file mode 100644 index 85aae9ab6f1e..000000000000 --- a/src/modules/MouseUtils/MouseJumpUI/Models/Layout/LayoutConfig.cs +++ /dev/null @@ -1,123 +0,0 @@ -// 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; - } -} diff --git a/src/modules/MouseUtils/MouseJumpUI/Models/Layout/LayoutInfo.cs b/src/modules/MouseUtils/MouseJumpUI/Models/Layout/LayoutInfo.cs deleted file mode 100644 index fee84a0d8560..000000000000 --- a/src/modules/MouseUtils/MouseJumpUI/Models/Layout/LayoutInfo.cs +++ /dev/null @@ -1,113 +0,0 @@ -// 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; - -namespace MouseJumpUI.Models.Layout; - -public sealed class LayoutInfo -{ - public sealed class Builder - { - public Builder() - { - this.ScreenBounds = new(); - } - - public LayoutConfig? LayoutConfig - { - get; - set; - } - - public RectangleInfo? FormBounds - { - get; - set; - } - - public RectangleInfo? PreviewBounds - { - get; - set; - } - - public List ScreenBounds - { - get; - set; - } - - public RectangleInfo? ActivatedScreenBounds - { - get; - set; - } - - public LayoutInfo Build() - { - return new LayoutInfo( - layoutConfig: this.LayoutConfig ?? throw new InvalidOperationException(), - formBounds: this.FormBounds ?? throw new InvalidOperationException(), - previewBounds: this.PreviewBounds ?? throw new InvalidOperationException(), - screenBounds: this.ScreenBounds ?? throw new InvalidOperationException(), - activatedScreenBounds: this.ActivatedScreenBounds ?? throw new InvalidOperationException()); - } - } - - public LayoutInfo( - LayoutConfig layoutConfig, - RectangleInfo formBounds, - RectangleInfo previewBounds, - IEnumerable screenBounds, - RectangleInfo activatedScreenBounds) - { - this.LayoutConfig = layoutConfig ?? throw new ArgumentNullException(nameof(layoutConfig)); - this.FormBounds = formBounds ?? throw new ArgumentNullException(nameof(formBounds)); - this.PreviewBounds = previewBounds ?? throw new ArgumentNullException(nameof(previewBounds)); - this.ScreenBounds = new( - (screenBounds ?? throw new ArgumentNullException(nameof(screenBounds))) - .ToList()); - this.ActivatedScreenBounds = activatedScreenBounds ?? throw new ArgumentNullException(nameof(activatedScreenBounds)); - } - - /// - /// Gets the original LayoutConfig settings used to calculate coordinates. - /// - public LayoutConfig LayoutConfig - { - get; - } - - /// - /// Gets the size and location of the preview form. - /// - public RectangleInfo FormBounds - { - get; - } - - /// - /// Gets the size and location of the preview image. - /// - public RectangleInfo PreviewBounds - { - get; - } - - public ReadOnlyCollection ScreenBounds - { - get; - } - - public RectangleInfo ActivatedScreenBounds - { - get; - } -} diff --git a/src/modules/MouseUtils/MouseJumpUI/Models/Screen/ScreenInfo.cs b/src/modules/MouseUtils/MouseJumpUI/Models/Screen/ScreenInfo.cs deleted file mode 100644 index 2d05d19c1fb6..000000000000 --- a/src/modules/MouseUtils/MouseJumpUI/Models/Screen/ScreenInfo.cs +++ /dev/null @@ -1,47 +0,0 @@ -// 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 MouseJumpUI.Models.Drawing; - -namespace MouseJumpUI.Models.Screen; - -/// -/// Immutable version of a System.Windows.Forms.Screen object so we don't need to -/// take a dependency on WinForms just for screen info. -/// -public sealed class ScreenInfo -{ - internal ScreenInfo(int handle, bool primary, RectangleInfo displayArea, RectangleInfo workingArea) - { - this.Handle = handle; - this.Primary = primary; - this.DisplayArea = displayArea ?? throw new ArgumentNullException(nameof(displayArea)); - this.WorkingArea = workingArea ?? throw new ArgumentNullException(nameof(workingArea)); - } - - public int Handle - { - get; - } - - public bool Primary - { - get; - } - - public RectangleInfo DisplayArea - { - get; - } - - public RectangleInfo Bounds => - this.DisplayArea; - - public RectangleInfo WorkingArea - { - get; - } -}