/// <summary> /// Fills the rectangle specified by <para>dest</para> and <para>size</para> with the <para>fillChar</para> character and colors specified by <paramref name="fore"/> and <paramref name="back"/> /// </summary> /// <param name="fillChar"></param> /// <param name="dest"></param> /// <param name="foreColor"></param> /// <param name="backColor"></param> /// <remarks></remarks> public void Fill(char fillChar, Rectangle dest, ConsoleColor foreColor, ConsoleColor backColor) { var x = dest.X; var y = dest.Y; var clip_bottom = dest.Y + dest.Height; var clip_right = dest.X + dest.Width; BufferChar ch; while (y < clip_bottom) { x = dest.X; while (x < clip_right) { ch = new BufferChar() { Ch = fillChar, ForeColor = foreColor, BackColor = backColor }; this[x, y] = ch; x += 1; } y += 1; } }
public Buffer(Size size) { _size = size; _clipRectangle = new Rectangle(new Point(0, 0), _size); _internalBuffer = new BufferChar[_size.Height - 1 + 1][]; CurrentForeColor = ConsoleColor.White; CurrentBackColor = ConsoleColor.Black; var x = 0; var y = 0; for (y = 0; y <= _size.Height - 1; y++) { _internalBuffer[y] = new BufferChar[_size.Width - 1 + 1]; for (x = 0; x <= _size.Width - 1; x++) { _internalBuffer[y][x] = new BufferChar() { Ch = ' ', BackColor = CurrentBackColor, ForeColor = CurrentForeColor } } ; } }
/// <summary> /// /// </summary> /// <param name="s"></param> /// <param name="dest"></param> /// <param name="foreColor"></param> /// <param name="backColor"></param> /// <remarks></remarks> public void DrawString(string s, Rectangle dest, ConsoleColor foreColor, ConsoleColor backColor) { var i = 0; var x = dest.X; var y = dest.Y; var clip_bottom = dest.Y + dest.Height; var clip_right = dest.X + dest.Width; var last_cr = false; BufferChar ch; // read the string s, char by char while (i < s.Length && y < clip_bottom) { if (s[i] == '\n') { // if vbCr ==> return to left; one more row x = dest.X; y += 1; last_cr = true; } else if (s[i] == '\r') { // if it was vbCrLf do nothing // otherwise ==> return to left; one more row if (last_cr == false) { x = dest.X; y += 1; } last_cr = false; } else // if visibile, normal character to be printed if (y >= 0 && y < _size.Height && x >= 0 && x < _size.Width && y < clip_bottom && x < clip_right) { ch = new BufferChar() { Ch = s[i], ForeColor = foreColor, BackColor = backColor }; this[x, y] = ch; last_cr = false; x += 1; // wrap around if (x >= clip_right) { x = dest.X; y += 1; } } i += 1; } }