コード例 #1
0
ファイル: Cursor.cs プロジェクト: zacharycarter/SadConsole
        public Cursor(ITextSurface surface)
        {
            privateEditor = new SurfaceEditor(surface);
            _console      = new WeakReference(privateEditor);

            Constructor();
        }
コード例 #2
0
            public static EffectsManager Load(string file, ITextSurface surface)
            {
                EffectsManagerSerialized data    = Serializer.Load <EffectsManagerSerialized>(file);
                EffectsManager           manager = new EffectsManager(surface);

                foreach (var effect in data.Effects.Keys)
                {
                    int[] effectCellIndexes = data.Effects[effect];

                    List <Cell> cells = new List <Cell>(effectCellIndexes.Length);

                    foreach (var index in effectCellIndexes)
                    {
                        cells.Add(surface.Cells[index]);
                    }

                    var effectData = new CellEffectData(effect)
                    {
                        Cells = cells
                    };

                    manager._effects.Add(effect, effectData);

                    foreach (var cell in cells)
                    {
                        manager._effectCells.Add(cell, effectData);
                    }
                }

                return(manager);
            }
コード例 #3
0
        public void MouseMoveSurface(MouseInfo info, ITextSurface surface)
        {
            Brush.Position = info.ConsoleLocation;
            Brush.IsVisible = true;

            if (info.LeftButtonDown)
            {
                var cell = surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y);

                if (!settingsPanel.IgnoreForeground)
                    cell.Foreground = CharacterPickPanel.SharedInstance.SettingForeground;

                if (!settingsPanel.IgnoreBackground)
                    cell.Background = CharacterPickPanel.SharedInstance.SettingBackground;
            }
            else if (info.RightButtonDown)
            {
                var cell = surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y);

                if (!settingsPanel.IgnoreForeground)
                    CharacterPickPanel.SharedInstance.SettingForeground = cell.Foreground;

                if (!settingsPanel.IgnoreBackground)
                    CharacterPickPanel.SharedInstance.SettingBackground = cell.Background;
            }
        }
コード例 #4
0
ファイル: Cursor.cs プロジェクト: Thraka/SadConsole
        public Cursor(ITextSurface surface)
        {
            privateEditor = new SurfaceEditor(surface);
            _console = new WeakReference(privateEditor);

            Constructor();
        }
コード例 #5
0
        /// <summary>
        /// Copies the contents of this cell surface at the specified x,y coordinates to the destination, only with the specified width and height, and copies it to the specified <paramref name="destinationX"/> and <paramref name="destinationY"/> position.
        /// </summary>
        /// <param name="source">The source surface</param>
        /// <param name="x">The x coordinate to start from.</param>
        /// <param name="y">The y coordinate to start from.</param>
        /// <param name="width">The width to copy from.</param>
        /// <param name="height">The height to copy from.</param>
        /// <param name="destination">The destination surface.</param>
        /// <param name="destinationX">The x coordinate to copy to.</param>
        /// <param name="destinationY">The y coordinate to copy to.</param>
        public static void Copy(this ITextSurface source, int x, int y, int width, int height, ITextSurface destination, int destinationX, int destinationY)
        {
            int destX = destinationX;
            int destY = destinationY;

            for (int curx = 0; curx < width; curx++)
            {
                for (int cury = 0; cury < height; cury++)
                {
                    int sourceIndex;
                    int destIndex;

                    if (source.IsValidCell(curx + x, cury + y, out sourceIndex) && destination.IsValidCell(destX, destY, out destIndex))
                    {
                        var sourceCell = source.Cells[sourceIndex];
                        var desCell    = destination.Cells[destIndex];
                        sourceCell.CopyAppearanceTo(desCell);
                        desCell.Effect = sourceCell.Effect;
                    }
                    destY++;
                }
                destY = destinationY;
                destX++;
            }
        }
コード例 #6
0
        /// <summary>
        /// Copies the contents of this cell surface at the specified x,y coordinates to the destination, only with the specified width and height, and copies it to the specified <paramref name="destinationX"/> and <paramref name="destinationY"/> position.
        /// </summary>
        /// <param name="source">The source surface</param>
        /// <param name="x">The x coordinate to start from.</param>
        /// <param name="y">The y coordinate to start from.</param>
        /// <param name="width">The width to copy from.</param>
        /// <param name="height">The height to copy from.</param>
        /// <param name="destination">The destination surface.</param>
        /// <param name="destinationX">The x coordinate to copy to.</param>
        /// <param name="destinationY">The y coordinate to copy to.</param>
        public static void Copy(this ITextSurface source, int x, int y, int width, int height, ITextSurface destination, int destinationX, int destinationY)
        {
            int destX = destinationX;
            int destY = destinationY;

            for (int curx = 0; curx < width; curx++)
            {
                for (int cury = 0; cury < height; cury++)
                {
                    int sourceIndex;
                    int destIndex;

                    if (source.IsValidCell(curx + x, cury + y, out sourceIndex) && destination.IsValidCell(destX, destY, out destIndex))
                    {
                        var sourceCell = source.Cells[sourceIndex];
                        var desCell = destination.Cells[destIndex];
                        sourceCell.CopyAppearanceTo(desCell);
                        desCell.Effect = sourceCell.Effect;
                    }
                    destY++;
                }
                destY = destinationY;
                destX++;
            }
        }
コード例 #7
0
 ParseCommandBase CustomParseCommand(string command, string parameters, ColoredGlyph[] glyphString,
                                                   ITextSurface surface, SurfaceEditor editor, ParseCommandStacks commandStacks)
 {
     switch (command)
     {
         case "t":
             return new ParseCommandRetext(parameters);
         default:
             return null; ;
     }
 }
