Ejemplo n.º 1
0
        void __touchBegin(EventContext context)
        {
            if (_lines.Count == 0)
            {
                return;
            }

            ClearSelection();

            CharPosition cp;

            if (_textChanged) //maybe the text changed in user's touchBegin
            {
                cp.charIndex = 0;
                cp.lineIndex = 0;
            }
            else
            {
                Vector3 v = Stage.touchPosition;
                v    = this.GlobalToLocal(v);
                v.x += this.pivotX;
                v.y += this.pivotY;
                cp   = GetCharPosition(v);
            }

            //AdjustCaret(cp);
            _selectionStart = cp;
            //Stage.inst.onTouchMove.AddCapture(__touchMove);
            gOwner.appContext.stage.onTouchMove.AddCapture(__touchMove);
            //Stage.inst.onTouchEnd.AddCapture(__touchEnd);
            gOwner.appContext.stage.onTouchEnd.AddCapture(__touchEnd);
        }
Ejemplo n.º 2
0
 void ClearSelection()
 {
     if (_selectionStart != null)
     {
         //if (_highlighter != null)
         //    _highlighter.Clear();
         _selectionStart = null;
     }
 }
Ejemplo n.º 3
0
 void __touchEnd(EventContext context)
 {
     if (_selectionStart != null && ((CharPosition)_selectionStart).charIndex == _caretPosition)
     {
         _selectionStart = null;
     }
     //Stage.inst.onTouchMove.RemoveCapture(__touchMove);
     gOwner.appContext.stage.onTouchMove.RemoveCapture(__touchMove);
     gOwner.appContext.stage.onTouchEnd.RemoveCapture(__touchEnd);
 }
Ejemplo n.º 4
0
 void ClearSelection()
 {
     if (_selectionStart != null)
     {
         if (_selectionShape != null)
         {
             _selectionShape.Clear();
         }
         _selectionStart = null;
     }
 }
Ejemplo n.º 5
0
        void __focusIn(EventContext context)
        {
            if (!editable || !Application.isPlaying)
            {
                return;
            }

            if (Stage.keyboardInput)
            {
                Stage.inst.OpenKeyboard(textField.text, false, _displayAsPassword ? false : !textField.singleLine,
                                        _displayAsPassword, false, null, keyboardType);
            }
            else
            {
                Input.imeCompositionMode = IMECompositionMode.On;
                _editing = true;

                if (_caret == null)
                {
                    CreateCaret();
                }

                if (!string.IsNullOrEmpty(_promptText))
                {
                    UpdateAlternativeText();
                }

                float caretSize;
                //如果界面缩小过,光标很容易看不见,这里放大一下
                if (UIConfig.inputCaretSize == 1 && GRoot.contentScaleFactor < 1)
                {
                    caretSize = (float)UIConfig.inputCaretSize / GRoot.contentScaleFactor;
                }
                else
                {
                    caretSize = UIConfig.inputCaretSize;
                }
                _caret.SetSize(caretSize, textField.textFormat.size);
                _caret.DrawRect(0, Color.clear, textField.textFormat.color);
                AddChild(_caret);

                _selectionShape.Clear();
                AddChild(_selectionShape);

                _caretPosition = textField.text.Length;
                CharPosition cp = GetCharPosition(_caretPosition);
                AdjustCaret(cp);
                _selectionStart = cp;
            }
        }
Ejemplo n.º 6
0
        void __touchEnd(EventContext context)
        {
            Stage.inst.onTouchMove.RemoveCapture(_touchMoveDelegate);

            if (isDisposed)
            {
                return;
            }

            if (_selectionStart != null && ((CharPosition)_selectionStart).charIndex == _caretPosition)
            {
                _selectionStart = null;
            }
        }
Ejemplo n.º 7
0
        void __touchBegin(EventContext context)
        {
            if (!_editing || textField.lines.Count == 0)
            {
                return;
            }

            ClearSelection();

            Vector3 v = Stage.inst.touchPosition;

            v = this.GlobalToLocal(v);
            CharPosition cp = GetCharPosition(v);

            AdjustCaret(cp);
            _selectionStart = cp;

            context.CaptureTouch();
            Stage.inst.onTouchMove.AddCapture(_touchMoveDelegate);
        }
