From 3eff80ff502453f66f6305d1b962adf5c0ffe124 Mon Sep 17 00:00:00 2001 From: BWiegell Date: Tue, 15 Nov 2022 23:10:43 +0100 Subject: [PATCH] about window and more work on post process chain --- AstroWall/AboutViewController.designer.cs | 35 ++++++ .../ApplicationLayer/Helpers/General.Macos.cs | 4 + .../View/AboutViewController.cs | 56 ++++++++++ .../View/AboutViewController.designer.cs | 35 ++++++ AstroWall/AstroWall.csproj | 5 + AstroWall/BusinessLayer/ApplicationHandler.cs | 2 +- AstroWall/BusinessLayer/ImgWrap.cs | 46 +++++--- .../Preferences/AddText.model.cs | 4 +- .../Preferences/PostProcess.model.cs | 11 +- .../BusinessLayer/Preferences/Preferences.cs | 9 +- .../Wallpaper/PostProcess/AddText.cs | 63 +++++++---- .../Wallpaper/PostProcess/Compose.cs | 25 +++++ .../Wallpaper/PostProcess/ScaleAndCrop.cs | 18 +++- .../BusinessLayer/Wallpaper/Wallpaper.cs | 2 +- AstroWall/Main.storyboard | 101 +++++++++++++++--- 15 files changed, 354 insertions(+), 62 deletions(-) create mode 100644 AstroWall/AboutViewController.designer.cs create mode 100644 AstroWall/ApplicationLayer/View/AboutViewController.cs create mode 100644 AstroWall/ApplicationLayer/View/AboutViewController.designer.cs create mode 100644 AstroWall/BusinessLayer/Wallpaper/PostProcess/Compose.cs diff --git a/AstroWall/AboutViewController.designer.cs b/AstroWall/AboutViewController.designer.cs new file mode 100644 index 0000000..cf09f67 --- /dev/null +++ b/AstroWall/AboutViewController.designer.cs @@ -0,0 +1,35 @@ +// WARNING +// +// This file has been generated automatically by Visual Studio to store outlets and +// actions made in the UI designer. If it is removed, they will be lost. +// Manual changes to this file may not be handled correctly. +// +using Foundation; +using System.CodeDom.Compiler; + +namespace AstroWall +{ + [Register ("AboutViewController")] + partial class AboutViewController + { + [Outlet] + AppKit.NSTextField OutletVersion2 { get; set; } + + [Action ("ActionGithub:")] + partial void ActionGithub (Foundation.NSObject sender); + + [Action ("ActionIssues:")] + partial void ActionIssues (Foundation.NSObject sender); + + [Action ("ActionWeb:")] + partial void ActionWeb (Foundation.NSObject sender); + + void ReleaseDesignerOutlets () + { + if (OutletVersion2 != null) { + OutletVersion2.Dispose (); + OutletVersion2 = null; + } + } + } +} diff --git a/AstroWall/ApplicationLayer/Helpers/General.Macos.cs b/AstroWall/ApplicationLayer/Helpers/General.Macos.cs index cc1dba3..7f39576 100644 --- a/AstroWall/ApplicationLayer/Helpers/General.Macos.cs +++ b/AstroWall/ApplicationLayer/Helpers/General.Macos.cs @@ -17,6 +17,10 @@ public class General public General() { } + public static string currentVersion() + { + return NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString(); + } public static string getAstroDirectory() { diff --git a/AstroWall/ApplicationLayer/View/AboutViewController.cs b/AstroWall/ApplicationLayer/View/AboutViewController.cs new file mode 100644 index 0000000..f73d415 --- /dev/null +++ b/AstroWall/ApplicationLayer/View/AboutViewController.cs @@ -0,0 +1,56 @@ +// This file has been autogenerated from a class added in the UI designer. + +using System; + +using Foundation; +using AppKit; + +namespace AstroWall +{ + public partial class AboutViewController : NSViewController + { + + + public AboutViewController(IntPtr handle) : base(handle) + { + } + + public override void ViewDidLoad() + { + base.ViewDidLoad(); + OutletVersion.StringValue = General.currentVersion(); + } + + //public override void + //{ + // base.DidAddSubview(subview); + //} + + partial void ActionGithub(NSObject sender) + { + openWebPage("https://github.com/wiegell/AstroWall/"); + } + partial void ActionWeb(NSObject sender) + { + openWebPage("https://wiegell.github.io/AstroWall/"); + } + partial void ActionIssues(NSObject sender) + { + openWebPage("https://github.com/wiegell/AstroWall/issues"); + } + + private void openWebPage(string url) + { + NSTask nstask = new NSTask(); + nstask.LaunchPath = "/bin/bash"; + nstask.Arguments = new string[] + { + "-c", + "open "+url + }; + //+" " + nstask.Launch(); + nstask.WaitUntilExit(); + } + } +} diff --git a/AstroWall/ApplicationLayer/View/AboutViewController.designer.cs b/AstroWall/ApplicationLayer/View/AboutViewController.designer.cs new file mode 100644 index 0000000..c8a3a89 --- /dev/null +++ b/AstroWall/ApplicationLayer/View/AboutViewController.designer.cs @@ -0,0 +1,35 @@ +// WARNING +// +// This file has been generated automatically by Visual Studio to store outlets and +// actions made in the UI designer. If it is removed, they will be lost. +// Manual changes to this file may not be handled correctly. +// +using Foundation; +using System.CodeDom.Compiler; + +namespace AstroWall +{ + [Register ("AboutViewController")] + partial class AboutViewController + { + [Outlet] + AppKit.NSTextField OutletVersion { get; set; } + + [Action ("ActionGithub:")] + partial void ActionGithub (Foundation.NSObject sender); + + [Action ("ActionIssues:")] + partial void ActionIssues (Foundation.NSObject sender); + + [Action ("ActionWeb:")] + partial void ActionWeb (Foundation.NSObject sender); + + void ReleaseDesignerOutlets () + { + if (OutletVersion != null) { + OutletVersion.Dispose (); + OutletVersion = null; + } + } + } +} diff --git a/AstroWall/AstroWall.csproj b/AstroWall/AstroWall.csproj index 4d1b06c..8aa8c2a 100644 --- a/AstroWall/AstroWall.csproj +++ b/AstroWall/AstroWall.csproj @@ -186,6 +186,11 @@ + + + AboutViewController.cs + + diff --git a/AstroWall/BusinessLayer/ApplicationHandler.cs b/AstroWall/BusinessLayer/ApplicationHandler.cs index d3a4ad5..cadd47b 100644 --- a/AstroWall/BusinessLayer/ApplicationHandler.cs +++ b/AstroWall/BusinessLayer/ApplicationHandler.cs @@ -20,7 +20,7 @@ public class ApplicationHandler // Misc public Version CurrentVersion { private set; get; } - private string currentVersionString = NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString(); + private string currentVersionString = General.currentVersion(); public ApplicationHandler(AppDelegate del) diff --git a/AstroWall/BusinessLayer/ImgWrap.cs b/AstroWall/BusinessLayer/ImgWrap.cs index 8699ff3..4383186 100644 --- a/AstroWall/BusinessLayer/ImgWrap.cs +++ b/AstroWall/BusinessLayer/ImgWrap.cs @@ -3,7 +3,7 @@ using SkiaSharp; using System.IO; using System.Threading.Tasks; -using AstroWall.BusinessLayer.Preferences; +using AstroWall.BusinessLayer; using System.Collections.Generic; using System.Linq; using AstroWall.ApplicationLayer.Helpers; @@ -174,9 +174,11 @@ private async Task createPreviewFromFullSize(int width = 250, int height = 180) return; } - public async Task createPostProcessedImages(Dictionary screens) + public async Task createPostProcessedImages(Dictionary screens, Dictionary postProcessPrefsDictionary) { Console.WriteLine("creating postprocessed images"); + + // Load full res image SKBitmap image; try { @@ -188,17 +190,36 @@ public async Task createPostProcessedImages(Dictionary screens) return; } + // Prep Dictionary vars for postprocess + Dictionary unProcessedImagesByScreenId = + screens.ToDictionary( + // Set Screen instance as key + screenKV => screenKV.Value, + // Value as unprocessed full res image loaded above + screenKV => image + ); + Dictionary postProcessedImagesByScreenId; + + // Prep postprocess chain + Func> postProcessChain = + Wallpaper.PostProcess.ComposePostProcess( + () => unProcessedImagesByScreenId, + //Wallpaper.PostProcess.AddTextCurry( + // (Preferences.AddText)postProcessPrefsDictionary[Preferences.PostProcessType.AddText], + // Title, + // Description + // ), + Wallpaper.PostProcess.AddTextCurry( + (Preferences.AddText)postProcessPrefsDictionary[Preferences.PostProcessType.AddText], + Title, + "TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST TEEEEEEEEEST " + ) + ); + // Do the postprocessing - Dictionary postProcessedImagesByScreenId; try { - postProcessedImagesByScreenId = - screens.ToDictionary( - screenKV => - screenKV.Key, - screenKV => - Wallpaper.PostProcess.AddText(image, Title, Description)); - + postProcessedImagesByScreenId = postProcessChain(); } catch (Exception ex) { @@ -209,11 +230,12 @@ public async Task createPostProcessedImages(Dictionary screens) // Save files and register file paths try { + // This is the format saved in prefs ImgLocalPostProcessedUrlsByScreenId = postProcessedImagesByScreenId.ToDictionary( - bitmapKV => bitmapKV.Key, + bitmapKV => bitmapKV.Key.Id, bitmapKV => { - string path = $"{ImgLocalUrl}_postprocessed_{bitmapKV.Key}.{FileType}"; + string path = $"{ImgLocalUrl}_postprocessed_{bitmapKV.Key.Id}.{FileType}"; FileStream f = File.Create(path); bitmapKV.Value.Encode(f, (OnlineUrlIsJPG() ? SKEncodedImageFormat.Jpeg : SKEncodedImageFormat.Png), 90); Console.WriteLine($"postprocess for screen {bitmapKV.Key} saved: {path}"); diff --git a/AstroWall/BusinessLayer/Preferences/AddText.model.cs b/AstroWall/BusinessLayer/Preferences/AddText.model.cs index 8077069..4102727 100644 --- a/AstroWall/BusinessLayer/Preferences/AddText.model.cs +++ b/AstroWall/BusinessLayer/Preferences/AddText.model.cs @@ -6,9 +6,9 @@ namespace AstroWall.BusinessLayer.Preferences [JsonObject] public class AddText : PostProcess { - public AddText(bool isEnabled) : base("Add text", isEnabled) + public AddText(bool isEnabled) : base(PostProcessType.AddText, isEnabled) { - + } public AddText(AddText otherObj, bool isEnabled) : base(otherObj, isEnabled) { diff --git a/AstroWall/BusinessLayer/Preferences/PostProcess.model.cs b/AstroWall/BusinessLayer/Preferences/PostProcess.model.cs index 5517048..51bc068 100644 --- a/AstroWall/BusinessLayer/Preferences/PostProcess.model.cs +++ b/AstroWall/BusinessLayer/Preferences/PostProcess.model.cs @@ -3,6 +3,11 @@ namespace AstroWall.BusinessLayer.Preferences { + public enum PostProcessType + { + AddText, + ScaleAndCrop + } [JsonObject] public abstract class PostProcess @@ -10,14 +15,14 @@ public abstract class PostProcess [JsonProperty] public readonly bool isEnabled; [JsonProperty] - public readonly string name; + public readonly PostProcessType name; - public PostProcess(string name, bool isEnabled) + public PostProcess(PostProcessType name, bool isEnabled) { this.name = name; this.isEnabled = isEnabled; } - public PostProcess(PostProcess otherObj, string name) + public PostProcess(PostProcess otherObj, PostProcessType name) { this.name = name; this.isEnabled = otherObj.isEnabled; diff --git a/AstroWall/BusinessLayer/Preferences/Preferences.cs b/AstroWall/BusinessLayer/Preferences/Preferences.cs index f18524e..459bb68 100644 --- a/AstroWall/BusinessLayer/Preferences/Preferences.cs +++ b/AstroWall/BusinessLayer/Preferences/Preferences.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using AppKit; using Newtonsoft.Json; @@ -37,13 +38,13 @@ public class Preferences [JsonProperty] public AddText AddTextPostProcess; - public List PostProcesses + public Dictionary PostProcesses { get { - var retList = new List(); - retList.Add(AddTextPostProcess); - return retList; + var retDict = new Dictionary(); + retDict.Add(PostProcessType.AddText, AddTextPostProcess); + return retDict; } } diff --git a/AstroWall/BusinessLayer/Wallpaper/PostProcess/AddText.cs b/AstroWall/BusinessLayer/Wallpaper/PostProcess/AddText.cs index ba27bc2..3048349 100644 --- a/AstroWall/BusinessLayer/Wallpaper/PostProcess/AddText.cs +++ b/AstroWall/BusinessLayer/Wallpaper/PostProcess/AddText.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Text; +using AstroWall.ApplicationLayer.Helpers; using SkiaSharp; namespace AstroWall.BusinessLayer.Wallpaper @@ -13,45 +14,61 @@ public PostProcess() { } - public static SkiaSharp.SKBitmap AddText(SKBitmap inputBitmap, string title, string description) + public static Func, Dictionary> AddTextCurry(Preferences.AddText options, string title, string description) { - SKBitmap toBitmap; + return (Dictionary dic) => + { + return AddText(dic, options, title, description); + }; + } + + public static Dictionary AddText(Dictionary dic, Preferences.AddText options, string title, string description) + { + SKBitmap mainScreenBitmap; + Screen mainScreen; + try + { + mainScreen = dic.Where(screen => screen.Key.isMainScreen).ToArray()[0].Key; + mainScreenBitmap = dic[mainScreen]; + } + catch (Exception ex) + { + throw new Exception("Could not get main screen from input dict", ex); + } + if (mainScreenBitmap == null) + { + throw new Exception("Could not get main screen from input dict"); + } + + SKBitmap returnBitmap; Console.WriteLine("running postprocess"); try { - toBitmap = inputBitmap.Copy(); - } catch (Exception ex) + returnBitmap = mainScreenBitmap.Copy(); + } + catch (Exception ex) { var exx = ex; Console.WriteLine("Problem copying bitmap"); throw ex; } - var canvas = new SKCanvas(toBitmap); - // Draw a bitmap rescaled - //canvas.SetMatrix(SKMatrix.MakeScale(resizeFactor, resizeFactor)); - canvas.DrawBitmap(inputBitmap, 0, 0); + var canvas = new SKCanvas(returnBitmap); + canvas.DrawBitmap(mainScreenBitmap, 0, 0); canvas.ResetMatrix(); - //var font = SKTypeface.FromFamilyName("Arial"); - //var brush = new SKPaint - //{ - // Typeface = font, - // TextSize = 20f, - // IsAntialias = true, - // Color = new SKColor(255, 255, 255, 255) - //}; - //canvas.DrawText(description, 80, toBitmap.Height - 120, brush); - - PaintToRect(canvas, 1000, 500, 80, toBitmap.Height - 120, description + PaintToRect(canvas, 1000, 500, 80, returnBitmap.Height - 120, description ); canvas.Flush(); + canvas.Dispose(); + // Create shallow dict copy to return + var returnDic = dic.ToDictionary(x => x.Key, x => x.Value); - canvas.Dispose(); - //brush.Dispose(); - //font.Dispose(); - return toBitmap; + // Replace main screen with new bitmap + returnDic[mainScreen] = returnBitmap; + + return returnDic; } private static void PaintToRect(SKCanvas canvas, int width, int height, int x, int y, string text) { diff --git a/AstroWall/BusinessLayer/Wallpaper/PostProcess/Compose.cs b/AstroWall/BusinessLayer/Wallpaper/PostProcess/Compose.cs new file mode 100644 index 0000000..3dc1bbc --- /dev/null +++ b/AstroWall/BusinessLayer/Wallpaper/PostProcess/Compose.cs @@ -0,0 +1,25 @@ +using System; +using AstroWall.ApplicationLayer.Helpers; +using System.Collections.Generic; +using SkiaSharp; + +namespace AstroWall.BusinessLayer.Wallpaper +{ + partial class PostProcess + { + public static Func> ComposePostProcess( + Func> f1, + Func, Dictionary> f2, + Func, Dictionary> f3) + { + return () => f3(f2(f1())); + } + public static Func> ComposePostProcess( + Func> f1, + Func, Dictionary> f2) + { + return () => f2(f1()); + } + } +} + diff --git a/AstroWall/BusinessLayer/Wallpaper/PostProcess/ScaleAndCrop.cs b/AstroWall/BusinessLayer/Wallpaper/PostProcess/ScaleAndCrop.cs index 82d8867..50fb5b7 100644 --- a/AstroWall/BusinessLayer/Wallpaper/PostProcess/ScaleAndCrop.cs +++ b/AstroWall/BusinessLayer/Wallpaper/PostProcess/ScaleAndCrop.cs @@ -1,10 +1,26 @@ using System; +using System.Collections.Generic; +using AstroWall.ApplicationLayer.Helpers; +using SkiaSharp; + namespace AstroWall.BusinessLayer.Wallpaper { partial class PostProcess { - //public static SkiaSharp.SKBitmap ScaleAndCrop() + public Func, Dictionary> ScaleAndCropCurry() + { + // Not really needed atm, might be later + return (Dictionary dic) => + { + return ScaleAndCrop(dic); + }; + } + + public static Dictionary ScaleAndCrop(Dictionary dic) + { + return new Dictionary(); + } } } diff --git a/AstroWall/BusinessLayer/Wallpaper/Wallpaper.cs b/AstroWall/BusinessLayer/Wallpaper/Wallpaper.cs index 380bcfe..4b2057e 100644 --- a/AstroWall/BusinessLayer/Wallpaper/Wallpaper.cs +++ b/AstroWall/BusinessLayer/Wallpaper/Wallpaper.cs @@ -45,7 +45,7 @@ public async Task RunPostProcessAndSetWallpaperAllScreens(ImgWrap imgWrap) var currentScreensConnectedById = Screen.FromCurrentConnected(); // Create postprocessed images - await imgWrap.createPostProcessedImages(currentScreensConnectedById); + await imgWrap.createPostProcessedImages(currentScreensConnectedById, applicationHandler.Prefs.PostProcesses); // Set wallpapers Dictionary postProcessedImageUrlByScreen = imgWrap.ImgLocalPostProcessedUrlsByScreenId.ToDictionary( diff --git a/AstroWall/Main.storyboard b/AstroWall/Main.storyboard index 3f72f78..6157021 100644 --- a/AstroWall/Main.storyboard +++ b/AstroWall/Main.storyboard @@ -616,7 +616,7 @@ - + @@ -650,10 +650,9 @@ - + - - + @@ -672,25 +671,96 @@ - + - + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -840,6 +910,7 @@ +