Example #1
0
 public void Call(FairyGUI.EventContext param0)
 {
     func.BeginPCall();
     func.PushObject(param0);
     func.PCall();
     func.EndPCall();
 }
Example #2
0
 static void OnCopy(EventContext context)
 {
     TextEditor te = new TextEditor();
     #if (UNITY_5_3 || UNITY_5_4)
     te.text = (string)context.data;
     #else
     te.content = new GUIContent((string)context.data);
     #endif
     te.OnFocus();
     te.Copy();
 }
 static public int get_data(IntPtr l)
 {
     try {
         FairyGUI.EventContext self = (FairyGUI.EventContext)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.data);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int CaptureTouch(IntPtr l)
 {
     try {
         FairyGUI.EventContext self = (FairyGUI.EventContext)checkSelf(l);
         self.CaptureTouch();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #5
0
 static void OnPaste(EventContext context)
 {
     TextField target = (TextField)context.data;
     TextEditor te = new TextEditor();
     te.Paste();
     #if (UNITY_5_3 || UNITY_5_4)
     string value = te.text;
     #else
     string value = te.content.text;
     #endif
     if (!string.IsNullOrEmpty(value))
         target.ReplaceSelection(value);
 }
 static public int constructor(IntPtr l)
 {
     try {
         FairyGUI.EventContext o;
         o = new FairyGUI.EventContext();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #7
0
    static int DispatchEvent(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes <FairyGUI.EventContext>(L, 2))
            {
                FairyGUI.EventDispatcher obj  = (FairyGUI.EventDispatcher)ToLua.CheckObject <FairyGUI.EventDispatcher>(L, 1);
                FairyGUI.EventContext    arg0 = (FairyGUI.EventContext)ToLua.ToObject(L, 2);
                bool o = obj.DispatchEvent(arg0);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes <string>(L, 2))
            {
                FairyGUI.EventDispatcher obj = (FairyGUI.EventDispatcher)ToLua.CheckObject <FairyGUI.EventDispatcher>(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                bool   o    = obj.DispatchEvent(arg0);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 3)
            {
                FairyGUI.EventDispatcher obj = (FairyGUI.EventDispatcher)ToLua.CheckObject <FairyGUI.EventDispatcher>(L, 1);
                string arg0 = ToLua.CheckString(L, 2);
                object arg1 = ToLua.ToVarObject(L, 3);
                bool   o    = obj.DispatchEvent(arg0, arg1);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 4)
            {
                FairyGUI.EventDispatcher obj = (FairyGUI.EventDispatcher)ToLua.CheckObject <FairyGUI.EventDispatcher>(L, 1);
                string arg0 = ToLua.CheckString(L, 2);
                object arg1 = ToLua.ToVarObject(L, 3);
                object arg2 = ToLua.ToVarObject(L, 4);
                bool   o    = obj.DispatchEvent(arg0, arg1, arg2);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: FairyGUI.EventDispatcher.DispatchEvent"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
 static public int set_type(IntPtr l)
 {
     try {
         FairyGUI.EventContext self = (FairyGUI.EventContext)checkSelf(l);
         System.String         v;
         checkType(l, 2, out v);
         self.type = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #9
0
 static int PreventDefault(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         FairyGUI.EventContext obj = (FairyGUI.EventContext)ToLua.CheckObject(L, 1, typeof(FairyGUI.EventContext));
         obj.PreventDefault();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int CaptureTouch(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         FairyGUI.EventContext obj = (FairyGUI.EventContext)ToLua.CheckObject <FairyGUI.EventContext>(L, 1);
         obj.CaptureTouch();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #11
0
        void SkillClick(FairyGUI.EventContext evt)
        {
            var skill = (evt.data as GObject).data as Skill;

            if (selectedSkill == skill)
            {
                //再点一下表示取消选择
                selectedSkill = null;
            }
            else
            {
                selectedSkill = skill;
            }
            flushSkills();
        }
Example #12
0
 public void CallInternal(EventContext context)
 {
     _dispatching = true;
     context.sender = owner;
     try
     {
         if (_callback1 != null)
             _callback1(context);
         if (_callback0 != null)
             _callback0();
     }
     finally
     {
         _dispatching = false;
     }
 }
Example #13
0
        public void CallCaptureInternal(EventContext context)
        {
            if (_captureCallback == null)
                return;

            _dispatching = true;
            context.sender = owner;
            try
            {
                _captureCallback(context);
            }
            finally
            {
                _dispatching = false;
            }
        }
    static int set_type(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.EventContext obj = (FairyGUI.EventContext)o;
            string arg0 = ToLua.CheckString(L, 2);
            obj.type = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index type on a nil value"));
        }
    }
Example #15
0
    static int get_initiator(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.EventContext obj = (FairyGUI.EventContext)o;
            object ret = obj.initiator;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index initiator on a nil value" : e.Message));
        }
    }
    static int get_isDefaultPrevented(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.EventContext obj = (FairyGUI.EventContext)o;
            bool ret = obj.isDefaultPrevented;
            LuaDLL.lua_pushboolean(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index isDefaultPrevented on a nil value"));
        }
    }
    static int set_data(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.EventContext obj = (FairyGUI.EventContext)o;
            object arg0 = ToLua.ToVarObject(L, 2);
            obj.data = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index data on a nil value"));
        }
    }
    static int get_sender(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.EventContext    obj = (FairyGUI.EventContext)o;
            FairyGUI.EventDispatcher ret = obj.sender;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index sender on a nil value"));
        }
    }
    static int get_inputEvent(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.EventContext obj = (FairyGUI.EventContext)o;
            FairyGUI.InputEvent   ret = obj.inputEvent;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index inputEvent on a nil value"));
        }
    }
    static int get_type(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.EventContext obj = (FairyGUI.EventContext)o;
            string ret = obj.type;
            LuaDLL.lua_pushstring(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index type on a nil value"));
        }
    }
    static int _CreateFairyGUI_EventContext(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                FairyGUI.EventContext obj = new FairyGUI.EventContext();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: FairyGUI.EventContext.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #22
0
 internal static void Return(EventContext value)
 {
     pool.Push(value);
 }
Example #23
0
        void __stageTouchBegin(EventContext context)
        {
            if (_tooltipWin != null)
                HideTooltips();

            CheckPopups();
        }
Example #24
0
        private void __touchMove(EventContext context)
        {
            InputEvent evt = context.inputEvent;
            if (_dragTouchId != evt.touchId)
                return;

            int sensitivity;
            if (Stage.touchScreen)
                sensitivity = UIConfig.touchDragSensitivity;
            else
                sensitivity = UIConfig.clickDragSensitivity;
            if (Mathf.Abs(_dragTouchStartPos.x - evt.x) < sensitivity
                && Mathf.Abs(_dragTouchStartPos.y - evt.y) < sensitivity)
                return;

            Reset();

            if (displayObject == null || displayObject.isDisposed)
                return;

            if (!onDragStart.Call(_dragTouchId))
                DragBegin(evt.touchId);
        }
        private void __clickItem(EventContext context)
        {
            if (dropdown.parent is GRoot)
                ((GRoot)dropdown.parent).HidePopup(dropdown);
            _selectedIndex = _list.GetChildIndex((GObject)context.data);
            if (_selectedIndex >= 0)
                this.text = _items[_selectedIndex];
            else
                this.text = string.Empty;

            onChanged.Call();
        }
Example #26
0
 void freeUse_CardClick(FairyGUI.EventContext evt)
 {
     checkUseAble();
 }
Example #27
0
 void __stageTouchEnd(EventContext context)
 {
     CheckPopups(false);
 }
Example #28
0
 void __onChanged(EventContext context)
 {
     _text = _textField.text;
     UpdateSize();
 }
Example #29
0
        private void __dragStart(EventContext context)
        {
            context.PreventDefault();

            this.StartDrag(null);
        }
Example #30
0
 private void __mouseDown(EventContext context)
 {
     if (this.isShowing)
     {
         BringToFront();
     }
 }
        private void __touchEnd(EventContext context)
        {
            if (_down)
            {
                if (this.displayObject == null || this.displayObject.isDisposed)
                    return;

                _down = false;
                if (dropdown != null && dropdown.parent != null)
                {
                    if (_over)
                        SetState(GButton.OVER);
                    else
                        SetState(GButton.UP);
                }
            }
        }
        private void __touchBegin(EventContext context)
        {
            _down = true;

            if (dropdown != null)
                ShowDropdown();

            context.CaptureTouch();
        }
Example #33
0
        private void __touchEnd(EventContext context)
        {
            if (_dragTouchId != context.inputEvent.touchId)
                return;

            Reset();
        }
Example #34
0
        private void __touchBegin(EventContext context)
        {
            InputEvent evt = context.inputEvent;
            _dragTouchId = evt.touchId;
            _dragTouchStartPos = evt.position;

            Stage.inst.onTouchEnd.Add(__touchEnd);
            Stage.inst.onTouchMove.Add(__touchMove);
        }
		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;
			}
		}
Example #36
0
        private void __touchEnd2(EventContext context)
        {
            InputEvent evt = context.inputEvent;
            if (_dragTouchId != -1 && _dragTouchId != evt.touchId)
                return;

            if (draggingObject == this)
            {
                StopDrag();

                if (displayObject == null || displayObject.isDisposed)
                    return;

                onDragEnd.Call();
            }
        }
		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;
					}
			}
		}
Example #38
0
        private void __touchMove2(EventContext context)
        {
            InputEvent evt = context.inputEvent;
            if (_dragTouchId != -1 && _dragTouchId != evt.touchId || this.parent == null)
                return;

            if (displayObject == null || displayObject.isDisposed)
                return;

            float xx = evt.x - sGlobalDragStart.x + sGlobalRect.x;
            float yy = evt.y - sGlobalDragStart.y + sGlobalRect.y;

            if (dragBounds != null)
            {
                Rect rect = GRoot.inst.LocalToGlobal((Rect)dragBounds);
                if (xx < rect.x)
                    xx = rect.x;
                else if (xx + sGlobalRect.width > rect.xMax)
                {
                    xx = rect.xMax - sGlobalRect.width;
                    if (xx < rect.x)
                        xx = rect.x;
                }

                if (yy < rect.y)
                    yy = rect.y;
                else if (yy + sGlobalRect.height > rect.yMax)
                {
                    yy = rect.yMax - sGlobalRect.height;
                    if (yy < rect.y)
                        yy = rect.y;
                }
            }

            Vector2 pt = this.parent.GlobalToLocal(new Vector2(xx, yy));
            if (float.IsNaN(pt.x))
                return;

            sUpdateInDragging = true;
            this.SetXY(Mathf.RoundToInt(pt.x), Mathf.RoundToInt(pt.y));
            sUpdateInDragging = false;

            onDragMove.Call();
        }
		void __touchMove(EventContext context)
		{
			if (isDisposed)
				return;

			if (_selectionStart == null)
				return;

			Vector3 v = Stage.inst.touchPosition;
			v = this.GlobalToLocal(v);
			if (float.IsNaN(v.x))
				return;

			Vector2 offset = _GetPositionOffset();
			v.x += offset.x;
			v.y += offset.y;

			CharPosition cp = GetCharPosition(v);
			if (cp.charIndex != _caretPosition)
				AdjustCaret(cp);
		}
Example #40
0
        private void __dragStart(EventContext context)
        {
            context.PreventDefault();

            this.StartDrag((int)context.data);
        }
        private void __dragStart(EventContext context)
        {
            context.PreventDefault();

            this.StartDrag((int)context.data);
        }
		void __focusOut(EventContext contxt)
		{
			if (_mobileInputAdapter != null)
			{
				_mobileInputAdapter.CloseKeyboard();
			}

			if (_caret != null)
			{
				_caret.SetParent(null);
				_caret = null;
				_highlighter.SetParent(null);
				_highlighter = null;
			}
		}
Example #43
0
        private void __mouseWheel(EventContext context)
        {
            if (!_mouseWheelEnabled)
                return;

            InputEvent evt = context.inputEvent;
            int delta = evt.mouseWheelDelta;
            if (_hScroll && !_vScroll)
            {
                if (delta < 0)
                    this.SetPercX(_xPerc - GetDeltaX(_mouseWheelSpeed), false);
                else
                    this.SetPercX(_xPerc + GetDeltaX(_mouseWheelSpeed), false);
            }
            else
            {
                if (delta < 0)
                    this.SetPercY(_yPerc - GetDeltaY(_mouseWheelSpeed), false);
                else
                    this.SetPercY(_yPerc + GetDeltaY(_mouseWheelSpeed), false);
            }
        }
		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);
		}
