Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 [Mouse Jump] Customisable appearance - borders, margins, colours, etc #29292

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/modules/MouseUtils/MouseJump/MouseJump.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Generated Files\resource.h">
<Filter>Generated Files</Filter>
</ClInclude>
<ClInclude Include="trace.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand All @@ -40,16 +40,10 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="resource.h">
<Filter>Header Files</Filter>
</None>
<None Include="MouseJump.rc">
<Filter>Resource Files</Filter>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Generated Files\MouseJump.rc">
<ResourceCompile Include="MouseJump.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/MouseUtils/MouseJump/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,4 @@ class MouseJump : public PowertoyModuleIface
extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create()
{
return new MouseJump();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public TestCase(PointInfo previewLocation, SizeInfo previewSize, RectangleInfo
this.ExpectedResult = expectedResult;
}

public PointInfo PreviewLocation { get; set; }
public PointInfo PreviewLocation { get; }

public SizeInfo PreviewSize { get; set; }
public SizeInfo PreviewSize { get; }

public RectangleInfo DesktopBounds { get; set; }
public RectangleInfo DesktopBounds { get; }

public PointInfo ExpectedResult { get; set; }
public PointInfo ExpectedResult { get; }
}

public static IEnumerable<object[]> GetTestCases()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
// 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.Drawing;
using System.Text.Json;
using Microsoft.MouseJumpUI.UnitTests.TestUtils;
using Microsoft.PowerToys.Settings.UI.Library.Modules.MouseJump;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.MouseJumpUI.UnitTests.Models.Settings.V2_0;

