Exemplo n.º 1
0
        internal protected override void Draw(Cairo.Context cr, Cairo.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
        {
            MarginMarker marker = null;

            if (lineSegment != null)
            {
                foreach (var m in editor.Document.GetMarkers(lineSegment))
                {
                    var mm = m as MarginMarker;
                    if (mm != null && mm.CanDraw(this))
                    {
                        marker = mm;
                        break;
                    }
                }
            }

            if (marker != null)
            {
                bool hasDrawn = marker.DrawBackground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
                if (!hasDrawn)
                {
                    marker = null;
                }
            }

            foldSegmentSize  = marginWidth * 4 / 6;
            foldSegmentSize -= (foldSegmentSize) % 2;

            Cairo.Rectangle drawArea = new Cairo.Rectangle(x, y, marginWidth, lineHeight);
            var             state    = editor.Document.GetLineState(lineSegment);

            bool isFoldStart  = false;
            bool isContaining = false;
            bool isFoldEnd    = false;

            bool isStartSelected      = false;
            bool isContainingSelected = false;
            bool isEndSelected        = false;

            if (editor.Options.ShowFoldMargin && line <= editor.Document.LineCount)
            {
                startFoldings.Clear();
                containingFoldings.Clear();
                endFoldings.Clear();
                if (lineSegment != null)
                {
                    foreach (FoldSegment segment in editor.Document.GetFoldingContaining(lineSegment))
                    {
                        if (segment.GetStartLine(editor.Document)?.Offset == lineSegment.Offset)
                        {
                            startFoldings.Add(segment);
                        }
                        else if (segment.GetEndLine(editor.Document)?.Offset == lineSegment.Offset)
                        {
                            endFoldings.Add(segment);
                        }
                        else
                        {
                            containingFoldings.Add(segment);
                        }
                    }
                }

                isFoldStart  = startFoldings.Count > 0;
                isContaining = containingFoldings.Count > 0;
                isFoldEnd    = endFoldings.Count > 0;

                isStartSelected      = this.lineHover != null && IsMouseHover(startFoldings);
                isContainingSelected = this.lineHover != null && IsMouseHover(containingFoldings);
                isEndSelected        = this.lineHover != null && IsMouseHover(endFoldings);
            }

            if (marker == null)
            {
                if (editor.GetTextEditorData().HighlightCaretLine&& editor.Caret.Line == line)
                {
                    editor.TextViewMargin.DrawCaretLineMarker(cr, x, y, Width, lineHeight);
                }
                else
                {
                    var bgGC = foldBgGC;
                    if (editor.TextViewMargin.BackgroundRenderer != null)
                    {
                        if (isContainingSelected || isStartSelected || isEndSelected)
                        {
                            bgGC = foldBgGC;
                        }
                        else
                        {
                            bgGC = foldLineHighlightedGCBg;
                        }
                    }

                    cr.Rectangle(drawArea);
                    cr.SetSourceColor(bgGC);
                    cr.Fill();
                }
            }

            if (editor.Options.EnableQuickDiff && state != TextDocument.LineState.Unchanged)
            {
                var prevState = lineSegment?.PreviousLine != null?editor.Document.GetLineState(lineSegment.PreviousLine) : TextDocument.LineState.Unchanged;

                var nextState = lineSegment?.NextLine != null?editor.Document.GetLineState(lineSegment.NextLine) : TextDocument.LineState.Unchanged;

                if (state == TextDocument.LineState.Changed)
                {
                    cr.SetSourceColor(lineStateChangedGC);
                }
                else if (state == TextDocument.LineState.Dirty)
                {
                    cr.SetSourceColor(lineStateDirtyGC);
                }

                if ((prevState == TextDocument.LineState.Unchanged && prevState != state ||
                     nextState == TextDocument.LineState.Unchanged && nextState != state))
                {
                    FoldingScreenbackgroundRenderer.DrawRoundRectangle(
                        cr,
                        prevState == TextDocument.LineState.Unchanged,
                        nextState == TextDocument.LineState.Unchanged,
                        x + 1,
                        y,
                        lineHeight / 4,
                        marginWidth / 4,
                        lineHeight
                        );
                }
                else
                {
                    cr.Rectangle(x + 1, y, marginWidth / 4, lineHeight);
                }
                cr.Fill();
            }

            if (editor.Options.ShowFoldMargin && line <= editor.Document.LineCount)
            {
                double foldSegmentYPos = y + System.Math.Floor(editor.LineHeight - foldSegmentSize) / 2;
                double xPos            = x + System.Math.Floor(marginWidth / 2) + 0.5;

                if (isFoldStart)
                {
                    bool isVisible         = true;
                    bool moreLinedOpenFold = false;
                    foreach (FoldSegment foldSegment in startFoldings)
                    {
                        if (foldSegment.IsCollapsed)
                        {
                            isVisible = false;
                        }
                        else
                        {
                            moreLinedOpenFold = foldSegment.GetEndLine(editor.Document).Offset > foldSegment.GetStartLine(editor.Document).Offset;
                        }
                    }
                    bool isFoldEndFromUpperFold = false;
                    foreach (FoldSegment foldSegment in endFoldings)
                    {
                        if (foldSegment.GetEndLine(editor.Document).Offset > foldSegment.GetStartLine(editor.Document).Offset&& !foldSegment.IsCollapsed)
                        {
                            isFoldEndFromUpperFold = true;
                        }
                    }
                    DrawFoldSegment(cr, x, y, isVisible, isStartSelected);

                    if (isContaining || isFoldEndFromUpperFold)
                    {
                        cr.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, foldSegmentYPos - 2);
                    }
                    if (isContaining || moreLinedOpenFold)
                    {
                        cr.DrawLine(isEndSelected || (isStartSelected && isVisible) || isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, foldSegmentYPos + foldSegmentSize + 2, xPos, drawArea.Y + drawArea.Height);
                    }
                }
                else
                {
                    if (isFoldEnd)
                    {
                        double yMid = System.Math.Floor(drawArea.Y + drawArea.Height / 2) + 0.5;
                        cr.DrawLine(isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, x + marginWidth - 2, yMid);
                        cr.DrawLine(isContainingSelected || isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, yMid);

                        if (isContaining)
                        {
                            cr.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, xPos, drawArea.Y + drawArea.Height);
                        }
                    }
                    else if (isContaining)
                    {
                        cr.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, drawArea.Y + drawArea.Height);
                    }
                }
            }
        }
            public override void Draw(Context cr, Rectangle area, DocumentLine line, int lineNumber, double x, double y, double lineHeight)
            {
                MarginMarker marker   = GetMarginMarker(line);
                bool         hasDrawn = false;

                if (marker != null)
                {
                    hasDrawn = marker.DrawBackground(Editor, cr, new MarginDrawMetrics(Margin, area, line, lineNumber, x, y, lineHeight));
                }

                if (!hasDrawn)
                {
                    if (Editor.GetTextEditorData().HighlightCaretLine&& Editor.Caret.Line == lineNumber)
                    {
                        Editor.TextViewMargin.DrawCaretLineMarker(cr, x, y, Margin.Width, lineHeight);
                    }
                    else
                    {
                        cr.Rectangle(x, y, Margin.Width, lineHeight);
                        cr.SetSourceColor(backgroundColor);
                        cr.Fill();
                    }
                }

                var state = Editor.Document.GetLineState(line);

                if (Editor.Options.EnableQuickDiff && state != TextDocument.LineState.Unchanged)
                {
                    var prevState = line?.PreviousLine != null?Editor.Document.GetLineState(line.PreviousLine) : TextDocument.LineState.Unchanged;

                    var nextState = line?.NextLine != null?Editor.Document.GetLineState(line.NextLine) : TextDocument.LineState.Unchanged;

                    if (state == TextDocument.LineState.Changed)
                    {
                        cr.SetSourceColor(lineStateChangedGC);
                    }
                    else if (state == TextDocument.LineState.Dirty)
                    {
                        cr.SetSourceColor(lineStateDirtyGC);
                    }

                    if ((prevState == TextDocument.LineState.Unchanged && prevState != state ||
                         nextState == TextDocument.LineState.Unchanged && nextState != state))
                    {
                        FoldingScreenbackgroundRenderer.DrawRoundRectangle(
                            cr,
                            prevState == TextDocument.LineState.Unchanged,
                            nextState == TextDocument.LineState.Unchanged,
                            x + 1,
                            y,
                            lineHeight / 4,
                            Margin.Width / 4,
                            lineHeight
                            );
                    }
                    else
                    {
                        cr.Rectangle(x + 1, y, Margin.Width / 4, lineHeight);
                    }
                    cr.Fill();
                }
            }