XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEToolBox

【WPF】XFE工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Globalization;
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using XFEToolBox.QuickTools;

namespace QuickTools.Validation;

internal static partial class Program
{
    // Same layered tile, translucent light and dimensional object language as the older tools.
    // All shapes are native geometry; no dependency on installed icon fonts.
    private static partial void GenerateIcons()
    {
        string[] lights = ["#82E6EE", "#9DACFF", "#FFC581", "#7EDBF4", "#98DEC9", "#FFE29B", "#A6B6FF", "#9DC5E8"];
        string[] darks = ["#128EAD", "#514BC4", "#D96A35", "#2861BE", "#287F94", "#E29E27", "#6150C2", "#466BA5"];
        var sheet = new DrawingVisual();
        using var grid = sheet.RenderOpen();
        grid.DrawRectangle(B("#F4F5FB"), null, new Rect(0, 0, 1120, 620));
        for (int i = 0; i < Folders.Length; i++)
        {
            var visual = new DrawingVisual();
            using (var dc = visual.RenderOpen())
            {
                dc.DrawRoundedRectangle(B("#162746"), null, new Rect(20, 34, 216, 208), 48, 48);
                dc.DrawRoundedRectangle(Gradient(lights[i], darks[i]), new Pen(B("#60FFFFFF"), 1.5), new Rect(20, 18, 216, 212), 48, 48);
                dc.PushClip(new RectangleGeometry(new Rect(21, 19, 214, 210), 47, 47));
                dc.DrawEllipse(new RadialGradientBrush(C("#A0FFFFFF"), C("#00FFFFFF")), null, new Point(65, 40), 162, 140);
                dc.DrawRectangle(Gradient("#00FFFFFF", "#35FFFFFF"), null, new Rect(20, 18, 216, 110));
                dc.Pop();
                dc.PushTransform(new TranslateTransform(1, 6));
                dc.PushOpacity(.16);
                DrawObject(dc, i, B("#0A224A"), B("#0A224A"), true);
                dc.Pop(); dc.Pop();
                DrawObject(dc, i, Gradient("#FFFFFF", "#DDECFD"), B(darks[i]), false);
            }
            var bitmap = new RenderTargetBitmap(256, 256, 96, 96, PixelFormats.Pbgra32); bitmap.Render(visual); bitmap.Freeze();
            var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmap)); using var bytes = new MemoryStream(); encoder.Save(bytes);
            string directory = Path.Combine(WorkspaceRoot, Folders[i], "Assets"); Directory.CreateDirectory(directory);
            QuickToolPaths.AtomicWrite(Path.Combine(directory, "icon.png"), bytes.ToArray());
            string hostIcons = Path.GetFullPath("XFEToolBox/Resources/Image/QuickTools");
            if (Directory.Exists(hostIcons)) QuickToolPaths.AtomicWrite(Path.Combine(hostIcons, QuickToolCatalog.All[i].Kind + ".png"), bytes.ToArray());
            int x = (i % 4) * 280 + 12, y = (i / 4) * 310;
            grid.DrawImage(bitmap, new Rect(x, y, 256, 256));
            var title = new FormattedText(QuickToolCatalog.All[i].Name, CultureInfo.GetCultureInfo("zh-CN"), FlowDirection.LeftToRight, new Typeface("Microsoft YaHei UI"), 17, B("#28364E"), 1);
            grid.DrawText(title, new Point(x + 128 - title.Width / 2, y + 272));
        }
        grid.Close();
        var contact = new RenderTargetBitmap(1120, 620, 96, 96, PixelFormats.Pbgra32); contact.Render(sheet);
        var png = new PngBitmapEncoder(); png.Frames.Add(BitmapFrame.Create(contact)); using var output = File.Create(Path.Combine(root, "icons-contact-sheet.png")); png.Save(output);
    }
    private static Color C(string value) => (Color)ColorConverter.ConvertFromString(value);
    private static Brush B(string value) => new SolidColorBrush(C(value));
    private static Brush Gradient(string a, string b) => new LinearGradientBrush(C(a), C(b), new Point(0, 0), new Point(1, 1));
    private static void R(DrawingContext dc, Brush b, double x, double y, double w, double h, double radius = 7) => dc.DrawRoundedRectangle(b, null, new Rect(x, y, w, h), radius, radius);
    private static void Line(DrawingContext dc, Brush b, double x1, double y1, double x2, double y2, double width = 8) => dc.DrawLine(new Pen(b, width) { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round, LineJoin = PenLineJoin.Round }, new Point(x1, y1), new Point(x2, y2));
    private static void Shape(DrawingContext dc, Brush b, string geometry) => dc.DrawGeometry(b, null, Geometry.Parse(geometry));
    private static void DrawObject(DrawingContext dc, int kind, Brush paper, Brush accent, bool shadow)
    {
        Brush light = shadow ? paper : B("#C6DEF5"), blue = shadow ? paper : Gradient("#64D6FB", "#287EE0");
        switch (kind)
        {
            case 0: // Clipboard, paper layers and an actual clip, not a font glyph.
                R(dc, light, 58, 63, 127, 142, 14); R(dc, paper, 69, 53, 126, 144, 14);
                R(dc, accent, 99, 42, 67, 29, 10); R(dc, paper, 118, 39, 29, 14, 7);
                for (int row = 0; row < 3; row++) { R(dc, light, 87, 90 + row * 29, 65, 8, 4); R(dc, light, 87, 103 + row * 29, 89, 6, 3); }
                dc.DrawEllipse(blue, new Pen(paper, 5), new Point(184, 182), 30, 30);
                Line(dc, paper, 171, 181, 181, 191, 6); Line(dc, paper, 181, 191, 199, 170, 6);
                break;
            case 1: // Display, corner selection marks, magnifier.
                R(dc, paper, 47, 57, 164, 113, 14); R(dc, blue, 57, 67, 144, 91, 8);
                Shape(dc, light, "M58,146 L94,104 L124,132 L145,110 L201,147 L201,158 L57,158 Z");
                dc.DrawEllipse(paper, null, new Point(167, 89), 11, 11);
                R(dc, paper, 109, 165, 34, 23, 3); R(dc, paper, 85, 186, 82, 9, 4);
                dc.DrawEllipse(accent, new Pen(paper, 7), new Point(183, 177), 26, 26);
                Line(dc, paper, 202, 198, 218, 213, 11); Line(dc, paper, 171, 177, 195, 177, 4); Line(dc, paper, 183, 165, 183, 189, 4);
                break;
            case 2: // Dimensional calculator with a display and tactile keys.
                R(dc, light, 65, 47, 133, 163, 19); R(dc, paper, 58, 42, 133, 163, 19);
                R(dc, accent, 73, 58, 103, 38, 7);
                Line(dc, paper, 134, 70, 164, 70, 4); Line(dc, paper, 164, 70, 164, 85, 4); Line(dc, paper, 144, 86, 155, 86, 4);
                for (int r = 0; r < 3; r++) for (int c = 0; c < 3; c++) R(dc, c == 2 ? accent : light, 75 + c * 34, 110 + r * 27, 23, 19, 5);
                Line(dc, paper, 148, 173, 161, 173, 3); Line(dc, paper, 148, 179, 161, 179, 3);
                break;
            case 3: // Network socket, cable and a diagnostic lens.
                R(dc, paper, 46, 62, 160, 115, 19); R(dc, accent, 61, 77, 90, 78, 8);
                Shape(dc, light, "M74,86 L137,86 L137,128 L122,128 L122,144 L89,144 L89,128 L74,128 Z");
                for (int c = 0; c < 5; c++) R(dc, accent, 82 + c * 10, 88, 5, 20, 2);
                R(dc, blue, 166, 84, 19, 9, 4); R(dc, light, 166, 105, 19, 9, 4);
                Line(dc, paper, 100, 177, 100, 197, 12); Line(dc, paper, 100, 197, 144, 197, 12);
                dc.DrawEllipse(blue, new Pen(paper, 7), new Point(177, 169), 28, 28); Line(dc, paper, 197, 190, 217, 210, 11);
                break;
            case 4: // Code sheet with folded corner and syntax marks.
                Shape(dc, paper, "M68,43 L155,43 L197,85 L197,197 Q197,210 184,210 L68,210 Q55,210 55,197 L55,56 Q55,43 68,43 Z");
                Shape(dc, light, "M155,43 L155,72 Q155,85 169,85 L197,85 Z");
                R(dc, light, 75, 65, 57, 7, 3);
                Line(dc, accent, 100, 104, 81, 124, 8); Line(dc, accent, 81, 124, 100, 144, 8);
                Line(dc, accent, 153, 104, 172, 124, 8); Line(dc, accent, 172, 124, 153, 144, 8); Line(dc, blue, 136, 100, 117, 148, 8);
                R(dc, light, 76, 169, 72, 7, 3); R(dc, light, 76, 184, 102, 7, 3);
                break;
            case 5: // Overlapping file cards and pencil.
                R(dc, light, 48, 60, 98, 133, 12); R(dc, paper, 69, 47, 107, 142, 12);
                R(dc, accent, 85, 69, 64, 10, 5); R(dc, light, 85, 98, 69, 8, 4); R(dc, light, 85, 118, 52, 8, 4); R(dc, light, 85, 138, 42, 8, 4);
                dc.PushTransform(new RotateTransform(35, 178, 155));
                R(dc, blue, 165, 98, 26, 105, 4); R(dc, paper, 165, 99, 26, 18, 4);
                Shape(dc, paper, "M165,203 L191,203 L178,224 Z"); Shape(dc, accent, "M174,217 L182,217 L178,224 Z"); dc.Pop();
                break;
            case 6: // Readable finder patterns, not a arbitrary symbol.
                R(dc, paper, 46, 45, 166, 165, 19);
                foreach (var p in new[] { new Point(65, 64), new Point(145, 64), new Point(65, 144) })
                { R(dc, accent, p.X, p.Y, 44, 44, 7); R(dc, paper, p.X + 7, p.Y + 7, 30, 30, 3); R(dc, accent, p.X + 14, p.Y + 14, 16, 16, 2); }
                foreach (var p in new[] { new Point(121,64),new Point(121,88),new Point(65,121),new Point(89,121),new Point(113,121),new Point(145,120),new Point(177,120),new Point(120,146),new Point(145,145),new Point(177,146),new Point(145,170),new Point(170,181),new Point(120,178) }) R(dc, accent, p.X, p.Y, 12, 12, 2);
                Line(dc, blue, 40, 126, 218, 126, 5);
                break;
            case 7: // Three distinct system adjustment sliders.
                R(dc, paper, 45, 58, 167, 141, 20);
                foreach (double y in new[] { 90d, 128, 166 }) R(dc, light, 65, y - 4, 126, 8, 4);
                R(dc, blue, 65, 86, 73, 8, 4); R(dc, blue, 65, 124, 32, 8, 4); R(dc, blue, 65, 162, 89, 8, 4);
                foreach (var p in new[] {new Point(138,90),new Point(97,128),new Point(154,166)}) { dc.DrawEllipse(accent, null, new Point(p.X,p.Y+2), 13,13); dc.DrawEllipse(blue, new Pen(paper,3), p, 12,12); }
                break;
        }
    }
}