/// <summary> /// Applies this appearance instance values to the destination appearance. /// </summary> /// <param name="destination">The target of the appearance copy.</param> public void CopyAppearanceTo(ICellAppearance destination) { destination.Foreground = this.Foreground; destination.Background = this.Background; destination.GlyphIndex = this.GlyphIndex; destination.SpriteEffect = this.SpriteEffect; }
public void Draw(CellSurface surface) { if (BorderAppearance == null) BorderAppearance = new CellAppearance(Color.Blue, Color.Black, 4); Algorithms.Circle(Center.X, Center.Y, Radius, (x, y) => { if (surface.IsValidCell(x, y)) surface.SetCellAppearance(x, y, BorderAppearance); }); }
/// <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> /// 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> /// <param name="templateEffect">Effect to apply to the text as its printed.</param> /// <returns>Returns this cursor object.</returns> public Cursor Print(string text, ICellAppearance template, ICellEffect templateEffect) { var coloredString = text.CreateColored(template.Foreground, template.Background, template.SpriteEffect); coloredString.SetEffect(templateEffect); return(Print(coloredString)); }
/// <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> /// Applies this appearance instance values to the destination appearance. /// </summary> /// <param name="destination">The target of the appearance copy.</param> public void CopyAppearanceTo(ICellAppearance destination) { destination.Foreground = this.Foreground; destination.Background = this.Background; destination.SpriteEffect = this.SpriteEffect; if (this.CharacterIndex != -1) destination.CharacterIndex = this.CharacterIndex; }
/// <summary> /// Creates a <see cref="ColoredString"/> object from an existing string with the specified foreground, background, and cell effect. /// </summary> /// <param name="value">The current string.</param> /// <param name="appearance">The foreground and background color.</param> /// <param name="effect">The cell effect.</param> /// <returns>A <see cref="ColoredString"/> object instace.</returns> public static ColoredString CreateColored(this string value, ICellAppearance appearance, ICellEffect effect) { ColoredString newString = new ColoredString(value); newString.Foreground = appearance.Foreground; newString.Background = appearance.Background; newString.Effect = effect; newString.UpdateWithDefaults(); return(newString); }
/// <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> /// Applies this appearance instance values to the destination appearance. /// </summary> /// <param name="destination">The target of the appearance copy.</param> public void CopyAppearanceTo(ICellAppearance destination) { destination.Foreground = this.Foreground; destination.Background = this.Background; destination.SpriteEffect = this.SpriteEffect; if (this.CharacterIndex != -1) { destination.CharacterIndex = this.CharacterIndex; } }
public void Draw(CellSurface surface) { if (BorderAppearance == null) { BorderAppearance = new CellAppearance(Color.Blue, Color.Black, 4); } Algorithms.Circle(Center.X, Center.Y, Radius, (x, y) => { if (surface.IsValidCell(x, y)) { surface.SetCellAppearance(x, y, BorderAppearance); } }); }
/// <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> /// <param name="templateEffect">Effect to apply to the text as its printed.</param> /// <returns>Returns this cursor object.</returns> public Cursor Print(string text, ICellAppearance template) { ColoredString coloredString; if (UseStringParser) { var console = (SurfaceEditor)_console.Target; coloredString = ColoredString.Parse(text, _position.Y * console.TextSurface.Width + _position.X, console.TextSurface, console, new StringParser.ParseCommandStacks()); } else { coloredString = text.CreateColored(template.Foreground, template.Background); } return(Print(coloredString)); }
/// <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> /// Creates a <see cref="ColoredString"/> object from an existing string with the specified foreground and background. /// </summary> /// <param name="value">The current string.</param> /// <param name="appearance">The foreground and background color.</param> /// <returns>A <see cref="ColoredString"/> object instace.</returns> public static ColoredString CreateColored(this string value, ICellAppearance appearance) { ColoredString newString = new ColoredString(value); newString.Foreground = appearance.Foreground; newString.Background = appearance.Background; newString.Effect = null; newString.UpdateWithDefaults(); return newString; }
/// <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> /// <param name="templateEffect">Effect to apply to the text as its printed.</param> /// <returns>Returns this cursor object.</returns> public Cursor Print(string text, ICellAppearance template, ICellEffect templateEffect) { ColoredString coloredString; if (UseStringParser) { var console = (SurfaceEditor)_console.Target; coloredString = ColoredString.Parse(text, _position.Y * console.TextSurface.Width + _position.X, console.TextSurface, console, new StringParser.ParseCommandStacks()); } else { coloredString = text.CreateColored(template.Foreground, template.Background, template.SpriteEffect); coloredString.SetEffect(templateEffect); } return Print(coloredString); }
/// <summary> /// Applies this appearance instance values to the destination appearance. /// </summary> /// <param name="destination">The target of the appearance copy.</param> public void CopyAppearanceTo(ICellAppearance destination) { destination.Foreground = this.Foreground; destination.Background = this.Background; destination.CharacterIndex = this.CharacterIndex; }
/// <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> /// 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++; } }