Example #1
0
        public ViewsAndSubViews() : base(1, 1)
        {
            mainView = new Console(60, 23);
            subView  = Console.FromSurface(mainView.GetViewSurface(new Rectangle(0, 0, 20, 23)));

            IsVisible = false;
            UseMouse  = true;

            mainView.DrawLine(new Point(59, 0), new Point(59, 22), Color.White, glyph: ConnectedLineThin[(int)ConnectedLineIndex.Left]);

            // Setup main view
            mainView.Position   = new Point(0, 2);
            mainView.MouseMove += (s, e) => { if (e.MouseState.Mouse.LeftButtonDown)
                                              {
                                                  e.MouseState.Cell.Background = Color.Blue; mainView.IsDirty = true;
                                              }
            };
            mainView.DirtyChanged += (s, e) => subView.IsDirty = true;

            // Setup sub view
            subView.Position = new Point(60, 2);
            //subView.SetViewFromSurface(new Rectangle(0, 0, 20, 23), mainView);
            subView.MouseMove += (s, e) => { if (e.MouseState.Mouse.LeftButtonDown)
                                             {
                                                 e.MouseState.Cell.Background = Color.Red; subView.IsDirty = true;
                                             }
            };
            subView.DirtyChanged += (s, e) => mainView.IsDirty = true;

            // Ad the consoles to the list.
            Children.Add(mainView);
            Children.Add(subView);
        }
        public SubConsoleCursor()
        {
            mainView = new Console(80, 23);
            subView  = Console.FromSurface(mainView.GetViewSurface(new Rectangle(30, 4, 25, 10)));

            UseKeyboard = true;

            // Setup main view
            mainView.FillWithRandomGarbage();
            mainView.MouseMove += (s, e) => { if (e.MouseState.Mouse.LeftButtonDown)
                                              {
                                                  e.MouseState.Cell.Background = Color.Blue;
                                              }
            };

            // Setup sub view
            subView.Position          = new Point(4, 4);
            subView.DefaultBackground = Color.Black;
            subView.MouseMove        += (s, e) => { if (e.MouseState.Mouse.LeftButtonDown)
                                                    {
                                                        e.MouseState.Cell.Background = Color.Red;
                                                    }
            };
            subView.DirtyChanged += (s, e) => mainView.IsDirty = subView.IsDirty;
            subView.Clear();
            subView.Cursor.IsVisible = true;
            subView.Cursor
            .Print("The left box is a whole console which is a view into the box on the right.")
            .CarriageReturn()
            .LineFeed();


            // Ad the consoles to the list.
            Children.Add(mainView);
            Children.Add(subView);

            IsVisible = false;
        }