Example #45
0
        private void __mouseMove(EventContext context)
        {
            InputEvent evt = context.inputEvent;
            if (_touchId != evt.touchId)
                return;

            Vector2 pt = _owner.GlobalToLocal(new Vector2(evt.x, evt.y));

            float diff;
            bool sv = false, sh = false, st = false;

            if (_scrollType == ScrollType.Vertical)
            {
                if (!_isHoldAreaDone)
                {
                    diff = Mathf.Abs(_holdAreaPoint.y - pt.y);
                    if (diff < _holdArea)
                        return;
                }

                sv = true;
            }
            else if (_scrollType == ScrollType.Horizontal)
            {
                if (!_isHoldAreaDone)
                {
                    diff = Mathf.Abs(_holdAreaPoint.x - pt.x);
                    if (diff < _holdArea)
                        return;
                }

                sh = true;
            }
            else
            {
                if (!_isHoldAreaDone)
                {
                    diff = Mathf.Abs(_holdAreaPoint.y - pt.y);
                    if (diff < _holdArea)
                    {
                        diff = Mathf.Abs(_holdAreaPoint.x - pt.x);
                        if (diff < _holdArea)
                            return;
                    }
                }

                sv = sh = true;
            }

            float t = Time.time;
            if (t - _time2 > 0.05f)
            {
                _time2 = _time1;
                _time1 = t;
                st = true;
            }

            if (sv)
            {
                float y = pt.y - _yOffset;
                if (y > 0)
                {
                    if (!_bouncebackEffect)
                        _maskContentHolder.y = 0;
                    else
                        _maskContentHolder.y = (int)(y * 0.5);
                }
                else if (y < -_yOverlap)
                {
                    if (!_bouncebackEffect)
                        _maskContentHolder.y = -(int)_yOverlap;
                    else
                        _maskContentHolder.y = (int)((y - _yOverlap) * 0.5);
                }
                else
                {
                    _maskContentHolder.y = y;
                }

                if (st)
                {
                    _y2 = _y1;
                    _y1 = _maskContentHolder.y;
                }

                _yPerc = CalcYPerc();
            }

            if (sh)
            {
                float x = pt.x - _xOffset;
                if (x > 0)
                {
                    if (!_bouncebackEffect)
                        _maskContentHolder.x = 0;
                    else
                        _maskContentHolder.x = (int)(x * 0.5);
                }
                else if (x < 0 - _xOverlap)
                {
                    if (!_bouncebackEffect)
                        _maskContentHolder.x = -(int)_xOverlap;
                    else
                        _maskContentHolder.x = (int)((x - _xOverlap) * 0.5);
                }
                else
                {
                    _maskContentHolder.x = x;
                }

                if (st)
                {
                    _x2 = _x1;
                    _x1 = _maskContentHolder.x;
                }

                _xPerc = CalcXPerc();
            }

            _maskHolder.touchable = false;
            _isHoldAreaDone = true;
            _isMouseMoved = true;
            OnScrolling();

            _owner.onScroll.Call();
        }
		void __touchEnd(EventContext context)
		{
			Stage.inst.onTouchMove.RemoveCapture(_touchMoveDelegate);

			if (isDisposed)
				return;

			if (_selectionStart != null && ((CharPosition)_selectionStart).charIndex == _caretPosition)
				_selectionStart = null;
		}
        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)
                {
                    TextField.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)
                {
                    TextField.CharPosition cp = GetCharPosition(_caretPosition + 1);
                    AdjustCaret(cp);
                }
                break;
            }

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

                TextField.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();
                }

                TextField.CharPosition cp = GetCharPosition(_caretPosition);
                if (cp.lineIndex == textField.lines.Count - 1)
                {
                    cp.caretIndex = 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();

                TextField.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();

                TextField.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;
            }
            }
        }
 private void __touchBegin(EventContext context)
 {
     if (this.isShowing && bringToFontOnClick)
     {
         BringToFront();
     }
 }
