mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
[Mouse Jump] Customisable appearance - borders, margins, colours, etc - final part (#35521)
* [MouseJump] move Mouse Jump settings into separate control (#27511) * [MouseJump] added Mouse Jump style controls to Settings UI (#27511) * [MouseJump] added Mouse Jump style controls to Settings UI (#27511) * [MouseJump] removing unused MouseJumpUI code (#27511) * [MouseJump] whitespace (#27511) * [MouseJump] fix spellcheck (#27511) * [MouseJump] enabled "Copy to custom style" (#27511) * [MouseJump] fixing build (internal members -> public) (#27511) * [MouseJump] remove unused "using"s (#27511) * [MouseJump] use custom styles in preview image (#27511) * [MouseJump] fixing failing test (#27511) * [MouseJump] fixing failing test (#27511) * [MouseJump] fixing failing test (#27511) * [MouseJump] fixing failing test (#27511) * [MouseJump] delinting to trigger a build (#27511) * [MouseJump] updated settings preview image ("browser" header) (#27511) * [MouseJump] upgrade default "custom" style settings in config (#27511) * [MouseJump] fixed a glitch in settings upgrade (#27511) * [MouseJump] fixed spell checker (#27511) * [MouseJump] typo in resource strings (image -> images) (#27511) * Remove unused include
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
// 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.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MouseJump.Common.Helpers;
|
||||
using MouseJump.Common.Imaging;
|
||||
@@ -16,7 +17,7 @@ namespace MouseJump.Common.UnitTests.Helpers;
|
||||
public static class DrawingHelperTests
|
||||
{
|
||||
[TestClass]
|
||||
public sealed class GetPreviewLayoutTests
|
||||
public sealed class RenderPreviewTests
|
||||
{
|
||||
public sealed class TestCase
|
||||
{
|
||||
@@ -46,7 +47,7 @@ public static class DrawingHelperTests
|
||||
yield return new object[]
|
||||
{
|
||||
new TestCase(
|
||||
previewStyle: StyleHelper.DefaultPreviewStyle,
|
||||
previewStyle: StyleHelper.BezelledPreviewStyle,
|
||||
screens: new List<RectangleInfo>()
|
||||
{
|
||||
new(0, 0, 500, 500),
|
||||
@@ -62,7 +63,7 @@ public static class DrawingHelperTests
|
||||
yield return new object[]
|
||||
{
|
||||
new TestCase(
|
||||
previewStyle: StyleHelper.DefaultPreviewStyle,
|
||||
previewStyle: StyleHelper.BezelledPreviewStyle,
|
||||
screens: new List<RectangleInfo>()
|
||||
{
|
||||
new(5120, 349, 1920, 1080),
|
||||
@@ -79,7 +80,7 @@ public static class DrawingHelperTests
|
||||
public void RunTestCases(TestCase data)
|
||||
{
|
||||
// load the fake desktop image
|
||||
using var desktopImage = GetPreviewLayoutTests.LoadImageResource(data.DesktopImageFilename);
|
||||
using var desktopImage = RenderPreviewTests.LoadImageResource(data.DesktopImageFilename);
|
||||
|
||||
// draw the preview image
|
||||
var previewLayout = LayoutHelper.GetPreviewLayout(
|
||||
@@ -90,28 +91,29 @@ public static class DrawingHelperTests
|
||||
using var actual = DrawingHelper.RenderPreview(previewLayout, imageCopyService);
|
||||
|
||||
// load the expected image
|
||||
var expected = GetPreviewLayoutTests.LoadImageResource(data.ExpectedImageFilename);
|
||||
var expected = RenderPreviewTests.LoadImageResource(data.ExpectedImageFilename);
|
||||
|
||||
// compare the images
|
||||
var screens = System.Windows.Forms.Screen.AllScreens;
|
||||
AssertImagesEqual(expected, actual);
|
||||
}
|
||||
|
||||
private static Bitmap LoadImageResource(string filename)
|
||||
{
|
||||
// assume embedded resources are in the same source folder as this
|
||||
// class, and the namespace hierarchy matches the folder structure.
|
||||
// that way we can build resource names from the current namespace
|
||||
var resourcePrefix = typeof(DrawingHelperTests).Namespace;
|
||||
var resourceName = $"{resourcePrefix}.{filename}";
|
||||
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var assemblyName = new AssemblyName(assembly.FullName ?? throw new InvalidOperationException());
|
||||
var resourceName = $"{typeof(DrawingHelperTests).Namespace}.{filename.Replace("/", ".")}";
|
||||
var resourceNames = assembly.GetManifestResourceNames();
|
||||
if (!resourceNames.Contains(resourceName))
|
||||
{
|
||||
var message = $"Embedded resource '{resourceName}' does not exist. " +
|
||||
"Valid resource names are: \r\n" + string.Join("\r\n", resourceNames);
|
||||
throw new InvalidOperationException(message);
|
||||
var message = new StringBuilder();
|
||||
message.AppendLine(CultureInfo.InvariantCulture, $"Embedded resource '{resourceName}' does not exist.");
|
||||
message.AppendLine($"Known resources:");
|
||||
foreach (var name in resourceNames)
|
||||
{
|
||||
message.AppendLine(name);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(message.ToString());
|
||||
}
|
||||
|
||||
var stream = assembly.GetManifestResourceStream(resourceName)
|
||||
@@ -121,7 +123,7 @@ public static class DrawingHelperTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Naive / brute force image comparison - we can optimise this later :-)
|
||||
/// Naive / brute force image comparison - we can optimize this later :-)
|
||||
/// </summary>
|
||||
private static void AssertImagesEqual(Bitmap expected, Bitmap actual)
|
||||
{
|
||||
|
||||
@@ -129,7 +129,7 @@ public static class LayoutHelperTests
|
||||
public static IEnumerable<object[]> GetTestCases()
|
||||
{
|
||||
// happy path - single screen with 50% scaling,
|
||||
// *has* a preview borders but *no* screenshot borders
|
||||
// *has* a preview border but *no* screenshot borders
|
||||
//
|
||||
// +----------------+
|
||||
// | |
|
||||
@@ -160,7 +160,7 @@ public static class LayoutHelperTests
|
||||
new(0, 0, 1024, 768),
|
||||
};
|
||||
var activatedLocation = new PointInfo(512, 384);
|
||||
var previewLayout = new PreviewLayout(
|
||||
var expectedResult = new PreviewLayout(
|
||||
virtualScreen: new(0, 0, 1024, 768),
|
||||
screens: screens,
|
||||
activatedScreenIndex: 0,
|
||||
@@ -183,7 +183,7 @@ public static class LayoutHelperTests
|
||||
contentBounds: new(6, 6, 512, 384)
|
||||
),
|
||||
});
|
||||
yield return new object[] { new TestCase(previewStyle, screens, activatedLocation, previewLayout) };
|
||||
yield return new object[] { new TestCase(previewStyle, screens, activatedLocation, expectedResult) };
|
||||
|
||||
// happy path - single screen with 50% scaling,
|
||||
// *no* preview borders but *has* screenshot borders
|
||||
@@ -217,7 +217,7 @@ public static class LayoutHelperTests
|
||||
new(0, 0, 1024, 768),
|
||||
};
|
||||
activatedLocation = new PointInfo(512, 384);
|
||||
previewLayout = new PreviewLayout(
|
||||
expectedResult = new PreviewLayout(
|
||||
virtualScreen: new(0, 0, 1024, 768),
|
||||
screens: screens,
|
||||
activatedScreenIndex: 0,
|
||||
@@ -240,7 +240,59 @@ public static class LayoutHelperTests
|
||||
contentBounds: new(6, 6, 500, 372)
|
||||
),
|
||||
});
|
||||
yield return new object[] { new TestCase(previewStyle, screens, activatedLocation, previewLayout) };
|
||||
yield return new object[] { new TestCase(previewStyle, screens, activatedLocation, expectedResult) };
|
||||
|
||||
// rounding error check - single screen with 33% scaling,
|
||||
// no borders, check to make sure form scales to exactly
|
||||
// fill the canvas size with no rounding errors.
|
||||
//
|
||||
// in this test the preview width is 300 and the desktop is
|
||||
// 900, so the scaling factor is 1/3, but this gets rounded
|
||||
// to 0.3333333333333333333333333333, and 900 times this value
|
||||
// is 299.99999999999999999999999997. if we don't scale correctly
|
||||
// the resulting form width might only be 299 pixels instead of 300
|
||||
//
|
||||
// +----------------+
|
||||
// | |
|
||||
// | 0 |
|
||||
// | |
|
||||
// +----------------+
|
||||
previewStyle = new PreviewStyle(
|
||||
canvasSize: new(
|
||||
width: 300,
|
||||
height: 200
|
||||
),
|
||||
canvasStyle: BoxStyle.Empty,
|
||||
screenStyle: BoxStyle.Empty);
|
||||
screens = new List<RectangleInfo>
|
||||
{
|
||||
new(0, 0, 900, 200),
|
||||
};
|
||||
activatedLocation = new PointInfo(450, 100);
|
||||
expectedResult = new PreviewLayout(
|
||||
virtualScreen: new(0, 0, 900, 200),
|
||||
screens: screens,
|
||||
activatedScreenIndex: 0,
|
||||
formBounds: new(300, 66.5m, 300, 67),
|
||||
previewStyle: previewStyle,
|
||||
previewBounds: new(
|
||||
outerBounds: new(0, 0, 300, 67),
|
||||
marginBounds: new(0, 0, 300, 67),
|
||||
borderBounds: new(0, 0, 300, 67),
|
||||
paddingBounds: new(0, 0, 300, 67),
|
||||
contentBounds: new(0, 0, 300, 67)
|
||||
),
|
||||
screenshotBounds: new()
|
||||
{
|
||||
new(
|
||||
outerBounds: new(0, 0, 300, 67),
|
||||
marginBounds: new(0, 0, 300, 67),
|
||||
borderBounds: new(0, 0, 300, 67),
|
||||
paddingBounds: new(0, 0, 300, 67),
|
||||
contentBounds: new(0, 0, 300, 67)
|
||||
),
|
||||
});
|
||||
yield return new object[] { new TestCase(previewStyle, screens, activatedLocation, expectedResult) };
|
||||
|
||||
// primary monitor not topmost / leftmost - if there are screens
|
||||
// that are further left or higher up than the primary monitor
|
||||
@@ -291,7 +343,7 @@ public static class LayoutHelperTests
|
||||
new(0, 0, 5120, 1440),
|
||||
};
|
||||
activatedLocation = new(-960, 60);
|
||||
previewLayout = new PreviewLayout(
|
||||
expectedResult = new PreviewLayout(
|
||||
virtualScreen: new(-1920, -480, 7040, 1920),
|
||||
screens: screens,
|
||||
activatedScreenIndex: 0,
|
||||
@@ -321,7 +373,7 @@ public static class LayoutHelperTests
|
||||
contentBounds: new(204, 60, 500, 132)
|
||||
),
|
||||
});
|
||||
yield return new object[] { new TestCase(previewStyle, screens, activatedLocation, previewLayout) };
|
||||
yield return new object[] { new TestCase(previewStyle, screens, activatedLocation, expectedResult) };
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 215 KiB After Width: | Height: | Size: 202 KiB |
@@ -15,45 +15,49 @@ public static class SizeInfoTests
|
||||
{
|
||||
public sealed class TestCase
|
||||
{
|
||||
public TestCase(SizeInfo obj, SizeInfo bounds, SizeInfo expectedResult)
|
||||
public TestCase(SizeInfo source, SizeInfo bounds, SizeInfo expectedResult, decimal scalingRatio)
|
||||
{
|
||||
this.Obj = obj;
|
||||
this.Source = source;
|
||||
this.Bounds = bounds;
|
||||
this.ExpectedResult = expectedResult;
|
||||
this.ScalingRatio = scalingRatio;
|
||||
}
|
||||
|
||||
public SizeInfo Obj { get; }
|
||||
public SizeInfo Source { get; }
|
||||
|
||||
public SizeInfo Bounds { get; }
|
||||
|
||||
public SizeInfo ExpectedResult { get; }
|
||||
|
||||
public decimal ScalingRatio { get; }
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GetTestCases()
|
||||
{
|
||||
// identity tests
|
||||
yield return new object[] { new TestCase(new(512, 384), new(512, 384), new(512, 384)), };
|
||||
yield return new object[] { new TestCase(new(1024, 768), new(1024, 768), new(1024, 768)), };
|
||||
yield return new object[] { new TestCase(new(512, 384), new(512, 384), new(512, 384), 1), };
|
||||
yield return new object[] { new TestCase(new(1024, 768), new(1024, 768), new(1024, 768), 1), };
|
||||
|
||||
// general tests
|
||||
yield return new object[] { new TestCase(new(512, 384), new(2048, 1536), new(2048, 1536)), };
|
||||
yield return new object[] { new TestCase(new(2048, 1536), new(1024, 768), new(1024, 768)), };
|
||||
yield return new object[] { new TestCase(new(512, 384), new(2048, 1536), new(2048, 1536), 4), };
|
||||
yield return new object[] { new TestCase(new(2048, 1536), new(1024, 768), new(1024, 768), 0.5m), };
|
||||
|
||||
// scale to fit width
|
||||
yield return new object[] { new TestCase(new(512, 384), new(2048, 3072), new(2048, 1536)), };
|
||||
yield return new object[] { new TestCase(new(512, 384), new(2048, 3072), new(2048, 1536), 4), };
|
||||
|
||||
// scale to fit height
|
||||
yield return new object[] { new TestCase(new(512, 384), new(4096, 1536), new(2048, 1536)), };
|
||||
yield return new object[] { new TestCase(new(512, 384), new(4096, 1536), new(2048, 1536), 4), };
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DynamicData(nameof(GetTestCases), DynamicDataSourceType.Method)]
|
||||
public void RunTestCases(TestCase data)
|
||||
{
|
||||
var actual = data.Obj.ScaleToFit(data.Bounds);
|
||||
var actual = data.Source.ScaleToFit(data.Bounds, out var scalingRatio);
|
||||
var expected = data.ExpectedResult;
|
||||
Assert.AreEqual(expected.Width, actual.Width);
|
||||
Assert.AreEqual(expected.Height, actual.Height);
|
||||
Assert.AreEqual(scalingRatio, data.ScalingRatio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user