Ejemplo n.º 8
0
		void __keydown(EventContext context)
		{
			if (_caret == null || context.isDefaultPrevented)
				return;

			InputEvent evt = context.inputEvent;

			switch (evt.keyCode)
			{
				case KeyCode.Backspace:
					{
						context.PreventDefault();
						if (_selectionStart != null)
						{
							DeleteSelection();
							OnChanged();
						}
						else if (_caretPosition > 0)
						{
							int tmp = _caretPosition; //this.text 会修改_caretPosition
							_caretPosition--;
							this.text = _text.Substring(0, tmp - 1) + _text.Substring(tmp);
							OnChanged();
						}

						break;
					}

				case KeyCode.Delete:
					{
						context.PreventDefault();
						if (_selectionStart != null)
						{
							DeleteSelection();
							OnChanged();
						}
						else if (_caretPosition < _text.Length)
						{
							this.text = _text.Substring(0, _caretPosition) + _text.Substring(_caretPosition + 1);
							OnChanged();
						}

						break;
					}

				case KeyCode.LeftArrow:
					{
						context.PreventDefault();
						if (evt.shift)
						{
							if (_selectionStart == null)
								_selectionStart = GetCharPosition(_caretPosition);
						}
						else
							ClearSelection();
						if (_caretPosition > 0)
						{
							CharPosition cp = GetCharPosition(_caretPosition - 1);

							AdjustCaret(cp);
						}
						break;
					}

				case KeyCode.RightArrow:
					{
						context.PreventDefault();
						if (evt.shift)
						{
							if (_selectionStart == null)
								_selectionStart = GetCharPosition(_caretPosition);
						}
						else
							ClearSelection();
						if (_caretPosition < _text.Length)
						{
							CharPosition cp = GetCharPosition(_caretPosition + 1);
							AdjustCaret(cp);
						}
						break;
					}

				case KeyCode.UpArrow:
					{
						context.PreventDefault();
						if (evt.shift)
						{
							if (_selectionStart == null)
								_selectionStart = GetCharPosition(_caretPosition);
						}
						else
							ClearSelection();

						CharPosition cp = GetCharPosition(_caretPosition);
						if (cp.lineIndex == 0)
							return;

						LineInfo line = _lines[cp.lineIndex - 1];
						cp = GetCharPosition(new Vector3(_caret.cachedTransform.localPosition.x + _GetPositionOffset().x, line.y, 0));
						AdjustCaret(cp);
						break;
					}


				case KeyCode.DownArrow:
					{
						context.PreventDefault();
						if (evt.shift)
						{
							if (_selectionStart == null)
								_selectionStart = GetCharPosition(_caretPosition);
						}
						else
							ClearSelection();

						CharPosition cp = GetCharPosition(_caretPosition);
						if (cp.lineIndex == _lines.Count - 1)
							return;

						LineInfo line = _lines[cp.lineIndex + 1];
						cp = GetCharPosition(new Vector3(_caret.cachedTransform.localPosition.x + _GetPositionOffset().x, line.y, 0));
						AdjustCaret(cp);
						break;
					}

				case KeyCode.PageUp:
					{
						context.PreventDefault();
						ClearSelection();

						break;
					}

				case KeyCode.PageDown:
					{
						context.PreventDefault();
						ClearSelection();

						break;
					}

				case KeyCode.Home:
					{
						context.PreventDefault();
						ClearSelection();

						CharPosition cp = GetCharPosition(_caretPosition);
						LineInfo line = _lines[cp.lineIndex];
						cp = GetCharPosition(new Vector3(int.MinValue, line.y, 0));
						AdjustCaret(cp);
						break;
					}

				case KeyCode.End:
					{
						context.PreventDefault();
						ClearSelection();

						CharPosition cp = GetCharPosition(_caretPosition);
						LineInfo line = _lines[cp.lineIndex];
						cp = GetCharPosition(new Vector3(int.MaxValue, line.y, 0));
						AdjustCaret(cp);

						break;
					}

				//Select All
				case KeyCode.A:
					{
						if (evt.ctrl)
						{
							context.PreventDefault();
							_selectionStart = GetCharPosition(0);
							AdjustCaret(GetCharPosition(_text.Length));
						}
						break;
					}

				// Copy
				case KeyCode.C:
					{
						if (evt.ctrl && !_displayAsPassword)
						{
							context.PreventDefault();
							string s = GetSelection();
							if (!string.IsNullOrEmpty(s))
								Stage.inst.onCopy.Call(s);
						}
						break;
					}

				// Paste
				case KeyCode.V:
					{
						if (evt.ctrl)
						{
							context.PreventDefault();
							Stage.inst.onPaste.Call(this);
						}
						break;
					}

				// Cut
				case KeyCode.X:
					{
						if (evt.ctrl && !_displayAsPassword)
						{
							context.PreventDefault();
							string s = GetSelection();
							if (!string.IsNullOrEmpty(s))
							{
								Stage.inst.onCopy.Call(s);
								DeleteSelection();
								OnChanged();
							}
						}
						break;
					}

				case KeyCode.Return:
				case KeyCode.KeypadEnter:
					{
						if (!evt.ctrl && !evt.shift)
						{
							context.PreventDefault();

							if (!_singleLine)
							{
								InsertText("\n");
								OnChanged();
							}
						}
						break;
					}
			}
		}
