Ejemplo n.º 1
0
        public SubConsoleCursor()
        {
            mainView = new Console(80, 25);
            subView  = new Console(25, 10);

            IsVisible = false;

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

            // Setup sub view
            subView.Position    = new Point(4, 4);
            subView.TextSurface = new TextSurfaceView(mainView.TextSurface, new Rectangle(4, 4, 25, 10));
            subView.MouseMove  += (s, e) => { if (e.LeftButtonDown)
                                              {
                                                  e.Cell.Background = Color.Red;
                                              }
            };
            subView.Clear();

            // Ad the consoles to the list.
            Add(mainView);
            //Add(subView);
        }
Ejemplo n.º 2
0
        public FadingExample()
        {
            // Simulate two consoles
            backgroundConsole = new Console(80, 25);
            foregroundConsole = new Console(80, 25);

            // To work with our sample project, all consoles default to not visible. If you're using this
            // on your own, outside of the starter project, delete this line.
            IsVisible = false;

            // Setup main view
            backgroundConsole.FillWithRandomGarbage();

            // Setup sub view
            // Normally the text surface uses a transparent background so you can easily layer. We don't want that.
            foregroundConsole.TextSurface.DefaultBackground = Color.Black;
            foregroundConsole.Clear();

            // Some visuals on the surface so we can see something fade.
            var border = SadConsole.Shapes.Box.GetDefaultBox();

            border.Location = new Point(0, 0);
            border.Width    = 80;
            border.Height   = 25;
            border.Draw(foregroundConsole);

            for (int y = 2; y < 23; y += 2)
            {
                foregroundConsole.Print(9, y, "This is a console that will fade, showing whatever is beind it", Color.Black.GetRandomColor(SadConsole.Engine.Random));
            }

            foregroundConsole.Print(2, 0, "[c:r f:Black][c:r b:White]  PRESS SPACE TO START FADE  ");

            // Console has been drawn on and is ready to be cached for the fade.
            foregroundConsole.Renderer = new SadConsole.Consoles.CachedTextSurfaceRenderer(foregroundConsole.TextSurface);

            // Because of the way the cached renderer handles tinting, we need to set tinting to white
            // This means "render the cahced surface exactly how it was originally drawn."
            foregroundConsole.TextSurface.Tint = Color.White;

            // Ad the consoles to the list.
            Add(backgroundConsole);
            Add(foregroundConsole);

            // Setup the fade animation to go from white to transparent in 2 seconds.
            tintFade = new SadConsole.Instructions.FadeTextSurfaceTint(foregroundConsole.TextSurface, new ColorGradient(Color.White, Color.Transparent), TimeSpan.FromSeconds(2));
        }
Ejemplo n.º 3
0
        public FadingExample()
        {
            // Simulate two consoles
            backgroundConsole = new Console(80, 25);
            foregroundConsole = new Console(80, 25);

            // To work with our sample project, all consoles default to not visible. If you're using this
            // on your own, outside of the starter project, delete this line.
            IsVisible = false;

            // Setup main view
            backgroundConsole.FillWithRandomGarbage();

            // Setup sub view
            // Normally the text surface uses a transparent background so you can easily layer. We don't want that.
            foregroundConsole.TextSurface.DefaultBackground = Color.Black;
            foregroundConsole.Clear();

            // Some visuals on the surface so we can see something fade.
            var border = SadConsole.Shapes.Box.GetDefaultBox();
            border.Location = new Point(0, 0);
            border.Width = 80;
            border.Height = 25;
            border.Draw(foregroundConsole);

            for (int y = 2; y < 23; y += 2)
                foregroundConsole.Print(9, y, "This is a console that will fade, showing whatever is beind it", Color.Black.GetRandomColor(SadConsole.Engine.Random));

            foregroundConsole.Print(2, 0, "[c:r f:Black][c:r b:White]  PRESS SPACE TO START FADE  ");

            // Console has been drawn on and is ready to be cached for the fade.
            foregroundConsole.Renderer = new SadConsole.Consoles.CachedTextSurfaceRenderer(foregroundConsole.TextSurface);

            // Because of the way the cached renderer handles tinting, we need to set tinting to white
            // This means "render the cahced surface exactly how it was originally drawn."
            foregroundConsole.TextSurface.Tint = Color.White;

            // Ad the consoles to the list.
            Add(backgroundConsole);
            Add(foregroundConsole);

            // Setup the fade animation to go from white to transparent in 2 seconds.
            tintFade = new SadConsole.Instructions.FadeTextSurfaceTint(foregroundConsole.TextSurface, new ColorGradient(Color.White, Color.Transparent), TimeSpan.FromSeconds(2));
        }