Example #49
0
 internal static void Return(EventContext value)
 {
     pool.Push(value);
 }
Example #50
0
        private void __mouseUp(EventContext context)
        {
            if (!_touchEffect)
            {
                _isMouseMoved = false;
                return;
            }

            InputEvent evt = context.inputEvent;
            if (_touchId != evt.touchId)
                return;

            _container.stage.onMouseMove.Remove(__mouseMove);
            _container.stage.onMouseUp.Remove(__mouseUp);

            if (!_isMouseMoved)
                return;

            _isMouseMoved = false;

            float time = Time.time - _time2;
            if (time == 0)
                time = 0.001f;
            float yVelocity = (_maskContentHolder.y - _y2) / time;
            float xVelocity = (_maskContentHolder.x - _x2) / time;

            float minDuration = _bouncebackEffect ? 0.3f : 0;
            float maxDuration = 0.5f;
            int overShoot = _bouncebackEffect ? 1 : 0;

            float xMin = -_xOverlap, yMin = -_yOverlap;
            float xMax = 0, yMax = 0;

            float duration = 0f;

            if (_hScroll)
                ThrowTween.CalculateDuration(_maskContentHolder.x, xMin, xMax, xVelocity, overShoot, ref duration);
            if (_vScroll)
                ThrowTween.CalculateDuration(_maskContentHolder.y, yMin, yMax, yVelocity, overShoot, ref duration);

            if (duration > maxDuration)
                duration = maxDuration;
            else if (duration < minDuration)
                duration = minDuration;

            _throwTween.start.x = _maskContentHolder.x;
            _throwTween.start.y = _maskContentHolder.y;

            Vector2 change1, change2;
            float endX = 0, endY = 0;

            if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Horizontal)
            {
                change1.x = ThrowTween.CalculateChange(xVelocity, duration);
                change2.x = 0;
                endX = _maskContentHolder.x + change1.x;
            }
            else
                change1.x = change2.x = 0;

            if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Vertical)
            {
                change1.y = ThrowTween.CalculateChange(yVelocity, duration);
                change2.y = 0;
                endY = _maskContentHolder.y + change1.y;
            }
            else
                change1.y = change2.y = 0;

            if (_snapToItem)
            {
                endX = -endX / GRoot.contentScaleFactor;
                endY = -endY / GRoot.contentScaleFactor;
                _owner.FindObjectNear(ref endX, ref endY);
                endX = -endX * GRoot.contentScaleFactor;
                endY = -endY * GRoot.contentScaleFactor;
                change1.x = endX - _maskContentHolder.x;
                change1.y = endY - _maskContentHolder.y;
            }

            if (xMax < endX)
                change2.x = xMax - _maskContentHolder.x - change1.x;
            else if (xMin > endX)
                change2.x = xMin - _maskContentHolder.x - change1.x;

            if (yMax < endY)
                change2.y = yMax - _maskContentHolder.y - change1.y;
            else if (yMin > endY)
                change2.y = yMin - _maskContentHolder.y - change1.y;

            _throwTween.value = 0;
            _throwTween.change1 = change1;
            _throwTween.change2 = change2;

            if (_tweener != null)
                _tweener.Complete();

            _tweener = DOTween.To(() => _throwTween.value, v => _throwTween.value = v, 1, duration)
                .SetEase(Ease.OutCubic)
                .OnUpdate(__tweenUpdate2)
                .OnComplete(__tweenComplete2);
        }
