protected override void Update(float dt) { DragEvent de = MouseTouch.Drag; switch (DirectionScroable) { case ScrollDirection.Vertical: if (de.Active) { if (Math.Abs(de.Delta.X) < Math.Abs(de.Delta.Y)) { ScrollOffset.X += de.Delta.X; } } break; case ScrollDirection.Horizontal: if (de.Active) { if (Math.Abs(de.Delta.X) > Math.Abs(de.Delta.Y)) { ScrollOffset.X += de.Delta.X; } } break; case ScrollDirection.None: ScrollOffset = Vector2.Zero; break; } }
public override void handleDragEvent(DragEvent e) { if (e.state != DragState.DRAG || !isDrag) { return; } object o = e.getParam(ClickAndDragTranslate.PARAM_DRAG_STRENGTH); if (!(o is Vector3)) { throw new Exception("Expected velocity to be of type Vector3"); } Vector3 v = (Vector3)o; // This finds the length of the component of v which is parallel to maxVelocity float speed = Vector3.Dot(v, maxVelocity.normalized); Vector3 force = maxVelocity.normalized * speed; force = force * maxVelocity.magnitude; if (capForce > 0 && force.magnitude > capForce) { force = force.normalized * capForce; } child.constantForce.force = transform.TransformDirection(force); }
public bool OnDrag(View view, DragEvent e) { switch (e.Action) { case DragAction.Started: return(true); case DragAction.Entered: return(true); case DragAction.Exited: return(true); case DragAction.Drop: objVehicleMarkDamageDetails = rentRunningTrans.RentVehicleDamage.Where(x => x.DamageNumber == Convert.ToInt32(e.ClipData.GetItemAt(0).Text)).First(); objVehicleMarkDamageDetails.DamageLocationX = (int)e.GetX(); objVehicleMarkDamageDetails.DamageLocationY = (int)e.GetY(); this.DrawDamageCircle(objVehicleMarkDamageDetails); //view.Visibility = (ViewStates.Invisible); //droppedIndex = Convert.ToInt16(view.GetTag(Resource.String.keyval)); ; return(true); case DragAction.Ended: return(true); } return(false); }
/// <summary> /// Invoke /// </summary> public bool OnDrag(View view, DragEvent args) { var dragEventArgs = new DragEventArgs(args); Invoke(view, dragEventArgs); return(dragEventArgs.IsHandled); }
private void dragInProgress(DragEvent e) { Vector2[] oldControlPoints = slider.Path.ControlPoints.Select(cp => cp.Position).ToArray(); var oldPosition = slider.Position; double oldStartTime = slider.StartTime; if (selectedControlPoints.Contains(slider.Path.ControlPoints[0])) { // Special handling for selections containing head control point - the position of the slider changes which means the snapped position and time have to be taken into account Vector2 newHeadPosition = Parent.ToScreenSpace(e.MousePosition + (dragStartPositions[0] - dragStartPositions[draggedControlPointIndex])); var result = snapProvider?.SnapScreenSpacePositionToValidTime(newHeadPosition); Vector2 movementDelta = Parent.ToLocalSpace(result?.ScreenSpacePosition ?? newHeadPosition) - slider.Position; slider.Position += movementDelta; slider.StartTime = result?.Time ?? slider.StartTime; for (int i = 1; i < slider.Path.ControlPoints.Count; i++) { var controlPoint = slider.Path.ControlPoints[i]; // Since control points are relative to the position of the slider, all points that are _not_ selected // need to be offset _back_ by the delta corresponding to the movement of the head point. // All other selected control points (if any) will move together with the head point // (and so they will not move at all, relative to each other). if (!selectedControlPoints.Contains(controlPoint)) { controlPoint.Position -= movementDelta; } } } else { for (int i = 0; i < controlPoints.Count; ++i) { var controlPoint = controlPoints[i]; if (selectedControlPoints.Contains(controlPoint)) { controlPoint.Position = dragStartPositions[i] + (e.MousePosition - e.MouseDownPosition); } } } if (!slider.Path.HasValidLength) { for (int i = 0; i < slider.Path.ControlPoints.Count; i++) { slider.Path.ControlPoints[i].Position = oldControlPoints[i]; } slider.Position = oldPosition; slider.StartTime = oldStartTime; return; } // Maintain the path types in case they got defaulted to bezier at some point during the drag. for (int i = 0; i < slider.Path.ControlPoints.Count; i++) { slider.Path.ControlPoints[i].Type = dragPathTypes[i]; } }
private void RearrangeCards(int selectedCardIndex, DragEvent e) { var newIndex = GetCardIndexFromYPosition(Cards[selectedCardIndex].Y); Cards.Swap(selectedCardIndex, newIndex); stepList.SetLayoutPosition(Cards[selectedCardIndex], newIndex); }
protected override void OnDrag(DragEvent e) { base.OnDrag(e); ScreenSpaceDragPosition = e.ScreenSpaceMousePosition; DragPosition = DrawableObject.ToLocalSpace(e.ScreenSpaceMousePosition); }
/// <summary> /// Moves the current selected blueprints. /// </summary> /// <param name="e">The <see cref="DragEvent"/> defining the movement event.</param> /// <returns>Whether a movement was active.</returns> private bool moveCurrentSelection(DragEvent e) { if (movementBlueprints == null) { return(false); } if (snapProvider == null) { return(true); } Debug.Assert(movementBlueprintOriginalPositions != null); Vector2 distanceTravelled = e.ScreenSpaceMousePosition - e.ScreenSpaceMouseDownPosition; // check for positional snap for every object in selection (for things like object-object snapping) for (var i = 0; i < movementBlueprintOriginalPositions.Length; i++) { var testPosition = movementBlueprintOriginalPositions[i] + distanceTravelled; var positionalResult = snapProvider.SnapScreenSpacePositionToValidPosition(testPosition); if (positionalResult.ScreenSpacePosition == testPosition) { continue; } // attempt to move the objects, and abort any time based snapping if we can. if (SelectionHandler.HandleMovement(new MoveSelectionEvent(movementBlueprints[i], positionalResult.ScreenSpacePosition))) { return(true); } } // if no positional snapping could be performed, try unrestricted snapping from the earliest // hitobject in the selection. // The final movement position, relative to movementBlueprintOriginalPosition. Vector2 movePosition = movementBlueprintOriginalPositions.First() + distanceTravelled; // Retrieve a snapped position. var result = snapProvider.SnapScreenSpacePositionToValidTime(movePosition); // Move the hitobjects. if (!SelectionHandler.HandleMovement(new MoveSelectionEvent(movementBlueprints.First(), result.ScreenSpacePosition))) { return(true); } if (result.Time.HasValue) { // Apply the start time at the newly snapped-to position double offset = result.Time.Value - movementBlueprints.First().HitObject.StartTime; Beatmap.PerformOnSelection(obj => obj.StartTime += offset); } return(true); }
/// <summary> /// /// </summary> /// <param name="startpos"> 拖动起始位置</param> /// <param name="dir">方向</param> /// <param name="duration">持续时间</param> public static void Drag(Point startpos, Vector2 dir, int duration, DragEvent callback = null) { mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN, (int)startpos.X * 65536 / GameCapture.SW, (int)startpos.Y * 65536 / GameCapture.SH, 0, 0); int timeCount = 0; System.Windows.Forms.Timer timerFingerMove = new System.Windows.Forms.Timer(); timerFingerMove.Interval = 1; timerFingerMove.Enabled = true; timerFingerMove.Start(); timerFingerMove.Tick += (sen, eve) => { if (timeCount < duration) { timeCount++; mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, ((int)startpos.X + (int)(dir.X * timeCount)) * 65536 / GameCapture.SW, ((int)startpos.Y + (int)(dir.Y * timeCount)) * 65536 / GameCapture.SH, 0, 0); } else { ((System.Windows.Forms.Timer)sen).Stop(); ((System.Windows.Forms.Timer)sen).Dispose(); mouse_event(MOUSEEVENTF_LEFTUP, (0) * 65536 / GameCapture.SW, (0) * 65536 / GameCapture.SH, 0, 0); if (callback != null) { callback(); } } }; }
private void performDragMovement(DragEvent dragEvent) { foreach (var b in SelectedBlueprints) { var hitObject = b.HitObject; var objectParent = (HitObjectContainer)hitObject.Parent; // Using the hitobject position is required since AdjustPosition can be invoked multiple times per frame // without the position having been updated by the parenting ScrollingHitObjectContainer hitObject.Y += dragEvent.Delta.Y; float targetPosition; // If we're scrolling downwards, a position of 0 is actually further away from the hit target // so we need to flip the vertical coordinate in the hitobject container's space if (scrollingInfo.Direction.Value == ScrollingDirection.Down) { targetPosition = -hitObject.Position.Y; } else { targetPosition = hitObject.Position.Y; } objectParent.Remove(hitObject); hitObject.HitObject.StartTime = scrollingInfo.Algorithm.TimeAt(targetPosition, editorClock.CurrentTime, scrollingInfo.TimeRange.Value, objectParent.DrawHeight); objectParent.Add(hitObject); } }
public void HandleDragHoverChild(DragEvent evt, int index) { if (evt is TestDragEvent textEvt) { dragList.Add($"hover:child{index}:{textEvt.sourceName}"); } }
protected override void OnDrag(DragEvent e) { if (ControlPoint == slider.Path.ControlPoints[0]) { // Special handling for the head control point - the position of the slider changes which means the snapped position and time have to be taken into account var result = snapProvider?.SnapScreenSpacePositionToValidTime(e.ScreenSpaceMousePosition); Vector2 movementDelta = Parent.ToLocalSpace(result?.ScreenSpacePosition ?? e.ScreenSpaceMousePosition) - slider.Position; slider.Position += movementDelta; slider.StartTime = result?.Time ?? slider.StartTime; // Since control points are relative to the position of the slider, they all need to be offset backwards by the delta for (int i = 1; i < slider.Path.ControlPoints.Count; i++) { slider.Path.ControlPoints[i].Position.Value -= movementDelta; } } else { ControlPoint.Position.Value = dragStartPosition + (e.MousePosition - e.MouseDownPosition); } // Maintain the path type in case it got defaulted to bezier at some point during the drag. PointsInSegment[0].Type.Value = dragPathType; }
public override void handleDragEvent(DragEvent e) { if (e.state == DragState.DRAG) { if (handle.constantForce.force.x < 0 && prevForce.x > 0) handleBang.Play(); prevForce = handle.constantForce.force; } Vector3 v = (Vector3) e.getParam(ClickAndDragTranslate.PARAM_VELOCITY); if (v.magnitude >= MIN_V_TRIGGER) { strengthenSlide(); } if (v.magnitude == 0) { if (startRest == -1) { startRest = Time.time; } else if (Time.time - startRest >= MIN_REST_TRIGGER) { stopSlide(); } } else { startRest = -1; // check for "impact" in the x direction Vector3 newP = (Vector3) e.getParam(ClickAndDragTranslate.PARAM_NEW_P); Vector3 desiredNewP = (Vector3) e.getParam(ClickAndDragTranslate.PARAM_DESIRED_NEW_P); if (newP.x != desiredNewP.x) { drawerBang.volume = Mathf.Clamp(v.magnitude / 50, 0.0f, 1.0f); drawerBang.Play(); } } }
protected override bool doSnap(DragEvent toPopulate, int snapToIndex) { Vector3 direction = snapTo[snapToIndex] - transform.localPosition; v = direction.normalized * speed; speed += a * Time.deltaTime; //Populate event toPopulate.putParam(PARAM_VELOCITY, v); toPopulate.putParam(PARAM_OLD_P, transform.position); Vector3 desiredNewP; bool retVal; if (v.magnitude * Time.deltaTime + 0.001 >= direction.magnitude) { desiredNewP = snapTo[snapToIndex]; retVal = true; } else { desiredNewP = (v * Time.deltaTime) + transform.localPosition; retVal = false; } setPosition(desiredNewP); toPopulate.putParam(PARAM_DESIRED_NEW_P, desiredNewP); toPopulate.putParam(PARAM_NEW_P, transform.position); return retVal; }
protected override bool OnDrag(DragEvent e) { cameraOffsetBindable.Value += e.Delta; foreach (var child in Children) { if (child is IDraggable draggable) { if (draggable.Draggable) { child.Position += e.Delta; } } if (child is Grid grid) { grid.Position = new Vector2( -GetCoordinate(cameraOffsetBindable.Value.X) + cameraOffsetBindable.Value.X, -GetCoordinate(cameraOffsetBindable.Value.Y) + cameraOffsetBindable.Value.Y); } if (child is GridOrigin gridOrigin) { gridOrigin.GridOriginPosition = new Vector2( -GetCoordinate(cameraOffsetBindable.Value.X) + cameraOffsetBindable.Value.X, -GetCoordinate(cameraOffsetBindable.Value.Y) + cameraOffsetBindable.Value.Y); } } return(true); }
static void Drag2_end(Vector2 endPos, DragEvent callback = null) { //鼠标原地随机移动一下 int timeCount = 0; System.Windows.Forms.Timer timerFingerMove = new System.Windows.Forms.Timer(); timerFingerMove.Interval = 1; timerFingerMove.Enabled = true; timerFingerMove.Start(); timerFingerMove.Tick += (sen, eve) => { if (timeCount < 50) { timeCount++; Random rd = new Random(); int tempx = rd.Next((int)endPos.X, (int)endPos.X + 10); mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, tempx * 65536 / GameCapture.SW, ((int)endPos.Y) * 65536 / GameCapture.SH, 0, 0); } else { ((System.Windows.Forms.Timer)sen).Stop(); ((System.Windows.Forms.Timer)sen).Dispose(); mouse_event(MOUSEEVENTF_LEFTUP, ((int)endPos.X) * 65536 / GameCapture.SW, ((int)endPos.Y) * 65536 / GameCapture.SH, 0, 0); if (callback != null) { callback(); } } }; }
private void handleScrollViaDrag(DragEvent e) { lastDragEvent = e; if (lastDragEvent == null) { return; } if (timeline != null) { var timelineQuad = timeline.ScreenSpaceDrawQuad; var mouseX = e.ScreenSpaceMousePosition.X; // scroll if in a drag and dragging outside visible extents if (mouseX > timelineQuad.TopRight.X) { timeline.ScrollBy((float)((mouseX - timelineQuad.TopRight.X) / 10 * Clock.ElapsedFrameTime)); } else if (mouseX < timelineQuad.TopLeft.X) { timeline.ScrollBy((float)((mouseX - timelineQuad.TopLeft.X) / 10 * Clock.ElapsedFrameTime)); } } }
public bool OnDrag(View v, DragEvent e) { switch (e.Action) { case DragAction.Entered: break; case DragAction.Exited: break; case DragAction.Ended: break; case DragAction.Drop: View dropView = (View)e.LocalState; if (dropView.Parent is ListView) { if (((ListView)dropView.Parent).Adapter is CharacterListAdapter) { CharacterListAdapter dropAd = (CharacterListAdapter)((ListView)dropView.Parent).Adapter; Character dropChar = dropAd[(int)dropView.Tag]; CombatFragment.CombatState.MoveDroppedCharacter(dropChar, null, _monsters); } } break; } return(true); }
/// <summary> /// Moves the current selected blueprints. /// </summary> /// <param name="e">The <see cref="DragEvent"/> defining the movement event.</param> /// <returns>Whether a movement was active.</returns> private bool moveCurrentSelection(DragEvent e) { if (movementBlueprint == null) { return(false); } Debug.Assert(movementBlueprintOriginalPosition != null); HitObject draggedObject = movementBlueprint.HitObject; // The final movement position, relative to screenSpaceMovementStartPosition Vector2 movePosition = movementBlueprintOriginalPosition.Value + e.ScreenSpaceMousePosition - e.ScreenSpaceMouseDownPosition; (Vector2 snappedPosition, double snappedTime) = snapProvider.GetSnappedPosition(ToLocalSpace(movePosition), draggedObject.StartTime); // Move the hitobjects if (!selectionHandler.HandleMovement(new MoveSelectionEvent(movementBlueprint, ToScreenSpace(snappedPosition)))) { return(true); } // Apply the start time at the newly snapped-to position double offset = snappedTime - draggedObject.StartTime; foreach (HitObject obj in selectionHandler.SelectedHitObjects) { obj.StartTime += offset; } return(true); }
protected override bool OnDrag(DragEvent e) { var newControlPoints = slider.Path.ControlPoints.ToArray(); if (index == 0) { // Special handling for the head - only the position of the slider changes slider.Position += e.Delta; // Since control points are relative to the position of the slider, they all need to be offset backwards by the delta for (int i = 1; i < newControlPoints.Length; i++) { newControlPoints[i] -= e.Delta; } } else { newControlPoints[index] += e.Delta; } if (isSegmentSeparatorWithNext) { newControlPoints[index + 1] = newControlPoints[index]; } if (isSegmentSeparatorWithPrevious) { newControlPoints[index - 1] = newControlPoints[index]; } slider.Path = new SliderPath(slider.Path.Type, newControlPoints); return(true); }
private void BeginDrag() { if (currentDragEvent != null) { return; } if (m_MouseDownElements.size == 0) { return; } mouseState.leftMouseButtonState.isDrag = mouseState.isLeftMouseDown; mouseState.rightMouseButtonState.isDrag = mouseState.isRightMouseDown; mouseState.middleMouseButtonState.isDrag = mouseState.isMiddleMouseDown; IsDragging = true; m_EventPropagator.Reset(mouseState); m_EventPropagator.origin = m_MouseDownElements.array[0]; for (int i = 0; i < m_MouseDownElements.Count; i++) { UIElement element = m_MouseDownElements[i]; if (element.isDestroyed || element.isDisabled || element.inputHandlers == null) { continue; } if ((element.inputHandlers.handledEvents & InputEventType.DragCreate) == 0) { continue; } for (int creatorIndex = 0; creatorIndex < element.inputHandlers.dragCreators.size; creatorIndex++) { InputHandlerGroup.DragCreatorData data = element.inputHandlers.dragCreators.array[creatorIndex]; currentDragEvent = data.handler.Invoke(new MouseInputEvent(m_EventPropagator, InputEventType.DragCreate, m_KeyboardState.modifiersThisFrame, false, element)); if (currentDragEvent != null) { currentDragEvent.StartTime = Time.realtimeSinceStartup; currentDragEvent.DragStartPosition = MousePosition; currentDragEvent.origin = element; currentDragEvent.Begin(); UpdateDrag(true); return; } } } if (currentDragEvent == null) { IsDragging = false; } // todo -- capture phase }
// ---------------------------------------------------------------------------------------------------------------- // Executes after the user initiates a Drag event. // Whilst the drag is still in progress // Reference: https://forums.xamarin.com/discussion/63590/drag-and-drop-in-android-c public bool OnDrag(View v, DragEvent args) { switch (args.Action) { case DragAction.Entered: return(true); case DragAction.Exited: return(true); case DragAction.Ended: // Essentially if the Player moves the disk out of the game screen // the disk will disappear; returnDiskToPlacement(args); return(true); case DragAction.Started: return(true); case DragAction.Drop: // Parameter v is of type LinearLayout and is defined as the dropzone // the new disk will be added to. allowableMove(v); return(true); default: return(false); } }
/// <summary> /// Moves the current selected blueprints. /// </summary> /// <param name="e">The <see cref="DragEvent"/> defining the movement event.</param> /// <returns>Whether a movement was active.</returns> private bool moveCurrentSelection(DragEvent e) { if (movementBlueprint == null) { return(false); } Debug.Assert(movementBlueprintOriginalPosition != null); HitObject draggedObject = movementBlueprint.HitObject; // The final movement position, relative to movementBlueprintOriginalPosition. Vector2 movePosition = movementBlueprintOriginalPosition.Value + e.ScreenSpaceMousePosition - e.ScreenSpaceMouseDownPosition; // Retrieve a snapped position. var result = snapProvider.SnapScreenSpacePositionToValidTime(movePosition); // Move the hitobjects. if (!selectionHandler.HandleMovement(new MoveSelectionEvent(movementBlueprint, result.ScreenSpacePosition))) { return(true); } if (result.Time.HasValue) { // Apply the start time at the newly snapped-to position double offset = result.Time.Value - draggedObject.StartTime; foreach (HitObject obj in selectionHandler.SelectedHitObjects) { obj.StartTime += offset; } } return(true); }
protected override void OnDrag(DragEvent e) { if (placementControlPoint != null) { placementControlPoint.Position = e.MousePosition - HitObject.Position; } }
public static Point GetTouchPositionFromDragEvent(View item, DragEvent e) { Rect rItem = new Rect(); item.GetGlobalVisibleRect(rItem); return(new Point(rItem.Left + (int)Math.Round(e.GetX()), rItem.Top + (int)Math.Round(e.GetY()))); }
public override void HandleDrag(SelectionBlueprint blueprint, DragEvent dragEvent) { adjustOrigins((CrossSelectionBlueprint)blueprint); performDragMovement(dragEvent); performColumnMovement(dragEvent); base.HandleDrag(blueprint, dragEvent); }
private float convertDragEventToAngleOfRotation(DragEvent e) { // Adjust coordinate system to the center of SelectionBox float startAngle = MathF.Atan2(e.LastMousePosition.Y - selectionBox.DrawHeight / 2, e.LastMousePosition.X - selectionBox.DrawWidth / 2); float endAngle = MathF.Atan2(e.MousePosition.Y - selectionBox.DrawHeight / 2, e.MousePosition.X - selectionBox.DrawWidth / 2); return((endAngle - startAngle) * 180 / MathF.PI); }
protected override void OnDrag(DragEvent e) { if (!CanUpdateAnchor(Editor)) { return; } Note.UpdateCoordinates(Editor.MousePosition); }
protected override bool OnDrag(DragEvent e) { Debug.Assert(placementControlPointIndex != null); HitObject.Path.ControlPoints[placementControlPointIndex.Value].Position.Value = e.MousePosition - HitObject.Position; return(true); }
protected override void OnDrag(DragEvent e) { if (!DelayDrag) { UpdateSlider(e.ScreenSpaceMousePosition); DelayDrag = true; } }
protected override bool OnDrag(DragEvent e) { Position += e.Delta; audio.Balance.Value = X / 100f; audio.Frequency.Value = 1 - Y / 100f; return(true); }
protected override void OnDrag(DragEvent e) { Vector2 mousePosition = ToRelativePosition(e.ScreenSpaceMousePosition); double timeDelta = PositionToTime(mousePosition.Y) - PositionToTime(dragStartPosition.Y); float xDelta = mousePosition.X - dragStartPosition.X; MoveSelectedVertices(timeDelta, xDelta); }
protected override void doDrag(DragEvent toPopulate, Vector3 dragStartMousePosition, Vector3 currentMousePosition) { float dY = (currentMousePosition - dragStartMousePosition).y / ((float) Screen.height); float dTime = dAnimationTimePerDMouseY * dY * animation[animName].length; animation[animName].time = Mathf.Clamp(dragStartAnimPos + dTime, 0.0f, animation[animName].length); animation[animName].speed = 0; animation.Play(animName); }
protected override bool doSnap(DragEvent toPopulate, int snapToIndex) { float percent = (Time.time - snapStartTime) / snapDuration; if (percent >= 1) { if (sound != null) sound.Stop(); setVisualState(snapToIndex); return true; } setRotation(Quaternion.Slerp(snapStartRotation, snapTo[snapToIndex], percent)); return false; }
protected override void doDrag(DragEvent toPopulate, Vector3 dragStartMousePosition, Vector3 currentMousePosition) { Quaternion oldR = transform.localRotation; Quaternion desiredNewR = Quaternion.Euler(getDirection(currentMousePosition).eulerAngles + dDragRotation); setRotation(desiredNewR); Quaternion newR = transform.localRotation; toPopulate.putParam(PARAM_OLD_R, oldR); toPopulate.putParam(PARAM_NEW_R, newR); toPopulate.putParam(PARAM_DESIRED_NEW_R, desiredNewR); // toPopulate.putParam(PARAM_D_ROTATION_X, dX); // toPopulate.putParam(PARAM_D_ROTATION_Y, dY); // toPopulate.putParam(PARAM_D_ROTATION_Z, dZ); }
protected override bool doSnap(DragEvent toPopulate, int snapToIndex) { float t = animation[animName].time; bool done = (animation[animName].speed > 0 && (t >= snapTo[snapToIndex] || t == 0)) || (animation[animName].speed < 0 && t <= snapTo[snapToIndex]); if (done) { animation[animName].time = snapTo[snapToIndex]; animation[animName].speed = 0; animation.Play(animName); } return done; }
public override void handleDragEvent(DragEvent e) { if (e.state == DragState.DRAG) { float dBaseX = (float) e.getParam(ClickAndDragRotate.PARAM_D_ROTATION_X); float dBaseY = (float) e.getParam(ClickAndDragRotate.PARAM_D_ROTATION_Y); float dBaseZ = (float) e.getParam(ClickAndDragRotate.PARAM_D_ROTATION_Z); float dX = (dXPerDBaseX * dBaseX) + (dXPerDBaseY * dBaseY) + (dXPerDBaseZ * dBaseZ); float dY = (dYPerDBaseX * dBaseX) + (dYPerDBaseY * dBaseY) + (dYPerDBaseZ * dBaseZ); float dZ = (dZPerDBaseX * dBaseX) + (dZPerDBaseY * dBaseY) + (dZPerDBaseZ * dBaseZ); Vector3 newR = getNewRotation(dX, dY, dZ); toRotate.transform.localRotation = Quaternion.Euler(newR); } }
protected override void doDrag(DragEvent toPopulate, Vector3 dragStartMousePosition, Vector3 currentMousePosition) { //Vector3 mouseP = CameraController.instance.camera.cameraToWorldMatrix.MultiplyPoint(currentMousePosition); float dMouseX = currentMousePosition.x - dragStartMousePosition.x; float dMouseY = currentMousePosition.y - dragStartMousePosition.y; float fX = (fXPerDMouseX * dMouseX) + (fXPerDMouseY * dMouseY); float fY = (fYPerDMouseX * dMouseX) + (fYPerDMouseY * dMouseY); float fZ = (fZPerDMouseX * dMouseX) + (fZPerDMouseY * dMouseY); Vector3 force = new Vector3(fX, fY, fZ); this.constantForce.force = force; //Populate event toPopulate.putParam(PARAM_FORCE, force); }
protected override bool doSnap(DragEvent toPopulate, int snapToIndex) { if ((snapTo[snapToIndex] - transform.localPosition).magnitude <= 0.001) { constantForce.force = Vector3.zero; transform.position = snapTo[snapToIndex]; return true; } Vector3 force = new Vector3(0, 0, 0); foreach (Vector3 v in snapTo) { Vector3 distance = v - transform.localPosition; Vector3 fCurrent = distance.normalized / (float) Math.Pow(distance.magnitude, 2); force = force + fCurrent; } this.constantForce.force = force; return false; }
public override void handleDragEvent(DragEvent e) { if (e.state != DragState.DRAG || !isDrag) return; object o = e.getParam(ClickAndDragTranslate.PARAM_DRAG_STRENGTH); if (!(o is Vector3)) throw new Exception("Expected velocity to be of type Vector3"); Vector3 v = (Vector3) o; // This finds the length of the component of v which is parallel to maxVelocity float speed = Vector3.Dot(v, maxVelocity.normalized); Vector3 force = maxVelocity.normalized * speed; force = force * maxVelocity.magnitude; if (capForce > 0 && force.magnitude > capForce) force = force.normalized * capForce; child.constantForce.force = transform.TransformDirection(force); }
protected override void doDrag(DragEvent toPopulate, Vector3 dragStartMousePosition, Vector3 currentMousePosition) { float dMouseX = currentMousePosition.x - dragStartMousePosition.x; float dMouseY = currentMousePosition.y - dragStartMousePosition.y; float dX = (dXPerDMouseX * dMouseX) + (dXPerDMouseY * dMouseY); float dY = (dYPerDMouseX * dMouseX) + (dYPerDMouseY * dMouseY); float dZ = (dZPerDMouseX * dMouseX) + (dZPerDMouseY * dMouseY); Quaternion oldR = transform.localRotation; Vector3 newRotation = getNewRotation(dX, dY, dZ); Quaternion desiredNewR = Quaternion.Euler(newRotation); setRotation(desiredNewR); Quaternion newR = transform.localRotation; toPopulate.putParam(PARAM_OLD_R, oldR); toPopulate.putParam(PARAM_NEW_R, newR); toPopulate.putParam(PARAM_DESIRED_NEW_R, desiredNewR); toPopulate.putParam(PARAM_D_ROTATION_X, dX); toPopulate.putParam(PARAM_D_ROTATION_Y, dY); toPopulate.putParam(PARAM_D_ROTATION_Z, dZ); }
protected override void doDrag(DragEvent toPopulate, Vector3 dragStartMousePosition, Vector3 currentMousePosition) { float dMouseX = currentMousePosition.x - dragStartMousePosition.x; float dMouseY = currentMousePosition.y - dragStartMousePosition.y; float dX = (dXPerDMouseX * dMouseX) + (dXPerDMouseY * dMouseY); float dY = (dYPerDMouseX * dMouseX) + (dYPerDMouseY * dMouseY); float dZ = (dZPerDMouseX * dMouseX) + (dZPerDMouseY * dMouseY); Vector3 oldP = transform.localPosition; Vector3 desiredNewP = new Vector3(p.x + dX, p.y + dY, p.z + dZ); setPosition(desiredNewP); Vector3 newP = transform.localPosition; //Update velocity v = (newP - oldP) / Time.deltaTime; //Populate event toPopulate.putParam(PARAM_VELOCITY, this.isActive ? v : new Vector3(0, 0, 0)); toPopulate.putParam(PARAM_DRAG_STRENGTH, (desiredNewP - oldP) / Time.deltaTime); toPopulate.putParam(PARAM_OLD_P, oldP); toPopulate.putParam(PARAM_DESIRED_NEW_P, desiredNewP); toPopulate.putParam(PARAM_NEW_P, this.isActive ? newP : oldP); }
private void DragDropped() { foreach (Droppable d in mDroppables.Values) { bool hit = IsHit(d, (int)mX, (int)mY); int ev = d.OnUpEvent(hit); DragEvent dragEvent = new DragEvent(mDragBundle, ev, (int) mX, (int) mY); d.Listener.OnDrag(d.View, dragEvent); } Invalidate(); }
private void DragAborted() { DragEvent dragEnded = new DragEvent(mDragBundle, DragEvent.ACTION_DRAG_ENDED, 0, 0); foreach (Droppable d in mDroppables.Values) { d.Listener.OnDrag(d.View, dragEnded); } mDrag = false; Invalidate(); }
private void DragStarted(Bundle dragBundle) { if (mDrag) DragAborted(); mDragBundle = dragBundle; DragEvent dragStarted = new DragEvent(mDragBundle, DragEvent.ACTION_DRAG_STARTED, 0, 0); foreach (Droppable d in mDroppables.Values) { d.Listener.OnDrag(d.View, dragStarted); } mDrag = true; }
public override bool onDrag(View v, DragEvent @event) { if ((@event.LocalState is View) && ((View) @event.LocalState).Id == v.Context.GetHashCode()) { if (DragEvent.ACTION_DROP == @event.Action) { float x = @event.X; float y = @event.Y; int alignment = outerInstance.getBorder(x, y); outerInstance.putBarOnBoard(alignment); outerInstance.mRecyclerView.scrollToPosition(0); } else if (DragEvent.ACTION_DRAG_ENDED == @event.Action && [email protected]) { outerInstance.putBarOnBoard(outerInstance.mBarAlignment); } return true; } return false; }
protected abstract bool doSnap(DragEvent toPopulate, int snapToIndex);
protected abstract void doDrag(DragEvent toPopulate, Vector3 dragStartMousePosition, Vector3 currentMousePosition);
void Update() { if (!Input.GetMouseButton(0) && state == DragState.DRAG) { endDrag(); CursorManager.giveUpCursorFocus(this); } if (state == DragState.DRAG) { CursorManager.takeCursorFocus(this, downCursor, Vector2.zero); DragEvent e = new DragEvent(DragState.DRAG); doDrag(e, dragStartMousePos, Input.mousePosition); foreach (DragModifier m in modifiers()) m.handleDragEvent(e); } else if (state == DragState.SNAP) { DragEvent e = new DragEvent(DragState.SNAP); bool isSnapDone = doSnap(e, snapToIndex); foreach (DragModifier m in modifiers()) m.handleDragEvent(e); if (isSnapDone) { state = DragState.NONE; foreach (DragModifier m in modifiers()) m.endSnap(); } } if (!isActive) setVisualState(snapToIndex); }
public abstract void handleDragEvent(DragEvent e);