Ejemplo n.º 9
0
		void __focusIn(EventContext context)
		{
			if (_mobileInputAdapter != null)
			{
				OpenKeyboard();
			}
			else
			{
				_caret = Stage.inst.inputCaret;
				_caret.grahpics.sortingOrder = this.renderingOrder + 1;
				_caret.SetParent(cachedTransform);
				_caret.SetSizeAndColor(_textFormat.size, _textFormat.color);

				_highlighter = Stage.inst.highlighter;
				_highlighter.grahpics.sortingOrder = this.renderingOrder + 2;
				_highlighter.SetParent(cachedTransform);

				_caretPosition = _text.Length;
				CharPosition cp = GetCharPosition(_caretPosition);
				AdjustCaret(cp);
				_selectionStart = cp;
			}
		}
Ejemplo n.º 10
0
		void ClearSelection()
		{
			if (_selectionStart != null)
			{
				if (_highlighter != null)
					_highlighter.Clear();
				_selectionStart = null;
			}
		}
Ejemplo n.º 11
0
		void __touchEnd(EventContext context)
		{
			if (_selectionStart != null && ((CharPosition)_selectionStart).charIndex == _caretPosition)
				_selectionStart = null;
			Stage.inst.onTouchMove.RemoveCapture(__touchMove);
			Stage.inst.onTouchEnd.RemoveCapture(__touchEnd);
		}
Ejemplo n.º 12
0
        void __keydown(EventContext context)
        {
            if (!_editing || context.isDefaultPrevented)
            {
                return;
            }

            InputEvent evt = context.inputEvent;

            switch (evt.keyCode)
            {
            case KeyCode.Backspace:
            {
                context.PreventDefault();
                if (_selectionStart != null)
                {
                    ReplaceSelection(null);
                }
                else if (_caretPosition > 0)
                {
                    int tmp = _caretPosition;
                    _caretPosition--;
                    ReplaceText(textField.text.Substring(0, tmp - 1) + textField.text.Substring(tmp));
                }

                break;
            }

            case KeyCode.Delete:
            {
                context.PreventDefault();
                if (_selectionStart != null)
                {
                    ReplaceSelection(null);
                }
                else if (_caretPosition < textField.text.Length)
                {
                    ReplaceText(textField.text.Substring(0, _caretPosition) + textField.text.Substring(_caretPosition + 1));
                }

                break;
            }

            case KeyCode.LeftArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }
                if (_caretPosition > 0)
                {
                    CharPosition cp = GetCharPosition(_caretPosition - 1);
                    AdjustCaret(cp);
                }
                break;
            }

            case KeyCode.RightArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }
                if (_caretPosition < textField.text.Length)
                {
                    CharPosition cp = GetCharPosition(_caretPosition + 1);
                    AdjustCaret(cp);
                }
                break;
            }

            case KeyCode.UpArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }

                CharPosition cp = GetCharPosition(_caretPosition);
                if (cp.lineIndex == 0)
                {
                    return;
                }

                TextField.LineInfo line = textField.lines[cp.lineIndex - 1];
                cp = GetCharPosition(new Vector2(_caret.x, line.y + textField.y));
                AdjustCaret(cp);
                break;
            }

            case KeyCode.DownArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }

                CharPosition cp = GetCharPosition(_caretPosition);
                if (cp.lineIndex == textField.lines.Count - 1)
                {
                    cp.charIndex = textField.charPositions.Count - 1;
                }
                else
                {
                    TextField.LineInfo line = textField.lines[cp.lineIndex + 1];
                    cp = GetCharPosition(new Vector2(_caret.x, line.y + textField.y));
                }
                AdjustCaret(cp);
                break;
            }

            case KeyCode.PageUp:
            {
                context.PreventDefault();
                ClearSelection();

                break;
            }

            case KeyCode.PageDown:
            {
                context.PreventDefault();
                ClearSelection();

                break;
            }

            case KeyCode.Home:
            {
                context.PreventDefault();
                ClearSelection();

                CharPosition       cp   = GetCharPosition(_caretPosition);
                TextField.LineInfo line = textField.lines[cp.lineIndex];
                cp = GetCharPosition(new Vector2(int.MinValue, line.y + textField.y));
                AdjustCaret(cp);
                break;
            }

            case KeyCode.End:
            {
                context.PreventDefault();
                ClearSelection();

                CharPosition       cp   = GetCharPosition(_caretPosition);
                TextField.LineInfo line = textField.lines[cp.lineIndex];
                cp = GetCharPosition(new Vector2(int.MaxValue, line.y + textField.y));
                AdjustCaret(cp);

                break;
            }

            //Select All
            case KeyCode.A:
            {
                if (evt.ctrl)
                {
                    context.PreventDefault();
                    _selectionStart = GetCharPosition(0);
                    AdjustCaret(GetCharPosition(textField.text.Length));
                }
                break;
            }

            //Copy
            case KeyCode.C:
            {
                if (evt.ctrl && !_displayAsPassword)
                {
                    context.PreventDefault();
                    string s = GetSelection();
                    if (!string.IsNullOrEmpty(s))
                    {
                        DoCopy(s);
                    }
                }
                break;
            }

            //Paste
            case KeyCode.V:
            {
                if (evt.ctrl)
                {
                    context.PreventDefault();
                    DoPaste();
                }
                break;
            }

            //Cut
            case KeyCode.X:
            {
                if (evt.ctrl && !_displayAsPassword)
                {
                    context.PreventDefault();
                    string s = GetSelection();
                    if (!string.IsNullOrEmpty(s))
                    {
                        DoCopy(s);
                        ReplaceSelection(null);
                    }
                }
                break;
            }

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
            {
                if (!evt.ctrl && !evt.shift)
                {
                    context.PreventDefault();

                    if (!textField.singleLine)
                    {
                        ReplaceSelection("\n");
                    }
                }
                break;
            }
            }
        }
