public void Clear(string boxName) { DisplayBox box = displayBoxes.FirstOrDefault(x => x.Name == boxName); if (box != null) { for (int i = box.DisplayX; i < box.DisplayX + box.DisplayWidth; i++) { for (int j = box.DisplayY; j < box.DisplayY + box.DisplayHeight; j++) { buffer[i, j] = new ColoredChar(); } } } }
public void Add(DisplayBox box) { if (displayBoxes.Exists(x => x.Name == box.Name)) { throw new DisplayBoxExistsException(box.Name); } else { foreach (DisplayBox boxInList in displayBoxes) { Rect intersection = Rect.Intersect(box.Rectangle, boxInList.Rectangle); if (intersection.Width > 0 && intersection.Height > 0) { throw new DisplayBoxOverlapException(); } } } displayBoxes.Add(box); }
public void WriteString(string boxName, string str, ConsoleColor foregroundColor, ConsoleColor backgroundColor, int line, int col) { DisplayBox box = displayBoxes.FirstOrDefault(x => x.Name == boxName); if (box != null) { for (int i = 0; i < str.Length; i++) { if (col + i < box.DisplayWidth) { buffer[box.DisplayX + col + i, box.DisplayY + line] = new ColoredChar { BackgroundColor = backgroundColor, Character = str[i], ForegroundColor = foregroundColor } } ; } } else { throw new ArgumentException("Display box with given name does not exists"); } }