void SetIndex(ref PressInfo press, int index)
 {
     if (index <= 0)
     {
         press.Row    = 0;
         press.Offset = 0;
     }
     else if (index > cha.Length)
     {
         press.Row    = lines.Length - 1;
         press.Offset = lines[StartPress.Row].Count;
     }
     else
     {
         int c = lines.Length - 1;
         for (int i = c; i >= 0; i--)
         {
             if (lines[i].StartIndex < index)
             {
                 press.Row    = i;
                 press.Offset = index - lines[i].StartIndex;
                 return;
             }
         }
         press.Row    = 0;
         press.Offset = index;
     }
 }
Beispiel #2
0
        public override void OnMouseDown(UserAction action)
        {
            base.OnMouseDown(action);
            PressInfo press = new PressInfo();

            CheckPointer(action, ref press);
            input.OnMouseDown(action, ref press);
        }
Beispiel #3
0
        /// <summary>
        /// 设置输入法显示位置,win平台
        /// </summary>
        /// <param name="start">光标按压位置</param>
        public void SetCursorPos(ref PressInfo start)
        {
            if (start.Row < 0)
            {
                return;
            }
            if (start.Row >= lines.Count)
            {
                return;
            }
            int index = start.Index;

            if (index < 0)
            {
                return;
            }
            if (index >= chars.Count)
            {
                return;
            }
            int row = start.Row;

            for (int i = 0; i < lines.Count; i++)
            {
                if (index <= lines[i].endIdx)
                {
                    row = i;
                    break;
                }
            }
            float p;

            if (index > lines[row].endIdx)
            {
                index--;
                if (index < 0)
                {
                    index = 0;
                }
                p = chars[index].cursorPos.x + chars[index].charWidth;
            }
            else
            {
                p = chars[index].cursorPos.x;
            }
            float right = p + 1;
            float down  = lines[row].endY - text.m_fontSize * 0.55f;
            var   gl    = UIElement.GetGlobaInfo(text.transform, false);
            float rx    = gl.Scale.x * right;
            float rd    = gl.Scale.y * down;

            gl.Postion.x      += rx;
            gl.Postion.y      += rd;
            gl.Postion        *= HCanvas.MainCanvas.PhysicalScale;
            gl.Postion.x      += Screen.width / 2;
            gl.Postion.y      += Screen.height / 2;
            Keyboard.CursorPos = new Vector2(gl.Postion.x, Screen.height - gl.Postion.y);
        }
Beispiel #4
0
 protected override void OnDrag(UserAction action)
 {
     if (Pressed)
     {
         if (action.CanPosition != action.LastPosition)
         {
             if (!entry)
             {
                 float oy = action.CanPosition.y - GlobalPosition.y;
                 float py = GlobalScale.y * text.SizeDelta.y * 0.5f;
                 if (oy > 0)
                 {
                     oy -= py;
                 }
                 else
                 {
                     oy += py;
                 }
                 if (oy > overDistance)
                 {
                     oy = overDistance;
                 }
                 float per = 5000 / oy;
                 if (per < 0)
                 {
                     per = -per;
                 }
                 overTime += UserAction.TimeSlice;
                 if (overTime >= per)
                 {
                     overTime -= per;
                     if (oy > 0)
                     {
                         if (TextOperation.ContentMoveUp())
                         {
                             input.SetShowText();
                         }
                     }
                     else
                     {
                         if (TextOperation.ContentMoveDown())
                         {
                             input.SetShowText();
                         }
                     }
                 }
             }
             PressInfo press = new PressInfo();
             CheckPointer(action, ref press);
             input.OnDrag(action, ref press);
         }
     }
     base.OnDrag(action);
 }
 public override void OnMouseDown(UserAction action)
 {
     Focus = true;
     if (TextCom != null)
     {
         EndPress = StartPress = GetPressIndex(action, Vector2.zero);
         InputCaret.SetParent(TextCom.transform);
         InputCaret.Active();
         ShowChanged = true;
     }
     base.OnMouseDown(action);
 }
Beispiel #6
0
 /// <summary>
 /// 检测当前光标按在哪两个字符中间了
 /// </summary>
 /// <param name="action"></param>
 /// <param name="press"></param>
 public void CheckPointer(UserAction action, ref PressInfo press)
 {
     if (lines.Count > 0)
     {
         var offset = action.CanPosition;
         offset.x -= GlobalPosition.x;//全局坐标
         offset.y -= GlobalPosition.y;
         var q = Quaternion.Inverse(GlobalRotation);
         offset = q * offset;
         var scale = GlobalScale;//全局尺寸
         offset.x /= scale.x;
         offset.y /= scale.y;
         int end = Content.FilterString.Length;
         int row = 0;
         if (lines.Count > 0)
         {
             for (int i = 0; i < lines.Count; i++)
             {
                 if (offset.y > lines[i].topY)
                 {
                     end = lines[i].startCharIdx;
                     break;
                 }
                 else
                 {
                     row = i;
                 }
             }
         }
         if (end > chars.Count)
         {
             end = chars.Count;
         }
         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;
     }
 }
        protected PressInfo GetPressIndex(UserAction action, Vector2 dir)
        {
            PressInfo info = new PressInfo();

            if (TextCom == null)
            {
                return(info);
            }
            Vector3 pos    = GlobalPosition;//全局坐标
            var     offset = pos;

            offset.x -= action.CanPosition.x;
            offset.y -= action.CanPosition.y;
            var q = Quaternion.Inverse(GlobalRotation);

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

            offset.x /= scale.x;
            offset.y /= scale.y;
            float ox = -offset.x;
            float oy = -offset.y - TextCom.SizeDelta.y * 0.5f;

            oy += lines[ShowStart].top;
            int r = GetPressLine(oy, dir.y);

            info.Row = r;
            int os = GetPressOffset(r, ox, dir.x);

            info.Offset = os;
            if (os >= lines[r].Count)
            {
                os--;
            }
            return(info);
        }