コード例 #8
0
 /// <summary>
 /// Tests if a cell is valid based on its x,y position.
 /// </summary>
 /// <param name="surface">The surface to check.</param>
 /// <param name="x">The x coordinate of the cell to test.</param>
 /// <param name="y">The y coordinate of the cell to test.</param>
 /// <returns>A true value indicating the cell by x,y does exist in this cell surface.</returns>
 public static bool IsValidCell(this ITextSurface surface, int x, int y)
 {
     if (x >= 0 && x < surface.Width && y >= 0 && y < surface.Height)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #9
0
 public override void Draw(ITextSurface surface, Rectangle area)
 {
     string value = ((FileLoaders.IFileLoader)Item).FileTypeName;
     if (value.Length < area.Width)
         value += new string(' ', area.Width - value.Length);
     else if (value.Length > area.Width)
         value = value.Substring(0, area.Width);
     var editor = new SurfaceEditor(surface);
     editor.Print(area.Left, area.Top, value, _currentAppearance);
     _isDirty = false;
 }
コード例 #10
0
        public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
        {
            glyphState.Effect = BlinkEffect;

            if (Counter != -1)
            {
                Counter--;

                if (Counter == 0)
                    commandStack.RemoveSafe(this);
            }
        }
コード例 #11
0
        public override void Draw(ITextSurface surface, Rectangle area)
        {
            string value = ((Editors.EntityEditor.FrameWrapper)Item).CurrentIndex.ToString();
            if (value.Length < area.Width)
                value += new string(' ', area.Width - value.Length);
            else if (value.Length > area.Width)
                value = value.Substring(0, area.Width);

            var editor = new SurfaceEditor(surface);
            editor.Print(area.X, area.Y, value, _currentAppearance);
            _isDirty = false;
        }
コード例 #12
0
        ParseCommandBase CustomParseCommand(string command, string parameters, ColoredGlyph[] glyphString,
                                            ITextSurface surface, SurfaceEditor editor, ParseCommandStacks commandStacks)
        {
            switch (command)
            {
            case "t":
                return(new ParseCommandRetext(parameters));

            default:
                return(null);;
            }
        }
コード例 #13
0
        public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
        {
            if (CommandType == CommandTypes.Background)
                glyphState.Background = GradientString[Length - Counter].Foreground;
            else
                glyphState.Foreground = GradientString[Length - Counter].Foreground;

            Counter--;

            if (Counter == 0)
                commandStack.RemoveSafe(this);
        }
コード例 #14
0
ファイル: TextTool.cs プロジェクト: Thraka/SadConsoleEditor
        public void MouseMoveSurface(MouseInfo info, ITextSurface surface)
        {
            if (info.LeftClicked)
            {
                EditorConsoleManager.AllowKeyboardToMoveConsole = false;
                writing = true;

                tempConsole.TextSurface = (ITextSurfaceRendered)surface;
                tempConsole.VirtualCursor.Position = Brush.Position = info.ConsoleLocation;

                Brush.IsVisible = true;
            }
        }
コード例 #15
0
 /// <summary>
 /// Tests if a cell is valid based on its x,y position.
 /// </summary>
 /// <param name="surface">The surface to check.</param>
 /// <param name="x">The x coordinate of the cell to test.</param>
 /// <param name="y">The y coordinate of the cell to test.</param>
 /// <param name="index">If the cell is valid, the index of the cell when found.</param>
 /// <returns>A true value indicating the cell by x,y does exist in this cell surface.</returns>
 public static bool IsValidCell(this ITextSurface surface, int x, int y, out int index)
 {
     if (x >= 0 && x < surface.Width && y >= 0 && y < surface.Height)
     {
         index = y * surface.Width + x;
         return(true);
     }
     else
     {
         index = -1;
         return(false);
     }
 }
コード例 #16
0
        public void Save(object surface, string file)
        {
            ITextSurface  textSurface = (ITextSurface)surface;
            SurfaceEditor editor      = new SurfaceEditor(textSurface);

            string[] lines = new string[textSurface.Height];

            for (int y = 0; y < textSurface.Height; y++)
            {
                lines[y] = editor.GetString(0, y, textSurface.Width);
            }

            System.IO.File.WriteAllLines(file, lines);
        }
コード例 #17
0
        /// <summary>
        /// Creates and adds a new layer based on an existing surface.
        /// </summary>
        /// <param name="surface">The surface. Must be the same width/height of this </param>
        /// <returns></returns>
        public Layer Add(ITextSurface surface)
        {
            if (surface.Cells.Length != width * height)
            {
                throw new Exception("The length of cells passed in must match the width * height of this surface");
            }

            var layer = new Layer();

            layer.Cells = surface.Cells;
            ResetAreaLayer(layer);
            layers.Add(layer);
            SyncLayerIndex();
            return(layer);
        }
コード例 #18
0
        public void MouseMoveSurface(MouseInfo info, ITextSurface surface)
        {
            Brush.Position = info.ConsoleLocation;
            Brush.IsVisible = true;

            if (info.LeftClicked)
            {
                var cell = surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y);
                var editor = EditorConsoleManager.ActiveEditor as Editors.GameObjectEditor;

                if (editor != null)
                {
                    editor.SetAnimationCenter(new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y));
                }
            }
        }
