public override void Draw(ConsoleGraphics graphics) { graphics.FillRectangle(Position, Size, Background); ConsoleGraphics innerGraphics; if (HasBorder) { graphics.DrawRectangle(Position, Size, Border); int maxLength = Size.X - 2; int captionLength = Math.Max(0, Math.Min(maxLength, Text.Length)); if (captionLength > 0 && Size.Y > 0) { string caption = null; Vector2 start = new Vector2(Position.X + 1, Position.Y); switch (CaptionAlignment) { case TextAlignment.Left: caption = Text.Substring(0, captionLength); break; case TextAlignment.Right: start.X += maxLength - captionLength; caption = Text.Substring(Text.Length - captionLength, captionLength); break; case TextAlignment.Center: start.X += (maxLength - captionLength) / 2; int diff = Text.Length - captionLength; caption = Text.Substring(diff / 2, captionLength); break; } graphics.DrawLine(start, caption, CharColor, Border.BackColor); } innerGraphics = graphics.CreateRegion( new Viewport(Position.X + 1, Position.Y + 1, Size.X - 2, Size.Y - 2)); } else { innerGraphics = graphics.CreateRegion( new Viewport(Position.X, Position.Y, Size.X, Size.Y)); } var controls = Controls.OrderBy(c => c.ZIndex); foreach (Control control in controls) { control.Draw(innerGraphics); } }
private Application() { screenBuffer = new ConsoleBuffer( SoftwareGraphics.Devices.ConsoleGraphicsDevice.GetConsoleViewport()); screenGraphics = new ConsoleGraphics(screenBuffer); background = new Brush(' ', ConsoleColor.White, ConsoleColor.Black); Controls = new ControlCollection( PreviewControlAdd, ControlAdded, PreviewControlRemove, ControlRemoved); CursorVisible = false; System.Console.CancelKeyPress += Console_CancelKeyPress; }
public ConsoleGraphics CreateRegion(Viewport region) { Vector2 offset = Offset + new Vector2(region.X, region.Y); // right and bottom are excluded values int left = Math.Max(ClipRegion.X, Math.Min(excludedMax.X, offset.X)); int top = Math.Max(ClipRegion.Y, Math.Min(excludedMax.Y, offset.Y)); int right = Math.Max(ClipRegion.X, Math.Min(excludedMax.X, offset.X + region.Width)); int bottom = Math.Max(ClipRegion.Y, Math.Min(excludedMax.Y, offset.Y + region.Height)); ConsoleGraphics clipped = new ConsoleGraphics(); clipped.consoleBuffer = this.consoleBuffer; clipped.Offset = offset; clipped.ClipRegion = new Viewport(left, top, right - left, bottom - top); return(clipped); }
public virtual void Draw(ConsoleGraphics graphics) { }
public override void Draw(ConsoleGraphics graphics) { if (Text.Length == 0) { return; } graphics.FillRectangle(Position, Size, Background); if (AutoSize) { for (int i = 0; i < lines.Length; i++) { graphics.DrawLine(new Vector2(Position.X, Position.Y + i), lines[i], CharColor, Background.BackColor); } } else { List <string> wrappedLines = new List <string>(); var size = Size; foreach (string line in lines) { string remainder = line; while (remainder.Length > 0 && wrappedLines.Count < size.Y) { int cutLength = Math.Min(size.X, remainder.Length); wrappedLines.Add(remainder.Substring(0, cutLength)); remainder = remainder.Remove(0, cutLength); } if (wrappedLines.Count >= size.Y) { break; } } switch (TextAlignment) { case TextAlignment.Left: for (int i = 0; i < wrappedLines.Count; i++) { graphics.DrawLine(new Vector2(Position.X, Position.Y + i), wrappedLines[i], CharColor, Background.BackColor); } break; case TextAlignment.Right: for (int i = 0; i < wrappedLines.Count; i++) { string line = wrappedLines[i]; graphics.DrawLine( new Vector2(Position.X + size.X - line.Length, Position.Y + i), line, CharColor, Background.BackColor); } break; case TextAlignment.Center: for (int i = 0; i < wrappedLines.Count; i++) { string line = wrappedLines[i]; graphics.DrawLine( new Vector2(Position.X + (size.X - line.Length) / 2, Position.Y + i), line, CharColor, Background.BackColor); } break; } } }