/// <summary> /// Draws the string on the console at the specified location, wrapping if needed. /// </summary> /// <param name="x">X location of the text.</param> /// <param name="y">Y location of the text.</param> /// <param name="text">The string to display.</param> /// <param name="appearance">The appearance of the cell</param> /// <param name="effect">An optional effect to apply to the printed cells.</param> public void Print(int x, int y, string text, ICellAppearance appearance, ICellEffect effect = null) { if (String.IsNullOrEmpty(text)) { return; } if (x >= textSurface.Width || x < 0 || y >= textSurface.Height || y < 0) { throw new Exception("X,Y is out of range for Print"); } int index = y * textSurface.Width + x; int total = index + text.Length > textSurface.Cells.Length ? textSurface.Cells.Length - index : index + text.Length; int charIndex = 0; for (; index < total; index++) { Cell cell = textSurface.Cells[index]; appearance.CopyAppearanceTo(cell); cell.GlyphIndex = text[charIndex]; Effects.SetEffect(cell, effect); charIndex++; } }
/// <summary> /// Changes the appearance of the cell. The appearance represents the look of a cell and will first be cloned, then applied to the cell. /// </summary> /// <param name="x">The x location of the cell.</param> /// <param name="y">The y location of the cell.</param> /// <param name="appearance">The desired appearance of the cell. A null value cannot be passed.</param> public void SetCellAppearance(int x, int y, ICellAppearance appearance) { if (appearance == null) { throw new NullReferenceException("Appearance may not be null."); } appearance.CopyAppearanceTo(textSurface.Cells[y * textSurface.Width + x]); }
/// <summary> /// Prints text on the console. /// </summary> /// <param name="text">The text to print.</param> /// <param name="template">The way the text will look when it is printed.</param> /// <returns>Returns this cursor object.</returns> public Cursor Print(string text, ICellAppearance template, ICellEffect templateEffect) { // TODO: Look for the flag 7 on settings. This means allow word wrap. So without it we need to test if the text will reach the end of the screen and cut it off. //((Console)_console.Target).DrawString(_location.X, _location.Y, text, PrintAppearance.Foreground, PrintAppearance.Background, PrintAppearance.Effect); var console = (Console)_console.Target; foreach (var character in text) { if (character == '\r') { CarriageReturn(); } else if (character == '\n') { LineFeed(); } else { var cell = console.CellData[_position.X, _position.Y]; if (!PrintOnlyCharacterData) { template.CopyAppearanceTo(cell); console._cellData.SetEffect(cell, templateEffect); } cell.CharacterIndex = character; _position.X += 1; if (_position.X >= console.CellData.Width) { _position.X = 0; _position.Y += 1; if (_position.Y >= console.CellData.Height) { _position.Y -= 1; if (AutomaticallyShiftRowsUp) { console.CellData.ShiftUp(); if (console.CellData.ResizeOnShift) { _position.Y++; } } } } } } return(this); }
/// <summary> /// Prints text on the console. /// </summary> /// <param name="text">The text to print.</param> /// <param name="template">The way the text will look when it is printed.</param> /// <returns>Returns this cursor object.</returns> public Cursor Print(string text, ICellAppearance template, ICellEffect templateEffect) { // TODO: Look for the flag 7 on settings. This means allow word wrap. So without it we need to test if the text will reach the end of the screen and cut it off. //((Console)_console.Target).DrawString(_location.X, _location.Y, text, PrintAppearance.Foreground, PrintAppearance.Background, PrintAppearance.Effect); var console = (Console)_console.Target; foreach (var character in text) { if (character == '\r') { CarriageReturn(); } else if (character == '\n') { LineFeed(); } else { var cell = console.CellData[_position.X, _position.Y]; if (!PrintOnlyCharacterData) { template.CopyAppearanceTo(cell); console._cellData.SetEffect(cell, templateEffect); } cell.CharacterIndex = character; _position.X += 1; if (_position.X > console.CellData.Width - 1) { _position.X = 0; _position.Y += 1; if (_position.Y > console.CellData.Height - 1) { _position.Y -= 1; if (AutomaticallyShiftRowsUp) console.CellData.ShiftRowsUp(); } } } } return this; }
/// <summary> /// Changes the appearance of the cell. The appearance represents the look of a cell and will first be cloned, then applied to the cell. /// </summary> /// <param name="x">The x location of the cell.</param> /// <param name="y">The y location of the cell.</param> /// <param name="appearance">The desired appearance of the cell. A null value cannot be passed.</param> public void SetCellAppearance(int x, int y, ICellAppearance appearance) { if (appearance == null) throw new NullReferenceException("Appearance may not be null."); appearance.CopyAppearanceTo(textSurface.Cells[y * textSurface.Width + x]); }
/// <summary> /// Draws the string on the console at the specified location, wrapping if needed. /// </summary> /// <param name="x">X location of the text.</param> /// <param name="y">Y location of the text.</param> /// <param name="text">The string to display.</param> /// <param name="appearance">The appearance of the cell</param> /// <param name="effect">An optional effect to apply to the printed cells.</param> public void Print(int x, int y, string text, ICellAppearance appearance, ICellEffect effect = null) { if (String.IsNullOrEmpty(text)) return; if (x >= textSurface.Width || x < 0 || y >= textSurface.Height || y < 0) throw new Exception("X,Y is out of range for Print"); int index = y * textSurface.Width + x; int total = index + text.Length > textSurface.Cells.Length ? textSurface.Cells.Length - index : index + text.Length; int charIndex = 0; for (; index < total; index++) { Cell cell = textSurface.Cells[index]; appearance.CopyAppearanceTo(cell); cell.GlyphIndex = text[charIndex]; Effects.SetEffect(cell, effect); charIndex++; } }