Ejemplo n.º 4
0
        public SubConsoleCursor()
        {
            mainView = new Console(80, 25);
            subView = new Console(25, 10);

            IsVisible = false;

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

            // Setup sub view
            subView.Position = new Point(4, 4);
            subView.TextSurface = new TextSurfaceView(mainView.TextSurface, new Rectangle(4, 4, 25, 10));
            subView.MouseMove += (s, e) => { if (e.LeftButtonDown) e.Cell.Background = Color.Red; };
            subView.Clear();

            // Ad the consoles to the list.
            Add(mainView);
            //Add(subView);
        }
        public static void Initialize()
        {
            Consoles = new CustomConsoleList();

            // Hook the update event that happens each frame so we can trap keys and respond.
            SadConsole.Engine.ConsoleRenderStack = Consoles;
            SadConsole.Engine.ActiveConsole = Consoles;

            // Create the basic consoles
            QuickSelectPane = new SadConsoleEditor.Consoles.QuickSelectPane();
            QuickSelectPane.Redraw();
            QuickSelectPane.IsVisible = false;

            topBarPane = new SadConsole.Consoles.Console(Settings.Config.WindowWidth, 1);
            topBarPane.TextSurface.DefaultBackground = Settings.Color_MenuBack;
            topBarPane.Clear();
            topBarPane.MouseCanFocus = false;
            topBarPane.IsVisible = false;

            borderConsole = new SadConsoleEditor.Consoles.BorderConsole(10, 10);
            borderConsole.IsVisible = false;
            borderConsole.CanUseMouse = false;

            ToolsPane = new Consoles.ToolPane();
            ToolsPane.Position = new Point(Settings.Config.WindowWidth - ToolsPane.Width - 1, 1);
            ToolsPane.IsVisible = false;

            // Scroll bar for toolpane
            // Create scrollbar
            ToolsPaneScroller = SadConsole.Controls.ScrollBar.Create(System.Windows.Controls.Orientation.Vertical, Settings.Config.WindowHeight - 1);
            ToolsPaneScroller.Maximum = ToolsPane.TextSurface.Height - Settings.Config.WindowHeight;
            ToolsPaneScroller.ValueChanged += (o, e) =>
            {
                ToolsPane.TextSurface.RenderArea = new Rectangle(0, ToolsPaneScroller.Value, ToolsPane.Width, Settings.Config.WindowHeight);
            };
            scrollerContainer = new ControlsConsole(1, ToolsPaneScroller.Height);
            scrollerContainer.Add(ToolsPaneScroller);
            scrollerContainer.Position = new Point(Settings.Config.WindowWidth - 1, 1);
            scrollerContainer.IsVisible = false;
            scrollerContainer.MouseCanFocus = false;
            scrollerContainer.ProcessMouseWithoutFocus = true;

            var boundsLocation = new Point(0, topBarPane.TextSurface.Height).TranslateFont(topBarPane.TextSurface.Font, Settings.Config.ScreenFont) + new Point(1);
            InnerEmptyBounds = new Rectangle(boundsLocation, new Point(0, QuickSelectPane.Position.Y).WorldLocationToConsole(QuickSelectPane.TextSurface.Font.Size.X, QuickSelectPane.TextSurface.Font.Size.Y)  - boundsLocation);
            InnerEmptyBounds.Width = new Point(ToolsPane.Position.X, 0).TranslateFont(ToolsPane.TextSurface.Font, Settings.Config.ScreenFont).X - 1;

            // Add the consoles to the main console list
            Consoles.Add(QuickSelectPane);
            Consoles.Add(topBarPane);
            Consoles.Add(ToolsPane);
            Consoles.Add(scrollerContainer);

            // Setup the file types for base editors.
            EditorFileTypes = new Dictionary<Type, FileLoaders.IFileLoader[]>(3);
            OpenEditors = new List<SadConsoleEditor.Editors.IEditor>();
            //EditorFileTypes.Add(typeof(Editors.DrawingEditor), new FileLoaders.IFileLoader[] { new FileLoaders.TextSurface() });

            // Add valid editors
            Editors = new Dictionary<string, SadConsoleEditor.Editors.Editors>();
            Editors.Add("Console Draw", SadConsoleEditor.Editors.Editors.Console);
            Editors.Add("Animated Game Object", SadConsoleEditor.Editors.Editors.GameObject);
            Editors.Add("Game Scene", SadConsoleEditor.Editors.Editors.Scene);
            //Editors.Add("User Interface Console", SadConsoleEditor.Editors.Editors.GUI);

            // Show new window
            ShowStartup();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Interprets an individual ansi code.
        /// </summary>
        /// <param name="code">The ANSI.SYS code to read.</param>
        public void AnsiInterpret(string code)
        {
            if (code[0] == (char)27 && code[1] == '[')
            {
                string   data   = code.Substring(2, code.Length - 3);
                string[] values = data.Split(';');

                switch (code[code.Length - 1])
                {
                case 'H':
                case 'h':
                    if (values.Length == 2)
                    {
                        if (values[0] == "")
                        {
                            _cursor.Position = new Point(0, _cursor.Position.Y);
                        }
                        else
                        {
                            _cursor.Position = new Point(Convert.ToInt32(values[0]) - 1, _cursor.Position.Y);
                        }

                        if (values[1] == "")
                        {
                            _cursor.Position = new Point(_cursor.Position.X, 0);
                        }
                        else
                        {
                            _cursor.Position = new Point(_cursor.Position.X, Convert.ToInt32(values[1]) - 1);
                        }
                    }
                    //else
                    //    System.Diagnostics.Debugger.Break();
                    break;

                case 'F':
                case 'f':
                    break;

                case 'A':
                case 'a':
                    if (data.Length == 0)
                    {
                        _cursor.Up(1);
                    }
                    else
                    {
                        _cursor.Up(Convert.ToInt32(data));
                    }
                    break;

                case 'B':
                case 'b':
                    if (data.Length == 0)
                    {
                        _cursor.Down(1);
                    }
                    else
                    {
                        _cursor.Down(Convert.ToInt32(data));
                    }
                    break;

                case 'C':
                case 'c':
                    if (data.Length == 0)
                    {
                        _cursor.Right(1);
                    }
                    else
                    {
                        _cursor.Right(Convert.ToInt32(data));
                    }
                    break;

                case 'D':
                case 'd':
                    if (data.Length == 0)
                    {
                        _cursor.Left(1);
                    }
                    else
                    {
                        _cursor.Left(Convert.ToInt32(data));
                    }
                    break;

                case 'J':
                case 'j':
                    if (data == "" || data == "0")
                    {
                        for (int i = _cursor.Position.X; i < _console.TextSurface.Width; i++)
                        {
                            _console.Clear(i, _cursor.Position.Y);
                        }
                    }

                    else if (data == "1")
                    {
                        for (int i = _cursor.Position.X; i >= 0; i--)
                        {
                            _console.Clear(i, _cursor.Position.Y);
                        }
                    }

                    else if (data == "2")
                    {
                        _console.Clear();
                        _cursor.Position = new Point(0, 0);
                    }
                    break;

                case 'K':
                case 'k':
                    if (data == "" || data == "0")
                    {
                        for (int i = _cursor.Position.X; i < _console.TextSurface.Width; i++)
                        {
                            _console.Clear(i, _cursor.Position.Y);
                        }
                    }

                    else if (data == "1")
                    {
                        for (int i = _cursor.Position.X; i >= 0; i--)
                        {
                            _console.Clear(i, _cursor.Position.Y);
                        }
                    }

                    else if (data == "2")
                    {
                        for (int i = 0; i < _console.TextSurface.Width; i++)
                        {
                            _console.Clear(i, _cursor.Position.Y);
                        }
                    }
                    break;

                case 'S':
                case 's':
                    _storedCursorLocation = _cursor.Position;
                    break;

                case 'U':
                case 'u':
                    _cursor.Position = _storedCursorLocation;
                    break;

                case 'M':
                case 'm':

                    if (data == "")
                    {
                        _ansiState.AnsiResetVideo();
                    }

                    else
                    {
                        for (int i = 0; i < values.Length; i++)
                        {
                            int value = Convert.ToInt32(values[i]);
                            switch (value)
                            {
                            case 0:
                                _ansiState.AnsiResetVideo();
                                break;

                            case 1:
                                _ansiState.Bold = true;
                                _ansiState.AnsiCorrectPrintColor();
                                break;

                            case 5:
                                //Appearance.Effect = BlinkEffect;
                                break;

                            case 7:
                                Color tempFore = _ansiState.Foreground;
                                _ansiState.Foreground = Helpers.AnsiAdjustColor(_ansiState.Background, _ansiState.Bold);
                                _ansiState.Background = Helpers.AnsiJustNormalColor(tempFore);
                                break;

                            case 30:
                            case 31:
                            case 32:
                            case 33:
                            case 34:
                            case 35:
                            case 36:
                            case 37:
                                Helpers.AnsiConfigurePrintColor(false, value - 30, _ansiState);
                                break;

                            case 40:
                            case 41:
                            case 42:
                            case 43:
                            case 44:
                            case 45:
                            case 46:
                            case 47:
                                Helpers.AnsiConfigurePrintColor(true, value - 40, _ansiState);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    break;

                default:
                    System.Diagnostics.Debugger.Break();
                    break;
                }
            }
        }