Beispiel #1
0
 /// <summary>
 /// 删除选中的文本
 /// </summary>
 /// <returns></returns>
 public static bool DeleteSelectString()
 {
     if (StartPress.Index == EndPress.Index)
     {
         return(false);
     }
     if (EndPress.Index < StartPress.Index)
     {
         int c = StartPress.Index - EndPress.Index;
         Content.Remove(EndPress.Index, c);
         StartPress = EndPress;
     }
     else
     {
         int c = EndPress.Index - StartPress.Index;
         Content.Remove(StartPress.Index, c);
         EndPress = StartPress;
     }
     ChangeText(Target, Content);
     if (StartPress.Row < ShowStart)
     {
         ShowStart = StartPress.Row;
     }
     else if (StartPress.Row >= ShowStart + ShowRow)
     {
         ShowStart = StartPress.Row - ShowRow + 1;
     }
     return(true);
 }
Beispiel #2
0
        public static void PointerDown(UserEvent user, UserAction action, ref PressInfo press)
        {
            var offset = action.CanPosition;

            offset.x -= user.GlobalPosition.x;//全局坐标
            offset.y -= user.GlobalPosition.y;
            var q = Quaternion.Inverse(user.GlobalRotation);

            offset = q * offset;
            var scale = user.GlobalScale;//全局尺寸

            offset.x /= scale.x;
            offset.y /= scale.y;
            float oy = lines[0].topY - lines[ShowStart].topY;

            offset.y -= oy;
            offset.y += StartY;
            int row = ShowStart;
            int end = VisibleCount;

            if (lines.Count > 0)
            {
                for (int i = ShowStart; i < lines.Count; i++)
                {
                    if (offset.y > lines[i].topY)
                    {
                        end = lines[i].startCharIdx;
                        break;
                    }
                    else
                    {
                        row = i;
                    }
                }
            }
            int start = lines[row].startCharIdx;
            int col   = end - start;

            for (int i = start; i < end; i++)
            {
                if (offset.x < chars[i].cursorPos.x + chars[i].charWidth * 0.5f)
                {
                    col = i - start;
                    break;
                }
            }
            press.Row    = row;
            press.Offset = col;
            press.Index  = start + col;
        }
Beispiel #3
0
 /// <summary>
 /// 设置光标位置
 /// </summary>
 /// <param name="index">光标位置</param>
 /// <param name="LineChanged">是否改变的行号</param>
 /// <returns>是否改变成功</returns>
 public static bool SetPressIndex(int index, ref bool LineChanged)
 {
     if (SetPressIndex(index, ref StartPress))
     {
         EndPress = StartPress;
         if (StartPress.Row < ShowStart)
         {
             ShowStart   = StartPress.Row;
             LineChanged = true;
         }
         else
         if (StartPress.Row >= ShowStart + ShowRow)
         {
             ShowStart   = StartPress.Row - ShowRow + 1;
             LineChanged = true;
         }
         return(true);
     }
     return(false);
 }
Beispiel #4
0
 /// <summary>
 /// 设置光标位置
 /// </summary>
 /// <param name="index"></param>
 /// <param name="press"></param>
 /// <returns></returns>
 static bool SetPressIndex(int index, ref PressInfo press)
 {
     if (index < 0)
     {
         index = 0;
     }
     if (lines.Count == 0)
     {
         press.Index  = 0;
         press.Row    = 0;
         press.Offset = 0;
         return(false);
     }
     if (index == press.Index)
     {
         return(false);
     }
     if (index >= chars.Count)
     {
         index = chars.Count - 1;
         if (index == press.Index)
         {
             return(false);
         }
         press.Index  = index;
         press.Row    = lines.Count - 1;
         press.Offset = index - lines[press.Row].startCharIdx;
         return(true);
     }
     for (int i = 0; i < lines.Count; i++)
     {
         if (index <= lines[i].endIdx)
         {
             press.Index  = index;
             press.Row    = i;
             press.Offset = index - lines[i].startCharIdx;
             break;
         }
     }
     return(true);
 }