Beispiel #8
0
        /// <summary>
        /// 获取选中区域的网格
        /// </summary>
        /// <param name="tri">三角形列表</param>
        /// <param name="vert">顶点列表</param>
        /// <param name="color">填充颜色</param>
        /// <param name="start">开始按压位置信息</param>
        /// <param name="end">结束按压位置信息</param>
        public void GetSelectArea(List <int> tri, List <HVertex> vert, ref Color32 color, ref PressInfo start, ref PressInfo end)
        {
            int sr = start.Row;
            int er = end.Row + 1;
            int st = 0;
            int c  = lines.Count;

            if (c > er)
            {
                c = er;
            }
            if (sr < 0)
            {
                sr = 0;
            }
            for (int i = sr; i < c; i++)
            {
                LineInfo info = lines[i];
                int      ls   = info.startCharIdx;
                if (ls > end.Index)
                {
                    break;
                }
                int le = lines[i].endIdx;
                if (le <= start.Index)
                {
                    continue;
                }
                int   si = start.Index;
                int   ei = end.Index;
                float left;
                if (si < ls)
                {
                    left = chars[ls].cursorPos.x;
                }
                else
                {
                    left = chars[si].cursorPos.x;
                }
                float right;
                if (ei > le)
                {
                    right = chars[le].cursorPos.x + chars[le].charWidth;
                }
                else
                {
                    right = chars[ei].cursorPos.x;
                }
                float top  = info.topY;
                float down = info.endY;

                var v = new HVertex();
                v.position.x = left;
                v.position.y = down;
                v.color      = color;
                vert.Add(v);
                v.position.x = right;
                v.position.y = down;
                v.color      = color;
                vert.Add(v);
                v.position.x = left;
                v.position.y = top;
                v.color      = color;
                vert.Add(v);
                v.position.x = right;
                v.position.y = top;
                v.color      = color;
                vert.Add(v);
                tri.Add(st);
                tri.Add(st + 2);
                tri.Add(st + 3);
                tri.Add(st);
                tri.Add(st + 3);
                tri.Add(st + 1);
                st += 4;
            }
        }
Beispiel #9
0
        /// <summary>
        /// 获取光标的显示网格
        /// </summary>
        /// <param name="tri">三角形列表</param>
        /// <param name="vert">顶点列表</param>
        /// <param name="color">填充颜色</param>
        /// <param name="start">按压信息</param>
        public void GetPointer(List <int> tri, List <HVertex> vert, ref Color32 color, ref PressInfo start)
        {
            if (start.Row < 0)
            {
                return;
            }
            if (start.Row >= lines.Count)
            {
                return;
            }
            int index = start.Index;

            if (index < 0)
            {
                return;
            }
            if (index >= chars.Count)
            {
                return;
            }
            int row = start.Row;

            for (int i = 0; i < lines.Count; i++)
            {
                if (index <= lines[i].endIdx)
                {
                    row = i;
                    break;
                }
            }
            float top  = lines[row].topY;
            float down = lines[row].endY;
            float p;

            if (index > lines[row].endIdx)
            {
                index--;
                if (index < 0)
                {
                    index = 0;
                }
                p = chars[index].cursorPos.x + chars[index].charWidth;
            }
            else
            {
                p = chars[index].cursorPos.x;
            }
            float left  = p - 1;
            float right = p + 1;
            var   v     = new HVertex();

            v.position.x = left;
            v.position.y = down;
            v.color      = color;
            vert.Add(v);
            v.position.x = right;
            v.position.y = down;
            v.color      = color;
            vert.Add(v);
            v.position.x = left;
            v.position.y = top;
            v.color      = color;
            vert.Add(v);
            v.position.x = right;
            v.position.y = top;
            v.color      = color;
            vert.Add(v);
            tri.Add(0);
            tri.Add(2);
            tri.Add(3);
            tri.Add(0);
            tri.Add(3);
            tri.Add(1);
        }
 protected override void OnDrag(UserAction action)
 {
     if (Pressed)
     {
         if (TextCom != null)
         {
             Style = 2;
             if (action.Motion != Vector2.zero)
             {
                 var p = GetPressIndex(action, action.CanPosition - RawPosition);
                 if (p.Offset != EndPress.Offset | p.Row != EndPress.Row)
                 {
                     ShowChanged = true;
                 }
                 EndPress = p;
             }
             else if (!entry)
             {
                 float oy = action.CanPosition.y - GlobalPosition.y;
                 float py = GlobalScale.y * TextCom.SizeDelta.y * 0.5f;
                 if (oy > 0)
                 {
                     oy -= py;
                 }
                 else
                 {
                     oy += py;
                 }
                 if (oy > overDistance)
                 {
                     oy = overDistance;
                 }
                 float per = 5000 / oy;
                 if (per < 0)
                 {
                     per = -per;
                 }
                 overTime += UserAction.TimeSlice;
                 if (overTime >= per)
                 {
                     overTime -= per;
                     if (oy > 0)
                     {
                         MoveUp();
                     }
                     else
                     {
                         MoveDown();
                     }
                     var p = GetPressIndex(action, action.CanPosition - RawPosition);
                     if (p.Offset != EndPress.Offset | p.Row != EndPress.Row)
                     {
                         ShowChanged = true;
                     }
                     EndPress = p;
                 }
             }
         }
     }
     base.OnDrag(action);
 }