private void InflateRectIfActive(DrawingParameters parameters, Rectangle surroundingRect)
 {
     if (parameters.IsActive)
     {
         surroundingRect.Inflate(0, Convert.ToInt32(Font.Size / 2));
         surroundingRect.Y -= Convert.ToInt32(Font.Size / 3);
     }
 }
        private void DrawCustomOnEndLine(int endCharIndex, int lineIndex, DrawingParameters parameters, DrawingDelegate draw)
        {
            //Scope ends on the next line
            //outline the final lineToTheEnd
            int charPos = GetFirstCharIndexFromLine(lineIndex);

            parameters.StartPoint = GetPositionFromCharIndex(charPos);
            parameters.EndPoint   = GetPositionFromCharIndex(endCharIndex);
            draw(parameters);
        }
        public void DrawCustom(int startIndex, int length, DrawingParameters parameters, DrawingDelegate drawCallback)
        {
            List <Rectangle> rects;

            rects = GetSurroundingRects(startIndex, length);
            foreach (Rectangle rect in rects)
            {
                parameters.Rect = rect;
                drawCallback(parameters);
            }
        }
        private void DrawFill(DrawingParameters parameters)
        {
            //Rectangle surroundingRect = GetSurroundingRectForSingleLinedScope(parameters.StartPoint, parameters.EndPoint);
            Rectangle surroundingRect = parameters.Rect;

            InflateRectIfActive(parameters, surroundingRect);

            if (surroundingRect == Rectangle.Empty)
            {
                return;
            }
            fillRectWithColor(surroundingRect, parameters.FillColor, parameters.G, parameters.Opacity);
        }
        protected void DrawFill(DrawingParameters parameters)
        {
            if (parameters.FillColor == Color.Empty)
            {
                return;
            }
            Rectangle surroundingRect = parameters.Rect;

            if (surroundingRect == Rectangle.Empty)
            {
                return;
            }
            fillRectWithColor(surroundingRect, parameters.FillColor, parameters.G, parameters.Opacity);
        }
        public void DrawCustomOLD(int startIndex, int length, DrawingParameters parameters, DrawingDelegate drawCallback)
        {
            int endIndex = startIndex + length;

            int startLineIndex = GetLineFromCharIndex(startIndex);
            int endLineIndex   = GetLineFromCharIndex(endIndex);


            if (startLineIndex == endLineIndex)//spans one line
            {
                parameters.StartPoint = GetPositionFromCharIndex(startIndex);
                parameters.EndPoint   = GetPositionFromCharIndex(endIndex);
                drawCallback(parameters);
                //DrawBorder(parameters);
            }

            //compensate for first line being zero so calculations won't break
            int endLineForComparison   = endLineIndex + 1;
            int startLineForComparison = startLineIndex + 1;

            if (endLineForComparison - startLineForComparison == 1)//spans 2 lines
            {
                parameters.StartPoint = GetPositionFromCharIndex(startIndex);
                parameters.EndPoint   = getEndPointForLine(startLineIndex);

                drawCallback(parameters);

                DrawCustomOnEndLine(endIndex, endLineIndex, parameters, drawCallback);
            }

            if ((endLineForComparison - startLineForComparison) > 1)//spans >2 lines
            {
                int scopeLines = endLineIndex - startLineIndex;

                parameters.StartPoint = GetPositionFromCharIndex(startIndex);
                parameters.EndPoint   = getEndPointForLine(startLineIndex);

                drawCallback(parameters);

                for (int i = startLineIndex + 1; i < scopeLines; i++)
                {
                    int startLineCharPos = GetFirstCharIndexFromLine(i);

                    parameters.StartPoint = GetPositionFromCharIndex(startLineCharPos);
                    parameters.EndPoint   = getEndPointForLine(i);
                    drawCallback(parameters);
                }
                DrawCustomOnEndLine(endIndex, endLineIndex, parameters, drawCallback);
            }
        }
        protected void DrawBorder(DrawingParameters parameters)
        {
            Rectangle surroundingRect = parameters.Rect;

            if (parameters.BorderColor == Color.Empty)
            {
                return;
            }

            if (surroundingRect == Rectangle.Empty)
            {
                return;
            }
            drawRectWithColor(surroundingRect, parameters.BorderColor, parameters.G, parameters.Opacity, parameters.BorderWidth);
        }
        protected internal override void DrawCustomForSingleSurroundingRect(Rectangle rect, Scope scopeToDraw)
        {
            DrawingParameters borderParameters = new DrawingParameters(Color.Empty, graphics, RTB.ImplicitScopeBorderColor, 35, RTB.NonActiveScopeBorderWidth);
            DrawingParameters fillParameters = new DrawingParameters(Color.Empty, graphics, 35);
            fillParameters.IsActive = IsActive;
            borderParameters.IsActive = IsActive;

            borderParameters.BorderColor = RTB.NonActiveScopeBorderColor;
            borderParameters.BorderWidth = RTB.NonActiveScopeBorderWidth;

            fillParameters.FillColor = RTB.NonActiveScopeFillColor;

            borderParameters.Rect = rect;
            fillParameters.Rect = rect;

            DrawBorder(borderParameters);
            DrawFill(fillParameters);
        }
        protected internal override void DrawCustomForSingleSurroundingRect(Rectangle rect, Scope scopeToDraw)
        {
            DrawingParameters borderParameters = new DrawingParameters(Color.Empty, graphics, RTB.ImplicitScopeBorderColor, 255, RTB.NonActiveScopeBorderWidth);
            DrawingParameters fillParameters = new DrawingParameters(RTB.ActiveScopeFillColor, graphics, 50);
            fillParameters.IsActive = IsActive;
            borderParameters.IsActive = IsActive;

            borderParameters.BorderColor = RTB.ActiveScopeBorderColor;
            borderParameters.BorderWidth = 1;

            fillParameters.FillColor = RTB.ActiveScopeFillColor;
            fillParameters.BorderWidth = 1;
            visible = true;

            Rectangle finalRect = GetActiveRectange(IsActive, rect);
            fillParameters.Rect = finalRect;
            borderParameters.Rect = finalRect;

            DrawBorder(borderParameters);
            DrawFill(fillParameters);
        }
        protected internal override void DrawCustomForSingleSurroundingRect(Rectangle rect, Scope scopeToDraw)
        {
            DrawingParameters borderParameters = new DrawingParameters(Color.Empty, graphics, RTB.ImplicitScopeBorderColor, 35, RTB.NonActiveScopeBorderWidth);
            DrawingParameters fillParameters = new DrawingParameters(Color.Empty, graphics, 35);
            fillParameters.IsActive = IsActive;
            borderParameters.IsActive = IsActive;

            borderParameters.BorderColor = Color.Black;
            borderParameters.Opacity = 255;
            borderParameters.BorderWidth = 2;

            fillParameters.FillColor = Color.LightYellow;
            fillParameters.Opacity = 255;

            Rectangle biggerRect = GetHigherRect(rect);

            fillParameters.Rect = biggerRect;
            borderParameters.Rect = biggerRect;

            DrawBorder(borderParameters);
            DrawFill(fillParameters);

            if (scopeToDraw.Name == string.Empty)
            {
                return;
            }
            Font italicFont = new Font(txt.Font.FontFamily, txt.Font.Size - 2, FontStyle.Italic);
            SizeF nameWidth = graphics.MeasureString(scopeToDraw.Name, italicFont);

                        if(nameWidth.Width> rect.Width)
                        {
                            return;

                        }

            graphics.DrawString(scopeToDraw.Name,
                                italicFont,
                                new SolidBrush(Color.Black),
                                GetMiddleRect(biggerRect));
        }
        public void DrawScopeOfUnknownLength(Scope scope, bool isActive, Graphics g)
        {
            if (scope.IsRoot)
                return;

            DrawingParameters borderParameters =new DrawingParameters(Color.Empty, g, implicitScopeBorderColor, scopeOpacity, nonActiveScopeBorderWidth);
            DrawingParameters fillParameters =  new DrawingParameters(activeScopeFillColor, g, scopeOpacity);
            borderParameters.IsActive = isActive;
            fillParameters.IsActive = isActive;

            int startPos = scope.StartPosInRootScope;
            int length = scope.Length;

            if (scope.IsImplicit && scope.IsFlat)
            {
                borderParameters.BorderColor = implicitScopeBorderColor;
                borderParameters.BorderWidth = nonActiveScopeBorderWidth;
                rtb.DrawBorder(startPos, length, borderParameters);
            }
            if (!isActive && !scope.IsImplicit && scope.IsFlat)
            {
                borderParameters.BorderColor = nonActiveScopeBorderColor;
                rtb.DrawBorder(startPos, length, borderParameters);

                fillParameters.FillColor = nonActiveScopeFillColor;
                fillParameters.Opacity = 25;
                fillParameters.BorderWidth = nonActiveScopeBorderWidth;
                rtb.DrawFill(startPos, length, fillParameters);
            }

            if (isActive && !scope.IsImplicit && scope.IsFlat)
            {
                borderParameters.BorderColor = activeScopeBorderColor;
                borderParameters.BorderWidth = activeScopeBorderWidth;

                rtb.DrawBorder(startPos, length, borderParameters);
                fillParameters.FillColor = activeScopeFillColor;
                fillParameters.BorderWidth = activeScopeBorderWidth;

                rtb.DrawFill(startPos, length, fillParameters);
            }
        }
 public void DrawFill(int startIndex, int length, DrawingParameters parameters)
 {
     DrawCustom(startIndex, length, parameters, new DrawingDelegate(DrawFill));
 }
 public void DrawBorder(int startIndex, int length, DrawingParameters parameters)
 {
     DrawCustom(startIndex, length, parameters, DrawBorder);
 }
        protected void DrawFill(DrawingParameters parameters)
        {
            if (parameters.FillColor == Color.Empty)
            {
                return;
            }
            Rectangle surroundingRect = parameters.Rect;

            if (surroundingRect == Rectangle.Empty)
            {
                return;
            }
            fillRectWithColor(surroundingRect, parameters.FillColor, parameters.G, parameters.Opacity);
        }
        protected void DrawBorder(DrawingParameters parameters)
        {
            Rectangle surroundingRect = parameters.Rect;
            if (parameters.BorderColor == Color.Empty)
            {
                return;
            }

            if (surroundingRect == Rectangle.Empty)
            {
                return;
            }
            drawRectWithColor(surroundingRect, parameters.BorderColor, parameters.G, parameters.Opacity, parameters.BorderWidth);
        }
        protected override void HighlightText(Color fillColor, int fillOpacity, Color borderColor, int borderOpacity,
            int borderWidth, bool shouldDrawFill, bool shouldDrawBorder)
        {
            txt.SelectionLength = 0;
            DrawingParameters fillData = new DrawingParameters(fillColor, txt.CreateGraphics(), fillColor, fillOpacity, borderWidth);
            DrawingParameters borderData = new DrawingParameters(borderColor, txt.CreateGraphics(), borderColor, borderOpacity, borderWidth);

            if (shouldDrawFill)
            {
                txt.DrawFill(selStart, selLength, fillData);
            }

            if (shouldDrawBorder)
            {
                txt.DrawBorder(selStart, selLength, borderData);
            }
        }