Ejemplo n.º 1
0
        internal protected override void Draw(Cairo.Context cr, Cairo.Rectangle area, LineSegment lineSegment, int line, double x, double y, double lineHeight)
        {
            foldSegmentSize  = marginWidth * 4 / 6;
            foldSegmentSize -= (foldSegmentSize) % 2;

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

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

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

            if (line <= editor.Document.LineCount)
            {
                startFoldings.Clear();
                containingFoldings.Clear();
                endFoldings.Clear();
                foreach (FoldSegment segment in editor.Document.GetFoldingContaining(lineSegment))
                {
                    if (segment.StartLine.Offset == lineSegment.Offset)
                    {
                        startFoldings.Add(segment);
                    }
                    else if (segment.EndLine.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);
            }

            var bgGC = foldBgGC;

            if (editor.TextViewMargin.BackgroundRenderer != null)
            {
                if (isContainingSelected || isStartSelected || isEndSelected)
                {
                    bgGC = foldBgGC;
                }
                else
                {
                    bgGC = foldLineHighlightedGCBg;
                }
            }

            cr.Rectangle(drawArea);
            cr.Color = bgGC;
            cr.Fill();

            if (state == Document.LineState.Changed)
            {
                cr.Color = lineStateChangedGC;
                cr.Rectangle(x + 1, y, marginWidth / 3, lineHeight);
                cr.Fill();
            }
            else if (state == Document.LineState.Dirty)
            {
                cr.Color = lineStateDirtyGC;
                cr.Rectangle(x + 1, y, marginWidth / 3, lineHeight);
                cr.Fill();
            }

            if (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.IsFolded)
                        {
                            isVisible = false;
                        }
                        else
                        {
                            moreLinedOpenFold = foldSegment.EndLine.Offset > foldSegment.StartLine.Offset;
                        }
                    }
                    bool isFoldEndFromUpperFold = false;
                    foreach (FoldSegment foldSegment in endFoldings)
                    {
                        if (foldSegment.EndLine.Offset > foldSegment.StartLine.Offset && !foldSegment.IsFolded)
                        {
                            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 = drawArea.Y + drawArea.Height / 2;
                        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 + 1, xPos, drawArea.Y + drawArea.Height);
                        }
                    }
                    else if (isContaining)
                    {
                        cr.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Y, xPos, drawArea.Y + drawArea.Height);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        internal protected override void Draw(Gdk.Drawable win, Gdk.Rectangle area, int line, int x, int y, int lineHeight)
        {
            foldSegmentSize  = Width * 4 / 6;
            foldSegmentSize -= (foldSegmentSize) % 2;

            Gdk.Rectangle      drawArea = new Gdk.Rectangle(x, y, Width, lineHeight);
            Document.LineState state    = editor.Document.GetLineState(line);

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

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

            if (line < editor.Document.LineCount)
            {
                LineSegment lineSegment = editor.Document.GetLine(line);
                startFoldings.Clear();
                containingFoldings.Clear();
                endFoldings.Clear();
                foreach (FoldSegment segment in editor.Document.GetFoldingContaining(lineSegment))
                {
                    if (segment.StartLine.Offset == lineSegment.Offset)
                    {
                        startFoldings.Add(segment);
                    }
                    else if (segment.EndLine.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);
            }

            Gdk.GC bgGC = foldBgGC;
            if (editor.TextViewMargin.BackgroundRenderer != null)
            {
                if (isContainingSelected || isStartSelected || isEndSelected)
                {
                    bgGC = foldBgGC;
                }
                else
                {
                    bgGC = foldLineHighlightedGCBg;
                }
            }

            win.DrawRectangle(bgGC, true, drawArea);
            if (state == Document.LineState.Changed)
            {
                win.DrawRectangle(lineStateChangedGC, true, x + 1, y, Width / 3, lineHeight);
                //		win.DrawRectangle (bgGC, true, x + 3 , y, Width  - 3, lineHeight);
            }
            else if (state == Document.LineState.Dirty)
            {
                win.DrawRectangle(lineStateDirtyGC, true, x + 1, y, Width / 3, lineHeight);
                //		win.DrawRectangle (bgGC, true, x + 3 , y, Width - 3, lineHeight);
            }            /* else {
                          *     win.DrawRectangle (bgGC, true, drawArea);
                          * }*/

            if (line < editor.Document.LineCount)
            {
                int foldSegmentYPos = y + (editor.LineHeight - foldSegmentSize) / 2;
                int xPos            = x + Width / 2;

                if (isFoldStart)
                {
                    bool isVisible         = true;
                    bool moreLinedOpenFold = false;
                    foreach (FoldSegment foldSegment in startFoldings)
                    {
                        if (foldSegment.IsFolded)
                        {
                            isVisible = false;
                        }
                        else
                        {
                            moreLinedOpenFold = foldSegment.EndLine.Offset > foldSegment.StartLine.Offset;
                        }
                    }
                    bool isFoldEndFromUpperFold = false;
                    foreach (FoldSegment foldSegment in endFoldings)
                    {
                        if (foldSegment.EndLine.Offset > foldSegment.StartLine.Offset && !foldSegment.IsFolded)
                        {
                            isFoldEndFromUpperFold = true;
                        }
                    }
                    DrawFoldSegment(win, x, y, isVisible, isStartSelected);
                    if (isContaining || isFoldEndFromUpperFold)
                    {
                        win.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Top, xPos, foldSegmentYPos - 2);
                    }
                    if (isContaining || moreLinedOpenFold)
                    {
                        win.DrawLine(isEndSelected || (isStartSelected && isVisible) || isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, foldSegmentYPos + foldSegmentSize + 2, xPos, drawArea.Bottom);
                    }
                }
                else
                {
                    if (isFoldEnd)
                    {
                        int yMid = drawArea.Top + drawArea.Height / 2;
                        win.DrawLine(isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, x + Width - 2, yMid);
                        win.DrawLine(isContainingSelected || isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Top, xPos, yMid);
                        if (isContaining)
                        {
                            win.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid + 1, xPos, drawArea.Bottom);
                        }
                    }
                    else if (isContaining)
                    {
                        win.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Top, xPos, drawArea.Bottom);
                    }
                }
            }
        }