From 1a0d7413f6b09754219b8f0800742243df2b070a Mon Sep 17 00:00:00 2001 From: mikeclayton Date: Tue, 22 Oct 2024 17:51:47 +0100 Subject: [PATCH] [MouseJump] use custom styles in preview image (#27511) --- .../MouseJumpUI/Helpers/SettingsHelper.cs | 65 +++++++++++++++++++ .../MouseUtils/MouseJumpUI/MainForm.cs | 7 +- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/src/modules/MouseUtils/MouseJumpUI/Helpers/SettingsHelper.cs b/src/modules/MouseUtils/MouseJumpUI/Helpers/SettingsHelper.cs index cfd10fbd7855..efe721e87322 100644 --- a/src/modules/MouseUtils/MouseJumpUI/Helpers/SettingsHelper.cs +++ b/src/modules/MouseUtils/MouseJumpUI/Helpers/SettingsHelper.cs @@ -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; @@ -93,4 +97,65 @@ public void ReloadSettings() { this.CurrentSettings = this.LoadSettings(); } + + public static PreviewStyle GetActivePreviewStyle(MouseJumpSettings settings) + { + var previewType = Enum.TryParse(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; + } } diff --git a/src/modules/MouseUtils/MouseJumpUI/MainForm.cs b/src/modules/MouseUtils/MouseJumpUI/MainForm.cs index 9833d9e4b77a..bf1a9ebdbbae 100644 --- a/src/modules/MouseUtils/MouseJumpUI/MainForm.cs +++ b/src/modules/MouseUtils/MouseJumpUI/MainForm.cs @@ -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);