Ejemplo n.º 13
0
 void __mouseUp(EventContext context)
 {
     if (_selectionStart != null && ((CharPosition)_selectionStart).charIndex == _caretPosition)
         _selectionStart = null;
     Stage.inst.onMouseMove.RemoveCapture(__mouseMove);
     Stage.inst.onMouseUp.RemoveCapture(__mouseUp);
 }
Ejemplo n.º 14
0
        void __mouseDown(EventContext context)
        {
            if (_lines.Count == 0)
                return;

            ClearSelection();

            Vector3 v = new Vector3(Stage.mouseX, Stage.mouseY, 0);
            v = this.GlobalToLocal(v);
            v.x += this.pivotX;
            v.y += this.pivotY;
            CharPosition cp = GetCharPosition(v);
            AdjustCaret(cp);

            _selectionStart = cp;
            Stage.inst.onMouseMove.AddCapture(__mouseMove);
            Stage.inst.onMouseUp.AddCapture(__mouseUp);
        }
Ejemplo n.º 15
0
		void __touchBegin(EventContext context)
		{
			if (_caret == null || _lines.Count == 0)
				return;

			ClearSelection();

			CharPosition cp;
			if (_textChanged) //maybe the text changed in user's touchBegin
			{
				cp.charIndex = 0;
				cp.lineIndex = 0;
			}
			else
			{
				Vector3 v = Stage.inst.touchPosition;
				v = this.GlobalToLocal(v);
				Vector2 offset = _GetPositionOffset();
				v.x += offset.x;
				v.y += offset.y;
				cp = GetCharPosition(v);
			}

			AdjustCaret(cp);
			_selectionStart = cp;

			context.CaptureTouch();
			Stage.inst.onTouchMove.AddCapture(_touchMoveDelegate);
		}
Ejemplo n.º 16
0
		void __touchEnd(EventContext context)
		{
			Stage.inst.onTouchMove.RemoveCapture(_touchMoveDelegate);

			if (isDisposed)
				return;

			if (_selectionStart != null && ((CharPosition)_selectionStart).charIndex == _caretPosition)
				_selectionStart = null;
		}