コード例 #19
0
        public virtual void Draw(ITextSurface surface, Rectangle area)
        {
            string value = Item.ToString();

            if (value.Length < area.Width)
            {
                value += new string(' ', area.Width - value.Length);
            }
            else if (value.Length > area.Width)
            {
                value = value.Substring(0, area.Width);
            }
            var editor = new SurfaceEditor(surface);

            editor.Print(area.Left, area.Top, value, _currentAppearance);
            _isDirty = false;
        }
コード例 #20
0
        public override void Draw(ITextSurface surface, Rectangle area)
        {
            string value = ((Editors.EntityEditor.FrameWrapper)Item).CurrentIndex.ToString();

            if (value.Length < area.Width)
            {
                value += new string(' ', area.Width - value.Length);
            }
            else if (value.Length > area.Width)
            {
                value = value.Substring(0, area.Width);
            }

            var editor = new SurfaceEditor(surface);

            editor.Print(area.X, area.Y, value, _currentAppearance);
            _isDirty = false;
        }
コード例 #21
0
        /// <summary>
        /// Copies the contents of the cell surface to the destination at the specified x,y.
        /// </summary>
        /// <param name="x">The x coordinate of the destination.</param>
        /// <param name="y">The y coordinate of the destination.</param>
        /// <param name="source">The source surface</param>
        /// <param name="destination">The destination surface.</param>
        public static void Copy(this ITextSurface source, ITextSurface destination, int x, int y)
        {
            for (int curx = 0; curx < source.Width; curx++)
            {
                for (int cury = 0; cury < source.Height; cury++)
                {
                    int sourceIndex;
                    int destIndex;

                    if (source.IsValidCell(curx, cury, out sourceIndex) && destination.IsValidCell(x + curx, y + cury, out destIndex))
                    {
                        var sourceCell = source.Cells[sourceIndex];
                        var desCell    = destination.Cells[destIndex];
                        sourceCell.CopyAppearanceTo(desCell);
                        desCell.Effect = sourceCell.Effect;
                    }
                }
            }
        }
コード例 #22
0
        /// <summary>
        /// Copies the contents of the cell surface to the destination at the specified x,y.
        /// </summary>
        /// <param name="x">The x coordinate of the destination.</param>
        /// <param name="y">The y coordinate of the destination.</param>
        /// <param name="source">The source surface</param>
        /// <param name="destination">The destination surface.</param>
        public static void Copy(this ITextSurface source, ITextSurface destination, int x, int y)
        {
            for (int curx = 0; curx < source.Width; curx++)
            {
                for (int cury = 0; cury < source.Height; cury++)
                {
                    int sourceIndex;
                    int destIndex;

                    if (source.IsValidCell(curx, cury, out sourceIndex) && destination.IsValidCell(x + curx, y + cury, out destIndex))
                    {
                        var sourceCell = source.Cells[sourceIndex];
                        var desCell = destination.Cells[destIndex];
                        sourceCell.CopyAppearanceTo(desCell);
                        desCell.Effect = sourceCell.Effect;
                    }
                }
            }
        }
コード例 #23
0
        public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
        {
            Color newColor;

            if (Default)
            {
                if (CommandType == CommandTypes.Background)
                    newColor = surface != null ? surface.DefaultBackground : Color.Transparent;
                else
                    newColor = surface != null ? surface.DefaultForeground : Color.White;
            }
            else
            {
                if (CommandType == CommandTypes.Background)
                    newColor = glyphState.Background;
                else
                    newColor = glyphState.Foreground;

                if (!KeepRed)
                    newColor.R = R;
                if (!KeepGreen)
                    newColor.G = G;
                if (!KeepBlue)
                    newColor.B = B;
                if (!KeepAlpha)
                    newColor.A = A;
            }

            if (CommandType == CommandTypes.Background)
                glyphState.Background = newColor;
            else
                glyphState.Foreground = newColor;

            if (Counter != -1)
            {
                Counter--;

                if (Counter == 0)
                    commandStack.RemoveSafe(this);
            }
        }
コード例 #24
0
            public static void Save(EffectsManager effectsManager, ITextSurface surface, string file)
            {
                EffectsManagerSerialized data = new EffectsManagerSerialized();

                data.Effects = new Dictionary <ICellEffect, int[]>(effectsManager._effects.Count);
                List <Cell> currentCells = new List <Cell>(surface.Cells);

                foreach (var effectData in effectsManager._effects.Values)
                {
                    List <int> effectCellPositions = new List <int>(effectData.Cells.Count);

                    foreach (var cell in effectData.Cells)
                    {
                        effectCellPositions.Add(currentCells.IndexOf(cell));
                    }

                    data.Effects.Add(effectData.Effect, effectCellPositions.ToArray());
                }

                SadConsole.Serializer.Save(data, file);
            }
コード例 #25
0
        /// <summary>
        /// Copies the contents of the cell surface to the destination.
        /// </summary>
        /// <remarks>If the sizes to not match, it will always start at 0,0 and work with what it can and move on to the next row when either surface runs out of columns being processed</remarks>
        /// <param name="source">The source surface</param>
        /// <param name="destination">The destination surface.</param>
        public static void Copy(this ITextSurface source, ITextSurface destination)
        {
            int maxX = source.Width >= destination.Width ? destination.Width : source.Width;
            int maxY = source.Height >= destination.Height ? destination.Height : source.Height;

            for (int x = 0; x < maxX; x++)
            {
                for (int y = 0; y < maxY; y++)
                {
                    int sourceIndex;
                    int destIndex;

                    if (source.IsValidCell(x, y, out sourceIndex) && destination.IsValidCell(x, y, out destIndex))
                    {
                        var sourceCell = source.Cells[sourceIndex];
                        var desCell    = destination.Cells[destIndex];
                        sourceCell.CopyAppearanceTo(desCell);
                        desCell.Effect = sourceCell.Effect;
                    }
                }
            }
        }
