Skip to content

Commit

Permalink
[Mouse Jump] - fixing shimmer in preview image size - microsoft#25482
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeclayton committed Aug 6, 2024
1 parent 4782f1b commit 437ef32
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static PreviewLayout GetPreviewLayout(
return builder.Build();
}

private static RectangleInfo GetCombinedScreenBounds(List<RectangleInfo> screens)
public static RectangleInfo GetCombinedScreenBounds(List<RectangleInfo> screens)
{
return screens.Skip(1).Aggregate(
seed: screens.First(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public SizeInfo Clamp(SizeInfo max)
height: Math.Clamp(this.Height, 0, max.Height));
}

public SizeInfo Clamp(decimal maxWidth, decimal maxHeight)
{
return new(
width: Math.Clamp(this.Width, 0, maxWidth),
height: Math.Clamp(this.Height, 0, maxHeight));
}

public SizeInfo Enlarge(BorderStyle border) =>
new(
this.Width + border.Horizontal,
Expand Down
25 changes: 0 additions & 25 deletions src/modules/MouseUtils/MouseJumpUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,4 @@ private static void Main(string[] args)

Application.Run();
}

private static MouseJumpSettings ReadSettings()
{
var settingsUtils = new SettingsUtils();
var settingsPath = settingsUtils.GetSettingsFilePath(MouseJumpSettings.ModuleName);
if (!File.Exists(settingsPath))
{
var scaffoldSettings = new MouseJumpSettings();
settingsUtils.SaveSettings(JsonSerializer.Serialize(scaffoldSettings), MouseJumpSettings.ModuleName);
}

var settings = new MouseJumpSettings();
try
{
settings = settingsUtils.GetSettings<MouseJumpSettings>(MouseJumpSettings.ModuleName);
}
catch (Exception ex)
{
var errorMessage = $"There was a problem reading the configuration file. Error: {ex.GetType()} {ex.Message}";
Logger.LogInfo(errorMessage);
Logger.LogDebug(errorMessage);
}

return settings;
}
}
118 changes: 59 additions & 59 deletions src/settings-ui/Settings.UI.Library/Settings.UI.Library.csproj
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\Version.props" />

<PropertyGroup>
<TargetFrameworks>net8.0-windows</TargetFrameworks>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<TargetFramework>net8.0-windows</TargetFramework>
<Version>$(Version).0</Version>
<Authors>Microsoft Corporation</Authors>
<Product>PowerToys</Product>
<Description>PowerToys Settings UI Library</Description>
<AssemblyName>PowerToys.Settings.UI.Lib</AssemblyName>
<SelfContained>true</SelfContained>
</PropertyGroup>

<!-- SelfContained=true requires RuntimeIdentifier to be set -->
<PropertyGroup Condition="'$(Platform)'=='x64'">
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='ARM64'">
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<None Include="backup_restore_settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.IO.Abstractions" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\common\interop\PowerToys.Interop.vcxproj" />
<ProjectReference Include="..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Resources\Resources.Designer.cs">
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources\Resources.resx">
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
</ItemGroup>
<Import Project="..\..\Version.props" />

<PropertyGroup>
<TargetFrameworks>net8.0-windows</TargetFrameworks>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<TargetFramework>net8.0-windows</TargetFramework>
<Version>$(Version).0</Version>
<Authors>Microsoft Corporation</Authors>
<Product>PowerToys</Product>
<Description>PowerToys Settings UI Library</Description>
<AssemblyName>PowerToys.Settings.UI.Lib</AssemblyName>
<SelfContained>true</SelfContained>
</PropertyGroup>

<!-- SelfContained=true requires RuntimeIdentifier to be set -->
<PropertyGroup Condition="'$(Platform)'=='x64'">
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='ARM64'">
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<None Include="backup_restore_settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.IO.Abstractions" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\common\interop\PowerToys.Interop.vcxproj" />
<ProjectReference Include="..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Resources\Resources.Designer.cs">
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources\Resources.resx">
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
</ItemGroup>

</Project>
Binary file modified src/settings-ui/Settings.UI/Images/MouseJump-Desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@
IsExpanded="False">
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard
HorizontalAlignment="Center">
Height="300"
HorizontalAlignment="Center"
MaxHeight="300"
MinHeight="300"
VerticalAlignment="Center">
<Image Source="{x:Bind Path=ViewModel.MouseJumpPreviewImage, Mode=OneWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard x:Uid="MouseUtils_MouseJump_PreviewType" x:Name="MouseUtils_MouseJump_PreviewType">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public MouseJumpPanel()

private void PreviewTypeSetting_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// format controls based on whether the "Custom" preview type is selected
// hide or display controls based on whether the "Custom" preview type is selected
var selectedPreviewType = this.GetSelectedPreviewType();
var customPreviewTypeSelected = selectedPreviewType == PreviewType.Custom;
this.CopyStyleToCustom.IsEnabled = !customPreviewTypeSelected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,27 @@ public ImageSource MouseJumpPreviewImage
{
get
{
// keep these in sync with the layout of MouseJump-Desktop.png
var desktopSize = new SizeInfo(
width: 640,
height: 480);
// keep these in sync with the layout of "Images\MouseJump-Desktop.png"
var screens = new List<RectangleInfo>()
{
new(412, 111, 177, 110),
new(0, 0, 412, 221),
/*
these magic numbers are the pixel dimensions of the individual screens on the
fake desktop image - "Images\MouseJump-Desktop.png" - used to generate the
preview image in the Settings UI properties page for Mouse Jump. if you update
the fake desktop image be sure to update these values as well.
*/
new(635, 172, 272, 168),
new(0, 0, 635, 339),
};
var desktopSize = LayoutHelper.GetCombinedScreenBounds(screens).Size;
/*
magic number 283 is the content height left in the settings card after removing the top and bottom chrome:
300px settings card height - 1px top border - 7px top margin - 8px bottom margin - 1px bottom border = 283px image height
this ensures we get a preview image scaled at 100% so borders etc are shown at exact pixel sizes in the preview
*/
var canvasSize = new SizeInfo(desktopSize.Width, 283).Clamp(desktopSize);

var previewType = Enum.TryParse<PreviewType>(this.MouseJumpPreviewType, true, out var previewTypeResult)
? previewTypeResult
Expand All @@ -161,7 +173,7 @@ public ImageSource MouseJumpPreviewImage
PreviewType.Compact => StyleHelper.CompactPreviewStyle.WithCanvasSize(desktopSize),
PreviewType.Bezelled => StyleHelper.BezelledPreviewStyle.WithCanvasSize(desktopSize),
PreviewType.Custom => new PreviewStyle(
canvasSize: desktopSize,
canvasSize: canvasSize,
canvasStyle: new(
marginStyle: new(0),
borderStyle: new(
Expand Down

0 comments on commit 437ef32

Please sign in to comment.