private void OnTouchBegin(EventContext context)
    {
        if (touchId == -1)        //First touch
        {
            InputEvent evt = (InputEvent)context.data;
            touchId = evt.touchId;

            if (_tweener != null)
            {
                _tweener.Kill();
                _tweener = null;
            }

            Vector2 pt = GRoot.inst.GlobalToLocal(new Vector2(evt.x, evt.y));
            float   bx = pt.x;
            float   by = pt.y;
            _button.selected = true;

            if (bx < 0)
            {
                bx = 0;
            }
            else if (bx > _touchArea.width)
            {
                bx = _touchArea.width;
            }

            if (by > GRoot.inst.height)
            {
                by = GRoot.inst.height;
            }
            else if (by < _touchArea.y)
            {
                by = _touchArea.y;
            }

            _lastStageX  = bx;
            _lastStageY  = by;
            _startStageX = bx;
            _startStageY = by;

            _center.visible = true;
            _center.SetPosition(bx - _center.width / 2, by - _center.height / 2);
            _button.SetPosition(bx - _button.width / 2, by - _button.height / 2);

            float deltaX  = bx - _InitX;
            float deltaY  = by - _InitY;
            float degrees = (float)Math.Atan2(deltaY, deltaX) * 180 / (float)Math.PI;
            _thumb.rotation = degrees + 90;

            context.CaptureTouch();
        }
    }
Exemplo n.º 2
0
 static public int get_modifiers(IntPtr l)
 {
     try {
         FairyGUI.InputEvent self = (FairyGUI.InputEvent)checkSelf(l);
         pushValue(l, true);
         pushEnum(l, (int)self.modifiers);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 3
0
 static public int get_mouseWheelDelta(IntPtr l)
 {
     try {
         FairyGUI.InputEvent self = (FairyGUI.InputEvent)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.mouseWheelDelta);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 4
0
 static public int get_touchId(IntPtr l)
 {
     try {
         FairyGUI.InputEvent self = (FairyGUI.InputEvent)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.touchId);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 5
0
 static public int constructor(IntPtr l)
 {
     try {
         FairyGUI.InputEvent o;
         o = new FairyGUI.InputEvent();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    private void OnTouchMove(EventContext context)
    {
        InputEvent evt = (InputEvent)context.data;

        if (touchId != -1 && evt.touchId == touchId)
        {
            Vector2 pt    = GRoot.inst.GlobalToLocal(new Vector2(evt.x, evt.y));
            float   bx    = pt.x;
            float   by    = pt.y;
            float   moveX = bx - _lastStageX;
            float   moveY = by - _lastStageY;
            _lastStageX = bx;
            _lastStageY = by;
            float buttonX = _button.x + moveX;
            float buttonY = _button.y + moveY;

            float offsetX = buttonX + _button.width / 2 - _startStageX;
            float offsetY = buttonY + _button.height / 2 - _startStageY;

            float rad    = (float)Math.Atan2(offsetY, offsetX);
            float degree = rad * 180 / (float)Math.PI;
            _thumb.rotation = degree + 90;

            float maxX = radius * (float)Math.Cos(rad);
            float maxY = radius * (float)Math.Sin(rad);
            if ((float)Math.Abs(offsetX) > (float)Math.Abs(maxX))
            {
                offsetX = maxX;
            }
            if ((float)Math.Abs(offsetY) > (float)Math.Abs(maxY))
            {
                offsetY = maxY;
            }

            buttonX = _startStageX + offsetX;
            buttonY = _startStageY + offsetY;
            if (buttonX < 0)
            {
                buttonX = 0;
            }
            if (buttonY > GRoot.inst.height)
            {
                buttonY = GRoot.inst.height;
            }

            _button.SetPosition(buttonX - _button.width / 2, buttonY - _button.height / 2);

            this.onMove.Call(degree);
        }
    }
Exemplo n.º 7
0
    static int get_alt(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.InputEvent obj = (FairyGUI.InputEvent)o;
            bool ret = obj.alt;
            LuaDLL.lua_pushboolean(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index alt on a nil value" : e.Message));
        }
    }
Exemplo n.º 8
0
    static int get_clickCount(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.InputEvent obj = (FairyGUI.InputEvent)o;
            int ret = obj.clickCount;
            LuaDLL.lua_pushinteger(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index clickCount on a nil value"));
        }
    }
Exemplo n.º 9
0
    static int get_position(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.InputEvent obj = (FairyGUI.InputEvent)o;
            UnityEngine.Vector2 ret = obj.position;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index position on a nil value" : e.Message));
        }
    }
Exemplo n.º 10
0
    static int get_command(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.InputEvent obj = (FairyGUI.InputEvent)o;
            bool ret = obj.command;
            LuaDLL.lua_pushboolean(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index command on a nil value"));
        }
    }
Exemplo n.º 11
0
    static int get_button(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.InputEvent obj = (FairyGUI.InputEvent)o;
            int ret = obj.button;
            LuaDLL.lua_pushinteger(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index button on a nil value" : e.Message));
        }
    }
Exemplo n.º 12
0
    static int get_y(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.InputEvent obj = (FairyGUI.InputEvent)o;
            float ret = obj.y;
            LuaDLL.lua_pushnumber(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index y on a nil value"));
        }
    }
Exemplo n.º 13
0
    static int get_keyCode(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.InputEvent obj = (FairyGUI.InputEvent)o;
            UnityEngine.KeyCode ret = obj.keyCode;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index keyCode 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"));
        }
    }
Exemplo n.º 15
0
    static int get_modifiers(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            FairyGUI.InputEvent        obj = (FairyGUI.InputEvent)o;
            UnityEngine.EventModifiers ret = obj.modifiers;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index modifiers on a nil value"));
        }
    }
Exemplo n.º 16
0
    private void OnTouchEnd(EventContext context)
    {
        InputEvent inputEvt = (InputEvent)context.data;

        if (touchId != -1 && inputEvt.touchId == touchId)
        {
            touchId         = -1;
            _thumb.rotation = _thumb.rotation + 180;
            _center.visible = false;
            _tweener        = _button.TweenMove(new Vector2(_InitX - _button.width / 2, _InitY - _button.height / 2), 0.3f).OnComplete(() =>
            {
                _tweener         = null;
                _button.selected = false;
                _thumb.rotation  = 0;
                _center.visible  = true;
                _center.SetPosition(_InitX - _center.width / 2, _InitY - _center.height / 2);
            }
                                                                                                                                       );

            this.onEnd.Call();
        }
    }
Exemplo n.º 17
0
    static int _CreateFairyGUI_InputEvent(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                FairyGUI.InputEvent obj = new FairyGUI.InputEvent();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: FairyGUI.InputEvent.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 18
0
		public TouchInfo()
		{
			evt = new InputEvent();
			downTargets = new List<DisplayObject>();
			touchEndMonitors = new List<EventDispatcher>();
			Reset();
		}
        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;
            }
            }
        }
        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)
                {
                    onSubmit.Call();
                    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();
                }
            }
        }
