예제 #1
0
        /// <summary>
        /// 根据当前编辑器的索引位置,计算索引向上移动的位置,并移动
        /// </summary>
        /// <param name="area"></param>
        /// <param name="content"></param>
        private void EditorSelectIndexUpMove(EditorEditArea area, EditorContent content)
        {
            bool isInUpLine = false;                            // 是否检测到了上一行
            int lineEnterIndex = -1;                            // 换行对象
            for (int i = area.SelectIndex; i > 0; i--)
            {
                EditorContent cnt = area.ContentList[i - 1];
                if (cnt.getText() == "\r" || i==1)
                {
                    if (!isInUpLine)
                    {
                        // 如果进入了上一行
                        lineEnterIndex = i;          // 获取上一行换行符对象的索引
                        isInUpLine = true;           // 如果检查到了换行符,就代表是上一行
                    }
                    else
                    {
                        // 如果上一行尺寸小于光标在当前行的宽度,就将光标移动到换行符前面
                        if (lineEnterIndex > 0)
                        {
                            area.SelectIndex = lineEnterIndex - 1;
                        }
                        break;
                    }

                    continue;
                }

                if (cnt.Rectangle.IsCross(area.Caret.Rectangle.Left, cnt.Rectangle.Top+cnt.Rectangle.Height, 1, 1))
                {
                    area.SelectIndex = i - 1;
                    break;
                }
            }
        }
예제 #2
0
        public bool Input(EditorEditArea area, int pos, EditorContent content)
        {
            if (content == null || content.getText() != ((char)40).ToString()) return false;

            this.EditorSelectIndexDownMove(area, content);        // 当按向下按钮时,编辑器的选择索引下移一行。

            return false;
        }
예제 #3
0
        public bool Input(EditorEditArea area, int pos, EditorContent content)
        {
            if (content == null || content.getText() != ((char)39).ToString()) return false;

            area.SelectIndex = Math.Min(area.ContentList.Count(), pos + 1);

            return false;
        }
예제 #4
0
        public bool Input(EditorEditArea area, int pos, EditorContent content)
        {
            if (content == null || content.getText() != ((char)37).ToString()) return false;

            area.SelectIndex = Math.Max(0,pos - 1);

            return false;
        }
예제 #5
0
        public bool Input(EditorEditArea area, int pos, EditorContent content)
        {
            if (content == null || content.GetType() != typeof(EditorImage)) return false;

            area.ContentList.Insert(area.SelectIndex, content);
            area.SelectIndex = pos + 1;

            return false;
        }
예제 #6
0
        public bool Input(EditorEditArea area, int pos, EditorContent content)
        {
            if (content.GetType() != typeof(EditorMouse)) return false;

            EditorMouse mouse = (EditorMouse)content;

            if (mouse.KeyType != EditorMouse.MouseKeyType.LeftDown && mouse.KeyType != EditorMouse.MouseKeyType.RightDown) return false;

            this.SetCaretPos(area, mouse.Rectangle.Left, mouse.Rectangle.Top);        // 设置光标位置

            return false;
        }
예제 #7
0
        public bool Input(EditorEditArea area,int pos, EditorContent content)
        {
            foreach(IContentHandle obj in this.GetAllObjectHandleList())
            {
                if(obj.Input(area, pos, content))
                {
                    break;
                }
            }

            return false;
        }
예제 #8
0
 /// <summary>
 /// 根据给定的x,y坐标设置光标位置
 /// </summary>
 /// <param name="area"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 private void SetCaretPos(EditorEditArea area, float x, float y)
 {
     int index = 0;
     foreach (EditorContent content in area.ContentList)
     {
         if (content.Rectangle.IsCross(x, y, 1, 1))
         {
             area.SelectIndex = index + 1;
             break;
         }
         index++;
     }
 }
예제 #9
0
        public bool Input(EditorEditArea area, int pos, EditorContent content)
        {
            if (content == null || content.GetType() != typeof(EditorChar)) return false;

            Regex regex = new Regex("[\u4e00-\u9fa5_a-zA-Z0-9_\r,.;:\"'`~!@#$%^&*(){}\\| ]{1}");
            if (!regex.IsMatch(content.getText())) return false;            // 如果不是数字英文中文等普通字符,则返回false

            area.ContentList.Insert(pos, content);

            area.SelectIndex = pos+1;

            return true;
        }
