From 2ac35cd05b73fc8e1c479bc3c32271c4ae2b3ac7 Mon Sep 17 00:00:00 2001 From: "jetbrains-junie[bot]" Date: Wed, 4 Jun 2025 17:01:39 +0000 Subject: [PATCH] feat: allow selection of different overlay styles for icons The custom icon creator was modified to allow users to select different overlay styles, preserving the aspect ratios for the "Liaher" style. The UI was updated to include these options, enhancing the user experience by preventing improper resizing of icons. --- FoliCon/Modules/Media/ProIcon.cs | 66 ++++++++++-- FoliCon/Modules/Media/ProIcon.cs.orig | 20 ++++ .../ViewModels/CustomIconControlViewModel.cs | 49 +++++++-- FoliCon/Views/CustomIconControl.xaml | 101 ++++++++++++++++-- 4 files changed, 214 insertions(+), 22 deletions(-) create mode 100644 FoliCon/Modules/Media/ProIcon.cs.orig diff --git a/FoliCon/Modules/Media/ProIcon.cs b/FoliCon/Modules/Media/ProIcon.cs index be9033b0..1358ca21 100644 --- a/FoliCon/Modules/Media/ProIcon.cs +++ b/FoliCon/Modules/Media/ProIcon.cs @@ -1,20 +1,74 @@ namespace FoliCon.Modules.Media; -public class ProIcon(string filePath) +public class ProIcon { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private readonly string _filePath; + private readonly IconOverlay _iconOverlay; + private readonly string _rating; + private readonly string _ratingVisibility; + private readonly string _mockupVisibility; + private readonly string _mediaTitle; + + public ProIcon(string filePath) + { + _filePath = filePath; + _iconOverlay = IconOverlay.Legacy; + _rating = string.Empty; + _ratingVisibility = "hidden"; + _mockupVisibility = "hidden"; + _mediaTitle = string.Empty; + } + + public ProIcon(string filePath, IconOverlay iconOverlay, string rating = "", string ratingVisibility = "hidden", string mockupVisibility = "hidden", string mediaTitle = "") + { + _filePath = filePath; + _iconOverlay = iconOverlay; + _rating = rating; + _ratingVisibility = ratingVisibility; + _mockupVisibility = mockupVisibility; + _mediaTitle = mediaTitle; + } public Bitmap RenderToBitmap() { - Logger.Debug("Rendering icon to bitmap"); - return PosterIconBase.RenderTargetBitmapTo32BppArgb(AsRenderTargetBitmap()); + Logger.Debug("Rendering icon to bitmap with overlay: {Overlay}", _iconOverlay); + + if (_iconOverlay == IconOverlay.Legacy) + { + // Use the original simple resize for Legacy mode + return PosterIconBase.RenderTargetBitmapTo32BppArgb(AsRenderTargetBitmap()); + } + + // For other overlay types, use the appropriate PosterIcon implementation + using var task = _iconOverlay switch + { + IconOverlay.Alternate => StaTask.Start(() => + new PosterIconAlt(new PosterIcon(_filePath, _rating, _ratingVisibility, _mockupVisibility)) + .RenderToBitmap()), + IconOverlay.Liaher => StaTask.Start(() => + new PosterIconLiaher(new PosterIcon(_filePath, _rating, _ratingVisibility, _mockupVisibility)) + .RenderToBitmap()), + IconOverlay.Faelpessoal => StaTask.Start(() => new PosterIconFaelpessoal(new PosterIcon( + _filePath, _rating, + _ratingVisibility, _mockupVisibility, _mediaTitle)).RenderToBitmap()), + IconOverlay.FaelpessoalHorizontal => StaTask.Start(() => new PosterIconFaelpessoalHorizontal( + new PosterIcon( + _filePath, _rating, + _ratingVisibility, _mockupVisibility, _mediaTitle)).RenderToBitmap()), + _ => StaTask.Start(() => + new Views.PosterIcon(new PosterIcon(_filePath, _rating, _ratingVisibility, _mockupVisibility)) + .RenderToBitmap()) + }; + + return task.Result; } private BitmapSource AsRenderTargetBitmap() { - using var img = new Bitmap(filePath); + using var img = new Bitmap(_filePath); using var icon = new Bitmap(img, 256, 256); - Logger.Debug("Icon resized to 256x256, filePath: {FilePath}", filePath); + Logger.Debug("Icon resized to 256x256, filePath: {FilePath}", _filePath); return ImageUtils.LoadBitmap(icon); } -} \ No newline at end of file +} diff --git a/FoliCon/Modules/Media/ProIcon.cs.orig b/FoliCon/Modules/Media/ProIcon.cs.orig new file mode 100644 index 00000000..be9033b0 --- /dev/null +++ b/FoliCon/Modules/Media/ProIcon.cs.orig @@ -0,0 +1,20 @@ +namespace FoliCon.Modules.Media; + +public class ProIcon(string filePath) +{ + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + public Bitmap RenderToBitmap() + { + Logger.Debug("Rendering icon to bitmap"); + return PosterIconBase.RenderTargetBitmapTo32BppArgb(AsRenderTargetBitmap()); + } + + private BitmapSource AsRenderTargetBitmap() + { + using var img = new Bitmap(filePath); + using var icon = new Bitmap(img, 256, 256); + Logger.Debug("Icon resized to 256x256, filePath: {FilePath}", filePath); + return ImageUtils.LoadBitmap(icon); + } +} \ No newline at end of file diff --git a/FoliCon/ViewModels/CustomIconControlViewModel.cs b/FoliCon/ViewModels/CustomIconControlViewModel.cs index 4fcdf184..6a79d864 100644 --- a/FoliCon/ViewModels/CustomIconControlViewModel.cs +++ b/FoliCon/ViewModels/CustomIconControlViewModel.cs @@ -8,7 +8,7 @@ namespace FoliCon.ViewModels; public class CustomIconControlViewModel : BindableBase, IDialogAware, IFileDragDropTarget { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - + public IDropTarget ReOrderDropHandler { get; } = new ReOrderDropHandler(); private string _selectedDirectory; private string _selectedIconsDirectory; @@ -26,6 +26,9 @@ public class CustomIconControlViewModel : BindableBase, IDialogAware, IFileDragD private string _busyContent = Lang.CreatingIcons; private int _index; private int _totalIcons; + private string _iconOverlay = IconOverlay.Liaher.ToString(); + private bool _isRatingVisible; + private bool _isMockupVisible; public bool KeepExactOnly { get => _keepExactOnly; @@ -55,6 +58,24 @@ public bool IsUndoEnable set => SetProperty(ref _isUndoEnable, value); } + public string IconOverlay + { + get => _iconOverlay; + set => SetProperty(ref _iconOverlay, value); + } + + public bool IsRatingVisible + { + get => _isRatingVisible; + set => SetProperty(ref _isRatingVisible, value); + } + + public bool IsMockupVisible + { + get => _isMockupVisible; + set => SetProperty(ref _isMockupVisible, value); + } + private string SelectedDirectory { get => _selectedDirectory; @@ -109,6 +130,7 @@ public ObservableCollection Icons public DelegateCommand KeyPressFolderList { get; set; } public DelegateCommand KeyPressIconsList { get; set; } public DelegateCommand StopSearchCommand { get; set; } + public DelegateCommand IconOverlayChangedCommand { get; set; } public string BusyContent { get => _busyContent; @@ -129,6 +151,7 @@ public CustomIconControlViewModel() UndoIcons = new DelegateCommand(UndoCreatedIcons); KeyPressFolderList = new DelegateCommand(FolderListKeyPress); KeyPressIconsList = new DelegateCommand(IconsListKeyPress); + IconOverlayChangedCommand = new DelegateCommand(param => IconOverlay = param); } private async void UndoCreatedIcons() @@ -270,14 +293,26 @@ private int MakeIcons() var iconPath = Path.Combine(SelectedIconsDirectory, Icons[i]); var folderPath = Path.Combine(SelectedDirectory, Directories[i]); var newIconPath = Path.Combine(folderPath, $"{Directories[i]}.ico"); - + Logger.Debug("Creating icon for {Folder} from {Icon}, new Path is: {NewIconPath}", folderPath, iconPath, newIconPath); - + if (Path.GetExtension(Icons[i].ToLower(CultureInfo.InvariantCulture)) != ".ico") { - Logger.Info("Converting {Icon} to .ico", iconPath); - var icon = new ProIcon(iconPath).RenderToBitmap(); + Logger.Info("Converting {Icon} to .ico with overlay {Overlay}", iconPath, IconOverlay); + + // Parse the IconOverlay string to the enum value + if (!Enum.TryParse(IconOverlay, out var iconOverlay)) + { + iconOverlay = IconOverlay.Legacy; + } + + // Convert visibility booleans to strings + var ratingVisibility = IsRatingVisible ? "visible" : "hidden"; + var mockupVisibility = IsMockupVisible ? "visible" : "hidden"; + + // Use the new ProIcon constructor with overlay settings + var icon = new ProIcon(iconPath, iconOverlay, "", ratingVisibility, mockupVisibility).RenderToBitmap(); iconPath = iconPath.Replace(Path.GetExtension(Icons[i])!, ".ico"); PngToIcoService.Convert(icon, iconPath); icon.Dispose(); @@ -328,7 +363,7 @@ private void RestoreCollections() { Logger.Debug("Restoring collections from backup icon count: {Count}, backup directory count: {DirectoryCount}", _backupIcons.Count, _backupDirectories.Count); - + if (_backupIcons.Count == 0 || _backupDirectories.Count == 0) { return; @@ -383,4 +418,4 @@ public void OnFileDrop(string[] filePaths, string senderName) break; } } -} \ No newline at end of file +} diff --git a/FoliCon/Views/CustomIconControl.xaml b/FoliCon/Views/CustomIconControl.xaml index 811e280a..79eb8803 100644 --- a/FoliCon/Views/CustomIconControl.xaml +++ b/FoliCon/Views/CustomIconControl.xaml @@ -11,15 +11,21 @@ xmlns:langs="clr-namespace:FoliCon.Properties.Langs" xmlns:extension="clr-namespace:FoliCon.Modules.Extension" xmlns:ui="clr-namespace:FoliCon.Modules.UI" + xmlns:convertor="clr-namespace:FoliCon.Modules.Convertor" mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:CustomIconControlViewModel}" Background="{DynamicResource RegionBrush}" prism:ViewModelLocator.AutoWireViewModel="True" AllowDrop="True" > + + + + + @@ -84,13 +90,90 @@ - - -