float PaintFoldingText(Graphics g, int lineNumber, float physicalXPos, Rectangle lineRectangle, string text, bool drawSelected)
        {
            // TODO: get font and color from the highlighting file
            HighlightColor selectionColor  = textArea.Document.HighlightingStrategy.GetEnvironmentColorForName("Selection");
            Brush          bgColorBrush    = drawSelected ? BrushRegistry.GetBrush(selectionColor.BackgroundColor) : GetBgColorBrush(lineNumber);
            Brush          backgroundBrush = textArea.Enabled ? bgColorBrush : SystemBrushes.InactiveBorder;

            float      wordWidth = g.MeasureString(text, textArea.Font, Int32.MaxValue, measureStringFormat).Width;
            RectangleF rect      = new RectangleF(physicalXPos, lineRectangle.Y, wordWidth, lineRectangle.Height - 1);

            g.FillRectangle(backgroundBrush, rect);

            physicalColumn += text.Length;
            g.DrawString(text,
                         textArea.Font,
                         BrushRegistry.GetBrush(drawSelected ? selectionColor.Color : Color.Gray),
                         rect,
                         measureStringFormat);
            g.DrawRectangle(BrushRegistry.GetPen(drawSelected ? Color.DarkGray : Color.Gray), rect.X, rect.Y, rect.Width, rect.Height);

            // Bugfix for the problem - of overdrawn right rectangle lines.
            float ceiling = (float)Math.Ceiling(physicalXPos + wordWidth);

            if (ceiling - (physicalXPos + wordWidth) < 0.5)
            {
                ++ceiling;
            }
            return(ceiling);
        }
Example #2
0
        void DrawFoldMarker(Graphics g, RectangleF rectangle, bool isOpened, bool isSelected)
        {
            HighlightColor foldMarkerColor  = textArea.Document.HighlightingStrategy.GetEnvironmentColorForName("FoldMarker");
            HighlightColor foldLineColor    = textArea.Document.HighlightingStrategy.GetEnvironmentColorForName("FoldLine");
            HighlightColor selectedFoldLine = textArea.Document.HighlightingStrategy.GetEnvironmentColorForName("SelectedFoldLine");

            Rectangle 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 : foldMarkerColor.Color), intRect);

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

            g.DrawLine(BrushRegistry.GetPen(foldLineColor.BackgroundColor),
                       rectangle.X + space,
                       rectangle.Y + mid,
                       rectangle.X + rectangle.Width - space,
                       rectangle.Y + mid);

            if (!isOpened)
            {
                g.DrawLine(BrushRegistry.GetPen(foldLineColor.BackgroundColor),
                           rectangle.X + mid,
                           rectangle.Y + space,
                           rectangle.X + mid,
                           rectangle.Y + rectangle.Height - space);
            }
        }
        void DrawVerticalRuler(Graphics g, Rectangle lineRectangle)
        {
            if (TextEditorProperties.VerticalRulerRow < textArea.VirtualTop.X)
            {
                return;
            }
            HighlightColor vRulerColor = textArea.Document.HighlightingStrategy.GetEnvironmentColorForName("VRuler");

            int xpos = (int)(DrawingRectangle.Left + GetWidth(g, ' ') * (TextEditorProperties.VerticalRulerRow - textArea.VirtualTop.X));

            g.DrawLine(BrushRegistry.GetPen(vRulerColor.Color),
                       xpos,
                       lineRectangle.Top,
                       xpos,
                       lineRectangle.Bottom);
        }
        void DrawMarker(Graphics g, TextMarker marker, RectangleF drawingRect)
        {
            float drawYPos = drawingRect.Bottom - 1;

            switch (marker.TextMarkerType)
            {
            case TextMarkerType.Underlined:
                g.DrawLine(BrushRegistry.GetPen(marker.Color), drawingRect.X, drawYPos, drawingRect.Right, drawYPos);
                break;

            case TextMarkerType.WaveLine:
                int reminder = ((int)drawingRect.X) % 6;
                for (float i = drawingRect.X - reminder; i < drawingRect.Right + reminder; i += 6)
                {
                    g.DrawLine(BrushRegistry.GetPen(marker.Color), i, drawYPos + 3 - 4, i + 3, drawYPos + 1 - 4);
                    g.DrawLine(BrushRegistry.GetPen(marker.Color), i + 3, drawYPos + 1 - 4, i + 6, drawYPos + 3 - 4);
                }
                break;

            case TextMarkerType.SolidBlock:
                g.FillRectangle(BrushRegistry.GetBrush(marker.Color), drawingRect);
                break;
            }
        }
Example #5
0
        void PaintFoldMarker(Graphics g, int lineNumber, Rectangle drawingRectangle)
        {
            HighlightColor foldLineColor    = textArea.Document.HighlightingStrategy.GetEnvironmentColorForName("FoldLine");
            HighlightColor selectedFoldLine = textArea.Document.HighlightingStrategy.GetEnvironmentColorForName("SelectedFoldLine");

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

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

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

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

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


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

                bool isFoldEndFromUpperFold = false;
                foreach (FoldMarker 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)
                {
                    int midy = drawingRectangle.Top + drawingRectangle.Height / 2;
                    // draw line above fold end marker
                    g.DrawLine(BrushRegistry.GetPen(isBetweenSelected || isEndSelected ? selectedFoldLine.Color : foldLineColor.Color),
                               xPos,
                               drawingRectangle.Top,
                               xPos,
                               midy);

                    // draw fold end marker
                    g.DrawLine(BrushRegistry.GetPen(isBetweenSelected || isEndSelected ? selectedFoldLine.Color : foldLineColor.Color),
                               xPos,
                               midy,
                               xPos + foldMarkerSize / 2,
                               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);
                }
            }
        }