コード例 #1
0
ファイル: UITextEdit.cs プロジェクト: kevinmel2000/FreeSO
        /// <summary>
        /// Creates a list of segments to split the line into
        /// in order to draw selection boxes
        /// </summary>
        /// <returns></returns>
        protected List <UITextEditLineSegment> CalculateSegments(UITextEditLine line)
        {
            var result = new List <UITextEditLineSegment>();

            if (SelectionEnd != -1)
            {
                /** There is a selection **/
                var start = SelectionStart == -1 ? m_SBuilder.Length : SelectionStart;
                var end   = SelectionEnd == -1 ? m_SBuilder.Length : SelectionEnd;
                if (end < start)
                {
                    var temp = start;
                    start = end;
                    end   = temp;
                }

                var lineStart = line.StartIndex;
                var lineEnd   = lineStart + line.Text.Length;

                /**
                 * Options:
                 *  This line has no selection,
                 *  Selection starts on this line
                 *  Selection ends on this line
                 *  The whole line is selected
                 */

                if (start >= lineStart && start < lineEnd)
                {
                    /** Selection starts on this line, we need a prefix **/
                    var prefixEnd = start - lineStart;
                    if (prefixEnd != 0)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text     = line.Text.Substring(0, prefixEnd)
                        });
                    }

                    /** Up until the end **/
                    var selectionEnd = line.Text.Length;
                    if (end + 1 < lineEnd)
                    {
                        selectionEnd -= (lineEnd - end);
                    }

                    result.Add(new UITextEditLineSegment
                    {
                        Selected = true,
                        Text     = line.Text.Substring(prefixEnd, selectionEnd - prefixEnd)
                    });

                    /** Suffix? **/
                    if (end + 1 < lineEnd)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text     = line.Text.Substring(selectionEnd)
                        });
                    }
                }
                else if (start < lineStart && end >= lineStart && end <= lineEnd)
                {
                    /** Selection ends on this line **/
                    /** Up until the end **/
                    var selectionEnd = line.Text.Length;
                    if (end + 1 < lineEnd)
                    {
                        selectionEnd -= (lineEnd - end);
                    }

                    result.Add(new UITextEditLineSegment
                    {
                        Selected = true,
                        Text     = line.Text.Substring(0, selectionEnd)
                    });

                    /** Suffix? **/
                    if (end + 1 < lineEnd)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text     = line.Text.Substring(selectionEnd)
                        });
                    }
                }
                else if (start < lineStart && end > lineEnd)
                {
                    /** The whole line is selected **/
                    result.Add(new UITextEditLineSegment
                    {
                        Text     = line.Text,
                        Selected = true
                    });
                }
                else
                {
                    result.Add(new UITextEditLineSegment
                    {
                        Text     = line.Text,
                        Selected = false
                    });
                }
            }
            else
            {
                result.Add(new UITextEditLineSegment
                {
                    Text     = line.Text,
                    Selected = false
                });
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Creates a list of segments to split the line into
        /// in order to draw selection boxes
        /// </summary>
        /// <returns></returns>
        protected List <UITextEditLineSegment> CalculateSegments(UITextEditLine line, List <BBCodeCommand> bbcmds, ref int bbind)
        {
            var result = new List <UITextEditLineSegment>();

            var points = new List <Tuple <int, BBCodeCommand> >();

            var hasSelection = (SelectionEnd != -1);
            var start        = SelectionStart == -1 ? m_SBuilder.Length : SelectionStart;
            var end          = SelectionEnd == -1 ? m_SBuilder.Length : SelectionEnd;

            if (start > end)
            {
                var temp = start;
                start = end;
                end   = temp;
            }
            var lineStart = line.StartIndex;
            var lineEnd   = lineStart + line.Text.Length;

            var selected = hasSelection && (start < lineStart && end >= lineStart);
            var lastMod  = 0;

            while (true)
            {
                //check for selection first
                var nextBB = (bbind == bbcmds.Count) ? lineEnd : bbcmds[bbind].Index;
                if (hasSelection)
                {
                    if (!selected)
                    {
                        //look for selection start. is it before our next bbcommand?
                        if (start >= lastMod + lineStart && start <= nextBB)
                        {
                            selected = true;
                            if (start != nextBB || nextBB == lineEnd)
                            {
                                //
                                result.Add(new UITextEditLineSegment
                                {
                                    Selected = false, //prefix before we select the text
                                    Text     = line.Text.Substring(lastMod, (start - lineStart) - lastMod),
                                });
                            }
                            lastMod = start - lineStart;
                        }
                    }
                    if (selected)
                    {
                        //look for selection end. is it before our next bbcommand?
                        var selE = end - lineStart;
                        if (end >= lastMod + lineStart && end <= nextBB)
                        {
                            selected = false;
                            if (end != nextBB || nextBB == lineEnd)
                            {
                                result.Add(new UITextEditLineSegment
                                {
                                    Selected = true, //the remainder of the selected string
                                    Text     = line.Text.Substring(lastMod, (end - lineStart) - lastMod),
                                });
                            }
                            lastMod = end - lineStart;
                        }
                    }
                }

                if (nextBB < lineEnd)
                {
                    //this bbcmd happens on this line (or before we even drew anything (scroll))
                    //
                    if (bbcmds[bbind].Index - lineStart < 0)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected     = selected,
                            Text         = "",
                            BBCatchup    = true,
                            StartCommand = bbcmds[bbind++]
                        });
                    }
                    else
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected     = selected,
                            Text         = line.Text.Substring(lastMod, (bbcmds[bbind].Index - lineStart) - lastMod),
                            StartCommand = bbcmds[bbind++]
                        });
                        lastMod = (bbcmds[bbind - 1].Index - lineStart);
                    }
                }
                else
                {
                    //remainder of the line
                    result.Add(new UITextEditLineSegment
                    {
                        Selected = selected,
                        Text     = line.Text.Substring(lastMod, (lineEnd - lineStart) - lastMod),
                    });
                    break;
                }
            }
            return(result);
        }