コード例 #26
0
        /// <summary>
        /// Copies the contents of the cell surface to the destination.
        /// </summary>
        /// <remarks>If the sizes to not match, it will always start at 0,0 and work with what it can and move on to the next row when either surface runs out of columns being processed</remarks>
        /// <param name="source">The source surface</param>
        /// <param name="destination">The destination surface.</param>
        public static void Copy(this ITextSurface source, ITextSurface destination)
        {
            int maxX = source.Width >= destination.Width ? destination.Width : source.Width;
            int maxY = source.Height >= destination.Height ? destination.Height : source.Height;

            for (int x = 0; x < maxX; x++)
            {
                for (int y = 0; y < maxY; y++)
                {
                    int sourceIndex;
                    int destIndex;

                    if (source.IsValidCell(x, y, out sourceIndex) && destination.IsValidCell(x, y, out destIndex))
                    {
                        var sourceCell = source.Cells[sourceIndex];
                        var desCell = destination.Cells[destIndex];
                        sourceCell.CopyAppearanceTo(desCell);
                        desCell.Effect = sourceCell.Effect;
                    }
                }
            }
        }
コード例 #27
0
        public override void Draw(ITextSurface surface, Rectangle area)
        {
            if (Item is Color || Item is Tuple <Color, Color, string> )
            {
                var    editor = new SurfaceEditor(surface);
                string value  = new string(' ', area.Width - 2);

                CellAppearance cellLook = _currentAppearance.Clone();

                if (Item is Color)
                {
                    cellLook.Background = (Color)Item;
                    editor.Print(area.Left + 1, area.Top, value, cellLook);
                }
                else
                {
                    cellLook.Foreground = ((Tuple <Color, Color, string>)Item).Item2;
                    cellLook.Background = ((Tuple <Color, Color, string>)Item).Item1;
                    value = ((Tuple <Color, Color, string>)Item).Item3.Align(HorizontalAlignment.Left, area.Width - 2);
                    editor.Print(area.Left + 1, area.Top, value, cellLook);
                }

                editor.Print(area.Left, area.Top, " ", _currentAppearance);
                editor.Print(area.Left + area.Width - 1, area.Top, " ", _currentAppearance);

                if (IsSelected)
                {
                    editor.SetGlyph(area.Left, area.Top, 16);
                    editor.SetGlyph(area.Left + area.Width - 1, area.Top, 17);
                }

                IsDirty = false;
            }
            else
            {
                base.Draw(surface, area);
            }
        }
コード例 #28
0
ファイル: DrawTool.cs プロジェクト: Thraka/SadConsoleEditor
        public void MouseMoveSurface(MouseInfo info, ITextSurface surface)
        {
            Brush.IsVisible = true;
            Brush.Position = info.ConsoleLocation;

            if (info.LeftButtonDown)
            {
                var cell = surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y);
                cell.GlyphIndex = CharacterPickPanel.SharedInstance.SettingCharacter;
                cell.Foreground = CharacterPickPanel.SharedInstance.SettingForeground;
                cell.Background = CharacterPickPanel.SharedInstance.SettingBackground;
                cell.SpriteEffect = CharacterPickPanel.SharedInstance.SettingMirrorEffect;
            }

            if (info.RightButtonDown)
            {
                var cell = surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y);

                CharacterPickPanel.SharedInstance.SettingCharacter = cell.GlyphIndex;
                CharacterPickPanel.SharedInstance.SettingForeground = cell.Foreground;
                CharacterPickPanel.SharedInstance.SettingBackground = cell.Background;
                CharacterPickPanel.SharedInstance.SettingMirrorEffect = cell.SpriteEffect;
            }
        }