[TestClass]
public static class SettingsConverterTests
{
[TestClass]
public sealed class ParseAppSettingsTests
{
public sealed class TestCase
{
public TestCase(string settingsJson, MouseJumpSettings expectedResult)
{
this.SettingsJson = settingsJson;
this.ExpectedResult = expectedResult;
}

public string SettingsJson { get; }

public MouseJumpSettings ExpectedResult { get; }
}

public static IEnumerable<object[]> GetTestCases()
{
/* color conversion */
yield return new object[]
{
new TestCase(
settingsJson: SerializationUtils.SerializeAnonymousType(
new
{
version = "2.0",
properties = new
{
preview = new
{
canvas = new
{
border = new
{
color = "SystemColors.Highlight",
},
background = new
{
color1 = "#0D57D2",
color2 = "#0344C0",
},
},
screens = new
{
border = new
{
color = "#222222",
},
background = new
{
color1 = "Color.MidnightBlue",
color2 = "Color.MidnightBlue",
},
},
},
},
}),
expectedResult: new(
version: "2.0",
properties: new(
activationShortcut: null,
previewStyle: new(
canvasSize: null,
canvasStyle: new(
borderStyle: new(
color: SystemColors.Highlight,
width: null,
depth: null
),
paddingStyle: null,
backgroundStyle: new(
color1: Color.FromArgb(0xFF, 0x0D, 0x57, 0xD2),
color2: Color.FromArgb(0xFF, 0x03, 0x44, 0xC0)
)
),
screenStyle: new(
marginStyle: null,
borderStyle: new(
color: Color.FromArgb(0xFF, 0x22, 0x22, 0x22),
width: null,
depth: null
),
backgroundStyle: new(
color1: Color.MidnightBlue,
color2: Color.MidnightBlue
)
)
)
)
)),
};
/* all properties specified */
yield return new object[]
{
new TestCase(
settingsJson: SerializationUtils.SerializeAnonymousType(
new
{
version = "2.0",
properties = new
{
activation_shortcut = new
{
win = true,
ctrl = false,
alt = false,
shift = true,
code = 68,
},
preview = new
{
size = new
{
width = 800,
height = 600,
},
canvas = new
{
border = new
{
color = "SystemColors.Highlight",
width = 6,
depth = 0,
},
padding = new
{
width = 4,
},
background = new
{
color1 = "#0D57D2",
color2 = "#0344C0",
},
},
screens = new
{
margin = new
{
width = 2,
},
border = new
{
color = "#222222",
width = 10,
depth = 3,
},
background = new
{
color1 = "Color.MidnightBlue",
color2 = "Color.MidnightBlue",
},
},
},
},
}),
expectedResult: new(
version: "2.0",
properties: new(
activationShortcut: new(true, false, false, true, 68),
previewStyle: new(
canvasSize: new(800, 600),
canvasStyle: new(
borderStyle: new(
color: SystemColors.Highlight,
width: 6,
depth: 0
),
paddingStyle: new(
width: 4
),
backgroundStyle: new(
color1: Color.FromArgb(0xFF, 0x0D, 0x57, 0xD2),
color2: Color.FromArgb(0xFF, 0x03, 0x44, 0xC0)
)
),
screenStyle: new(
marginStyle: new(
width: 2
),
borderStyle: new(
color: Color.FromArgb(0xFF, 0x22, 0x22, 0x22),
width: 10,
depth: 3
),
backgroundStyle: new(
color1: Color.MidnightBlue,
color2: Color.MidnightBlue
)
)
)
)
)),
};
}

[TestMethod]
[DynamicData(nameof(GetTestCases), DynamicDataSourceType.Method)]
public void RunTestCases(TestCase data)
{
var actual = JsonSerializer.Deserialize<MouseJumpSettings>(data.SettingsJson)
?? throw new InvalidOperationException();
var expected = data.ExpectedResult;
Console.WriteLine(actual.ToJsonString());
Console.WriteLine(expected.ToJsonString());
Assert.AreEqual(expected.ToJsonString(), actual.ToJsonString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@ public TestCase(RectangleInfo rectangle, PointInfo point, RectangleInfo expected
this.ExpectedResult = expectedResult;
}

public RectangleInfo Rectangle { get; set; }
public RectangleInfo Rectangle { get; }

public PointInfo Point { get; set; }
public PointInfo Point { get; }

public RectangleInfo ExpectedResult { get; set; }
public RectangleInfo ExpectedResult { get; }
}

public static IEnumerable<object[]> GetTestCases()
{
// zero-sized
yield return new[] { new TestCase(new(0, 0, 0, 0), new(0, 0), new(0, 0, 0, 0)), };
yield return new object[] { new TestCase(new(0, 0, 0, 0), new(0, 0), new(0, 0, 0, 0)), };

// zero-origin
yield return new[] { new TestCase(new(0, 0, 200, 200), new(100, 100), new(0, 0, 200, 200)), };
yield return new[] { new TestCase(new(0, 0, 200, 200), new(500, 500), new(400, 400, 200, 200)), };
yield return new[] { new TestCase(new(0, 0, 800, 600), new(1000, 1000), new(600, 700, 800, 600)), };
yield return new object[] { new TestCase(new(0, 0, 200, 200), new(100, 100), new(0, 0, 200, 200)), };
yield return new object[] { new TestCase(new(0, 0, 200, 200), new(500, 500), new(400, 400, 200, 200)), };
yield return new object[] { new TestCase(new(0, 0, 800, 600), new(1000, 1000), new(600, 700, 800, 600)), };

// non-zero origin
yield return new[] { new TestCase(new(1000, 2000, 200, 200), new(100, 100), new(0, 0, 200, 200)), };
yield return new[] { new TestCase(new(1000, 2000, 200, 200), new(500, 500), new(400, 400, 200, 200)), };
yield return new[] { new TestCase(new(1000, 2000, 800, 600), new(1000, 1000), new(600, 700, 800, 600)), };
yield return new object[] { new TestCase(new(1000, 2000, 200, 200), new(100, 100), new(0, 0, 200, 200)), };
yield return new object[] { new TestCase(new(1000, 2000, 200, 200), new(500, 500), new(400, 400, 200, 200)), };
yield return new object[] { new TestCase(new(1000, 2000, 800, 600), new(1000, 1000), new(600, 700, 800, 600)), };

// negative result
yield return new[] { new TestCase(new(0, 0, 1000, 1200), new(300, 300), new(-200, -300, 1000, 1200)), };
yield return new object[] { new TestCase(new(0, 0, 1000, 1200), new(300, 300), new(-200, -300, 1000, 1200)), };
}

[TestMethod]
Expand Down Expand Up @@ -74,53 +74,53 @@ public TestCase(RectangleInfo inner, RectangleInfo outer, RectangleInfo expected
this.ExpectedResult = expectedResult;
}

public RectangleInfo Inner { get; set; }
public RectangleInfo Inner { get; }

public RectangleInfo Outer { get; set; }
public RectangleInfo Outer { get; }

public RectangleInfo ExpectedResult { get; set; }
public RectangleInfo ExpectedResult { get; }
}

public static IEnumerable<object[]> GetTestCases()
{
// already inside - obj fills bounds exactly
yield return new[]
yield return new object[]
{
new TestCase(new(0, 0, 100, 100), new(0, 0, 100, 100), new(0, 0, 100, 100)),
};

// already inside - obj exactly in each corner
yield return new[]
yield return new object[]
{
new TestCase(new(0, 0, 100, 100), new(0, 0, 200, 200), new(0, 0, 100, 100)),
};
yield return new[]
yield return new object[]
{
new TestCase(new(100, 0, 100, 100), new(0, 0, 200, 200), new(100, 0, 100, 100)),
};
yield return new[]
yield return new object[]
{
new TestCase(new(0, 100, 100, 100), new(0, 0, 200, 200), new(0, 100, 100, 100)),
};
yield return new[]
yield return new object[]
{
new TestCase(new(100, 100, 100, 100), new(0, 0, 200, 200), new(100, 100, 100, 100)),
};

// move inside - obj outside each corner
yield return new[]
yield return new object[]
{
new TestCase(new(-50, -50, 100, 100), new(0, 0, 200, 200), new(0, 0, 100, 100)),
};
yield return new[]
yield return new object[]
{
new TestCase(new(250, -50, 100, 100), new(0, 0, 200, 200), new(100, 0, 100, 100)),
};
yield return new[]
yield return new object[]
{
new TestCase(new(-50, 250, 100, 100), new(0, 0, 200, 200), new(0, 100, 100, 100)),
};
yield return new[]
yield return new object[]
{
new TestCase(new(150, 150, 100, 100), new(0, 0, 200, 200), new(100, 100, 100, 100)),
};
Expand Down
Loading
Loading