/// <summary>
        /// Creates a new instance of the class.
        /// </summary>
        /// <param name="pixelWidth">Width the source texture.</param>
        /// <param name="pixelHeight">Height of the source texture.</param>
        /// <param name="font">Font used for rendering.</param>
        public TextureToSurfaceReader(int pixelWidth, int pixelHeight, Font font)
        {
            this.width  = pixelWidth;
            this.height = pixelHeight;
            pixels      = new Color[pixelWidth * pixelHeight];
            indexes     = new int[pixelWidth * pixelHeight];
            surface     = new TextSurface(pixelWidth / font.Size.X, pixelHeight / font.Size.Y, font);
            fontPixels  = font.Size.X * font.Size.Y;
            editor      = new SurfaceEditor(surface);

            // build the indexes
            int currentIndex = 0;

            for (int h = 0; h < surface.Height; h++)
            {
                int startY = (h * surface.Font.Size.Y);
                //System.Threading.Tasks.Parallel.For(0, image.Width / surface.Font.Size.X, (w) =>
                for (int w = 0; w < surface.Width; w++)
                {
                    int startX = (w * surface.Font.Size.X);

                    for (int y = 0; y < surface.Font.Size.Y; y++)
                    {
                        for (int x = 0; x < surface.Font.Size.X; x++)
                        {
                            int cY = y + startY;
                            int cX = x + startX;

                            indexes[currentIndex] = cY * pixelWidth + cX;
                            currentIndex++;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Creates a new instance of the class.
        /// </summary>
        /// <param name="pixelWidth">Width the source texture.</param>
        /// <param name="pixelHeight">Height of the source texture.</param>
        /// <param name="font">Font used for rendering.</param>
        public TextureToSurfaceReader(int pixelWidth, int pixelHeight, Font font)
        {
            this.width = pixelWidth;
            this.height = pixelHeight;
            pixels = new Color[pixelWidth * pixelHeight];
            indexes = new int[pixelWidth * pixelHeight];
            surface = new TextSurface(pixelWidth / font.Size.X, pixelHeight / font.Size.Y, font);
            fontPixels = font.Size.X * font.Size.Y;
            editor = new SurfaceEditor(surface);

            // build the indexes
            int currentIndex = 0;
            for (int h = 0; h < surface.Height; h++)
            {
                int startY = (h * surface.Font.Size.Y);
                //System.Threading.Tasks.Parallel.For(0, image.Width / surface.Font.Size.X, (w) =>
                for (int w = 0; w < surface.Width; w++)
                {
                    int startX = (w * surface.Font.Size.X);

                    for (int y = 0; y < surface.Font.Size.Y; y++)
                    {
                        for (int x = 0; x < surface.Font.Size.X; x++)
                        {
                            int cY = y + startY;
                            int cX = x + startX;

                            indexes[currentIndex] = cY * pixelWidth + cX;
                            currentIndex++;
                        }
                    }

                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Determines the cells that would be drawn on and returns them instead of drawing the line.
        /// </summary>
        /// <param name="surface">The surface to get the cells from.</param>
        /// <returns>The cells the line would have drawn on.</returns>
        public IEnumerable <Cell> GetCells(TextSurface surface)
        {
            List <Cell> cells = new List <Cell>();

            Algorithms.Line(StartingLocation.X, StartingLocation.Y, EndingLocation.X, EndingLocation.Y, (x, y) => { cells.Add(surface[x, y]); return(true); });

            return(cells);
        }
Beispiel #4
0
 public FPSCounterComponent(Microsoft.Xna.Framework.Game game)
     : base(game)
 {
     console = new TextSurface(30, 1, Engine.DefaultFont);
     editor  = new SurfaceEditor(console);
     console.DefaultBackground = Color.Black;
     editor.Clear();
     consoleRender = new TextSurfaceRenderer();
 }
 public FPSCounterComponent(Microsoft.Xna.Framework.Game game)
     : base(game)
 {
     console = new TextSurface(30, 1, Engine.DefaultFont);
     editor = new SurfaceEditor(console);
     console.DefaultBackground = Color.Black;
     editor.Clear();
     consoleRender = new TextSurfaceRenderer();
 }
Beispiel #6
0
        public BorderedConsole(int width, int height) : base(width - 1, height - 1)
        {
            borderSurface = new TextSurface(width, height, base.textSurface.Font);
            borderEdit    = new SurfaceEditor(borderSurface);
            Box box = Box.GetDefaultBox();

            box.Width  = borderSurface.Width;
            box.Height = borderSurface.Height;
            box.Draw(borderEdit);
        }
Beispiel #7
0
 private void LoadAnsi()
 {
     _textSurface.Clear();
     SadConsole.Ansi.Document   doc    = new SadConsole.Ansi.Document($"./ansi/{files[fileIndex]}");
     SadConsole.Ansi.AnsiWriter writer = new SadConsole.Ansi.AnsiWriter(doc, this);
     writer.ReadEntireDocument();
     Data   = new TextSurface(80, 25 + _textSurface.TimesShiftedUp);
     writer = new SadConsole.Ansi.AnsiWriter(doc, this);
     writer.ReadEntireDocument();
 }
Beispiel #8
0
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var compositor = Window.Current.Compositor;

            _surface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/webster-pass.png"));

            var backgroundBrush = compositor.CreateSurfaceBrush(_surface);

            backgroundBrush.Stretch = CompositionStretch.UniformToFill;

            var saturationEffect = new SaturationEffect
            {
                Saturation = 0.0f,
                Source     = new CompositionEffectSourceParameter("mySource")
            };

            var saturationEffectFactory = compositor.CreateEffectFactory(saturationEffect);

            var bwEffect = saturationEffectFactory.CreateBrush();

            bwEffect.SetSourceParameter("mySource", backgroundBrush);

            _backgroundVisual       = compositor.CreateSpriteVisual();
            _backgroundVisual.Brush = bwEffect;
            _backgroundVisual.Size  = RootElement.RenderSize.ToVector2();


            _containerVisual = compositor.CreateContainerVisual();
            _containerVisual.Children.InsertAtBottom(_backgroundVisual);
            ElementCompositionPreview.SetElementChildVisual(RootElement, _containerVisual);

            // Text
            _surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(compositor);

            _textSurface = _surfaceFactory.CreateTextSurface("Weston Pass");
            _textSurface.ForegroundColor = Color.FromArgb(50, 255, 255, 255);
            _textSurface.FontSize        = 150;
            var textSurfaceBrush = compositor.CreateSurfaceBrush(_textSurface.Surface);


            _textVisual      = compositor.CreateSpriteVisual();
            _textVisual.Size = _textSurface.Size.ToVector2();
            _textVisual.RotationAngleInDegrees = 45f;
            _textVisual.AnchorPoint            = new Vector2(0.5f);

            _textVisual.Brush = textSurfaceBrush;
            _textVisual.StartAnimation(nameof(Visual.Offset), CreateTextOffsetAnimation(
                                           new Vector3((float)RootElement.ActualWidth / 2, (float)RootElement.ActualWidth / 2, 0)));

            _containerVisual.Children.InsertAtTop(_textVisual);

            AddLighting();

            StartLightingAnimationTimer();
        }
Beispiel #9
0
 private void LoadAnsi()
 {
     Clear();
     writer = new SadConsole.Ansi.AnsiWriter(doc, this);
     writer.ReadEntireDocument();
     TextSurface = new TextSurface(80, 25 + TimesShiftedUp);
     writer      = new SadConsole.Ansi.AnsiWriter(doc, this);
     writer.ReadEntireDocument();
     textSurface.RenderArea = new Rectangle(0, 0, 80, 25);
     writer = null;
 }
        public override void Render()
        {
            // These 3 render calls are a hack to get the console data generated and display a message to the user
            // Should add in async calls that let us generate these in the background... That would be cool.
            if (IsVisible)
            {
                if (!initialized)
                {
                    base.Render();
                }

                else if (!initializedStep2)
                {
                    initializedStep2 = true;
                    base.Render();
                }
                else if (!initializedStep3)
                {
                    base.Render();

                    // Generate the content
                    TextSurface = new TextSurface(2000, 2000, Engine.DefaultFont); //500mb ?? why?
                    //Data = new TextSurface(2000, 2000);
                    //DataViewport = new Rectangle(0, 0, 80, 25);
                    TextSurface.RenderArea = new Rectangle(0, 0, 80, 25);

                    // Clear message data and make it transparent so that it acts as a layer
                    messageData.Fill(Color.White, Color.Transparent, 0, null);

                    // We need to set celldata to the big console data so we can use the FillWithRandom method.
                    FillWithRandomGarbage();
                    initializedStep3 = true;
                }

                else
                {
                    // Set message data information about where the viewport is located
                    //messageData.Print(0, 0, $"{ViewArea.X} , {ViewArea.Y}            ", Color.White, Color.Black);

                    // Create a faux layering system.
                    base.Render();

                    //Renderer.Render(messageData.TextSurface, new Point(0, 0));
                }
            }
        }
        public override void Render()
        {
            // These 3 render calls are a hack to get the console data generated and display a message to the user
            // Should add in async calls that let us generate these in the background... That would be cool.
            if (IsVisible)
            {
                if (!initialized)
                    base.Render();

                else if (!initializedStep2)
                {
                    initializedStep2 = true;
                    base.Render();
                }
                else if (!initializedStep3)
                {
                    base.Render();

                    // Generate the content
                    TextSurface = new TextSurface(2000, 2000, Engine.DefaultFont); //500mb ?? why?
                    //Data = new TextSurface(2000, 2000);
                    //DataViewport = new Rectangle(0, 0, 80, 25);
                    TextSurface.RenderArea = new Rectangle(0, 0, 80, 25);

                    // Clear message data and make it transparent so that it acts as a layer
                    messageData.Fill(Color.White, Color.Transparent, 0, null);

                    // We need to set celldata to the big console data so we can use the FillWithRandom method.
                    FillWithRandomGarbage();
                    initializedStep3 = true;
                }

                else
                {
                    // Set message data information about where the viewport is located
                    //messageData.Print(0, 0, $"{ViewArea.X} , {ViewArea.Y}            ", Color.White, Color.Black);

                    // Create a faux layering system.
                    base.Render();

                    //Renderer.Render(messageData.TextSurface, new Point(0, 0));
                }
            }
        }
        public BorderedScrollingConsole(int width, int height, int bufferHeight) : base(width - 2, bufferHeight)
        {
            controlsContainer      = new SadConsole.Consoles.ControlsConsole(1, height - 2);
            textSurface.RenderArea = new Rectangle(1, 1, width, height - 2);
            scrollBar               = SadConsole.Controls.ScrollBar.Create(System.Windows.Controls.Orientation.Vertical, height - 2);
            scrollBar.IsEnabled     = false;
            scrollBar.ValueChanged += scrollBar_ValueChanged;
            controlsContainer.Add(scrollBar);
            controlsContainer.Position                 = new Point(Position.X + width, Position.Y);
            controlsContainer.IsVisible                = true;
            controlsContainer.MouseCanFocus            = false;
            controlsContainer.ProcessMouseWithoutFocus = true;
            scrollingCounter = 0;
            borderSurface    = new TextSurface(width, height, base.textSurface.Font);
            borderEdit       = new SurfaceEditor(borderSurface);
            Box box = Box.GetDefaultBox();

            box.Width  = width;
            box.Height = height;
            box.Draw(borderEdit);
        }
        void saveFrameToFile_ButtonClicked(object sender, EventArgs e)
        {
            SelectFilePopup popup = new SelectFilePopup();
            popup.Closed += (o2, e2) =>
            {
                if (popup.DialogResult)
                {
                    TextSurface surface = new TextSurface(selectedFrame.Width, selectedFrame.Height, selectedFrame.Cells, Settings.Config.ScreenFont);
                    surface.DefaultForeground = selectedFrame.DefaultForeground;
                    surface.DefaultBackground = selectedFrame.DefaultBackground;

                    popup.SelectedLoader.Save(surface, popup.SelectedFile);
                }
            };
            popup.CurrentFolder = Environment.CurrentDirectory;
            popup.FileLoaderTypes = new FileLoaders.IFileLoader[] { new FileLoaders.TextSurface(), new FileLoaders.TextFile() };
            popup.SelectButtonText = "Save";
            popup.SkipFileExistCheck = true;
            popup.Show(true);
            popup.Center();
        }
Beispiel #14
0
 private void LoadAnsi()
 {
     Clear();
     writer = new SadConsole.Ansi.AnsiWriter(doc, this);
     writer.ReadEntireDocument();
     TextSurface = new TextSurface(80, 25 + TimesShiftedUp);
     writer = new SadConsole.Ansi.AnsiWriter(doc, this);
     writer.ReadEntireDocument();
     textSurface.RenderArea = new Rectangle(0, 0, 80, 25);
     writer = null;
 }
Beispiel #15
0
 /// <summary>
 /// Returns the amount of cells (X,Y) given the specified <see cref="TextSurface"/> and current <see cref="Engine.WindowWidth"/> and <see cref="Engine.WindowHeight"/> properties.
 /// </summary>
 /// <param name="surface">The cell surface.</param>
 /// <returns>The amount of cells along the X and Y axis.</returns>
 public static Point GetScreenSizeInCells(TextSurface surface)
 {
     return(new Point(WindowWidth / surface.Font.Size.X, WindowHeight / surface.Font.Size.Y));
 }
Beispiel #16
0
        public unsafe static void ToSurface(this Texture2D image, TextSurface surface, Color[] cachedColorArray, bool blockMode = false)
        {
#if SFML
            int     imageWidth  = (int)image.Size.X;
            int     imageHeight = (int)image.Size.Y;
            Color[] pixels      = new Color[imageWidth * imageHeight];
            using (var imageData = image.CopyToImage())
            {
                int pixelChanIndex = 0;
                fixed(byte *pixelChan = imageData.Pixels)
                {
                    fixed(Color *color = pixels)
                    {
                        for (int i = 0; i < pixels.Length; i++)
                        {
                            color[i].R = pixelChan[pixelChanIndex];
                            color[i].G = pixelChan[pixelChanIndex + 1];
                            color[i].B = pixelChan[pixelChanIndex + 2];
                            color[i].A = pixelChan[pixelChanIndex + 3];

                            pixelChanIndex += 4;
                        }
                    }
                }
            }
#elif MONOGAME
            int imageWidth  = image.Width;
            int imageHeight = image.Height;
            image.GetData <Color>(cachedColorArray);
#endif

            SurfaceEditor editor = new SurfaceEditor(surface);
            editor.Clear();
            global::System.Threading.Tasks.Parallel.For(0, imageHeight / surface.Font.Size.Y, (h) =>
                                                        //for (int h = 0; h < imageHeight / surface.Font.Size.Y; h++)
            {
                int startY = (h * surface.Font.Size.Y);
                //System.Threading.Tasks.Parallel.For(0, imageWidth / surface.Font.Size.X, (w) =>
                for (int w = 0; w < imageWidth / surface.Font.Size.X; w++)
                {
                    int startX = (w * surface.Font.Size.X);

                    float allR = 0;
                    float allG = 0;
                    float allB = 0;

                    for (int y = 0; y < surface.Font.Size.Y; y++)
                    {
                        for (int x = 0; x < surface.Font.Size.X; x++)
                        {
                            int cY = y + startY;
                            int cX = x + startX;

                            Color color = cachedColorArray[cY * imageWidth + cX];

                            allR += color.R;
                            allG += color.G;
                            allB += color.B;
                        }
                    }

                    byte sr = (byte)(allR / (surface.Font.Size.X * surface.Font.Size.Y));
                    byte sg = (byte)(allG / (surface.Font.Size.X * surface.Font.Size.Y));
                    byte sb = (byte)(allB / (surface.Font.Size.X * surface.Font.Size.Y));

                    var newColor = new Color(sr, sg, sb);

                    float sbri = newColor.GetBrightness() * 255;

                    if (blockMode)
                    {
                        if (sbri > 204)
                        {
                            editor.SetGlyph(w, h, 219, newColor); //█
                        }
                        else if (sbri > 152)
                        {
                            editor.SetGlyph(w, h, 178, newColor); //▓
                        }
                        else if (sbri > 100)
                        {
                            editor.SetGlyph(w, h, 177, newColor); //▒
                        }
                        else if (sbri > 48)
                        {
                            editor.SetGlyph(w, h, 176, newColor); //░
                        }
                    }
                    else
                    {
                        if (sbri > 230)
                        {
                            editor.SetGlyph(w, h, (int)'#', newColor);
                        }
                        else if (sbri > 207)
                        {
                            editor.SetGlyph(w, h, (int)'&', newColor);
                        }
                        else if (sbri > 184)
                        {
                            editor.SetGlyph(w, h, (int)'$', newColor);
                        }
                        else if (sbri > 161)
                        {
                            editor.SetGlyph(w, h, (int)'X', newColor);
                        }
                        else if (sbri > 138)
                        {
                            editor.SetGlyph(w, h, (int)'x', newColor);
                        }
                        else if (sbri > 115)
                        {
                            editor.SetGlyph(w, h, (int)'=', newColor);
                        }
                        else if (sbri > 92)
                        {
                            editor.SetGlyph(w, h, (int)'+', newColor);
                        }
                        else if (sbri > 69)
                        {
                            editor.SetGlyph(w, h, (int)';', newColor);
                        }
                        else if (sbri > 46)
                        {
                            editor.SetGlyph(w, h, (int)':', newColor);
                        }
                        else if (sbri > 23)
                        {
                            editor.SetGlyph(w, h, (int)'.', newColor);
                        }
                    }
                }
            }
                                                        );
        }
Beispiel #17
0
        public SplashScreen()
            : base(80, 25)
        {
            IsVisible      = false;
            effectsManager = new EffectsManager(this.TextSurface);
            // Setup the console text background
            string textTemplate = "sole SadCon";

            System.Text.StringBuilder text = new System.Text.StringBuilder(2200);

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

            // Load the logo
#if MONOGAME
            System.IO.Stream imageStream = System.IO.File.OpenRead("sad.png");
            var image = Texture2D.FromStream(Engine.Device, imageStream);
            imageStream.Dispose();
#elif SFML
            var image = new Texture("sad.png");
#endif
            // Configure the logo
            _consoleImage         = image.ToSurface(Engine.DefaultFont, false);
            _consoleImagePosition = new Point(TextSurface.Width / 2 - _consoleImage.Width / 2, -1);
            _consoleImage.Tint    = Color.Black;

            // Configure the animations
            _animation = new InstructionSet();
            _animation.Instructions.AddLast(new Wait()
            {
                Duration = 0.3f
            });

            // Animation to move the angled gradient spotlight effect.
            var moveGradientInstruction = new CodeInstruction();
            moveGradientInstruction.CodeCallback = (inst) =>
            {
                _x += 1;

                if (_x > TextSurface.Width + 50)
                {
                    inst.IsFinished = true;
                }

                Color[] colors     = new Color[] { Color.Black, Color.Blue, Color.White, Color.Blue, Color.Black };
                float[] colorStops = new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f };

                Algorithms.GradientFill(TextSurface.Font.Size, new Point(_x, 12), 10, 45, new Rectangle(0, 0, TextSurface.Width, TextSurface.Height), new ColorGradient(colors, colorStops), SetForeground);
            };
            _animation.Instructions.AddLast(moveGradientInstruction);

            // Animation to clear the SadConsole text.
            _animation.Instructions.AddLast(new CodeInstruction()
            {
                CodeCallback = (i) => { Fill(Color.Black, Color.Transparent, 0, null); i.IsFinished = true; }
            });

            // Animation for the logo text.
            var logoText = new ColorGradient(new Color[] { Color.Magenta, Color.Yellow }, new float[] { 0.0f, 1f }).ToColoredString("[| Powered by SadConsole |]");
            logoText.SetEffect(new SadConsole.Effects.Fade()
            {
                DestinationForeground = Color.Blue, FadeForeground = true, FadeDuration = 1f, Repeat = false, RemoveOnFinished = true, Permanent = true, CloneOnApply = true
            });
            _animation.Instructions.AddLast(new DrawString(this)
            {
                Position = new Point(26, this.TextSurface.Height - 1), Text = logoText, TotalTimeToPrint = 1f
            });

            // Animation for fading in the logo picture.
            _animation.Instructions.AddLast(new FadeTextSurfaceTint(_consoleImage, new ColorGradient(Color.Black, Color.Transparent), new TimeSpan(0, 0, 0, 0, 2000)));

            // Animation to blink SadConsole in the logo text
            _animation.Instructions.AddLast(new CodeInstruction()
            {
                CodeCallback = (i) =>
                {
                    SadConsole.Effects.Fade fadeEffect = new SadConsole.Effects.Fade();
                    fadeEffect.AutoReverse             = true;
                    fadeEffect.DestinationForeground   = new ColorGradient(Color.Blue, Color.Yellow);
                    fadeEffect.FadeForeground          = true;
                    fadeEffect.UseCellForeground       = false;
                    fadeEffect.Repeat           = true;
                    fadeEffect.FadeDuration     = 0.7f;
                    fadeEffect.RemoveOnFinished = true;

                    List <Cell> cells = new List <Cell>();
                    for (int index = 0; index < 10; index++)
                    {
                        var point = new Point(26, this.TextSurface.Height - 1).ToIndex(this.TextSurface.Width) + 14 + index;
                        cells.Add(textSurface.Cells[point]);
                        cellindexes.Add(point);
                    }

                    effectsManager.SetEffect(cells, fadeEffect);
                    i.IsFinished = true;
                }
            });

            // Animation to delay, keeping the logo and all on there for 2 seconds, then destroy itself.
            _animation.Instructions.AddLast(new Wait()
            {
                Duration = 2.5f
            });
            _animation.Instructions.AddLast(new FadeTextSurfaceTint(_consoleImage, new ColorGradient(Color.Transparent, Color.Black), new TimeSpan(0, 0, 0, 0, 2000)));
            _animation.Instructions.AddLast(new CodeInstruction()
            {
                CodeCallback = (i) =>
                {
                    SplashCompleted?.Invoke();

                    i.IsFinished = true;
                }
            });
        }
Beispiel #18
0
        /// <summary>
        /// Determines the cells that would be drawn on and returns them instead of drawing the line.
        /// </summary>
        /// <param name="surface">The surface to get the cells from.</param>
        /// <returns>The cells the line would have drawn on.</returns>
        public IEnumerable<Cell> GetCells(TextSurface surface)
        {
            List<Cell> cells = new List<Cell>();

            Algorithms.Line(StartingLocation.X, StartingLocation.Y, EndingLocation.X, EndingLocation.Y, (x, y) => { cells.Add(surface[x, y]); return true; });

            return cells;
        }
Beispiel #19
0
        public SplashScreen()
            : base(80, 25)
        {
            IsVisible = false;
            effectsManager = new EffectsManager(this.TextSurface);
            // Setup the console text background
            string textTemplate = "sole SadCon";
            System.Text.StringBuilder text = new System.Text.StringBuilder(2200);

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

            // Load the logo
            System.IO.Stream imageStream = System.IO.File.OpenRead("sad.png");
            var image = Texture2D.FromStream(Engine.Device, imageStream);
            imageStream.Dispose();

            // Configure the logo
            _consoleImage = image.ToSurface(Engine.DefaultFont, false);
            _consoleImagePosition = new Point(TextSurface.Width / 2 - _consoleImage.Width / 2, -1);
            _consoleImage.Tint = Color.Black;

            // Configure the animations
            _animation = new InstructionSet();
            _animation.Instructions.AddLast(new Wait() { Duration = 0.3f });

            // Animation to move the angled gradient spotlight effect.
            var moveGradientInstruction = new CodeInstruction();
            moveGradientInstruction.CodeCallback = (inst) =>
            {
                _x += 1;

                if (_x > TextSurface.Width + 50)
                {
                    inst.IsFinished = true;
                }

                Color[] colors = new Color[] { Color.Black, Color.Blue, Color.White, Color.Blue, Color.Black };
                float[] colorStops = new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f };

                Algorithms.GradientFill(TextSurface.Font.Size, new Point(_x, 12), 10, 45, new Rectangle(0, 0, TextSurface.Width, TextSurface.Height), new ColorGradient(colors, colorStops), SetForeground);
            };
            _animation.Instructions.AddLast(moveGradientInstruction);

            // Animation to clear the SadConsole text.
            _animation.Instructions.AddLast(new CodeInstruction() { CodeCallback = (i) => { Fill(Color.Black, Color.Transparent, 0, null); i.IsFinished = true; } });

            // Animation for the logo text.
            var logoText = new ColorGradient(new Color[] { Color.Magenta, Color.Yellow }, new float[] { 0.0f, 1f }).ToColoredString("[| Powered by SadConsole |]");
            logoText.SetEffect(new SadConsole.Effects.Fade() { DestinationForeground = Color.Blue, FadeForeground = true, FadeDuration = 1f, Repeat = false, RemoveOnFinished = true, Permanent = true, CloneOnApply = true });
            _animation.Instructions.AddLast(new DrawString(this) { Position = new Point(26, this.TextSurface.Height - 1), Text = logoText, TotalTimeToPrint = 1f });

            // Animation for fading in the logo picture.
            _animation.Instructions.AddLast(new FadeTextSurfaceTint(_consoleImage, new ColorGradient(Color.Black, Color.Transparent), new TimeSpan(0, 0, 0, 0, 2000)));

            // Animation to blink SadConsole in the logo text
            _animation.Instructions.AddLast(new CodeInstruction()
            {
                CodeCallback = (i) =>
                {
                    SadConsole.Effects.Fade fadeEffect = new SadConsole.Effects.Fade();
                    fadeEffect.AutoReverse = true;
                    fadeEffect.DestinationForeground = new ColorGradient(Color.Blue, Color.Yellow);
                    fadeEffect.FadeForeground = true;
                    fadeEffect.UseCellForeground = false;
                    fadeEffect.Repeat = true;
                    fadeEffect.FadeDuration = 0.7f;
                    fadeEffect.RemoveOnFinished = true;

                    List<Cell> cells = new List<Cell>();
                    for (int index = 0; index < 10; index++)
                    {
                        var point = new Point(26, this.TextSurface.Height - 1).ToIndex(this.TextSurface.Width) + 14 + index;
                        cells.Add(textSurface.Cells[point]);
                        cellindexes.Add(point);
                    }

                    effectsManager.SetEffect(cells, fadeEffect);
                    i.IsFinished = true;
                }
            });

            // Animation to delay, keeping the logo and all on there for 2 seconds, then destroy itself.
            _animation.Instructions.AddLast(new Wait() { Duration = 2.5f });
            _animation.Instructions.AddLast(new FadeTextSurfaceTint(_consoleImage, new ColorGradient(Color.Transparent, Color.Black), new TimeSpan(0, 0, 0, 0, 2000)));
            _animation.Instructions.AddLast(new CodeInstruction()
            {
                CodeCallback = (i) =>
                {
                    SplashCompleted?.Invoke();

                    i.IsFinished = true;
                }
            });
        }
Beispiel #20
0
        void addNewLayerFromFile_ButtonClicked(object sender, EventArgs e)
        {
            SelectFilePopup popup = new SelectFilePopup();
            popup.Closed += (o2, e2) =>
            {
                if (popup.DialogResult)
                {
                    TextSurface newSurface = TextSurface.Load(popup.SelectedFile);

                    if (newSurface.Width != surface.Width || newSurface.Height != surface.Height)
                    {
                        var tempSurface = new TextSurface(surface.Width, surface.Height, surface.Font);
                        newSurface.Copy(tempSurface);
                        var newLayer = surface.Add(tempSurface);
                        LayerMetadata.Create("Loaded", true, true, true, newLayer);
                    }
                    else
                    {
                        var layer = surface.Add(newSurface);
                        LayerMetadata.Create("Loaded", true, true, true, layer);
                    }

                    RebuildListBox();
                }
            };
            popup.CurrentFolder = Environment.CurrentDirectory;
            popup.FileLoaderTypes = new FileLoaders.IFileLoader[] { new FileLoaders.TextSurface() };
            popup.Show(true);
            popup.Center();
        }
Beispiel #21
0
        void saveLayerToFile_ButtonClicked(object sender, EventArgs e)
        {
            var layer = (LayeredTextSurface.Layer)layers.SelectedItem;

            SelectFilePopup popup = new SelectFilePopup();
            popup.Closed += (o2, e2) =>
            {
                if (popup.DialogResult)
                {
                    TextSurface newSurface = new TextSurface(surface.Width, surface.Height, layer.Cells);
                    newSurface.Save(popup.SelectedFile);
                }
            };
            popup.CurrentFolder = Environment.CurrentDirectory;
            popup.FileLoaderTypes = new FileLoaders.IFileLoader[] { new FileLoaders.TextSurface() };
            popup.SelectButtonText = "Save";
            popup.SkipFileExistCheck = true;
            popup.Show(true);
            popup.Center();
        }
        public void LoadBrush(TextSurface surface)
        {
            _panel.State = SelectionToolPanel.CloneState.Clone;

            // Copy data to new animation
            var cloneAnimation = new AnimatedTextSurface("clone", surface.Width, surface.Height, Settings.Config.ScreenFont);
            var frame = cloneAnimation.CreateFrame();
            surface.Copy(frame);

            cloneAnimation.Center = new Point(cloneAnimation.Width / 2, cloneAnimation.Height / 2);

            Brush.SelectedSurface.Animation = cloneAnimation;
            //Brush.Animation.Tint = new Color(0f, 0f, 0f, 0f);

            Brush.IsVisible = true;

            MakeBoxAnimation(surface.Width, surface.Height, cloneAnimation.Center);
        }
        private TextSurface SaveBrush()
        {
            TextSurface newSurface = new TextSurface(Brush.SelectedSurface.Animation.CurrentFrame.Width,
                                                     Brush.SelectedSurface.Animation.CurrentFrame.Height, Settings.Config.ScreenFont);

            Brush.SelectedSurface.Animation.CurrentFrame.Copy(newSurface);

            return newSurface;
        }
Beispiel #24
0
        public unsafe static TextSurface ToSurface(this Texture2D image, SadConsole.Font font, bool blockMode = false)
        {
            int imageWidth  = image.Width;
            int imageHeight = image.Height;

            Color[] pixels = new Color[imageWidth * imageHeight];
            image.GetData <Color>(pixels);

            TextSurface   surface = new TextSurface(imageWidth / font.Size.X, imageHeight / font.Size.Y, font);
            SurfaceEditor editor  = new SurfaceEditor(surface);

            global::System.Threading.Tasks.Parallel.For(0, imageHeight / surface.Font.Size.Y, (h) =>
                                                        //for (int h = 0; h < imageHeight / surface.Font.Size.Y; h++)
            {
                int startY = (h * surface.Font.Size.Y);
                //System.Threading.Tasks.Parallel.For(0, imageWidth / surface.Font.Size.X, (w) =>
                for (int w = 0; w < imageWidth / surface.Font.Size.X; w++)
                {
                    int startX = (w * surface.Font.Size.X);

                    float allR = 0;
                    float allG = 0;
                    float allB = 0;

                    for (int y = 0; y < surface.Font.Size.Y; y++)
                    {
                        for (int x = 0; x < surface.Font.Size.X; x++)
                        {
                            int cY = y + startY;
                            int cX = x + startX;

                            Color color = pixels[cY * imageWidth + cX];

                            allR += color.R;
                            allG += color.G;
                            allB += color.B;
                        }
                    }

                    byte sr = (byte)(allR / (surface.Font.Size.X * surface.Font.Size.Y));
                    byte sg = (byte)(allG / (surface.Font.Size.X * surface.Font.Size.Y));
                    byte sb = (byte)(allB / (surface.Font.Size.X * surface.Font.Size.Y));

                    var newColor = new Color(sr, sg, sb);

                    float sbri = newColor.GetBrightness() * 255;

                    if (blockMode)
                    {
                        if (sbri > 204)
                        {
                            editor.SetGlyph(w, h, 219, newColor); //█
                        }
                        else if (sbri > 152)
                        {
                            editor.SetGlyph(w, h, 178, newColor); //▓
                        }
                        else if (sbri > 100)
                        {
                            editor.SetGlyph(w, h, 177, newColor); //▒
                        }
                        else if (sbri > 48)
                        {
                            editor.SetGlyph(w, h, 176, newColor); //░
                        }
                    }
                    else
                    {
                        if (sbri > 230)
                        {
                            editor.SetGlyph(w, h, (int)'#', newColor);
                        }
                        else if (sbri > 207)
                        {
                            editor.SetGlyph(w, h, (int)'&', newColor);
                        }
                        else if (sbri > 184)
                        {
                            editor.SetGlyph(w, h, (int)'$', newColor);
                        }
                        else if (sbri > 161)
                        {
                            editor.SetGlyph(w, h, (int)'X', newColor);
                        }
                        else if (sbri > 138)
                        {
                            editor.SetGlyph(w, h, (int)'x', newColor);
                        }
                        else if (sbri > 115)
                        {
                            editor.SetGlyph(w, h, (int)'=', newColor);
                        }
                        else if (sbri > 92)
                        {
                            editor.SetGlyph(w, h, (int)'+', newColor);
                        }
                        else if (sbri > 69)
                        {
                            editor.SetGlyph(w, h, (int)';', newColor);
                        }
                        else if (sbri > 46)
                        {
                            editor.SetGlyph(w, h, (int)':', newColor);
                        }
                        else if (sbri > 23)
                        {
                            editor.SetGlyph(w, h, (int)'.', newColor);
                        }
                    }
                }
            }
                                                        );

            return(surface);
        }
Beispiel #25
0
        public static unsafe void ToSurface(this Texture2D image, TextSurface surface, Color[] cachedColorArray, bool blockMode = false)
        {
            int imageWidth = image.Width;
            int imageHeight = image.Height;
            image.GetData<Color>(cachedColorArray);

            SurfaceEditor editor = new SurfaceEditor(surface);
            editor.Clear();
            global::System.Threading.Tasks.Parallel.For(0, imageHeight / surface.Font.Size.Y, (h) =>
            //for (int h = 0; h < imageHeight / surface.Font.Size.Y; h++)
            {
                int startY = (h * surface.Font.Size.Y);
                //System.Threading.Tasks.Parallel.For(0, imageWidth / surface.Font.Size.X, (w) =>
                for (int w = 0; w < imageWidth / surface.Font.Size.X; w++)
                {
                    int startX = (w * surface.Font.Size.X);

                    float allR = 0;
                    float allG = 0;
                    float allB = 0;

                    for (int y = 0; y < surface.Font.Size.Y; y++)
                    {
                        for (int x = 0; x < surface.Font.Size.X; x++)
                        {
                            int cY = y + startY;
                            int cX = x + startX;

                            Color color = cachedColorArray[cY * imageWidth + cX];

                            allR += color.R;
                            allG += color.G;
                            allB += color.B;
                        }
                    }

                    byte sr = (byte)(allR / (surface.Font.Size.X * surface.Font.Size.Y));
                    byte sg = (byte)(allG / (surface.Font.Size.X * surface.Font.Size.Y));
                    byte sb = (byte)(allB / (surface.Font.Size.X * surface.Font.Size.Y));

                    var newColor = new Color(sr, sg, sb);

                    float sbri = newColor.GetBrightness() * 255;

                    if (blockMode)
                    {
                        if (sbri > 204)
                            editor.SetGlyph(w, h, 219, newColor); //█
                        else if (sbri > 152)
                            editor.SetGlyph(w, h, 178, newColor); //▓
                        else if (sbri > 100)
                            editor.SetGlyph(w, h, 177, newColor); //▒
                        else if (sbri > 48)
                            editor.SetGlyph(w, h, 176, newColor); //░
                    }
                    else
                    {
                        if (sbri > 230)
                            editor.SetGlyph(w, h, (int)'#', newColor);
                        else if (sbri > 207)
                            editor.SetGlyph(w, h, (int)'&', newColor);
                        else if (sbri > 184)
                            editor.SetGlyph(w, h, (int)'$', newColor);
                        else if (sbri > 161)
                            editor.SetGlyph(w, h, (int)'X', newColor);
                        else if (sbri > 138)
                            editor.SetGlyph(w, h, (int)'x', newColor);
                        else if (sbri > 115)
                            editor.SetGlyph(w, h, (int)'=', newColor);
                        else if (sbri > 92)
                            editor.SetGlyph(w, h, (int)'+', newColor);
                        else if (sbri > 69)
                            editor.SetGlyph(w, h, (int)';', newColor);
                        else if (sbri > 46)
                            editor.SetGlyph(w, h, (int)':', newColor);
                        else if (sbri > 23)
                            editor.SetGlyph(w, h, (int)'.', newColor);
                    }
                }
            }
            );
        }
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            // Compositor
            _compositor = Window.Current.Compositor;

            // Load Image
            _imageSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/webster-pass.png"));
            var backgroundBrush = _compositor.CreateSurfaceBrush(_imageSurface);

            backgroundBrush.Stretch = CompositionStretch.UniformToFill;

            // Apply Saturation Effect (Win2D)
            var saturationEffect = new SaturationEffect
            {
                Saturation = 0,
                Source     = new CompositionEffectSourceParameter("background")
            };

            var saturationEffectFactory = _compositor.CreateEffectFactory(saturationEffect);
            var saturationBrush         = saturationEffectFactory.CreateBrush();

            saturationBrush.SetSourceParameter("background", backgroundBrush);

            // Add background to visual tree
            _backgroundVisual       = _compositor.CreateSpriteVisual();
            _backgroundVisual.Brush = saturationBrush;
            _backgroundVisual.Size  = RootElement.RenderSize.ToVector2();

            _containerVisual = _compositor.CreateContainerVisual();
            _containerVisual.Children.InsertAtBottom(_backgroundVisual);
            ElementCompositionPreview.SetElementChildVisual(RootElement, _containerVisual);

            // Add Lighting
            _ambientLight           = _compositor.CreateAmbientLight();
            _ambientLight.Intensity = 1.5f;
            _ambientLight.Color     = Colors.Purple;
            _ambientLight.Targets.Add(_backgroundVisual);

            _pointLight1                 = _compositor.CreatePointLight();
            _pointLight1.Color           = Colors.Yellow;
            _pointLight1.CoordinateSpace = _containerVisual;
            _pointLight1.Targets.Add(_backgroundVisual);
            _pointLight1.Offset = new Vector3((float)RootElement.ActualWidth, (float)RootElement.ActualHeight * 0.25f, 300);

            _pointLight2                 = _compositor.CreatePointLight();
            _pointLight2.Color           = Colors.Green;
            _pointLight2.Intensity       = 2f;
            _pointLight2.CoordinateSpace = _containerVisual;
            _pointLight2.Targets.Add(_backgroundVisual);
            _pointLight2.Offset = new Vector3(0, (float)RootElement.ActualHeight * 0.75f, 300);

            // Animate Lights - Create expression template
            var offsetAnimation = Window.Current.Compositor.CreateVector3KeyFrameAnimation();

            offsetAnimation.Target = nameof(PointLight.Offset);
            offsetAnimation.InsertExpressionKeyFrame(1.0f, "this.FinalValue");
            offsetAnimation.Duration = TimeSpan.FromSeconds(10);

            // Animate Lights - create implicit animations
            _implicitOffsetAnimation = _compositor.CreateImplicitAnimationCollection();
            _implicitOffsetAnimation[nameof(Visual.Offset)] = offsetAnimation;

            _pointLight1.ImplicitAnimations = _implicitOffsetAnimation;
            _pointLight2.ImplicitAnimations = _implicitOffsetAnimation;

            // Animate Lights - create timer
            _lightTimer          = new DispatcherTimer();
            _lightTimer.Interval = TimeSpan.FromSeconds(10);
            _lightTimer.Tick    += LightTimerOnTick;
            _lightTimer.Start();

            // AnimateLights - initial move
            MoveLights();

            // Add Text (RobMikh.SurfaceFactory) Ø
            _surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(_compositor);
            _textSurface    = _surfaceFactory.CreateTextSurface("Hello Øredev!");
            _textSurface.ForegroundColor = Color.FromArgb(50, 255, 255, 255);
            _textSurface.FontSize        = 150;
            var textBrush = _compositor.CreateSurfaceBrush(_textSurface.Surface);

            _textVisual      = _compositor.CreateSpriteVisual();
            _textVisual.Size = _textSurface.Size.ToVector2();
            _textVisual.RotationAngleInDegrees = 45f;
            _textVisual.AnchorPoint            = new Vector2(0.5f);
            _textVisual.Brush = textBrush;
            _textVisual.StartAnimation(nameof(Visual.Offset), CreateTextAnimation());

            _containerVisual.Children.InsertAtTop(_textVisual);
        }
Beispiel #27
0
        public bool HandleKeyboard(IConsole consoleObject, KeyboardInfo info)
        {
            // Upcast this because we know we're only using it with a Console type.
            var console = (Console)consoleObject;

            // Check each key pressed.
            foreach (var key in info.KeysPressed)
            {
                // If the character associated with the key pressed is a printable character, print it
                if (key.Character != '\0')
                {
                    console.VirtualCursor.Print(key.Character.ToString());
                }

                // Special character - BACKSPACE
#if MONOGAME
                else if (key.XnaKey == Keys.Back)
#elif SFML
                else if (key.XnaKey == Keys.BackSpace)
#endif
                {
                    // Get the prompt that the console has.
                    string prompt = ((CustomConsoles.DOSConsole)console).Prompt;

                    // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much.
                    if (console.TimesShiftedUp != 0)
                    {
                        VirtualCursorLastY    -= console.TimesShiftedUp;
                        console.TimesShiftedUp = 0;
                    }

                    // Do not let them backspace into the prompt
                    if (console.VirtualCursor.Position.Y != VirtualCursorLastY || console.VirtualCursor.Position.X > prompt.Length)
                    {
                        console.VirtualCursor.LeftWrap(1).Print(" ").LeftWrap(1);
                    }
                }

                // Special character - ENTER
#if MONOGAME
                else if (key.XnaKey == Keys.Enter)
#elif SFML
                else if (key.XnaKey == Keys.Return)
#endif
                {
                    // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much.
                    if (console.TimesShiftedUp != 0)
                    {
                        VirtualCursorLastY    -= console.TimesShiftedUp;
                        console.TimesShiftedUp = 0;
                    }

                    // Get the prompt to exclude it in determining the total length of the string the user has typed.
                    string prompt        = ((CustomConsoles.DOSConsole)console).Prompt;
                    int    startingIndex = TextSurface.GetIndexFromPoint(new Point(prompt.Length, VirtualCursorLastY), console.TextSurface.Width);
                    string data          = ((SadConsole.Consoles.Console)console).GetString(startingIndex, TextSurface.GetIndexFromPoint(console.VirtualCursor.Position, console.TextSurface.Width) - startingIndex);

                    // Move the cursor to the next line before we send the string data to the processor
                    console.VirtualCursor.CarriageReturn().LineFeed();

                    // Send the string data
                    EnterPressedAction(data);

                    // After they have processed the string, we will create a new line and display the prompt.
                    console.VirtualCursor.CarriageReturn().LineFeed();
                    console.VirtualCursor.Print(((CustomConsoles.DOSConsole)console).Prompt);
                    VirtualCursorLastY = console.VirtualCursor.Position.Y;

                    // Preparing the next lines could have scrolled the console, reset the counter
                    console.TimesShiftedUp = 0;
                }
            }

            return(true);
        }
Beispiel #28
0
        public bool HandleKeyboard(IConsole console, KeyboardInfo info)
        {
            var realConsole = (SadConsole.Consoles.Console)console;

            // Check each key pressed.
            foreach (var key in info.KeysPressed)
            {
                // If the character associated with the key pressed is a printable character, print it
                if (key.Character != '\0')
                {
                    int    startingIndex = TextSurface.GetIndexFromPoint(new Point(Room.MapWidth + 2, Room.MapHeight + 4), console.TextSurface.Width);
                    String data          = realConsole.GetString(startingIndex, TextSurface.GetIndexFromPoint(console.VirtualCursor.Position, console.TextSurface.Width) - startingIndex);
                    if (data.Length < 14)
                    {
                        console.VirtualCursor.Print(key.Character.ToString().ToUpper());
                    }
                }

                // Special character - BACKSPACE
                else if (key.XnaKey == Keys.Back)
                {
                    // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much.
                    if (realConsole.TimesShiftedUp != 0)
                    {
                        realConsole.TimesShiftedUp = 0;
                    }

                    // Do not let them backspace into the prompt
                    if (console.VirtualCursor.Position.Y != Room.MapHeight + 4 || console.VirtualCursor.Position.X > Room.MapWidth + 2)
                    {
                        console.VirtualCursor.LeftWrap(1).Print(" ").LeftWrap(1);
                    }
                }

                // Special character - ENTER
                else if (key.XnaKey == Keys.Enter)
                {
                    // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much.
                    if (realConsole.TimesShiftedUp != 0)
                    {
                        VirtualCursorLastY        -= realConsole.TimesShiftedUp;
                        realConsole.TimesShiftedUp = 0;
                    }

                    // Get the prompt to exclude it in determining the total length of the string the user has typed.
                    int    startingIndex = TextSurface.GetIndexFromPoint(new Point(Room.MapWidth + 2, Room.MapHeight + 4), console.TextSurface.Width);
                    String data          = realConsole.GetString(startingIndex, TextSurface.GetIndexFromPoint(console.VirtualCursor.Position, console.TextSurface.Width) - startingIndex);

                    // Move the cursor to the next line before we send the string data to the processor

                    // Send the string data
                    EnterPressedAction(data);

                    // After they have processed the string, we will create a new line and display the prompt.
                    VirtualCursorLastY = console.VirtualCursor.Position.Y;

                    // Preparing the next lines could have scrolled the console, reset the counter
                    realConsole.TimesShiftedUp = 0;
                }
            }

            return(true);
        }