コード例 #29
0
        public void MouseMoveSurface(MouseInfo info, ITextSurface surface)
        {
            Brush.IsVisible = true;
            //_entity.SyncLayers();

            if (info.LeftClicked)
            {
                if (_panel.State == SelectionToolPanel.CloneState.SelectingPoint1)
                {
                    _panel.State = SelectionToolPanel.CloneState.SelectingPoint2;
                    Brush.Animation.Tint = new Color(0f, 0f, 0f, 0.5f);
                }

                else if (_panel.State == SelectionToolPanel.CloneState.SelectingPoint2)
                {
                    _secondPoint = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y);
                    _panel.State = SelectionToolPanel.CloneState.Selected;

                    // Copy data to new animation

                    AnimatedTextSurface cloneAnimation = new AnimatedTextSurface("clone", Brush.Width, Brush.Height, Settings.Config.ScreenFont);
                    var frame = cloneAnimation.CreateFrame();
                    Point topLeftPoint = new Point(Math.Min(_firstPoint.Value.X, _secondPoint.Value.X), Math.Min(_firstPoint.Value.Y, _secondPoint.Value.Y));
                    surface.Copy(topLeftPoint.X, topLeftPoint.Y, cloneAnimation.Width, cloneAnimation.Height, frame, 0, 0);

                    if (_altPanel.SkipEmptyCells && _altPanel.UseAltEmptyColor)
                    {
                        foreach (var cell in frame.Cells)
                        {
                            if (cell.GlyphIndex == 0 && cell.Background == _altPanel.AltEmptyColor)
                                cell.Background = Color.Transparent;
                        }
                    }

                    cloneAnimation.Center = Brush.Animation.Center;

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

                    //// Display the rect
                    //var topLayer = new GameObject(Settings.Config.ScreenFont);
                    //Brush.UnderAnimation = topLayer;
                    //topLayer.Animations[_tempAnimation.Name] = _tempAnimation;
                    //topLayer.Animation = _tempAnimation;
                    //topLayer.Animation.Tint = new Color(0f, 0f, 0f, 0.35f);
                    //topLayer.Position = Brush.Position;
                    ////_entity.SyncLayers();
                }

                else if (_panel.State == SelectionToolPanel.CloneState.Selected)
                {

                }
                else if (_panel.State == SelectionToolPanel.CloneState.Clone)
                {
                    //StampBrush(info.ConsoleLocation.X, info.ConsoleLocation.Y, surface);
                }
                else if (_panel.State == SelectionToolPanel.CloneState.Clear)
                {
                    // Erase selected area
                }
                else if (_panel.State == SelectionToolPanel.CloneState.Move)
                {
                    // Move the selected cells
                }

            }
            else
            {

                if (_panel.State == SelectionToolPanel.CloneState.SelectingPoint1)
                {
                    Brush.Position = info.ConsoleLocation;
                    _firstPoint = Brush.Position;

                    // State was reset and we didn't know about it
                    if (_previousState != _panel.State || Brush.Animation.Name != AnimationSingle)
                    {
                        Brush.Animation = Brush.Animations[AnimationSingle];
                        Brush.Animation.Tint = new Color(0f, 0f, 0f, 0f);
                    }
                }

                if (_panel.State == SelectionToolPanel.CloneState.SelectingPoint2)
                {
                    int width = Math.Max(_firstPoint.Value.X, info.ConsoleLocation.X) - Math.Min(_firstPoint.Value.X, info.ConsoleLocation.X) + 1;
                    int height = Math.Max(_firstPoint.Value.Y, info.ConsoleLocation.Y) - Math.Min(_firstPoint.Value.Y, info.ConsoleLocation.Y) + 1;

                    Point p1;

                    if (_firstPoint.Value.X > info.ConsoleLocation.X)
                    {
                        if (_firstPoint.Value.Y > info.ConsoleLocation.Y)
                            p1 = new Point(width - 1, height - 1);
                        else
                            p1 = new Point(width - 1, 0);
                    }
                    else
                    {
                        if (_firstPoint.Value.Y > info.ConsoleLocation.Y)
                            p1 = new Point(0, height - 1);
                        else
                            p1 = new Point(0, 0);
                    }

                    MakeBoxAnimation(width, height, p1);
                }

            }

            _previousState = _panel.State;
        }
コード例 #30
0
 /// <summary>
 /// Gets a cell based on it's coordinates on the surface.
 /// </summary>
 /// <param name="surface">The surface to check.</param>
 /// <param name="x">The X coordinate.</param>
 /// <param name="y">The Y coordinate.</param>
 /// <returns>The indicated cell.</returns>
 public static Cell GetCell(this ITextSurface surface, int x, int y)
 {
     return(surface.Cells[y * surface.Width + x]);
 }
コード例 #31
0
 /// <summary>
 /// Called when the <see cref="TextSurface"/> property is changed. Sets <see cref="Effects"/> to a new instance of <see cref="EffectsManager"/>.
 /// </summary>
 /// <param name="oldSurface">The previous text surface.</param>
 /// <param name="newSurface">The new text surface.</param>
 protected virtual void OnSurfaceChanged(ITextSurface oldSurface, ITextSurface newSurface)
 {
     Effects = new EffectsManager(newSurface);
 }
コード例 #32
0
ファイル: Circle.cs プロジェクト: Thraka/SadConsoleEditor
        public void MouseMoveSurface(MouseInfo info, ITextSurface surface)
        {
            Brush.IsVisible = true;

            if (!firstPoint.HasValue)
            {
                Brush.Position = info.ConsoleLocation;

                settingsPanel.CircleWidth = 0;
                settingsPanel.CircleHeight = 0;
            }
            else
            {
                AnimatedTextSurface animation;
                // Draw the line (erase old) to where the mouse is
                // create the animation frame
                animation = new AnimatedTextSurface("line", Math.Max(firstPoint.Value.X, info.ConsoleLocation.X) - Math.Min(firstPoint.Value.X, info.ConsoleLocation.X) + 1,
                                                            Math.Max(firstPoint.Value.Y, info.ConsoleLocation.Y) - Math.Min(firstPoint.Value.Y, info.ConsoleLocation.Y) + 1,
                                                            Settings.Config.ScreenFont);

                var frame = animation.CreateFrame();

                Point p1;

                if (firstPoint.Value.X > info.ConsoleLocation.X)
                {
                    if (firstPoint.Value.Y > info.ConsoleLocation.Y)
                        p1 = new Point(frame.Width - 1, frame.Height - 1);
                    else
                        p1 = new Point(frame.Width - 1, 0);
                }
                else
                {
                    if (firstPoint.Value.Y > info.ConsoleLocation.Y)
                        p1 = new Point(0, frame.Height - 1);
                    else
                        p1 = new Point(0, 0);
                }

                settingsPanel.CircleWidth = frame.Width;
                settingsPanel.CircleHeight = frame.Height;

                animation.Center = p1;

                Settings.QuickEditor.TextSurface = frame;

                ellipseShape = new SadConsole.Shapes.Ellipse();
                ellipseShape.BorderAppearance = borderAppearance;
                ellipseShape.EndingPoint = new Point(frame.Width - 1, frame.Height - 1);
                ellipseShape.Draw(Settings.QuickEditor);

                Brush.Animation = animation;
            }

            // TODO: Make this work. They push DOWN on the mouse, start the line from there, if they "Click" then go to mode where they click a second time
            // If they don't click and hold it down longer than click, pretend a second click happened and draw the line.
            if (info.LeftClicked)
            {
                if (!firstPoint.HasValue)
                {
                    firstPoint = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y);
                    RefreshTool();
                }
                else
                {
                    secondPoint = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y);
                    Point p1 = new Point(Math.Min(firstPoint.Value.X, secondPoint.Value.X), Math.Min(firstPoint.Value.Y, secondPoint.Value.Y));
                    Point p2 = new Point(Math.Max(firstPoint.Value.X, secondPoint.Value.X), Math.Max(firstPoint.Value.Y, secondPoint.Value.Y));

                    Settings.QuickEditor.TextSurface = surface;

                    ellipseShape.StartingPoint = p1;
                    ellipseShape.EndingPoint = p2;
                    ellipseShape.Draw(Settings.QuickEditor);

                    Brush.Animation = Brush.Animations["single"];
                    Brush.Position = secondPoint.Value;

                    firstPoint = null;
                    secondPoint = null;

                    //surface.ResyncAllCellEffects();
                }
            }
            else if (info.RightClicked)
            {
                if (firstPoint.HasValue && !secondPoint.HasValue)
                {
                    firstPoint = null;
                    secondPoint = null;

                    settingsPanel.CircleWidth = 0;
                    settingsPanel.CircleHeight = 0;

                    Brush.Animation = Brush.Animations["single"];
                    Brush.Position = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y);
                }
            }
        }