Example #3
0
        public SplashScreen()
            : base(80, 23)
        {
            Cursor.IsEnabled = false;
            IsVisible        = false;

            // Setup the console text background pattern, which is hidden via colors
            // Print the text template on all of the console surface
            const string textTemplate = "sole SadCon";
            var          text         = new System.Text.StringBuilder(Width * Height);

            for (int i = 0; i < Width * Height; i++)
            {
                text.Append(textTemplate);
            }
            Print(0, 0, text.ToString(), Color.Black, Color.Transparent);

            // Load the logo and convert to a console
            using (System.IO.Stream imageStream = Microsoft.Xna.Framework.TitleContainer.OpenStream("sad.png"))
            {
                using (var image = Texture2D.FromStream(Global.GraphicsDevice, imageStream))
                {
                    CellSurface logo = image.ToSurface(Global.FontDefault, false);

                    _consoleImage         = Console.FromSurface(logo, Global.FontDefault);
                    _consoleImagePosition = new Point(Width / 2 - _consoleImage.Width / 2, -1);
                    _consoleImage.Tint    = Color.Black;
                }
            }

            // Animation for the logo text.
            var logoText = new ColorGradient(new[] { Color.Magenta, Color.Yellow }, new[] { 0.0f, 1f })
                           .ToColoredString("[| Powered by SadConsole |]");

            logoText.SetEffect(new Fade()
            {
                DestinationForeground = Color.Blue,
                FadeForeground        = true,
                FadeDuration          = 1f,
                Repeat           = false,
                RemoveOnFinished = true,
                Permanent        = true,
                CloneOnApply     = true
            });

            // Configure the animation
            InstructionSet animation = new InstructionSet()

                                       .Wait(TimeSpan.FromSeconds(0.3d))

                                       // Animation to move the angled gradient spotlight effect
                                       .Code(MoveGradient)

                                       // Clear the background text so new printing doesn't look bad
                                       .Code((console, delta) =>
            {
                console.Fill(Color.Black, Color.Transparent, 0);
                return(true);
            })

                                       // Draw the SadConsole text at the bottom
                                       .Instruct(new DrawString(logoText)
            {
                Position         = new Point(26, Height - 1),
                TotalTimeToPrint = 1f
            })

                                       // Fade in the logo
                                       .Instruct(new FadeTextSurfaceTint(_consoleImage,
                                                                         new ColorGradient(Color.Black, Color.Transparent),
                                                                         TimeSpan.FromSeconds(2)))

                                       // Blink SadConsole text at the bottom
                                       .Code(SetBlinkOnLogoText)

                                       // Delay so blinking effect is seen
                                       .Wait(TimeSpan.FromSeconds(2.5d))

                                       // Fade out main console and logo console.
                                       .InstructConcurrent(new FadeTextSurfaceTint(_consoleImage,
                                                                                   new ColorGradient(Color.Transparent, Color.Black),
                                                                                   TimeSpan.FromSeconds(2)),

                                                           new FadeTextSurfaceTint(this,
                                                                                   new ColorGradient(Color.Transparent, Color.Black),
                                                                                   TimeSpan.FromSeconds(1.0d)))

                                       // Animation has completed, call the callback this console uses to indicate it's complete
                                       .Code((con, delta) => { SplashCompleted?.Invoke(); return(true); })
            ;

            animation.RemoveOnFinished = true;

            Components.Add(animation);
        }
        private void Init()
        {
            splashConsole = new Console(140, 40);
            ShowIntro(splashConsole);
            splashConsole.Tint = Color.Black;

            const string textTemplate = "Pete's House of Code";
            var          text         = new System.Text.StringBuilder(Width * Height);

            for (var i = 0; i < Width * Height; i++)
            {
                text.Append(textTemplate);
            }

            Print(0, 0, text.ToString(), Color.Black, Color.Transparent);

            using (var imageStream = Microsoft.Xna.Framework.TitleContainer.OpenStream("Resources/PHOC-Splash.png"))
            {
                using (var image = Texture2D.FromStream(Global.GraphicsDevice, imageStream))
                {
                    var logo = image.ToSurface(Global.FontDefault, true);

                    consoleImage         = Console.FromSurface(logo, Global.FontDefault);
                    consoleImagePosition = new Point(Width / 2 - consoleImage.Width / 2, -1);
                    //consoleImage.Tint = Color.Black;
                    consoleImage.Fill(Color.Black, null, null);
                }
            }

            Children.Add(consoleImage);
            consoleImage.Position = consoleImagePosition;

            var animation = new InstructionSet()
                            .Wait(TimeSpan.FromSeconds(0.2d))
                            .Code(MoveGradient)
                            .Code((console, delta) =>
            {
                Children.Clear();
                console.Fill(Color.Black, Color.Transparent, 0);
                return(true);
            })
                            .Wait(TimeSpan.FromSeconds(2.5))
                            .Instruct(new FadeTextSurfaceTint(
                                          splashConsole,
                                          new ColorGradient(Color.Black, Color.Transparent),
                                          TimeSpan.FromSeconds(2)))
                            .Wait(TimeSpan.FromSeconds(3))
                            .InstructConcurrent(new FadeTextSurfaceTint(splashConsole,
                                                                        new ColorGradient(Color.Transparent, Color.Black),
                                                                        TimeSpan.FromSeconds(2)),

                                                new FadeTextSurfaceTint(this,
                                                                        new ColorGradient(Color.Transparent, Color.Black),
                                                                        TimeSpan.FromSeconds(1.0d)))

                            // Animation has completed, call the callback this console uses to indicate it's complete
                            .Code((con, delta) => { SplashDone.Invoke(); return(true); })
            ;

            animation.Finished += (s, e) => Components.Remove(animation);

            Components.Add(animation);
        }