Beispiel #5
0
 /// <summary>
 /// 光标向右移动
 /// </summary>
 /// <param name="LineChanged">是否改变了行号</param>
 /// <returns>是否移动成功</returns>
 public static bool PointerMoveRight(ref bool LineChanged)
 {
     if (StartPress.Index < chars.Count - 1)
     {
         StartPress.Index++;
         int r = StartPress.Row;
         if (StartPress.Index > lines[r].endIdx)
         {
             StartPress.Row++;
         }
         StartPress.Offset = StartPress.Index - lines[StartPress.Row].startCharIdx;
         EndPress          = StartPress;
         if (StartPress.Row >= ShowStart + ShowRow)
         {
             ShowStart   = StartPress.Row - ShowRow + 1;
             LineChanged = true;
         }
         return(true);
     }
     return(false);
 }
Beispiel #6
0
 /// <summary>
 /// 光标向左移动
 /// </summary>
 /// <param name="LineChanged">是否改变了行号</param>
 /// <returns>是否移动成功</returns>
 public static bool PointerMoveLeft(ref bool LineChanged)
 {
     if (StartPress.Index > 0)
     {
         StartPress.Index--;
         int r = StartPress.Row;
         if (StartPress.Index < lines[r].startCharIdx)
         {
             StartPress.Row--;
         }
         StartPress.Offset = StartPress.Index - lines[StartPress.Row].startCharIdx;
         EndPress          = StartPress;
         if (StartPress.Row < ShowStart)
         {
             ShowStart   = StartPress.Row;
             LineChanged = true;
         }
         return(true);
     }
     return(false);
 }
Beispiel #7
0
        public static void ChangeText(HText text, EmojiString str)
        {
            verts.Clear();
            lines.Clear();
            chars.Clear();
            Target  = text;
            Content = str;
            text.GetGenerationSettings(ref text.m_sizeDelta, ref HText.settings);
            HText.settings.richText = false;
            var    g  = HText.Generator;
            string fs = Content.FilterString;

            if (contentType == ContentType.Password)
            {
                ContentHeight = g.GetPreferredHeight(new string('●', fs.Length), HText.settings);
            }
            else
            {
                ContentHeight = g.GetPreferredHeight(fs, HText.settings);
            }
            VisibleCount = g.characterCountVisible;
            if (g.lines.Count > 0)
            {
                float per = ContentHeight / g.lines.Count;
                ShowRow = (int)(text.m_sizeDelta.y / per);
            }
            else
            {
                ShowRow = (int)text.m_sizeDelta.y / text.FontSize;
            }
            StartY = ContentHeight * 0.5f - text.m_sizeDelta.y * 0.5f;
            verts.AddRange(g.verts);
            chars.AddRange(g.characters);
            LineInfo line = new LineInfo();

            if (g.lines.Count > 0)
            {
                var l = g.lines[0];
                for (int i = 1; i < g.lines.Count; i++)
                {
                    var n = g.lines[i];
                    line.startCharIdx = l.startCharIdx;
                    line.endIdx       = n.startCharIdx - 1;
                    line.topY         = l.topY;
                    line.endY         = n.topY;
                    l = n;
                    lines.Add(line);
                }
                l = g.lines[g.lines.Count - 1];
                line.startCharIdx = l.startCharIdx;
                line.endIdx       = chars.Count - 1;
                line.topY         = l.topY;
                line.endY         = g.lines[0].topY - ContentHeight - g.lines[g.lines.Count - 1].leading;
                lines.Add(line);
            }
            if (StartPress.Index > fs.Length)
            {
                SetPressIndex(fs.Length, ref StartPress);
                EndPress = StartPress;
            }
            SetShowStart(ShowStart);
        }
Beispiel #8
0
 public static void SetStartPointer(UserEvent user, UserAction action)
 {
     PointerDown(user, action, ref StartPress);
     EndPress = StartPress;
 }