コード例 #33
0
ファイル: BoxTool.cs プロジェクト: Thraka/SadConsoleEditor
 public void MouseMoveSurface(MouseInfo info, ITextSurface surface)
 {
 }
コード例 #34
0
            public override void Draw(ITextSurface surface, Microsoft.Xna.Framework.Rectangle area)
            {
                string value = ((ResizableObject)Item).Name;

                if (string.IsNullOrEmpty(value))
                    value = "<no name>";

                if (value.Length < area.Width)
                    value += new string(' ', area.Width - value.Length);
                else if (value.Length > area.Width)
                    value = value.Substring(0, area.Width);
                var editor = new SurfaceEditor(surface);
                editor.Print(area.X, area.Y, value, _currentAppearance);
                _isDirty = false;
            }
コード例 #35
0
        public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
        {
            Color newColor;

            if (Default)
            {
                if (CommandType == CommandTypes.Background)
                {
                    newColor = surface != null ? surface.DefaultBackground : Color.Transparent;
                }
                else
                {
                    newColor = surface != null ? surface.DefaultForeground : Color.White;
                }
            }
            else
            {
                if (CommandType == CommandTypes.Background)
                {
                    newColor = glyphState.Background;
                }
                else
                {
                    newColor = glyphState.Foreground;
                }

                if (!KeepRed)
                {
                    newColor.R = R;
                }
                if (!KeepGreen)
                {
                    newColor.G = G;
                }
                if (!KeepBlue)
                {
                    newColor.B = B;
                }
                if (!KeepAlpha)
                {
                    newColor.A = A;
                }
            }

            if (CommandType == CommandTypes.Background)
            {
                glyphState.Background = newColor;
            }
            else
            {
                glyphState.Foreground = newColor;
            }

            if (Counter != -1)
            {
                Counter--;

                if (Counter == 0)
                {
                    commandStack.RemoveSafe(this);
                }
            }
        }
コード例 #36
0
ファイル: BoxTool.cs プロジェクト: Thraka/SadConsoleEditor
 public void MouseEnterSurface(MouseInfo info, ITextSurface surface)
 {
     Brush.IsVisible = true;
 }
コード例 #37
0
            public override void Draw(ITextSurface surface, Microsoft.Xna.Framework.Rectangle area)
            {
                string value = ((LayerMetadata)((LayeredTextSurface.Layer)Item).Metadata).Name;

                if (value.Length < area.Width)
                    value += new string(' ', area.Width - value.Length);
                else if (value.Length > area.Width)
                    value = value.Substring(0, area.Width);
                var editor = new SurfaceEditor(surface);
                editor.Print(area.X, area.Y, value, _currentAppearance);
                _isDirty = false;
            }
コード例 #38
0
ファイル: ParseCommandUndo.cs プロジェクト: Thraka/SadConsole
 public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
 {
 }
コード例 #39
0
        private void StampBrush(int consoleLocationX, int consoleLocationY, ITextSurface surface)
        {
            int destinationX = consoleLocationX - Brush.Animation.Center.X;
            int destinationY = consoleLocationY - Brush.Animation.Center.Y;
            int destX = destinationX;
            int destY = destinationY;

            for (int curx = 0; curx < Brush.SelectedSurface.Animation.Width; curx++)
            {
                for (int cury = 0; cury < Brush.SelectedSurface.Animation.Height; cury++)
                {
                    if (Brush.SelectedSurface.Animation.CurrentFrame.IsValidCell(curx, cury))
                    {
                        var sourceCell = Brush.SelectedSurface.Animation.CurrentFrame.GetCell(curx, cury);

                        // Not working, breakpoint here to remind me.
                        if (_altPanel.SkipEmptyCells && sourceCell.GlyphIndex == 0 && (sourceCell.Background == Color.Transparent || (_altPanel.UseAltEmptyColor && sourceCell.Background == _altPanel.AltEmptyColor)))
                        {
                            destY++;
                            continue;
                        }

                        if (surface.IsValidCell(destX, destY))
                        {
                            var desCell = surface.GetCell(destX, destY);
                            sourceCell.CopyAppearanceTo(desCell);
                            //TODO: effects
                            //surface.SetEffect(desCell, sourceCell.Effect);
                        }
                    }
                    destY++;
                }
                destY = destinationY;
                destX++;
            }
        }