Exemplo n.º 21
0
 public TouchInfo()
 {
     evt = new InputEvent();
     Reset();
 }
        internal bool InternalDispatchEvent(string strType, EventBridge bridge, object data, object initiator)
        {
            EventBridge gBridge = null;
            if ((this is DisplayObject) && ((DisplayObject)this).gOwner != null)
                gBridge = ((DisplayObject)this).gOwner.TryGetEventBridge(strType);

            bool b1 = bridge != null && !bridge.isEmpty;
            bool b2 = gBridge != null && !gBridge.isEmpty;
            if (b1 || b2)
            {
                EventContext context = EventContext.Get();
                context.initiator = initiator != null ? initiator : this;
                context.type = strType;
                context.data = data;
                if (data is InputEvent)
                    sCurrentInputEvent = (InputEvent)data;
                context.inputEvent = sCurrentInputEvent;

                if (b1)
                {
                    bridge.CallCaptureInternal(context);
                    bridge.CallInternal(context);
                }

                if (b2)
                {
                    gBridge.CallCaptureInternal(context);
                    gBridge.CallInternal(context);
                }

                EventContext.Return(context);
                context.initiator = null;
                context.sender = null;
                context.data = null;

                return context._defaultPrevented;
            }
            else
                return false;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strType"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool BroadcastEvent(string strType, object data)
        {
            EventContext context = EventContext.Get();
            context.initiator = this;
            context.type = strType;
            context.data = data;
            if (data is InputEvent)
                sCurrentInputEvent = (InputEvent)data;
            context.inputEvent = sCurrentInputEvent;
            List<EventBridge> bubbleChain = context.callChain;
            bubbleChain.Clear();

            if (this is Container)
                GetChildEventBridges(strType, (Container)this, bubbleChain);
            else if (this is GComponent)
                GetChildEventBridges(strType, (GComponent)this, bubbleChain);

            int length = bubbleChain.Count;
            for (int i = 0; i < length; ++i)
                bubbleChain[i].CallInternal(context);

            EventContext.Return(context);
            context.initiator = null;
            context.sender = null;
            context.data = null;
            return context._defaultPrevented;
        }
Exemplo n.º 24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="strType"></param>
        /// <param name="data"></param>
        /// <param name="addChain"></param>
        /// <returns></returns>
        internal bool BubbleEvent(string strType, object data, List <EventBridge> addChain)
        {
            EventContext context = EventContext.Get();

            context.initiator = this;

            context.type = strType;
            context.data = data;
            if (data is InputEvent)
            {
                sCurrentInputEvent = (InputEvent)data;
            }
            context.inputEvent = sCurrentInputEvent;
            List <EventBridge> bubbleChain = context.callChain;

            bubbleChain.Clear();

            GetChainBridges(strType, bubbleChain, true);

            int length = bubbleChain.Count;

            for (int i = length - 1; i >= 0; i--)
            {
                bubbleChain[i].CallCaptureInternal(context);
                if (context._touchEndCapture)
                {
                    context._touchEndCapture = false;
                    if (strType == "onTouchBegin")
                    {
                        Stage.inst.AddTouchEndMonitor(context.inputEvent.touchId, bubbleChain[i].owner);
                    }
                }
            }

            for (int i = 0; i < length; ++i)
            {
                bubbleChain[i].CallInternal(context);
                if (context._stopsPropagation)
                {
                    break;
                }

                if (context._touchEndCapture)
                {
                    context._touchEndCapture = false;
                    if (strType == "onTouchBegin")
                    {
                        Stage.inst.AddTouchEndMonitor(context.inputEvent.touchId, bubbleChain[i].owner);
                    }
                }
            }

            if (addChain != null)
            {
                length = addChain.Count;
                for (int i = 0; i < length; ++i)
                {
                    EventBridge bridge = addChain[i];
                    if (bubbleChain.IndexOf(bridge) == -1)
                    {
                        bridge.CallCaptureInternal(context);
                        bridge.CallInternal(context);
                    }
                }
            }

            EventContext.Return(context);
            context.initiator = null;
            context.sender    = null;
            context.data      = null;
            return(context._defaultPrevented);
        }
Exemplo n.º 25
0
        void SetSelectionOnEvent(GObject item, InputEvent evt)
        {
            if (!(item is GButton) || selectionMode == ListSelectionMode.None)
                return;

            _selectionHandled = true;
            bool dontChangeLastIndex = false;
            GButton button = (GButton)item;
            int index = GetChildIndex(item);

            if (selectionMode == ListSelectionMode.Single)
            {
                if (!button.selected)
                {
                    ClearSelectionExcept(button);
                    button.selected = true;
                }
            }
            else
            {
                if (evt.shift)
                {
                    if (!button.selected)
                    {
                        if (_lastSelectedIndex != -1)
                        {
                            int min = Math.Min(_lastSelectedIndex, index);
                            int max = Math.Max(_lastSelectedIndex, index);
                            max = Math.Min(max, _children.Count - 1);
                            for (int i = min; i <= max; i++)
                            {
                                GButton obj = GetChildAt(i).asButton;
                                if (obj != null && !obj.selected)
                                    obj.selected = true;
                            }

                            dontChangeLastIndex = true;
                        }
                        else
                        {
                            button.selected = true;
                        }
                    }
                }
                else if (evt.ctrl || selectionMode == ListSelectionMode.Multiple_SingleClick)
                {
                    button.selected = !button.selected;
                }
                else
                {
                    if (!button.selected)
                    {
                        ClearSelectionExcept(button);
                        button.selected = true;
                    }
                    else
                        ClearSelectionExcept(button);
                }
            }

            if (!dontChangeLastIndex)
                _lastSelectedIndex = index;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strType"></param>
        /// <param name="data"></param>
        /// <param name="addChain"></param>
        /// <returns></returns>
        internal bool BubbleEvent(string strType, object data, List<EventBridge> addChain)
        {
            EventContext context = EventContext.Get();
            context.initiator = this;

            context.type = strType;
            context.data = data;
            if (data is InputEvent)
                sCurrentInputEvent = (InputEvent)data;
            context.inputEvent = sCurrentInputEvent;
            List<EventBridge> bubbleChain = context.callChain;
            bubbleChain.Clear();

            GetChainBridges(strType, bubbleChain, true);

            int length = bubbleChain.Count;
            for (int i = length - 1; i >= 0; i--)
            {
                bubbleChain[i].CallCaptureInternal(context);
                if (context._touchEndCapture)
                {
                    context._touchEndCapture = false;
                    if (strType == "onTouchBegin")
                        Stage.inst.AddTouchEndMonitor(context.inputEvent.touchId, bubbleChain[i].owner);
                }
            }

            for (int i = 0; i < length; ++i)
            {
                bubbleChain[i].CallInternal(context);
                if (context._stopsPropagation)
                    break;

                if (context._touchEndCapture)
                {
                    context._touchEndCapture = false;
                    if (strType == "onTouchBegin")
                        Stage.inst.AddTouchEndMonitor(context.inputEvent.touchId, bubbleChain[i].owner);
                }
            }

            if (addChain != null)
            {
                length = addChain.Count;
                for (int i = 0; i < length; ++i)
                {
                    EventBridge bridge = addChain[i];
                    if (bubbleChain.IndexOf(bridge) == -1)
                    {
                        bridge.CallCaptureInternal(context);
                        bridge.CallInternal(context);
                    }
                }
            }

            EventContext.Return(context);
            context.initiator = null;
            context.sender = null;
            context.data = null;
            return context._defaultPrevented;
        }