void HandleMouseEvents() { TouchInfo touch = _touches[0]; if (touch.x != _touchPosition.x || touch.y != _touchPosition.y) { touch.x = _touchPosition.x; touch.y = _touchPosition.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); if (touch.lastRollOver != touch.target) { HandleRollOver(touch); } } if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2)) { if (!touch.began) { _touchCount = 1; touch.begin(); touch.button = Input.GetMouseButtonDown(2) ? 2 : (Input.GetMouseButtonDown(1) ? 1 : 0); this.focus = touch.target; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchBegin.BubbleCall(touch.evt); } } } if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1) || Input.GetMouseButtonUp(2)) { if (touch.began) { _touchCount = 0; touch.end(); DisplayObject clickTarget = touch.ClickTest(); if (clickTarget != null) { touch.UpdateEvent(); if (Input.GetMouseButtonUp(1)) { clickTarget.onRightClick.BubbleCall(touch.evt); } else { clickTarget.onClick.BubbleCall(touch.evt); } } } } }
void HandleCustomInput() { Vector2 pos = _customInputPos; pos.y = stageHeight - pos.y; TouchInfo touch = _touches[0]; if (touch.x != pos.x || touch.y != pos.y) { touch.x = pos.x; touch.y = pos.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); if (touch.lastRollOver != touch.target) { HandleRollOver(touch); } } if (_customInputButtonDown) { if (!touch.began) { _touchCount = 1; touch.begin(); this.focus = touch.target; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchBegin.BubbleCall(touch.evt); } } } else if (touch.began) { _touchCount = 0; touch.end(); DisplayObject clickTarget = touch.ClickTest(); if (clickTarget != null) { touch.UpdateEvent(); clickTarget.onClick.BubbleCall(touch.evt); } } }
internal void HandleGUIEvents(Event evt) { if (evt.rawType == EventType.KeyDown && evt.keyCode != KeyCode.None) { TouchInfo touch = _touches[0]; touch.keyCode = evt.keyCode; touch.modifiers = evt.modifiers; touch.UpdateEvent(); DisplayObject f = this.focus; if (f != null) { f.onKeyDown.BubbleCall(touch.evt); } else { this.onKeyDown.Call(touch.evt); } } else if (evt.rawType == EventType.KeyUp) { TouchInfo touch = _touches[0]; touch.modifiers = evt.modifiers; } else if (evt.type == EventType.scrollWheel) { if (_touchTarget != null) { TouchInfo touch = _touches[0]; touch.mouseWheelDelta = (int)evt.delta.y; touch.UpdateEvent(); _touchTarget.onMouseWheel.BubbleCall(touch.evt); } } }
internal void HandleGUIEvents(Event evt) { if (evt.rawType == EventType.KeyDown) { TouchInfo touch = _touches[0]; touch.keyCode = evt.keyCode; touch.modifiers = evt.modifiers; touch.character = evt.character; InputEvent.shiftDown = (evt.modifiers & EventModifiers.Shift) != 0; touch.UpdateEvent(); DisplayObject f = this.focus; if (f != null) { f.BubbleEvent("onKeyDown", touch.evt); } else { DispatchEvent("onKeyDown", touch.evt); } } else if (evt.rawType == EventType.KeyUp) { TouchInfo touch = _touches[0]; touch.keyCode = evt.keyCode; touch.modifiers = evt.modifiers; touch.character = evt.character; InputEvent.shiftDown = (evt.modifiers & EventModifiers.Shift) != 0; touch.UpdateEvent(); DisplayObject f = this.focus; if (f != null) { f.BubbleEvent("onKeyUp", touch.evt); } else { DispatchEvent("onKeyUp", touch.evt); } } #if UNITY_2017_1_OR_NEWER else if (evt.type == EventType.ScrollWheel) #else else if (evt.type == EventType.scrollWheel) #endif { if (_touchTarget != null) { TouchInfo touch = _touches[0]; touch.mouseWheelDelta = evt.delta.y; touch.UpdateEvent(); _touchTarget.BubbleEvent("onMouseWheel", touch.evt); touch.mouseWheelDelta = 0; } } }
internal void HandleGUIEvents(Event evt) { if (evt.rawType == EventType.KeyDown) { TouchInfo touch = _touches[0]; touch.keyCode = evt.keyCode; touch.modifiers = evt.modifiers; touch.character = evt.character; InputEvent.shiftDown = (evt.modifiers & EventModifiers.Shift) != 0; touch.UpdateEvent(); DisplayObject f = this.focus; if (f != null) { f.onKeyDown.BubbleCall(touch.evt); } else { this.onKeyDown.Call(touch.evt); } } else if (evt.rawType == EventType.KeyUp) { TouchInfo touch = _touches[0]; touch.modifiers = evt.modifiers; } else if (evt.type == EventType.scrollWheel) { if (_touchTarget != null) { TouchInfo touch = _touches[0]; touch.mouseWheelDelta = (int)evt.delta.y; touch.UpdateEvent(); _touchTarget.onMouseWheel.BubbleCall(touch.evt); touch.mouseWheelDelta = 0; } } }
void HandleTouchEvents() { int tc = Input.touchCount; for (int i = 0; i < tc; ++i) { Touch uTouch = Input.GetTouch(i); if (uTouch.phase == TouchPhase.Stationary) { continue; } Vector2 pos = uTouch.position; pos.y = stageHeight - pos.y; TouchInfo touch = null; for (int j = 0; j < 5; j++) { if (_touches[j].touchId == uTouch.fingerId) { touch = _touches[j]; break; } } if (touch == null) { continue; } if (touch.x != pos.x || touch.y != pos.y) { touch.x = pos.x; touch.y = pos.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); //no rollover/rollout on mobile } if (uTouch.phase == TouchPhase.Began) { if (!touch.began) { _touchCount++; touch.begin(); this.focus = touch.target; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchBegin.BubbleCall(touch.evt); } } } else if (uTouch.phase == TouchPhase.Canceled || uTouch.phase == TouchPhase.Ended) { if (touch.began) { _touchCount--; touch.end(); DisplayObject clickTarget = touch.ClickTest(); if (clickTarget != null) { touch.clickCount = uTouch.tapCount; touch.UpdateEvent(); clickTarget.onClick.BubbleCall(touch.evt); } } touch.Reset(); } } }
internal void HandleMouseEvents() { MouseState mouseState = Mouse.GetState(); _touchPosition = new Vector2(mouseState.Position.X, mouseState.Position.Y); _touchTarget = HitTest(_touchPosition, true); _touchInfo.target = _touchTarget; if (Math.Abs(_touchInfo.x - _touchPosition.X) > 0 || Math.Abs(_touchInfo.y - _touchPosition.Y) > 0) { _touchInfo.x = _touchPosition.X; _touchInfo.y = _touchPosition.Y; _touchInfo.Move(); } if (_touchInfo.lastRollOver != _touchInfo.target) { HandleRollOver(_touchInfo); } if (mouseState.LeftButton == ButtonState.Pressed || mouseState.RightButton == ButtonState.Pressed || mouseState.MiddleButton == ButtonState.Pressed) { if (!_touchInfo.began) { _touchInfo.Begin(); _touchInfo.button = (mouseState.LeftButton == ButtonState.Pressed) ? 0 : (mouseState.RightButton == ButtonState.Pressed ? 1 : 2); this.focus = _touchInfo.target; _touchInfo.UpdateEvent(); _touchInfo.target.BubbleEvent("onTouchBegin", _touchInfo.evt); } } else if (mouseState.LeftButton == ButtonState.Released || mouseState.RightButton == ButtonState.Released || mouseState.MiddleButton == ButtonState.Released) { if (_touchInfo.began) { _touchInfo.End(); DisplayObject clickTarget = _touchInfo.ClickTest(); if (clickTarget != null) { _touchInfo.UpdateEvent(); if (_touchInfo.button == 1) { clickTarget.BubbleEvent("onRightClick", _touchInfo.evt); } else { clickTarget.BubbleEvent("onClick", _touchInfo.evt); } } _touchInfo.button = -1; } } int deltaWheel = mouseState.ScrollWheelValue - _lastScrollWheelValue; if (deltaWheel != 0) { if (_touchTarget != null) { _touchInfo.mouseWheelDelta = -deltaWheel; _touchInfo.UpdateEvent(); _touchTarget.BubbleEvent("onMouseWheel", _touchInfo.evt); _touchInfo.mouseWheelDelta = 0; } _lastScrollWheelValue = mouseState.ScrollWheelValue; } }
void HandleTouchEvents() { int tc = Input.touchCount; for (int i = 0; i < tc; ++i) { Touch uTouch = Input.GetTouch(i); if (uTouch.phase == TouchPhase.Stationary) { continue; } Vector2 pos = uTouch.position; pos.y = stageHeight - pos.y; TouchInfo touch = null; for (int j = 0; j < 5; j++) { if (_touches[j].touchId == uTouch.fingerId) { touch = _touches[j]; break; } } if (touch == null) { continue; } if (touch.x != pos.x || touch.y != pos.y) { touch.x = pos.x; touch.y = pos.y; if (touch.began) { touch.Move(); } } if (touch.lastRollOver != touch.target) { HandleRollOver(touch); } if (uTouch.phase == TouchPhase.Began) { if (!touch.began) { _touchCount++; touch.Begin(); touch.button = 0; this.focus = touch.target; touch.UpdateEvent(); touch.target.BubbleEvent("onTouchBegin", touch.evt); } } else if (uTouch.phase == TouchPhase.Canceled || uTouch.phase == TouchPhase.Ended) { if (touch.began) { _touchCount--; touch.End(); if (uTouch.phase != TouchPhase.Canceled) { DisplayObject clickTarget = touch.ClickTest(); if (clickTarget != null) { touch.clickCount = uTouch.tapCount; touch.UpdateEvent(); clickTarget.BubbleEvent("onClick", touch.evt); } } touch.target = null; HandleRollOver(touch); touch.touchId = -1; } } } }
void HandleMouseEvents() { TouchInfo touch = _touches[0]; if (touch.x != _touchPosition.x || touch.y != _touchPosition.y) { touch.x = _touchPosition.x; touch.y = _touchPosition.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); if (touch.lastRollOver != touch.target) { HandleRollOver(touch); } } if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2)) { if (!touch.began) { touch.began = true; _touchCount = 1; touch.clickCancelled = false; touch.downX = touch.x; touch.downY = touch.y; touch.downTarget = touch.target; touch.button = Input.GetMouseButtonDown(2) ? 2 : (Input.GetMouseButtonDown(1) ? 1 : 0); this.focus = touch.target; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchBegin.BubbleCall(touch.evt); } } } if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1) || Input.GetMouseButtonUp(2)) { if (touch.began) { touch.began = false; _touchCount = 0; if (touch.target != null) { touch.UpdateEvent(); touch.CallTouchEnd(); } DisplayObject clickTarget = clickTest(touch); if (clickTarget != null) { if (Time.realtimeSinceStartup - touch.lastClickTime < 0.35f) { if (touch.clickCount == 2) { touch.clickCount = 1; } else { touch.clickCount++; } } else { touch.clickCount = 1; } touch.lastClickTime = Time.realtimeSinceStartup; touch.UpdateEvent(); if (Input.GetMouseButtonUp(1)) { clickTarget.onRightClick.BubbleCall(touch.evt); } else { clickTarget.onClick.BubbleCall(touch.evt); } } } } }
void HandleCustomInput() { Vector2 pos = _customInputPos; pos.y = stageHeight - pos.y; TouchInfo touch = _touches[0]; if (touch.x != pos.x || touch.y != pos.y) { touch.x = pos.x; touch.y = pos.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); if (touch.lastRollOver != touch.target) { HandleRollOver(touch); } } if (_customInputButtonDown) { if (!touch.began) { touch.began = true; _touchCount = 1; touch.clickCancelled = false; touch.downX = touch.x; touch.downY = touch.y; touch.downTarget = touch.target; this.focus = touch.target; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchBegin.BubbleCall(touch.evt); } } } else if (touch.began) { touch.began = false; _touchCount = 0; if (touch.target != null) { touch.UpdateEvent(); touch.CallTouchEnd(); DisplayObject clickTarget = clickTest(touch); if (clickTarget != null) { if (Time.realtimeSinceStartup - touch.lastClickTime < 0.35f) { if (touch.clickCount == 2) { touch.clickCount = 1; } else { touch.clickCount++; } } else { touch.clickCount = 1; } touch.lastClickTime = Time.realtimeSinceStartup; touch.UpdateEvent(); clickTarget.onClick.BubbleCall(touch.evt); } } } }
void HandleTouchEvents() { for (int i = 0; i < Input.touchCount; ++i) { Touch uTouch = Input.GetTouch(i); if (uTouch.phase == TouchPhase.Stationary) { continue; } Vector2 pos = uTouch.position; pos.y = stageHeight - pos.y; TouchInfo touch = null; for (int j = 0; j < 5; j++) { if (_touches[j].touchId == uTouch.fingerId) { touch = _touches[j]; break; } } if (touch == null) { continue; } if (touch.x != pos.x || touch.y != pos.y) { touch.x = pos.x; touch.y = pos.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); //no rollover/rollout on mobile } if (uTouch.phase == TouchPhase.Began) { if (!touch.began) { touch.began = true; _touchCount++; touch.clickCancelled = false; touch.downX = touch.x; touch.downY = touch.y; this.focus = touch.target; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchBegin.BubbleCall(touch.evt); } } } else if (uTouch.phase == TouchPhase.Canceled || uTouch.phase == TouchPhase.Ended) { if (touch.began) { touch.began = false; _touchCount--; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchEnd.BubbleCall(touch.evt); if (!touch.clickCancelled && Mathf.Abs(touch.x - touch.downX) < 50 && Mathf.Abs(touch.y - touch.downY) < 50) { touch.clickCount = uTouch.tapCount; touch.UpdateEvent(); touch.target.onClick.BubbleCall(touch.evt); } } } touch.Reset(); } } }
void HandleMouseEvents() { TouchInfo touch = _touches[0]; if (touch.x != _touchPosition.x || touch.y != _touchPosition.y) { touch.x = _touchPosition.x; touch.y = _touchPosition.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); if (touch.lastRollOver != touch.target) { HandleRollOver(touch); } } if (Input.GetMouseButtonDown(0)) { if (!touch.began) { touch.began = true; _touchCount++; touch.clickCancelled = false; touch.downX = touch.x; touch.downY = touch.y; this.focus = touch.target; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchBegin.BubbleCall(touch.evt); } } } if (Input.GetMouseButtonUp(0)) { if (touch.began) { touch.began = false; _touchCount--; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchEnd.BubbleCall(touch.evt); if (!touch.clickCancelled && Mathf.Abs(touch.x - touch.downX) < 50 && Mathf.Abs(touch.y - touch.downY) < 50) { if (Time.realtimeSinceStartup - touch.lastClickTime < 0.35f) { if (touch.clickCount == 2) { touch.clickCount = 1; } else { touch.clickCount++; } } else { touch.clickCount = 1; } touch.lastClickTime = Time.realtimeSinceStartup; touch.UpdateEvent(); touch.target.onClick.BubbleCall(touch.evt); } } } } if (Input.GetMouseButtonUp(1)) { if (touch.target != null) { touch.UpdateEvent(); touch.target.onRightClick.BubbleCall(touch.evt); } } }
internal void HandleMouseEvents(int iX, int iY, EHARDWAREMOUSEEVENT eHardwareMouseEvent, int wheelDelta) { if (wheelDelta != 0) { if (_touchTarget != null) { _touchInfo.mouseWheelDelta = -wheelDelta; _touchInfo.UpdateEvent(); _touchTarget.onMouseWheel.BubbleCall(_touchInfo.evt); _touchInfo.mouseWheelDelta = 0; } return; } _touchPosition = new Vector2(iX, iY); _touchTarget = HitTest(_touchPosition, true); _touchInfo.target = _touchTarget; if (_touchInfo.x != _touchPosition.x || _touchInfo.y != _touchPosition.y) { _touchInfo.x = _touchPosition.x; _touchInfo.y = _touchPosition.y; _touchInfo.Move(); } if (_touchInfo.lastRollOver != _touchInfo.target) { HandleRollOver(_touchInfo); } if (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONDOWN || eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONDOWN || eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_MBUTTONDOWN || eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONDOUBLECLICK) { if (!_touchInfo.began) { _touchInfo.Begin(); _touchInfo.button = (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONDOWN || eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONDOUBLECLICK) ? 0 : (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONDOWN ? 1 : 2); this.focus = _touchInfo.target; _touchInfo.UpdateEvent(); _touchInfo.target.BubbleEvent("onTouchBegin", _touchInfo.evt); } } if (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONUP || eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONUP || eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_MBUTTONUP) { if (_touchInfo.began) { _touchInfo.button = eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONUP ? 0 : (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONUP ? 1 : 2); _touchInfo.End(); DisplayObject clickTarget = _touchInfo.ClickTest(); if (clickTarget != null) { _touchInfo.UpdateEvent(); if (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONUP) { clickTarget.BubbleEvent("onRightClick", _touchInfo.evt); } else { clickTarget.BubbleEvent("onClick", _touchInfo.evt); } } _touchInfo.button = -1; } } }
void HandleTouchEvents() { for (int i = 0; i < Input.touchCount; ++i) { Touch uTouch = Input.GetTouch(i); if (uTouch.phase == TouchPhase.Stationary) { continue; } bool hitTested = false; Vector2 touchPosition = uTouch.position; touchPosition.y = stageHeight - touchPosition.y; TouchInfo touch = null; for (int j = 0; j < 5; j++) { if (_touches[j].touchId == uTouch.fingerId) { touch = _touches[j]; break; } if (_touches[j].touchId == -1) { touch = _touches[j]; } } if (touch == null) { continue; } touch.touchId = uTouch.fingerId; mouseX = touchPosition.x; mouseY = touchPosition.y; if (touch.x != mouseX || touch.y != mouseY) { touch.x = mouseX; touch.y = mouseY; _objectUnderMouse = HitTest(touchPosition, true); hitTested = true; touch.target = _objectUnderMouse; touch.UpdateEvent(); onMouseMove.Call(touch.evt); //no rollover/rollout on mobile //if (evt.lastRollOver != _objectUnderMouse) //HandleRollOver(evt); } if (uTouch.phase == TouchPhase.Began) { if (!touch.began) { touch.began = true; touch.clickCancelled = false; touch.downX = touch.x; touch.downY = touch.y; if (!hitTested) { _objectUnderMouse = HitTest(touchPosition, true); hitTested = true; touch.target = _objectUnderMouse; } this.focus = _objectUnderMouse; if (_objectUnderMouse != null) { touch.UpdateEvent(); _objectUnderMouse.onMouseDown.BubbleCall(touch.evt); } } } else if (uTouch.phase == TouchPhase.Canceled || uTouch.phase == TouchPhase.Ended) { if (touch.began) { touch.began = false; if (!hitTested) { _objectUnderMouse = HitTest(touchPosition, true); hitTested = true; touch.target = _objectUnderMouse; } if (_objectUnderMouse != null) { touch.UpdateEvent(); _objectUnderMouse.onMouseUp.BubbleCall(touch.evt); if (!touch.clickCancelled && Mathf.Abs(touch.x - touch.downX) < 50 && Mathf.Abs(touch.y - touch.downY) < 50) { touch.clickCount = uTouch.tapCount; touch.UpdateEvent(); _objectUnderMouse.onClick.BubbleCall(touch.evt); } } } touch.Reset(); } } }
void HandleMouseEvents() { bool hitTested = false; Vector2 mousePosition = Input.mousePosition; mousePosition.y = stageHeight - mousePosition.y; TouchInfo touch = _touches[0]; if (mousePosition.x >= 0 && mousePosition.y >= 0) { if (touch.x != mousePosition.x || touch.y != mousePosition.y) { mouseX = mousePosition.x; mouseY = mousePosition.y; touch.x = mouseX; touch.y = mouseY; _objectUnderMouse = HitTest(mousePosition, true); hitTested = true; touch.target = _objectUnderMouse; touch.UpdateEvent(); onMouseMove.Call(touch.evt); if (touch.lastRollOver != _objectUnderMouse) { HandleRollOver(touch); } } } else { mousePosition = new Vector2(mouseX, mouseY); } if (Input.GetMouseButtonDown(0)) { if (!touch.began) { touch.began = true; touch.clickCancelled = false; touch.downX = touch.x; touch.downY = touch.y; if (!hitTested) { _objectUnderMouse = HitTest(mousePosition, true); hitTested = true; touch.target = _objectUnderMouse; } this.focus = _objectUnderMouse; if (_objectUnderMouse != null) { touch.UpdateEvent(); _objectUnderMouse.onMouseDown.BubbleCall(touch.evt); } } } if (Input.GetMouseButtonUp(0)) { if (touch.began) { touch.began = false; if (!hitTested) { _objectUnderMouse = HitTest(mousePosition, true); hitTested = true; touch.target = _objectUnderMouse; } if (_objectUnderMouse != null) { touch.UpdateEvent(); _objectUnderMouse.onMouseUp.BubbleCall(touch.evt); if (!touch.clickCancelled && Mathf.Abs(touch.x - touch.downX) < 10 && Mathf.Abs(touch.y - touch.downY) < 10) { if (Time.realtimeSinceStartup - touch.lastClickTime < 0.35f) { if (touch.clickCount == 2) { touch.clickCount = 1; } else { touch.clickCount++; } } else { touch.clickCount = 1; } touch.lastClickTime = Time.realtimeSinceStartup; touch.UpdateEvent(); _objectUnderMouse.onClick.BubbleCall(touch.evt); } } } } if (Input.GetMouseButtonUp(1)) { if (!hitTested) { _objectUnderMouse = HitTest(mousePosition, true); hitTested = true; touch.target = _objectUnderMouse; } if (_objectUnderMouse != null) { touch.UpdateEvent(); _objectUnderMouse.onRightClick.BubbleCall(touch.evt); } } }