コード例 #40
0
        private void ClearBrush(int consoleLocationX, int consoleLocationY, ITextSurface surface)
        {
            int destinationX = consoleLocationX - Brush.SelectedSurface.Animation.Center.X;
            int destinationY = consoleLocationY - Brush.SelectedSurface.Animation.Center.Y;
            int destX = destinationX;
            int destY = destinationY;

            Settings.QuickEditor.TextSurface = surface;

            for (int curx = 0; curx < Brush.SelectedSurface.Animation.CurrentFrame.Width; curx++)
            {
                for (int cury = 0; cury < Brush.SelectedSurface.Animation.CurrentFrame.Height; cury++)
                {
                    if (Brush.SelectedSurface.Animation.CurrentFrame.IsValidCell(curx, cury))
                    {
                        if (surface.IsValidCell(destX, destY))
                        {
                            Settings.QuickEditor.Clear(destX, destY);
                        }
                    }
                    destY++;
                }
                destY = destinationY;
                destX++;
            }
        }
コード例 #41
0
        public void ProcessMouse(MouseInfo info, ITextSurface surface)
        {
            if (EditorConsoleManager.ToolsPane.IsMouseOver)
            {
                Brush.IsVisible = false;
                return;
            }
            else
                Brush.IsVisible = true;

            _previousSurface = surface;

            if (_panel.State == SelectionToolPanel.CloneState.Clone || _panel.State == SelectionToolPanel.CloneState.Move)
            {
                Brush.Position = info.ConsoleLocation;
            }

            if (info.RightClicked)
            {
                _panel.State = SelectionToolPanel.CloneState.SelectingPoint1;
            }

            if (info.LeftClicked)
            {
                if (_panel.State == SelectionToolPanel.CloneState.Clone)
                {
                    StampBrush(info.ConsoleLocation.X, info.ConsoleLocation.Y, surface);
                }
                else if (_panel.State == SelectionToolPanel.CloneState.Move)
                {
                    StampBrush(info.ConsoleLocation.X, info.ConsoleLocation.Y, surface);
                    _panel.State = SelectionToolPanel.CloneState.SelectingPoint1;
                }
            }
        }
コード例 #42
0
ファイル: BoxTool.cs プロジェクト: Thraka/SadConsoleEditor
 public bool ProcessKeyboard(KeyboardInfo info, ITextSurface surface)
 {
     return false;
 }
コード例 #43
0
 /// <summary>
 /// Gets the index of a location on the surface by point.
 /// </summary>
 /// <param name="surface">The surface to check.</param>
 /// <param name="location">The location of the index to get.</param>
 /// <returns>The cell index.</returns>
 public static int GetIndexFromPoint(this ITextSurface surface, Point location)
 {
     return(location.Y * surface.Width + location.X);
 }
コード例 #44
0
ファイル: BoxTool.cs プロジェクト: Thraka/SadConsoleEditor
        public void ProcessMouse(MouseInfo info, ITextSurface surface)
        {
            if (EditorConsoleManager.ToolsPane.IsMouseOver)
            {
                Brush.IsVisible = false;
                return;
            }
            else
                Brush.IsVisible = true;

            if (!firstPoint.HasValue)
            {
                Brush.Position = info.ConsoleLocation;
            }
            else
            {
                // Draw the line (erase old) to where the mouse is
                // create the animation frame
                AnimatedTextSurface animation = new AnimatedTextSurface("line", Math.Max(firstPoint.Value.X, info.ConsoleLocation.X) - Math.Min(firstPoint.Value.X, info.ConsoleLocation.X) + 1,
                                                                                Math.Max(firstPoint.Value.Y, info.ConsoleLocation.Y) - Math.Min(firstPoint.Value.Y, info.ConsoleLocation.Y) + 1,
                                                                                Settings.Config.ScreenFont);

                var frame = animation.CreateFrame();

                Point p1;

                if (firstPoint.Value.X > info.ConsoleLocation.X)
                {
                    if (firstPoint.Value.Y > info.ConsoleLocation.Y)
                        p1 = new Point(frame.Width - 1, frame.Height - 1);
                    else
                        p1 = new Point(frame.Width - 1, 0);
                }
                else
                {
                    if (firstPoint.Value.Y > info.ConsoleLocation.Y)
                        p1 = new Point(0, frame.Height - 1);
                    else
                        p1 = new Point(0, 0);
                }

                animation.Center = p1;

                boxShape = SadConsole.Shapes.Box.GetDefaultBox();

                if (_settingsPanel.UseCharacterBorder)
                    boxShape.LeftSideCharacter = boxShape.RightSideCharacter =
                    boxShape.TopLeftCharacter = boxShape.TopRightCharacter = boxShape.TopSideCharacter =
                    boxShape.BottomLeftCharacter = boxShape.BottomRightCharacter = boxShape.BottomSideCharacter =
                    _settingsPanel.BorderCharacter;

                boxShape.Foreground = _settingsPanel.LineForeColor;
                boxShape.FillColor = _settingsPanel.FillColor;
                boxShape.Fill = _settingsPanel.UseFill;
                boxShape.BorderBackground = _settingsPanel.LineBackColor;
                boxShape.Location = new Point(0, 0);
                boxShape.Width = frame.Width;
                boxShape.Height = frame.Height;
                boxShape.Draw(new SurfaceEditor(frame));

                Brush.Animation = animation;
            }

            // TODO: Make this work. They push DOWN on the mouse, start the line from there, if they "Click" then go to mode where they click a second time
            // If they don't click and hold it down longer than click, pretend a second click happened and draw the line.
            if (info.LeftClicked)
            {
                if (!firstPoint.HasValue)
                {
                    firstPoint = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y);
                }
                else
                {
                    secondPoint = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y);
                    Point p1 = new Point(Math.Min(firstPoint.Value.X, secondPoint.Value.X), Math.Min(firstPoint.Value.Y, secondPoint.Value.Y));
                    //Point p2 = new Point(Math.Max(_firstPoint.Value.X, _secondPoint.Value.X), Math.Max(_firstPoint.Value.Y, _secondPoint.Value.Y));

                    boxShape.Location = p1;
                    boxShape.Draw(new SurfaceEditor(surface));

                    firstPoint = null;
                    secondPoint = null;

                    Brush.Animation = Brush.Animations["single"];

                    //surface.ResyncAllCellEffects();
                }
            }
            else if (info.RightClicked)
            {
                if (firstPoint.HasValue && !secondPoint.HasValue)
                {
                    firstPoint = null;
                    secondPoint = null;

                    Brush.Animation = Brush.Animations["single"];
                }
            }
        }
