예제 #1
0
        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);
        }
예제 #2
0
        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;
        }
예제 #3
0
 public abstract void Paint(Graphics graphics, DirectText directText, Font defaultFont, int initialTop, int width);
예제 #4
0
 public abstract void Initialize(DirectText directText, Font defaultFont);
예제 #5
0
 public abstract int GetHeight(DirectText directText, Font defaultFont, int width);
예제 #6
0
        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];
            }
        }
예제 #7
0
        public override void Initialize(DirectText directText, Font defaultFont)
        {
            Size size = directText.MeasureString(_text, defaultFont);

            _fullWidthForEstimation = size.Width;
            _heightForEstimation = size.Height;
        }
예제 #8
0
        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;
            }
        }
예제 #9
0
        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;
                }
            }
        }
예제 #10
0
        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));
                }
            }
        }
예제 #11
0
 public override void Initialize(DirectText directText, Font defaultFont)
 {
 }
예제 #12
0
 public override int GetHeight(DirectText directText, Font defaultFont, int width)
 {
     return _height;
 }