Example #51
0
 private void __gripTouchEnd(EventContext context)
 {
     DispatchEvent("onGripTouchEnd", null);
 }
Example #52
0
        private void __mouseDown(EventContext context)
        {
            if (!_touchEffect)
                return;

            InputEvent evt = context.inputEvent;
            _touchId = evt.touchId;
            Vector2 pt = _owner.GlobalToLocal(new Vector2(evt.x, evt.y));
            if (_tweener != null)
            {
                _tweener.Complete();
                _tweener = null;
                Stage.inst.CancelClick(_touchId);
            }

            _y1 = _y2 = _maskContentHolder.y;
            _yOffset = pt.y - _maskContentHolder.y;

            _x1 = _x2 = _maskContentHolder.x;
            _xOffset = pt.x - _maskContentHolder.x;

            _time1 = _time2 = Time.time;
            _holdAreaPoint.x = pt.x;
            _holdAreaPoint.y = pt.y;
            _isHoldAreaDone = false;
            _isMouseMoved = false;

            _container.stage.onMouseMove.Add(__mouseMove);
            _container.stage.onMouseUp.Add(__mouseUp);
        }
        void __touchMove(EventContext context)
        {
            InputEvent evt = context.inputEvent;
            Vector2 pt1 = _host.GlobalToLocal(Stage.inst.GetTouchPosition(_touches[0]));
            Vector2 pt2 = _host.GlobalToLocal(Stage.inst.GetTouchPosition(_touches[1]));
            float dist = Vector2.Distance(pt1, pt2);

            if (!_started && Mathf.Abs(dist - _startDistance) > UIConfig.touchDragSensitivity)
            {
                _started = true;
                scale = 1;
                _lastScale = 1;

                onBegin.Call(evt);
            }

            if (_started)
            {
                float ss = dist / _startDistance;
                delta = ss - _lastScale;
                _lastScale = ss;
                this.scale += delta;
                onAction.Call(evt);
            }
        }
        void __touchBegin(EventContext context)
        {
            if (Stage.inst.touchCount == 2)
            {
                if (!_started)
                {
                    Stage.inst.GetAllTouch(_touches);
                    Vector2 pt1 = _host.GlobalToLocal(Stage.inst.GetTouchPosition(_touches[0]));
                    Vector2 pt2 = _host.GlobalToLocal(Stage.inst.GetTouchPosition(_touches[1]));
                    _startDistance = Vector2.Distance(pt1, pt2);

                    Stage.inst.onTouchMove.Add(__touchMove);
                    Stage.inst.onTouchEnd.Add(__touchEnd);
                }
            }
        }