コード例 #45
0
 /// <summary>
 /// Gets the index of a location on the surface by coordinate.
 /// </summary>
 /// <param name="surface">The surface to check.</param>
 /// <param name="x">The x of the location.</param>
 /// <param name="y">The y of the location.</param>
 /// <returns>The cell index.</returns>
 public static int GetIndexFromPoint(this ITextSurface surface, int x, int y)
 {
     return(y * surface.Width + x);
 }
コード例 #46
0
ファイル: BoxTool.cs プロジェクト: Thraka/SadConsoleEditor
 public void MouseExitSurface(MouseInfo info, ITextSurface surface)
 {
     Brush.IsVisible = false;
 }
コード例 #47
0
 /// <summary>
 /// Gets the x,y of an index on the surface.
 /// </summary>
 /// <param name="surface">The surface to check.</param>
 /// <param name="index">The index to get.</param>
 /// <returns>The x,y as a <see cref="Point"/>.</returns>
 public static Point GetPointFromIndex(this ITextSurface surface, int index)
 {
     return(new Point(index % surface.Width, index / surface.Width));
 }
コード例 #48
0
 /// <summary>
 /// Creates a new effects manager associated with a text surface.
 /// </summary>
 /// <param name="surface">Text surface to manage.</param>
 public EffectsManager(ITextSurface surface)
 {
     _effects       = new Dictionary <ICellEffect, CellEffectData>(20);
     _effectCells   = new Dictionary <Cell, CellEffectData>(50);
     backingSurface = surface;
 }
コード例 #49
0
        public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
        {
            if (CommandType == CommandTypes.Background)
            {
                glyphState.Background = GradientString[Length - Counter].Foreground;
            }
            else
            {
                glyphState.Foreground = GradientString[Length - Counter].Foreground;
            }

            Counter--;

            if (Counter == 0)
            {
                commandStack.RemoveSafe(this);
            }
        }
コード例 #50
0
            public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
            {
                glyphState.Glyph = Glyph;

                if (Counter != -1)
                {
                    Counter--;

                    if (Counter == 0)
                    {
                        commandStack.RemoveSafe(this);
                    }
                }
            }
コード例 #51
0
ファイル: LineTool.cs プロジェクト: Thraka/SadConsoleEditor
 public void ProcessMouse(MouseInfo info, ITextSurface surface)
 {
 }
コード例 #52
0
 /// <summary>
 /// Creates a new cell surface that can be resized and also have its textSurface.Cells resized.
 /// </summary>
 /// <remarks>You must set the Font property before rendering this cell surface.</remarks>
 public SurfaceEditor(ITextSurface surface)
 {
     TextSurface = surface;
 }
コード例 #53
0
ファイル: LineTool.cs プロジェクト: Thraka/SadConsoleEditor
        public void MouseMoveSurface(MouseInfo info, ITextSurface surface)
        {
            Brush.IsVisible = true;

            if (!firstPoint.HasValue)
            {
                Brush.Position = info.ConsoleLocation;
            }
            else
            {
                SetAnimationLine(info.ConsoleLocation);

            }

            // TODO: Make this work. They push DOWN on the mouse, start the line from there, if they "Click" then go to mode where they click a second time
            // If they don't click and hold it down longer than click, pretend a second click happened and draw the line.
            if (info.LeftClicked)
            {
                if (!firstPoint.HasValue)
                {
                    firstPoint = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y);
                }
                else
                {
                    secondPoint = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y);

                    lineShape.StartingLocation = firstPoint.Value;
                    lineShape.EndingLocation = secondPoint.Value;
                    lineShape.Draw(new SurfaceEditor(surface));

                    firstPoint = null;
                    secondPoint = null;
                    lineShape = null;

                    Brush.Animation = Brush.Animations["single"];

                    //surface.ResyncAllCellEffects();
                    settingsPanel.LineLength = 0;
                }
            }
            else if (info.RightClicked)
            {
                if (firstPoint.HasValue && !secondPoint.HasValue)
                {
                    ResetLine();
                }
            }
        }
コード例 #54
0
 public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
 {
 }
コード例 #55
0
 public void MouseExitSurface(MouseInfo info, ITextSurface surface)
 {
     if (_panel.State == SelectionToolPanel.CloneState.SelectingPoint1 || _panel.State == SelectionToolPanel.CloneState.SelectingPoint2)
     {
         Brush.IsVisible = false;
         //_entity.SyncLayers();
     }
 }