IsNearerToAThanB() static private method

static private IsNearerToAThanB ( int num, int a, int b ) : bool
num int
a int
b int
return bool
示例#1
0
        internal TextLocation GetLogicalColumn(int lineNumber, int visualPosX, out FoldMarker inFoldMarker)
        {
            int          logicalColumnInternal;
            FoldMarker   foldMarker;
            int          num;
            TextLocation textLocation = new TextLocation();

            visualPosX  += this.textArea.VirtualTop.X;
            inFoldMarker = null;
            if (lineNumber >= base.Document.TotalNumberOfLines)
            {
                return(new TextLocation(visualPosX / this.WideSpaceWidth, lineNumber));
            }
            if (visualPosX <= 0)
            {
                return(new TextLocation(0, lineNumber));
            }
            int endColumn = 0;
            int num1      = 0;

            using (Graphics graphic = this.textArea.CreateGraphics())
            {
                while (true)
                {
                    LineSegment lineSegment = base.Document.GetLineSegment(lineNumber);
                    foldMarker = this.FindNextFoldedFoldingOnLineAfterColumn(lineNumber, endColumn - 1);
                    int num2 = (foldMarker != null ? foldMarker.StartColumn : 2147483647);
                    logicalColumnInternal = this.GetLogicalColumnInternal(graphic, lineSegment, endColumn, num2, ref num1, visualPosX);
                    if (logicalColumnInternal < num2)
                    {
                        break;
                    }
                    lineNumber = foldMarker.EndLine;
                    endColumn  = foldMarker.EndColumn;
                    num        = num1 + 1 + this.MeasureStringWidth(graphic, foldMarker.FoldText, base.TextEditorProperties.FontContainer.RegularFont);
                    if (num >= visualPosX)
                    {
                        goto Label1;
                    }
                    num1 = num;
                }
                return(new TextLocation(logicalColumnInternal, lineNumber));
            }
            return(textLocation);

Label1:
            inFoldMarker = foldMarker;
            if (!TextView.IsNearerToAThanB(visualPosX, num1, num))
            {
                textLocation = new TextLocation(foldMarker.EndColumn, foldMarker.EndLine);
                return(textLocation);
            }
            else
            {
                textLocation = new TextLocation(foldMarker.StartColumn, foldMarker.StartLine);
                return(textLocation);
            }
        }
示例#2
0
        private int GetLogicalColumnInternal(Graphics g, LineSegment line, int start, int end, ref int drawingPos, int targetVisualPosX)
        {
            int num;

            if (start == end)
            {
                return(end);
            }
            int             tabIndent     = base.Document.TextEditorProperties.TabIndent;
            FontContainer   fontContainer = base.TextEditorProperties.FontContainer;
            List <TextWord> words         = line.Words;

            if (words == null)
            {
                return(0);
            }
            int length = 0;

            for (int i = 0; i < words.Count; i++)
            {
                TextWord item = words[i];
                if (length >= end)
                {
                    return(length);
                }
                if (length + item.Length >= start)
                {
                    switch (item.Type)
                    {
                    case TextWordType.Word:
                    {
                        int    num1 = Math.Max(length, start);
                        int    num2 = Math.Min(length + item.Length, end) - num1;
                        string text = base.Document.GetText(line.Offset + num1, num2);
                        Font   font = item.GetFont(fontContainer) ?? fontContainer.RegularFont;
                        num = drawingPos + this.MeasureStringWidth(g, text, font);
                        if (num < targetVisualPosX)
                        {
                            break;
                        }
                        for (int j = 0; j < text.Length; j++)
                        {
                            char chr = text[j];
                            num = drawingPos + this.MeasureStringWidth(g, chr.ToString(), font);
                            if (num >= targetVisualPosX)
                            {
                                if (TextView.IsNearerToAThanB(targetVisualPosX, drawingPos, num))
                                {
                                    return(num1 + j);
                                }
                                return(num1 + j + 1);
                            }
                            drawingPos = num;
                        }
                        return(num1 + text.Length);
                    }

                    case TextWordType.Space:
                    {
                        num = drawingPos + this.spaceWidth;
                        if (num < targetVisualPosX)
                        {
                            break;
                        }
                        if (TextView.IsNearerToAThanB(targetVisualPosX, drawingPos, num))
                        {
                            return(length);
                        }
                        return(length + 1);
                    }

                    case TextWordType.Tab:
                    {
                        drawingPos = (drawingPos + 4) / tabIndent / this.WideSpaceWidth * tabIndent * this.WideSpaceWidth;
                        num        = drawingPos + tabIndent * this.WideSpaceWidth;
                        if (num < targetVisualPosX)
                        {
                            break;
                        }
                        if (TextView.IsNearerToAThanB(targetVisualPosX, drawingPos, num))
                        {
                            return(length);
                        }
                        return(length + 1);
                    }

                    default:
                    {
                        throw new NotSupportedException();
                    }
                    }
                    drawingPos = num;
                }
                length += item.Length;
            }
            return(length);
        }