示例#1
0
        private void DrawFoldMarker(Graphics g, RectangleF rectangle, bool isOpened, bool isSelected)
        {
            var foldMarkerColor  = textArea.Document.HighlightingStrategy.GetColorFor("FoldMarker");
            var foldLineColor    = textArea.Document.HighlightingStrategy.GetColorFor("FoldLine");
            var selectedFoldLine = textArea.Document.HighlightingStrategy.GetColorFor("SelectedFoldLine");

            var intRect = new Rectangle((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width,
                                        (int)rectangle.Height);

            g.FillRectangle(BrushRegistry.GetBrush(foldMarkerColor.BackgroundColor), intRect);
            g.DrawRectangle(BrushRegistry.GetPen(isSelected ? selectedFoldLine.Color : foldLineColor.Color), intRect);

            var space = (int)Math.Round(rectangle.Height / 8d) + 1;
            var mid   = intRect.Height / 2 + intRect.Height % 2;

            // draw minus
            g.DrawLine(BrushRegistry.GetPen(foldMarkerColor.Color),
                       rectangle.X + space,
                       rectangle.Y + mid,
                       rectangle.X + rectangle.Width - space,
                       rectangle.Y + mid);

            // draw plus
            if (!isOpened)
            {
                g.DrawLine(BrushRegistry.GetPen(foldMarkerColor.Color),
                           rectangle.X + mid,
                           rectangle.Y + space,
                           rectangle.X + mid,
                           rectangle.Y + rectangle.Height - space);
            }
        }
示例#2
0
        private void PaintFoldMarker(Graphics g, int lineNumber, Rectangle drawingRectangle)
        {
            var foldLineColor    = textArea.Document.HighlightingStrategy.GetColorFor("FoldLine");
            var selectedFoldLine = textArea.Document.HighlightingStrategy.GetColorFor("SelectedFoldLine");

            var foldingsWithStart = textArea.Document.FoldingManager.GetFoldingsWithStart(lineNumber);
            var foldingsBetween   = textArea.Document.FoldingManager.GetFoldingsContainsLineNumber(lineNumber);
            var foldingsWithEnd   = textArea.Document.FoldingManager.GetFoldingsWithEnd(lineNumber);

            var isFoldStart = foldingsWithStart.Count > 0;
            var isBetween   = foldingsBetween.Count > 0;
            var isFoldEnd   = foldingsWithEnd.Count > 0;

            var isStartSelected   = SelectedFoldingFrom(foldingsWithStart);
            var isBetweenSelected = SelectedFoldingFrom(foldingsBetween);
            var isEndSelected     = SelectedFoldingFrom(foldingsWithEnd);

            var foldMarkerSize = (int)Math.Round(textArea.TextView.FontHeight * 0.57f);

            foldMarkerSize -= foldMarkerSize % 2;
            var foldMarkerYPos = drawingRectangle.Y + (drawingRectangle.Height - foldMarkerSize) / 2;
            var xPos           = drawingRectangle.X + (drawingRectangle.Width - foldMarkerSize) / 2 + foldMarkerSize / 2;


            if (isFoldStart)
            {
                var isVisible         = true;
                var moreLinedOpenFold = false;
                foreach (var foldMarker in foldingsWithStart)
                {
                    if (foldMarker.IsFolded)
                    {
                        isVisible = false;
                    }
                    else
                    {
                        moreLinedOpenFold = foldMarker.EndLine > foldMarker.StartLine;
                    }
                }

                var isFoldEndFromUpperFold = false;
                foreach (var foldMarker in foldingsWithEnd)
                {
                    if (foldMarker.EndLine > foldMarker.StartLine && !foldMarker.IsFolded)
                    {
                        isFoldEndFromUpperFold = true;
                    }
                }

                DrawFoldMarker(g, new RectangleF(drawingRectangle.X + (drawingRectangle.Width - foldMarkerSize) / 2,
                                                 foldMarkerYPos,
                                                 foldMarkerSize,
                                                 foldMarkerSize),
                               isVisible,
                               isStartSelected
                               );

                // draw line above fold marker
                if (isBetween || isFoldEndFromUpperFold)
                {
                    g.DrawLine(BrushRegistry.GetPen(isBetweenSelected ? selectedFoldLine.Color : foldLineColor.Color),
                               xPos,
                               drawingRectangle.Top,
                               xPos,
                               foldMarkerYPos - 1);
                }

                // draw line below fold marker
                if (isBetween || moreLinedOpenFold)
                {
                    g.DrawLine(
                        BrushRegistry.GetPen(isEndSelected || isStartSelected && isVisible || isBetweenSelected
                            ? selectedFoldLine.Color
                            : foldLineColor.Color),
                        xPos,
                        foldMarkerYPos + foldMarkerSize + 1,
                        xPos,
                        drawingRectangle.Bottom);
                }
            }
            else
            {
                if (isFoldEnd)
                {
                    var midy = drawingRectangle.Top + drawingRectangle.Height / 2;

                    // draw fold end marker
                    g.DrawLine(BrushRegistry.GetPen(isEndSelected ? selectedFoldLine.Color : foldLineColor.Color),
                               xPos,
                               midy,
                               xPos + foldMarkerSize / 2,
                               midy);

                    // draw line above fold end marker
                    // must be drawn after fold marker because it might have a different color than the fold marker
                    g.DrawLine(
                        BrushRegistry.GetPen(isBetweenSelected || isEndSelected
                            ? selectedFoldLine.Color
                            : foldLineColor.Color),
                        xPos,
                        drawingRectangle.Top,
                        xPos,
                        midy);

                    // draw line below fold end marker
                    if (isBetween)
                    {
                        g.DrawLine(
                            BrushRegistry.GetPen(isBetweenSelected ? selectedFoldLine.Color : foldLineColor.Color),
                            xPos,
                            midy + 1,
                            xPos,
                            drawingRectangle.Bottom);
                    }
                }
                else if (isBetween)
                {
                    // just draw the line :)
                    g.DrawLine(BrushRegistry.GetPen(isBetweenSelected ? selectedFoldLine.Color : foldLineColor.Color),
                               xPos,
                               drawingRectangle.Top,
                               xPos,
                               drawingRectangle.Bottom);
                }
            }
        }