コード例 #3
0
ファイル: UITextEdit.cs プロジェクト: RHY3756547/FreeSO
        /// <summary>
        /// Creates a list of segments to split the line into
        /// in order to draw selection boxes
        /// </summary>
        /// <returns></returns>
        protected List<UITextEditLineSegment> CalculateSegments(UITextEditLine line)
        {
            var result = new List<UITextEditLineSegment>();

            if (SelectionEnd != -1)
            {
                /** There is a selection **/
                var start = SelectionStart == -1 ? m_SBuilder.Length : SelectionStart;
                var end = SelectionEnd == -1 ? m_SBuilder.Length : SelectionEnd;
                if (end < start)
                {
                    var temp = start;
                    start = end;
                    end = temp;
                }

                var lineStart = line.StartIndex;
                var lineEnd = lineStart + line.Text.Length;

                /**
                 * Options:
                 *  This line has no selection,
                 *  Selection starts on this line
                 *  Selection ends on this line
                 *  The whole line is selected
                 */

                if (start >= lineStart && start < lineEnd)
                {
                    /** Selection starts on this line, we need a prefix **/
                    var prefixEnd = start - lineStart;
                    if (prefixEnd != 0)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text = line.Text.Substring(0, prefixEnd)
                        });
                    }

                    /** Up until the end **/
                    var selectionEnd = line.Text.Length;
                    if (end + 1 < lineEnd)
                    {
                        selectionEnd -= (lineEnd - end);
                    }

                    result.Add(new UITextEditLineSegment
                    {
                        Selected = true,
                        Text = line.Text.Substring(prefixEnd, selectionEnd - prefixEnd)
                    });

                    /** Suffix? **/
                    if (end + 1 < lineEnd)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text = line.Text.Substring(selectionEnd)
                        });
                    }
                }
                else if (start < lineStart && end >= lineStart && end <= lineEnd)
                {
                    /** Selection ends on this line **/
                    /** Up until the end **/
                    var selectionEnd = line.Text.Length;
                    if (end + 1 < lineEnd)
                    {
                        selectionEnd -= (lineEnd - end);
                    }

                    result.Add(new UITextEditLineSegment
                    {
                        Selected = true,
                        Text = line.Text.Substring(0, selectionEnd)
                    });

                    /** Suffix? **/
                    if (end + 1 < lineEnd)
                    {
                        result.Add(new UITextEditLineSegment
                        {
                            Selected = false,
                            Text = line.Text.Substring(selectionEnd)
                        });
                    }
                }
                else if (start < lineStart && end > lineEnd)
                {
                    /** The whole line is selected **/
                    result.Add(new UITextEditLineSegment
                    {
                        Text = line.Text,
                        Selected = true
                    });
                }
                else
                {
                    result.Add(new UITextEditLineSegment
                    {
                        Text = line.Text,
                        Selected = false
                    });
                }
            }
            else
            {
                result.Add(new UITextEditLineSegment
                {
                    Text = line.Text,
                    Selected = false
                });
            }
            return result;
        }