Example #55
0
        void __keydown(EventContext context)
        {
            if (!_editing || context.isDefaultPrevented)
            {
                return;
            }

            InputEvent evt = context.inputEvent;

            switch (evt.keyCode)
            {
            case KeyCode.Backspace:
            {
                context.PreventDefault();
                if (_selectionStart == _caretPosition && _caretPosition > 0)
                {
                    _selectionStart = _caretPosition - 1;
                }
                ReplaceSelection(null);
                break;
            }

            case KeyCode.Delete:
            {
                context.PreventDefault();
                if (_selectionStart == _caretPosition && _caretPosition < textField.charPositions.Count - 1)
                {
                    _selectionStart = _caretPosition + 1;
                }
                ReplaceSelection(null);
                break;
            }

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

            case KeyCode.RightArrow:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }
                if (_caretPosition < textField.charPositions.Count - 1)
                {
                    TextField.CharPosition cp = GetCharPosition(_caretPosition + 1);
                    AdjustCaret(cp, !evt.shift);
                }
                break;
            }

            case KeyCode.UpArrow:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

                TextField.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, !evt.shift);
                break;
            }

            case KeyCode.DownArrow:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

                TextField.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, !evt.shift);
                break;
            }

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

                break;
            }

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

                break;
            }

            case KeyCode.Home:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

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

            case KeyCode.End:
            {
                context.PreventDefault();
                if (!evt.shift)
                {
                    ClearSelection();
                }

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

                break;
            }

            //Select All
            case KeyCode.A:
            {
                if (evt.ctrl)
                {
                    context.PreventDefault();
                    _selectionStart = 0;
                    AdjustCaret(GetCharPosition(int.MaxValue));
                }
                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 (textField.singleLine)
                {
                    DispatchEvent("onSubmit", null);
                    return;
                }
                break;
            }
            }

            char c = evt.character;

            if (c != 0)
            {
                if (evt.ctrl)
                {
                    return;
                }

                if (c == '\r' || (int)c == 3)
                {
                    c = '\n';
                }

                if (c == 127 || textField.singleLine && c == '\n')
                {
                    return;
                }

                if (char.IsHighSurrogate(c))
                {
                    _highSurrogateChar = c;
                    return;
                }

                if (char.IsLowSurrogate(c))
                {
                    ReplaceSelection(char.ConvertFromUtf32(((int)c & 0x03FF) + ((((int)_highSurrogateChar & 0x03FF) + 0x40) << 10)));
                }
                else
                {
                    ReplaceSelection(c.ToString());
                }
            }
            else
            {
                if (Input.compositionString.Length > 0)
                {
                    UpdateText();
                }
            }
        }