Beispiel #1
0
        public override void OnPaintBackground(IGUIContext ctx, RectangleF bounds)
        {
            base.OnPaintBackground(ctx, bounds);

            try {
                if (BreakWidthRulerVisible && Padding.Right > 0)
                {
                    int breakWidth = (int)(bounds.Left + Padding.Left + BreakWidth);
                    ctx.DrawLine(Theme.Pens.Base01, breakWidth, bounds.Top, breakWidth, bounds.Bottom);
                }

                painter.Value.Clear();

                if (SelLength <= 0)
                {
                    return;
                }

                int Start        = SelStart;
                int End          = Start + SelLength;
                int paraIndexEnd = RowManager.FindParagraphIndexByPosition(End);

                int firstParagraphIndex = RowManager.FirstParagraphOnScreen;
                if (firstParagraphIndex > paraIndexEnd)
                {
                    return;
                }

                int   rowHeight = RowManager.LineHeight;
                float rowBorder = 1f * ScaleFactor;

                Paragraph         paraStart;
                ParagraphPosition ppStart;

                int paraIndex = RowManager.FindParagraphIndexByPosition(Start);

                int lineOffset = 0;

                if (paraIndex >= firstParagraphIndex)
                {
                    paraStart  = RowManager.Paragraphs [paraIndex];
                    ppStart    = paraStart.PositionAtIndex(Start - paraStart.PositionOffset);
                    lineOffset = ppStart.LineIndex;
                }
                else
                {
                    paraIndex  = firstParagraphIndex;
                    paraStart  = RowManager.Paragraphs [paraIndex];
                    lineOffset = firstParagraphIndex - paraStart.LineOffset;
                    ppStart    = paraStart.PositionAtIndex(0);
                }

                Paragraph         paraEnd = RowManager.Paragraphs[paraIndexEnd];
                ParagraphPosition ppEnd   = paraEnd.PositionAtIndex(End - paraEnd.PositionOffset);

                int absline    = paraStart.LineOffset + ppStart.LineIndex;
                int absEndLine = paraEnd.LineOffset + ppEnd.LineIndex;

                float xStart = ppStart.ColumnStart + bounds.Left + Padding.Left;
                float yStart = bounds.Top + Padding.Top + (absline * rowHeight) + ScrollOffsetY;
                float xEnd   = 0;

                if (absline == absEndLine)
                {
                    xEnd = ppEnd.ColumnStart + bounds.Left + Padding.Left;
                    painter.Value.AddRectangle(SelectionBrush, xStart, yStart, xEnd - xStart, rowHeight - rowBorder);

                    // >>> Paint end exit ,,
                    painter.Value.Flush();
                    return;
                }

                float startWidth = ppStart.ColumnStart;

                while (absline <= absEndLine)
                {
                    foreach (float w in paraStart.LineWidths().Skip(lineOffset))
                    {
                        if (absline++ == absEndLine || yStart > bounds.Bottom)
                        {
                            startWidth = ppEnd.ColumnStart;
                            painter.Value.AddRectangle(SelectionBrush, xStart, yStart, startWidth, rowHeight - rowBorder);

                            // >>> Paint end exit ,,
                            painter.Value.Flush();
                            return;
                        }

                        if (yStart + rowHeight > bounds.Top && yStart < bounds.Bottom)
                        {
                            painter.Value.AddRectangle(SelectionBrush, xStart, yStart, w - startWidth, rowHeight - rowBorder);
                        }
                        yStart    += rowHeight;
                        startWidth = 0;
                        xStart     = bounds.Left + Padding.Left;
                    }

                    paraIndex++;
                    if (paraIndex >= RowManager.Paragraphs.Count)
                    {
                        break;
                    }
                    paraStart  = RowManager.Paragraphs[paraIndex];
                    lineOffset = 0;
                }
            } catch (Exception ex) {
                ex.LogWarning();
            }
        }