public override void Paint(Graphics graphics, DirectText directText, Font defaultFont, int initialTop, int width) { graphics.FillRectangle(SystemBrushes.Window, new Rectangle(0, initialTop, width, _height)); Rectangle rectangle = new Rectangle( _margin, initialTop + (_height - 1) / 2, width - 2 * _margin, 1); graphics.FillRectangle(Brushes.Gray, rectangle); }
public override int GetHeight(DirectText directText, Font defaultFont, int width) { if (_layoutForWidth != width) { _layoutForWidth = width; List<string> lines = new List<string>(); List<int> lineHeights = new List<int>(); _layoutHeight = 0; string remaining = _text; int availableWidth = width - _leftPadding - _rightPadding; while (remaining.Length > 0) { // Break the remaining text into a line: int fittingCharacterCount = directText.MeasureFittingCharacterCount(remaining, availableWidth, defaultFont); fittingCharacterCount = Math.Max(1, fittingCharacterCount); string line = remaining.Substring(0, fittingCharacterCount); remaining = remaining.Substring(fittingCharacterCount); lines.Add(line); // Add the line height: Size size = directText.MeasureString(line, defaultFont); lineHeights.Add(size.Height); _layoutHeight += size.Height; } _lines = lines.ToArray(); _lineHeights = lineHeights.ToArray(); } return _layoutHeight; }
public abstract void Paint(Graphics graphics, DirectText directText, Font defaultFont, int initialTop, int width);
public abstract void Initialize(DirectText directText, Font defaultFont);
public abstract int GetHeight(DirectText directText, Font defaultFont, int width);
public override void Paint(Graphics graphics, DirectText directText, Font defaultFont, int initialTop, int width) { graphics.FillRectangle(SystemBrushes.Window, new Rectangle(0, initialTop, width, _layoutHeight)); int top = initialTop; for (int i = 0; i < _lines.Length; i++) { directText.DrawString(graphics, _lines[i], defaultFont, SystemColors.WindowText, _leftPadding, top); top += _lineHeights[i]; } }
public override void Initialize(DirectText directText, Font defaultFont) { Size size = directText.MeasureString(_text, defaultFont); _fullWidthForEstimation = size.Width; _heightForEstimation = size.Height; }
void InitializeNewRows(DirectText directText, int width) { if (_rows.Count == 0) return; LinkedListNode<ConsoleRow> current = _rows.Last; // The following method assumes at least one row needs initialisation: if (current.Value.Initialized) return; while (!current.Value.Initialized) { if (current.Previous == null) break; current = current.Previous; } // The current is now at the top of the uninitialised rows: int height = 0; if (current.Previous != null) height = current.Previous.Value.CumulativeEstimatedHeight; while (current != null) { current.Value.Initialize(directText, _defaultFont); current.Value.Initialized = true; height += current.Value.GetEstimatedHeight(width); current.Value.CumulativeEstimatedHeight = height; current = current.Next; } }
void EnsureEstimated(DirectText directText, int width) { if (_estimatedForWidth != width) { _estimatedForWidth = width; int height = 0; foreach (ConsoleRow row in _rows) { height += row.GetEstimatedHeight(_estimatedForWidth); row.CumulativeEstimatedHeight = height; } } }
protected override void OnPaint(PaintEventArgs e) { using (DirectText directText = new DirectText(e.Graphics)) { int width = Width - _scrollBarWidth; InitializeNewRows(directText, width); EnsureEstimated(directText, width); if (_scrollToBottom) { _offset = GetLastOffset(); _scrollToBottom = false; } UpdateScrollBar(); int top = 0; LinkedListNode<ConsoleRow> current = _offset; while (current != null && top < Height) { int height = current.Value.GetHeight(directText, _defaultFont, width); current.Value.Paint(e.Graphics, directText, _defaultFont, top, width); top += height; current = current.Next; } if (0 <= top && top < Height) { e.Graphics.FillRectangle(SystemBrushes.Window, new Rectangle(0, top, width, Height - top)); } } }
public override void Initialize(DirectText directText, Font defaultFont) { }
public override int GetHeight(DirectText directText, Font defaultFont, int width) { return _height; }