Skip to content

Commit

Permalink
[MouseJump] use custom styles in preview image (microsoft#27511)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeclayton committed Oct 22, 2024
1 parent 6f8e1a9 commit 1a0d741
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
65 changes: 65 additions & 0 deletions src/modules/MouseUtils/MouseJumpUI/Helpers/SettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using MouseJump.Common.Helpers;
using MouseJump.Common.Models.Drawing;
using MouseJump.Common.Models.Settings;
using MouseJump.Common.Models.Styles;

namespace MouseJumpUI.Helpers;

Expand Down Expand Up @@ -93,4 +97,65 @@ public void ReloadSettings()
{
this.CurrentSettings = this.LoadSettings();
}

public static PreviewStyle GetActivePreviewStyle(MouseJumpSettings settings)
{
var previewType = Enum.TryParse<PreviewType>(settings.Properties.PreviewType, true, out var previewTypeResult)
? previewTypeResult
: PreviewType.Bezelled;

var canvasSize = new SizeInfo(
settings.Properties.ThumbnailSize.Width,
settings.Properties.ThumbnailSize.Height);

var properties = settings.Properties;

var previewStyle = previewType switch
{
PreviewType.Compact => StyleHelper.CompactPreviewStyle.WithCanvasSize(canvasSize),
PreviewType.Bezelled => StyleHelper.BezelledPreviewStyle.WithCanvasSize(canvasSize),
PreviewType.Custom => new PreviewStyle(
canvasSize: canvasSize,
canvasStyle: new(
marginStyle: new(0),
borderStyle: new(
color: ConfigHelper.DeserializeFromConfigColorString(
properties.BorderColor),
all: properties.BorderThickness,
depth: properties.Border3dDepth
),
paddingStyle: new(
all: properties.BorderPadding
),
backgroundStyle: new(
color1: ConfigHelper.DeserializeFromConfigColorString(
properties.BackgroundColor1),
color2: ConfigHelper.DeserializeFromConfigColorString(
properties.BackgroundColor2)
)
),
screenStyle: new(
marginStyle: new(
all: properties.ScreenMargin
),
borderStyle: new(
color: ConfigHelper.DeserializeFromConfigColorString(
properties.BezelColor),
all: properties.BezelThickness,
depth: properties.Bezel3dDepth
),
paddingStyle: new(0),
backgroundStyle: new(
color1: ConfigHelper.DeserializeFromConfigColorString(
properties.ScreenColor1),
color2: ConfigHelper.DeserializeFromConfigColorString(
properties.ScreenColor2)
)
)),
_ => throw new InvalidOperationException(
$"Unhandled {nameof(PreviewType)} '{previewType}'"),
};

return previewStyle;
}
}
7 changes: 2 additions & 5 deletions src/modules/MouseUtils/MouseJumpUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,9 @@ public void ShowPreview()
var appSettings = this.SettingsHelper.CurrentSettings ?? throw new InvalidOperationException();
var screens = ScreenHelper.GetAllScreens().Select(screen => screen.DisplayArea).ToList();
var activatedLocation = MouseHelper.GetCursorPosition();

this.PreviewLayout = LayoutHelper.GetPreviewLayout(
previewStyle: StyleHelper.CompactPreviewStyle.WithCanvasSize(
new(
appSettings.Properties.ThumbnailSize.Width,
appSettings.Properties.ThumbnailSize.Height
)),
previewStyle: SettingsHelper.GetActivePreviewStyle(appSettings),
screens: screens,
activatedLocation: activatedLocation);

Expand Down

0 comments on commit 1a0d741

Please sign in to comment.