public static void ActUponInputToolTree(this IInputTool tool, Action <IInputTool> act)
        {
            act(tool);

            if (tool is IInputToolSelector)
            {
                foreach (var choice in (tool as ISelector).ObjOptions.Cast <IInputTool>())
                {
                    choice.ActUponInputToolTree(act);
                }
            }
        }
Beispiel #2
0
 public static IInputTool <T> Cast <T>(this IInputTool tool)
 {
     return((IInputTool <T>)tool);
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            Range.DefaultSlideWidth = 64;
            var red    = Range.New(0, 255, 1, Default: 0xFF, Title: "Primary color Red");
            var green  = Range.New(0, 255, 1, Default: 0xFF, Title: "Primary color Green");
            var blue   = Range.New(0, 255, 1, Default: 0xFF, Title: "Primary color Blue");
            var red2   = Range.New(0, 255, 1, Default: 0, Title: "Secondary color Red");
            var green2 = Range.New(0, 255, 1, Default: 0, Title: "Secondary color Green");
            var blue2  = Range.New(0, 255, 1, Default: 0, Title: "Secondary color Blue");

            red.SlideSplash = red2.SlideSplash = new Splash()
            {
                ForegroundColor = ConsoleColor.Red, BackgroundColor = ConsoleColor.DarkRed
            };
            green.SlideSplash = green2.SlideSplash = new Splash()
            {
                ForegroundColor = ConsoleColor.Green, BackgroundColor = ConsoleColor.DarkGreen
            };
            blue.SlideSplash = blue2.SlideSplash = new Splash()
            {
                ForegroundColor = ConsoleColor.Blue, BackgroundColor = ConsoleColor.DarkBlue
            };
            TextInput name = null;

            name = new TextInput(x =>
            {
                var chars = x.Intersect(Path.GetInvalidFileNameChars());

                if (x.Length == 0)
                {
                    name.ErrorMessage = $"Value cannot be empty";
                }
                else if (chars.Any())
                {
                    name.ErrorMessage = $"Remove: {Environment.NewLine}{string.Join(Environment.NewLine, chars)}";
                }
                else
                {
                    return(true);
                }
                return(false);
            })
            {
                Title  = "Finish",
                Header = "Choose filename:",
                Footer = "extension will be added (for example '.bmp')"
            };

            var options       = new IInputTool[] { red, green, blue, red2, green2, blue2, name };
            var imageSettings = new InputToolSelector <IInputTool>(options);
            var cancel        = new Selector <bool>(new bool[] { false, true })
            {
                Header = "Do you want to exit without saving?", DisplayFormat = x => x ? "Yes" : "No"
            };

            imageSettings.CancelTrigger = x => imageSettings.Cancel = cancel.Activate().IfType <Selector <bool> >(y => { }).Value;
            var bgsplash = new Splash()
            {
                ForegroundColor = ConsoleColor.DarkGray, BackgroundColor = ConsoleColor.Gray
            };

            imageSettings.ActUponInputToolTree(tool => tool.IfType <IRange <int> >(x =>
            {
                x.IncrementByModifiers[ConsoleModifiers.Control] = 5;
                x.IncrementByModifiers[ConsoleModifiers.Shift | ConsoleModifiers.Control] = 20;
                x.SlideBackgroundSplash = bgsplash;
                x.Header = x.Title;
            }));
            imageSettings.InputSplash.ForegroundColor = ConsoleColor.Cyan;
            name.PostActivateTrigger          = x => imageSettings.Cancel = true;
            name.FooterSplash.ForegroundColor = ConsoleColor.DarkGray;

            var format = new EnumSelector <ImageFormat> {
                Header = "Choose image format", InputSplash = imageSettings.InputSplash
            };

            while (true)
            {
                imageSettings.Activate();
                if (imageSettings.Cancel)
                {
                    return;
                }
                format.Activate();
                if (format.Cancel)
                {
                    continue;
                }

                var size   = 16;
                var drawer = new BitmapDrawer(name.Value, 32 * 8 * size, 32 * 5 * size)
                {
                    Iterations     = 64,
                    Zoom           = 4,
                    XScroll        = 0.45,
                    YScroll        = 0.05,
                    PrimaryColor   = Color.FromArgb(red.Value, green.Value, blue.Value),
                    SecondaryColor = Color.FromArgb(red2.Value, green2.Value, blue2.Value),
                    LimitAlpha     = 1,
                    ImageFormat    = format.Value
                };

                drawer.CreateImage();
                drawer.SaveImage();
                Process.Start($"{Directory.GetCurrentDirectory()}\\{drawer.FullFileName}");
                break;
            }
        }