Ejemplo n.º 17
0
        void __keydown(EventContext context)
        {
            if (context.isDefaultPrevented)
            {
                return;
            }

            InputEvent evt = context.inputEvent;

            switch (evt.keyCode)
            {
            case KeyCode.Backspace:
            {
                context.PreventDefault();
                if (_selectionStart != null)
                {
                    DeleteSelection();
                    onChanged.Call();
                }
                else if (_caretPosition > 0)
                {
                    int tmp = _caretPosition;         //this.text 会修改_caretPosition
                    _caretPosition--;
                    this.text = _text.Substring(0, tmp - 1) + _text.Substring(tmp);
                    onChanged.Call();
                }

                break;
            }

            case KeyCode.Delete:
            {
                context.PreventDefault();
                if (_selectionStart != null)
                {
                    DeleteSelection();
                    onChanged.Call();
                }
                else if (_caretPosition < _text.Length)
                {
                    this.text = _text.Substring(0, _caretPosition) + _text.Substring(_caretPosition + 1);
                    onChanged.Call();
                }

                break;
            }

            case KeyCode.LeftArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }
                if (_caretPosition > 0)
                {
                    CharPosition cp = GetCharPosition(_caretPosition - 1);
                    //调整输入光标
                    //AdjustCaret(cp);
                }
                break;
            }

            case KeyCode.RightArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }
                if (_caretPosition < _text.Length)
                {
                    CharPosition cp = GetCharPosition(_caretPosition + 1);
                    //AdjustCaret(cp);
                }
                break;
            }

            case KeyCode.UpArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }

                CharPosition cp = GetCharPosition(_caretPosition);
                if (cp.lineIndex == 0)
                {
                    return;
                }

                LineInfo line = _lines[cp.lineIndex - 1];
                //cp = GetCharPosition(new Vector3(_caret.cachedTransform.localPosition.x + this.pivotX, line.y, 0));
                //AdjustCaret(cp);
                break;
            }


            case KeyCode.DownArrow:
            {
                context.PreventDefault();
                if (evt.shift)
                {
                    if (_selectionStart == null)
                    {
                        _selectionStart = GetCharPosition(_caretPosition);
                    }
                }
                else
                {
                    ClearSelection();
                }

                CharPosition cp = GetCharPosition(_caretPosition);
                if (cp.lineIndex == _lines.Count - 1)
                {
                    return;
                }

                LineInfo line = _lines[cp.lineIndex + 1];
                //cp = GetCharPosition(new Vector3(_caret.cachedTransform.localPosition.x + this.pivotX, line.y, 0));
                //AdjustCaret(cp);
                break;
            }

            case KeyCode.PageUp:
            {
                context.PreventDefault();
                ClearSelection();

                break;
            }

            case KeyCode.PageDown:
            {
                context.PreventDefault();
                ClearSelection();

                break;
            }

            case KeyCode.Home:
            {
                context.PreventDefault();
                ClearSelection();

                CharPosition cp   = GetCharPosition(_caretPosition);
                LineInfo     line = _lines[cp.lineIndex];
                //cp = GetCharPosition(new Vector3(int.MinValue, line.y, 0));
                //AdjustCaret(cp);
                break;
            }

            case KeyCode.End:
            {
                context.PreventDefault();
                ClearSelection();

                CharPosition cp   = GetCharPosition(_caretPosition);
                LineInfo     line = _lines[cp.lineIndex];
                //cp = GetCharPosition(new Vector3(int.MaxValue, line.y, 0));
                //AdjustCaret(cp);

                break;
            }

            //Select All
            case KeyCode.A:
            {
                if (evt.ctrl)
                {
                    context.PreventDefault();
                    _selectionStart = GetCharPosition(0);
                    //AdjustCaret(GetCharPosition(_text.Length));
                }
                break;
            }

            // Copy
            case KeyCode.C:
            {
                if (evt.ctrl && !_displayAsPassword)
                {
                    context.PreventDefault();
                    string s = GetSelection();
                    if (!string.IsNullOrEmpty(s))
                    {
                        ToolSet.clipboard = s;
                    }
                }
                break;
            }

            // Paste
            case KeyCode.V:
            {
                if (evt.ctrl)
                {
                    context.PreventDefault();
                    string s = ToolSet.clipboard;
                    if (!string.IsNullOrEmpty(s))
                    {
                        InsertText(s);
                    }
                }
                break;
            }

            // Cut
            case KeyCode.X:
            {
                if (evt.ctrl && !_displayAsPassword)
                {
                    context.PreventDefault();
                    string s = GetSelection();
                    if (!string.IsNullOrEmpty(s))
                    {
                        ToolSet.clipboard = s;
                        DeleteSelection();
                        onChanged.Call();
                    }
                }
                break;
            }

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
            {
                if (!evt.ctrl && !evt.shift)
                {
                    context.PreventDefault();

                    if (!_singleLine)
                    {
                        InsertText("\n");
                    }
                }
                break;
            }
            }
        }