예제 #10
0
        /// <summary>
        /// 通过指定坐标转为编辑器中内容的索引值
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private int Pos2Index(EditorEditArea area, float x,float y)
        {
            int retIndex = -1;
            int index = -1;

            foreach(EditorContent content in area.ContentList)
            {
                index++;
                if (content.Rectangle.IsCross(x, y, 1, 1))
                {
                    retIndex = index;
                }
            }
            return retIndex;
        }
예제 #11
0
        public bool Input(EditorEditArea area, int pos, EditorContent content)
        {
            if (content.GetType() != typeof(EditorKey)) return false;           // 如果没当作按键,返回true,但不处理操作。
            if (pos <= 0) return false;                                         // 如果插入位置在0位,就不处理。
            if (content == null || content.getText() != "\b") return false;     // 如果不是退格键,返回false

            if ((area.SelectStart - area.SelectEnd) == 0){
                area.Remove(pos - 1, pos);
            }
            else
            {
                area.Remove(area.SelectStart, area.SelectEnd);
            }

            return false;
        }
예제 #12
0
        private int m_selectStartIndex = -1;            // 旋转开始的索引位置
            
        public bool Input(EditorEditArea area, int pos, EditorContent content)
        {
            if (content.GetType() != typeof(EditorMouse)) return false;

            EditorMouse mouse = (EditorMouse)content;
            switch (mouse.KeyType)
            {
                case EditorMouse.MouseKeyType.LeftDown:         // 鼠标左键按下
                    this.m_isMouseDown = true;
                    m_selectStartIndex = this.Pos2Index(area, content.Rectangle.Left, content.Rectangle.Top);
                    area.SelectStart = m_selectStartIndex;
                    area.SelectEnd = m_selectStartIndex;
                    break;
                case EditorMouse.MouseKeyType.LeftUp:           // 鼠标左键抬起
                    this.m_isMouseDown = false;
                    break;
                case EditorMouse.MouseKeyType.Move:             // 鼠标移动
                    if (!this.m_isMouseDown) break;             // 如果鼠标没点下,不执行已下代码

                    int endIndex = this.Pos2Index(area, content.Rectangle.Left, content.Rectangle.Top);

                    if (this.m_selectStartIndex < endIndex)
                    {
                        area.SelectStart = this.m_selectStartIndex;
                        area.SelectEnd = endIndex + 1;
                    }else if(this.m_selectStartIndex > endIndex)
                    {
                        area.SelectEnd = this.m_selectStartIndex + 1;
                        area.SelectStart = endIndex;
                    }else if (this.m_selectStartIndex == endIndex)
                    {
                        area.SelectStart = this.m_selectStartIndex;
                        area.SelectEnd = this.m_selectStartIndex;
                    }
                    
                    area.Caret.Hide();                           // 隐藏光标
#if DEBUG
                    Console.WriteLine(string.Format("select editor index:start={0}    end={1}", area.SelectStart, area.SelectEnd));
#endif
                    break;
            }

            return false;
        }
예제 #13
0
        /// <summary>
        /// 根据当前编辑器的索引位置,计算索引向下移动的位置,并移动
        /// </summary>
        /// <param name="area"></param>
        /// <param name="content"></param>
        private void EditorSelectIndexDownMove(EditorEditArea area, EditorContent content)
        {
            bool isInDownLine = false;                          // 是否检测到了下一行

            for (int i = area.SelectIndex; i < area.ContentList.Count(); i++)
            {
                EditorContent cnt = area.ContentList[i - 1];
                if (cnt.getText() == "\r")
                {
                    if (!isInDownLine)
                    {
                        // 如果进入了下一行
                        isInDownLine = true;                    // 如果检查到了换行符,就代表是上一行
                    }
                    else
                    {
                        // 如果上一行尺寸小于光标在当前行的宽度,就将光标移动到换行符前面
                        area.SelectIndex = i-1;
                        break;
                    }

                    continue;
                }

                if (!isInDownLine) continue;

                if (cnt.Rectangle.IsCross(area.Caret.Rectangle.Left, cnt.Rectangle.Top, 1, 1))
                {
                    area.SelectIndex = i-1;
                    break;
                }else if (i == area.ContentList.Count() - 1)
                {
                    area.SelectIndex = i + 1;
                }
            }
        }