Exemplo n.º 1
0
        public static void Draw(this Symbol symbol, ITerminalSink sink)
        {
            if (symbol is null)
            {
                throw new ArgumentNullException(nameof(symbol));
            }

            if (sink is null)
            {
                throw new ArgumentNullException(nameof(sink));
            }

            symbol.Draw(sink, new Rectangle(symbol.Region.TopLeft, symbol.Region.BottomRight));
        }
Exemplo n.º 2
0
        public static bool Write(this ITerminalSink sink, Catena catena, Rectangle destination)
        {
            CharInfo[,] result = new CharInfo[destination.Height, destination.Width];
            CharInfo[] buffer = catena.ToArray();
            int        index  = 0;

            for (int y = 0; y < destination.Height; y++)
            {
                for (int x = 0; x < destination.Width && index < buffer.Length; x++, index++)
                {
                    result[y, x] = buffer[index];
                }
            }

            return(sink.Write(result, new Coord(destination.Left, destination.Top)));
        }
        /// <summary>
        /// Gets the <see cref="Coord"/> that the <see cref="ITerminalSink.CursorPosition"/> of <paramref name="sink"/>
        /// would need to be set to in order to reverse the cursor's movement by one position.
        /// </summary>
        /// <param name="sink">
        /// The sink to retrieve the cursor position of.
        /// </param>
        /// <param name="width">
        /// The width of the terminal.
        /// </param>
        /// <returns>
        /// The <see cref="Coord"/> that the <see cref="ITerminalSink.CursorPosition"/> of <paramref name="sink"/>
        /// would need to be set to in order to reverse the cursor's movement by one position.
        /// </returns>
        public static Coord GetReverseCursorPosition(this ITerminalSink sink, ushort width)
        {
            if (sink is null)
            {
                throw new ArgumentNullException(nameof(sink));
            }

            Coord currentPosition = sink.CursorPosition;

            if (currentPosition.X - 1 < 0)
            {
                return(new Coord((short)(width - 1), (short)(currentPosition.Y - 1)));
            }
            else
            {
                return(new Coord((short)(currentPosition.X - 1), currentPosition.Y));
            }
        }
Exemplo n.º 4
0
        public override void Draw(ITerminalSink sink, Rectangle window)
        {
            if (!this.Region.Overlaps(window))
            {
                return;
            }

            Coord destination = new Coord(window.Left, window.Top);

            window -= this.Region.TopLeft;
            sink.Write(
                this.backingFill.GetFullSize(),
                destination,
                new Rectangle(
                    window.Left,
                    window.Top,
                    (short)(window.Right + 1),
                    (short)(window.Bottom + 1)));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Writes the specified <see cref="Catena"/> <paramref name="catena"/> starting at the coordinate specified by
 /// the <see cref="Coord"/> <paramref name="destination"/>, if possible. If the write operation completed,
 /// returns <see langword="true"/>; otherwise, returns <see langword="false"/>. The most common reason for an
 /// incomplete write operation is if the specified <paramref name="catena"/> extends past the writeable area of
 /// this sink.
 /// </summary>
 /// <param name="sink">
 /// The <see cref="ITerminalSink"/> to write to.
 /// </param>
 /// <param name="catena">
 /// The <see cref="Catena"/> to write.
 /// </param>
 /// <param name="destination">
 /// The destination to start writing <paramref name="catena"/> from.
 /// </param>
 /// <returns>
 /// <see langword="true"/> if the write operation completed; otherwise, <see langword="false"/>. The most
 /// common reason for an incomplete write operation is if the specified <paramref name="catena"/> extends past
 /// the writeable area of this sink.
 /// </returns>
 public static bool Write(this ITerminalSink sink, Catena catena, Coord destination)
 {
     return(sink.Write(catena.ToArray(), destination));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Writes the specified <see cref="Catena"/> <paramref name="catena"/> and advances the cursor to the start of
 /// the next line.
 /// </summary>
 /// <param name="sink">
 /// The <see cref="ITerminalSink"/> to write to.
 /// </param>
 /// <param name="catena">
 /// The <see cref="Catena"/> to write.
 /// </param>
 /// <returns>
 /// <see langword="true"/> if the write operation completed; otherwise, <see langword="false"/>. The most
 /// common reason for an incomplete write operation is if the specified <paramref name="catena"/> extends past
 /// the writeable area of this sink.
 /// </returns>
 public static bool WriteLine(this ITerminalSink sink, Catena catena)
 {
     return(sink.WriteLine(catena.ToArray()));
 }
Exemplo n.º 7
0
 public abstract void Draw(ITerminalSink sink, Rectangle window);