} // end of MaterialPicker SetDefaultSelection() public bool TouchIsOverMaterialSelection(TouchContact touch, Camera camera) { Matrix mat; BoundingSphere sphere; // Sphere we wrap around elements for hit testing. float? dist = null; // Dist to sphere bounds hit. // Test in-focus element for hit. UIGridMaterialElement e = grid.SelectionElement as UIGridMaterialElement; if (e != null) { Vector2 touchHit = touch.position; Ray ray = new Ray(camera.From, camera.ScreenToWorldCoords(touchHit)); mat = e.HitWorldMatrix; sphere = new BoundingSphere(mat.Translation, 2.5f * mat.M33); dist = ray.Intersects(sphere); if (dist != null) { return(true); } } return(false); }
/// <summary> /// /// </summary> /// <returns>Returns true if autorepeating.</returns> public bool Update() { bool result = false; hitBox.Set(position, position + size); // If pressed, see if touch is still active. If not, clear pressed state. if (Pressed) { TouchContact touch = TouchInput.GetOldestTouch(); if (touch == null || touch.phase == TouchPhase.Ended) { Pressed = false; } // If previously pressed, check for possible autorepeat. // Don't do this for keys with delegates (transition keys). // They should never autorepeat. if (Pressed && OnKey == null) { // Waited long enough to autorepeat? if (Time.GameTimeTotalSeconds - timeOfLastPress >= GamePadInput.Button.AutoRepeatDelay) { if (Time.GameTimeTotalSeconds - timeOfLastRepeat >= 1.0 / GamePadInput.Button.AutoRepeatRate) { // Trigger an autorepeat. result = true; timeOfLastRepeat = Time.GameTimeTotalSeconds; } } } } return(result); } // end of Update()
} // end of Update() private bool UpdateNonMenuItems() { bool inputHandled = false; // Check for click on signOut tile or url. if (MouseInput.Left.WasPressed || Actions.Select.WasPressed || TouchInput.WasTouched || TouchInput.WasLastReleased) { TouchContact touch = TouchInput.GetOldestTouch(); Vector2 touchHit = new Vector2(-1, -1); // touch off screen if no touch was found // url is in rt coords. if (touch != null) { touchHit = ScreenWarp.ScreenToRT(touch.position); } Vector2 mouseHit = MouseInput.GetMouseInRtCoords(); if (shared.urlBox.Contains(mouseHit) || (shared.urlBox.Contains(touchHit) && TouchInput.WasLastReleased)) { #if NETFX_CORE Launcher.LaunchUriAsync(new Uri(KoduGameLabUrl)); #else Process.Start(KoduGameLabUrl); #endif MouseInput.Left.ClearAllWasPressedState(); inputHandled = true; } } return(inputHandled); }
private void HandleTouchInput(TouchContact touch, Vector2 hit) { if (hitBox.Touched(touch, hit)) { Deactivate(); } // Check for hover and adjust text color to match. Color newColor; newColor = hitBox.Contains(hit) ? hoverTextColor : lightTextColor; if (newColor != labelATargetColor) { labelATargetColor = newColor; Vector3 curColor = new Vector3(labelAColor.R / 255.0f, labelAColor.G / 255.0f, labelAColor.B / 255.0f); Vector3 destColor = new Vector3(newColor.R / 255.0f, newColor.G / 255.0f, newColor.B / 255.0f); TwitchManager.Set <Vector3> set = delegate(Vector3 value, Object param) { labelAColor.R = (byte)(value.X * 255.0f + 0.5f); labelAColor.G = (byte)(value.Y * 255.0f + 0.5f); labelAColor.B = (byte)(value.Z * 255.0f + 0.5f); }; TwitchManager.CreateTwitch <Vector3>(curColor, destColor, set, 0.1f, TwitchCurve.Shape.EaseOut); } } // end of HandleTouchInput()
} // end of HandleMouseInput() public override void HandleTouchInput(TouchContact touch, Vector2 hitUV) { //check x button first if (xButtonBox.Contains(hitUV)) { if (TouchInput.WasTouched) { touch.TouchedObject = xButtonBox; } if (TouchInput.WasReleased && touch.TouchedObject == xButtonBox) { if (onXButton != null) { onXButton(); } } } else { // The hit region is the square at the left end of the tile. float maxU = height / width; if (hitUV.X < maxU) { if (touch.phase == TouchPhase.Began) { touch.TouchedObject = this; } if (touch.phase == TouchPhase.Ended && touch.TouchedObject == this) { ToggleState(); } } } }
} // end of c'tor public void Update() { if (active) { scrollableTextDisplay.Update(null); if (scrollableTextDisplay.Active) { return; } // // Input? // if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); Vector2 touchHit = touch.position; HandleTouchInput(touch, touchHit); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 hit = MouseInput.PositionVec; HandleMouseInput(hit); } } } // end of Update()
} // end of HandleMouseInput() public override void HandleTouchInput(TouchContact touch, Vector2 hitUV) { // Press in slider region? if (touch.phase == TouchPhase.Began && hitUV.Y > 0.5f) { touch.TouchedObject = this; } if (touch.TouchedObject == this && TouchPhase.Stationary != touch.phase) { // Adjust for ends of slide not filling all the way to border of shape. float value = hitUV.X; value = (value - 0.05f) / 0.9f; value = MyMath.Clamp(value, 0.0f, 1.0f); float delta = GetSliderPercentage() - value; if (SetSliderPercentage(value)) { // Only make nose if the value changes. if (delta > 0) { Foley.PlayClickDown(); } else if (delta < 0) { Foley.PlayClickUp(); } } } } // end of HandleTouchInput()
protected override void OnTouchMoved(TouchContact[] touches) { TouchContact tc = (GetRequiredTouchCount() != touches.Length || m_FingerID < 0) ? null : TouchInput.GetTouchContactByFingerId(m_FingerID, touches); if (null == tc) { SetState(GestureState.Failed); } else { m_PrevPosition = m_Position; m_Position = tc.position; m_MinMoveDelta += tc.deltaPosition; if (GestureState.Possible == GetState()) { bool bMoved = m_MinMoveDelta.LengthSquared() >= (k_MinDragDistance * k_MinDragDistance); bool bIdle = !bMoved && (Time.WallClockTotalSeconds - m_MinMoveTime) >= k_IdleTimeOut; if (bMoved) { m_MinMoveDelta = Vector2.Zero; m_MinMoveTime = Time.WallClockTotalSeconds; m_InitialPosition = m_Position; SetState(GestureState.Began); } } else { SetState(GestureState.Changed); } } }
private static void UpdateVirtualController_Buttons(TouchContact[] touches) { //Update button states. for (int i = 0; i < kNumButtons; i++) { TouchContact buttonTouch = null; for (int j = 0; j < touches.Length; ++j) { if (buttonHitBoxes[i].Contains(touches[j].position)) { buttonTouch = touches[j]; break; } } if (null != buttonTouch) { buttonState[i] = ButtonState.Pressed; } else { buttonState[i] = ButtonState.Released; } } }
} // end of Update() private void HandleTouchInput(TouchContact touch, Vector2 hit) { if (hitBox.Touched(touch, hit)) { Boku.Common.Gesture.TouchGestureManager.Get().TapGesture.ClearWasTapped(); AuthUI.ShowSignOutDialog(); } }
} // end of Update() private bool UpdateNonMenuItems() { bool inputHandled = false; // Check for click on signOut tile or url. if (MouseInput.Left.WasPressed || Actions.Select.WasPressed || TouchInput.WasTouched || TouchInput.WasLastReleased) { TouchContact touch = TouchInput.GetOldestTouch(); Vector2 touchHit = new Vector2(-1, -1); // touch off screen if no touch was found // url is in rt coords. if (touch != null) { touchHit = ScreenWarp.ScreenToRT(touch.position); } Vector2 mouseHit = MouseInput.GetMouseInRtCoords(); if (shared.urlBox.Contains(mouseHit) || (shared.urlBox.Contains(touchHit) && TouchInput.WasLastReleased)) { #if NETFX_CORE Launcher.LaunchUriAsync(new Uri(KoduGameLabUrl)); #else Process.Start(KoduGameLabUrl); #endif MouseInput.Left.ClearAllWasPressedState(); inputHandled = true; } //check for touch over scroll window (doesn't need to be released) if (!inputHandled && GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { if (TouchInput.WasTouched && touch != null && shared.liveFeed.IsInScrollwindow(touch.position)) { //touch in window? if so, activate the live feed shared.liveFeed.Activate(); inputHandled = true; } else { //deactivate the feed and don't consider the input handled shared.liveFeed.Deactivate(); } } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 pureMouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y); // mouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y); if (shared.liveFeed.IsInScrollwindow(pureMouseHit)) // mouseHit)) { shared.liveFeed.Activate(); } } return(inputHandled); }
} // end of c'tor public void Update() { if (active) { // // Input? // // Touch. for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); Vector2 touchHit = ScreenWarp.ScreenToRT(touch.position); HandleTouchInput(touch, touchHit); } // Mouse. Note, we explicitely look for mouse mode here so that // mouse hover doesn't change the focus level when changing it via // keyboard or gamepad. if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 mouseHit = MouseInput.GetMouseInRtCoords(); HandleMouseInput(mouseHit); } // Keyboard. // Arrows are handled via Actions in HandleGamePadInput(). if (KeyboardInput.WasPressed(Keys.Escape)) { OnCancel(); } if (KeyboardInput.WasPressed(Keys.Enter)) { OnSelect(); } // Gamepad. HandleGamepadInput(); // Set frame color to indicate focus. for (int i = 0; i < levels.Count; i++) { if (focusLevelIndex == i) { levels[i].FrameColor = new Color(0, 255, 13); } else { levels[i].FrameColor = Color.Transparent; } } } // end if active. } // end of Update()
/// <summary> /// Returns a signed angle in degrees between current touch position and a reference position /// </summary> /// <param name="touchZero"></param> /// <param name="touchOne"></param> /// <param name="refPosZero"></param> /// <param name="refPosOne"></param> /// <returns></returns> private static float SignedAngularGap(TouchContact touchZero, TouchContact touchOne, Vector2 refPosZero, Vector2 refPosOne) { Vector2 curDir = touchZero.position - touchOne.position; curDir.Normalize(); Vector2 refDir = refPosZero - refPosOne; refDir.Normalize(); return(SignedAngle(refDir, curDir)); }
/// <summary> /// Check if the input touches are moving in the same direction /// </summary> public static bool TouchesMovedInSameDirection(ref TouchContact tc0, ref TouchContact tc1, float maxDOT) { if (Vector2.Zero != tc0.deltaPosition && Vector2.Zero != tc1.deltaPosition) { Vector2 touchZeroDeltaNormal = Vector2.Normalize(tc0.deltaPosition); Vector2 touchOneDeltaNormal = Vector2.Normalize(tc1.deltaPosition); return(Vector2.Dot(touchZeroDeltaNormal, touchOneDeltaNormal) > maxDOT); } return(false); }
protected override void OnRecognized() { TouchContact[] fingers = new TouchContact[] { TouchInput.GetTouchContactByFingerId(m_FingerIdx[0]), TouchInput.GetTouchContactByFingerId(m_FingerIdx[1]) }; AveragePosition = GetAverageTouchPosition(ref fingers); UpdateDragDirection(); }
/// <summary> /// Test to see it the users Touch focus is over a pie menu element /// </summary> /// <param name="touch"></param> /// <param name="ignoreOnDrag"></param> /// <returns></returns> public bool IsOverUIButton(TouchContact touch, bool ignoreOnDrag) { /// For now, always return true is a pie is visible as the user should ONLY be /// effecting the pie when it is up. bool elementFound = true; if (Active == false) { elementFound = false; } return(elementFound); }
/// <summary> /// Check if the input touches are moving in opposite direction /// </summary> public static bool TouchesMovedInOppositeDirection(TouchContact tc0, TouchContact tc1, float minDOT) { bool bValid = Vector2.Zero == tc0.deltaPosition ^ Vector2.Zero == tc1.deltaPosition; if (!bValid) { Vector2 touchZeroDeltaNormal = Vector2.Normalize(tc0.deltaPosition); Vector2 touchOneDeltaNormal = Vector2.Normalize(tc1.deltaPosition); bValid = Vector2.Dot(touchZeroDeltaNormal, touchOneDeltaNormal) < minDOT; } return(bValid); }
} // end of MouseEditToolBox Update() public bool IsTouchOverMenuButton(TouchContact touch) { if (null != touch) { if (!MaterialPicker.Hidden || !WaterPicker.Hidden || !BrushPicker.Hidden) { return(true); } } return(false); }
protected override void OnTouchMoved(TouchContact[] touches) { TouchContact tc = (GetRequiredTouchCount() != touches.Length || m_FingerId < 0) ? null : TouchInput.GetTouchContactByFingerId(m_FingerId, touches); bool bFailed = (null == tc); if (!bFailed) { m_Position = tc.position; //Check if finger has drifted. bFailed |= (tc.position - tc.startPosition).LengthSquared() > (k_DriftRadiusLimit * k_DriftRadiusLimit); //Recognize gesture if we have exceeded the time. m_bRecognized = !bFailed && (Time.WallClockTotalSeconds - tc.startTime) >= k_TriggerHoldTime; //Recognize the slight hold if delta time is greater than check. m_bSlightHoldMade = !bFailed && m_bCheckSlightHold && (Time.WallClockTotalSeconds - tc.startTime) >= k_SlightHoldTime; if (m_bSlightHoldMade) { //When slight hold is made, Stop checking until gesture is reset. m_bCheckSlightHold = false; } } //Assert that both values are never both true. Debug.Assert(!(bFailed && m_bRecognized)); if (bFailed) { m_Position = new Vector2(); SetState(GestureState.Failed); } else if (m_bRecognized) { SetState(GestureState.Recognized); } else { //not failed, but not recognized - began! if (IsValidated) { SetState(GestureState.Changed); } else { SetState(GestureState.Began); } } }
//We can use the touch contact start position as the finger never left the screen. private bool IsTouchContactValidForTap(TouchContact tc) { bool bValid = (null != tc); if (bValid) { //Check position change since start. bValid &= (tc.position - tc.startPosition).LengthSquared() <= (k_MaxTouchRadius * k_MaxTouchRadius); //Check Time change since start bValid &= ((float)(Time.WallClockTotalSeconds - tc.startTime)) <= k_MaxTouchLifetime; } return(bValid); }
public static void Update() { if (InGame.inGame.CurrentUpdateMode != InGame.UpdateMode.RunSim) { return; } // All buttons are assumed to be invisible at the start every frame. Only when an active filter // from a brain attempts to read the state of the button does a button become visible. for (int i = 0; i < numButtons; i++) { touchButtonVisibility[i] = false; } // Handles touch input and keeping button state TouchContact touch = TouchInput.GetOldestTouch(); if ((GamePadInput.ActiveMode != GamePadInput.InputMode.Touch) || (touch == null)) { for (int i = 0; i < numButtons; i++) { touchButtonState[i] = ButtonState.Normal; } } else { Vector2 touchHit = touch.position; for (int i = 0; i < numButtons; i++) { if (touchButtonBoxes[i].Contains(touchHit)) { // Touch is over this button. if (touch.phase == TouchPhase.Ended) { touchButtonState[i] = ButtonState.Pressed; } else { touchButtonState[i] = ButtonState.Focus; } } else { touchButtonState[i] = ButtonState.Normal; } } } }
/// <summary> /// Find the correct position to add a node. /// </summary> /// <param name="camera"></param> /// <param name="from"></param> /// <returns></returns> private Vector3 AddPosition(Camera camera, WayPoint.Node from) { bool asRoad = false; float height = from.RenderPosition(asRoad).Z; Vector2 pos = Vector2.Zero; TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { pos = touch.position; } Vector3 hit = TouchEdit.FindAtHeight(camera, TouchInput.GetAsPoint(pos), height); return(hit); }
public void Update() { if (active) { string s = ""; s += Strings.Localize("auth.creator") + " : " + Auth.CreatorName; blob.RawText = s; float scale = 0.75f; Vector2 size = new Vector2(blob.GetLineWidth(0), tileTexture.Height * scale); // Add some extra width to allow the text to be centered horizontally. size.X += 32; Vector2 upperRightCorner = new Vector2((int)BokuGame.ScreenPosition.X + (int)BokuGame.ScreenSize.X, 0); Vector2 pos = upperRightCorner - new Vector2(size.X, 0); // Add a bit of a margin from the top of the screen. pos += new Vector2(-8, 8); pos = pos.Truncate(); hitBox.Set(pos, pos + size); tileRect = new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y); // // Input? // if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); Vector2 touchHit = touch.position; HandleTouchInput(touch, touchHit); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 hit = MouseInput.PositionVec; HandleMouseInput(hit); } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad) { // Do nothing. Since signing in requires keyboard/mouse it // really doesn't make sense to partially support gamepad. } } } // end of Update()
} // end of HandleMouseInput() public override void HandleTouchInput(TouchContact touch, Vector2 hitUV) { // See if we hit an element. int hit = -1; for (int i = 0; i < list.Count; i++) { if (list[i].Box.Contains(hitUV)) { hit = i; break; } } if (hit != -1) { if (TouchInput.WasTouched) { touch.TouchedObject = list[hit]; } if (TouchInput.WasReleased && touch.TouchedObject == list[hit]) { //Play sound. Foley.PlayPressA(); bool indexChanged = hit != curIndex; CurIndex = hit; if (null != onSelection) { onSelection(list[curIndex]); } if (indexChanged) { if (null != onChange) { onChange(list[curIndex]); } dirty = true; } } } }
} // end of Update() private void HandleTouchInput(TouchContact touch, Vector2 hit) { if (cancelButton.Box.Touched(touch, hit)) { Boku.Common.Gesture.TouchGestureManager.Get().TapGesture.ClearWasTapped(); OnCancel(); } for (int i = 0; i < levels.Count; i++) { if (levels[i].Box.Touched(touch, hit)) { Boku.Common.Gesture.TouchGestureManager.Get().TapGesture.ClearWasTapped(); focusLevelIndex = i; OnSelect(); } } } // end of HandleTouchInput()
} // end of HandleMouseInput() public override void HandleTouchInput(TouchContact touch, Vector2 hitUV) { /// \TODO: JB implement if (xButtonBox.Contains(hitUV)) { if (TouchInput.WasTouched) { touch.TouchedObject = xButtonBox; clickedOnIndex = -1; } if (TouchInput.WasReleased && touch.TouchedObject == xButtonBox) { if (onXButton != null) { onXButton(curIndex); } clickedOnIndex = -1; } } else if (iconButtonBox.Contains(hitUV)) { if (TouchInput.WasTouched) { touch.TouchedObject = iconButtonBox; clickedOnIndex = (int)(3.0f * (hitUV.X - iconButtonBox.Min.X) / (iconButtonBox.Max.X - iconButtonBox.Min.X)); } if (TouchInput.WasReleased) { // Make sure we're still over the ClickedOnItem. if (touch.TouchedObject == iconButtonBox) { int newIndex = (int)(3.0f * (hitUV.X - iconButtonBox.Min.X) / (iconButtonBox.Max.X - iconButtonBox.Min.X)); if (newIndex == clickedOnIndex && newIndex != CurIndex) { CurIndex = newIndex; } } clickedOnIndex = -1; } } }
} // end of Update() private void HandleTouchInput(TouchContact touch, Vector2 hit) { continueButton.SetHoverState(hit); backButton.SetHoverState(hit); exitTutorialButton.SetHoverState(hit); if (continueButton.Box.Contains(hit)) { if (touch.phase == TouchPhase.Ended) { if (OnContinue != null) { OnContinue(); } Deactivate(); } } else if (exitTutorialButton.Box.Contains(hit)) { if (touch.phase == TouchPhase.Ended) { if (OnExitTutorial != null) { OnExitTutorial(); } Deactivate(); } } else if (upBox.Contains(hit)) { if (touch.phase == TouchPhase.Ended) { ScrollDown(); } } else if (downBox.Contains(hit)) { if (touch.phase == TouchPhase.Ended) { ScrollUp(); } } } // end of HandleTouchInput()
protected override void OnTouchReleased(TouchContact[] touches) { bool bFailed = touches.Length != GetRequiredTouchCount(); TouchContact tc = TouchInput.GetTouchContactByFingerId(m_FingerId, touches); bFailed |= !IsTouchContactValidForTap(tc); if (bFailed) { SetState(GestureState.Failed); return; } else { if (m_bWaitingForNextTap) { m_bWaitingForNextTap = false; Debug.Assert(null != tc); m_position = tc.position; float deltaPosition = (m_position - m_initialPosition).Length(); if ((float)(Time.WallClockTotalSeconds - m_lastTapTime) <= k_MaxTouchGapTime && deltaPosition <= k_MaxTouchDrift) { SetState(GestureState.Recognized); } else { SetState(GestureState.Failed); } } else { m_lastTapTime = Time.WallClockTotalSeconds; m_bWaitingForNextTap = true; } } }
} // end of Update() private void HandleTouchInput(TouchContact touch, Vector2 hit) { if (checkBoxBox.Touched(touch, hit)) { Boku.Common.Gesture.TouchGestureManager.Get().TapGesture.ClearWasTapped(); keepSignedInChecked = !keepSignedInChecked; } // Buttons if (signOutButton.Box.Touched(touch, hit)) { Boku.Common.Gesture.TouchGestureManager.Get().TapGesture.ClearWasTapped(); OnAccept(); } if (cancelButton.Box.Touched(touch, hit)) { Boku.Common.Gesture.TouchGestureManager.Get().TapGesture.ClearWasTapped(); OnCancel(); } } // end of HandleTouchInput()
} // end of HandleMouseInput() public override void HandleTouchInput(TouchContact touch, Vector2 hitUV) { if (onXButton != null) { if (xButtonBox.Touched(touch, hitUV)) { onXButton(); Foley.PlayCut(); } } if (onAButton != null) { if (aButtonBox.Touched(touch, hitUV)) { onAButton(); Foley.PlayPressA(); } } } // end of HandleTouchInput()
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrameworkElement_TouchContactMove(object sender, TouchContactEventArgs e) { if (!this._elementTouchContacts.ContainsKey(e.TouchContact.ID)) { if (e.TouchContact.CapturedElement != this.AssociatedObject) { e.TouchContact.Release(); e.TouchContact.Capture(this.AssociatedObject); } if (!this._elementTouchContacts.ContainsKey(e.TouchContact.ID)) { this._elementTouchContacts.Add(e.TouchContact.ID, e.TouchContact); } this._keyTouchContact = e.TouchContact; this._previousKeyPosition = null; this._previousPosition = null; this._previousObjectParent = null; } else if (e.TouchContact == this._keyTouchContact) { UIElement parent = AssociatedObject.Parent as UIElement; if ((this._previousObjectParent != null) && (parent != this._previousObjectParent)) { this._previousObjectParent = parent; parent = null; } if (parent != null) { Point point = new Point(0.0, 0.0); foreach (TouchContact contact in this._elementTouchContacts.Values) { Point point2 = contact.GetPosition(parent); point.X += point2.X; point.Y += point2.Y; } point.X /= (double)this._elementTouchContacts.Count; point.Y /= (double)this._elementTouchContacts.Count; Point position = this._keyTouchContact.GetPosition(parent); if ((this._previousPosition.HasValue) && (this._previousKeyPosition.HasValue)) { double num; double num2; double num3; double num4; if (this._elementTouchContacts.Count == 1) { Point point4 = new Point(); if (AssociatedObject is ICentroid) { point4 = ((ICentroid)AssociatedObject).getCentroid(); } else { point4.X = this.AssociatedObject.ActualWidth / 2.0; point4.Y = this.AssociatedObject.ActualHeight / 2.0; } point4 = this.AssociatedObject.TranslatePoint(point4, parent); num = this._previousPosition.Value.X - point4.X; num2 = _previousPosition.Value.Y - point4.Y; num3 = point.X - point4.X; num4 = point.Y - point4.Y; } else { num = this._previousPosition.Value.X - this._previousKeyPosition.Value.X; num2 = this._previousPosition.Value.Y - this._previousKeyPosition.Value.Y; num3 = point.X - position.X; num4 = point.Y - position.Y; } double num5 = Math.Sqrt((num * num) + (num2 * num2)); double num6 = Math.Sqrt((num3 * num3) + (num4 * num4)); num /= num5; num2 /= num5; num3 /= num6; num4 /= num6; double d = (num * num3) + (num2 * num4); double num8 = (num * num4) - (num3 * num2); double num9 = (Math.Acos(d) * 180.0) / Math.PI; if ((_isRotateEnabled && (num9 > 0.0)) && (num9 <= 180.0)) { if (num8 > 0.0) { this._rotateTransform.Angle += num9; } else { this._rotateTransform.Angle -= num9; } if (AssociatedObject is ICentroid) { Point centroid = ((ICentroid)AssociatedObject).getCentroid(); _rotateTransform.CenterX = centroid.X; _rotateTransform.CenterY = centroid.Y; } else { _rotateTransform.CenterX = this.AssociatedObject.ActualWidth / 2.0; _rotateTransform.CenterY = this.AssociatedObject.ActualHeight / 2.0; } AssociatedObject.RenderTransform = _rotateTransform; } } this._previousKeyPosition = new Point(position.X, position.Y); this._previousPosition = new Point(point.X, point.Y); } } }
/// <summary> /// /// </summary> /// <param name="src"></param> /// <param name="args"></param> private void AssociatedObject_TouchContactMoved(object src, TouchContactEventArgs args) { //make sure that we have the key if (!this._touchContacts.ContainsKey(args.TouchContact.ID)) { if (args.TouchContact.CapturedElement != this.AssociatedObject) { args.TouchContact.Release(); args.TouchContact.Capture(this.AssociatedObject); this._touchContacts.Add(args.TouchContact.ID, args.TouchContact); } this._keyTouchContact = args.TouchContact; this._previousKeyPosition = null; this._previousPosition = null; this._previousDistance = 0.0; this._previousObjectParent = null; } else if ((this._touchContacts.Count >= 2)) { if (args.TouchContact != this._keyTouchContact) { return; //dont waste my time } UIElement parent = AssociatedObject.Parent as UIElement; if ((this._previousObjectParent != null) && (parent != _previousObjectParent)) { this._previousObjectParent = parent; parent = null; } if (parent != null) { Point point = new Point(0.0, 0.0); foreach (TouchContact contact in this._touchContacts.Values) { Point point2 = contact.GetPosition(this.AssociatedObject); point.X += point2.X; point.Y += point2.Y; } point.X /= (double)this._touchContacts.Count; point.Y /= (double)this._touchContacts.Count; Point point3 = this.AssociatedObject.TranslatePoint(point, parent); double num = 0.0; foreach (TouchContact contact2 in this._touchContacts.Values) { Point point4 = contact2.GetPosition(parent); num += Math.Sqrt(((point4.X - point3.X) * (point4.X - point3.X)) + ((point4.Y - point3.Y) * (point4.Y - point3.Y))); } num /= (double)this._touchContacts.Count; Point position = this._keyTouchContact.GetPosition(parent); if ((this._previousKeyPosition.HasValue && _previousPosition.HasValue) && (this._touchContacts.Count >= 1)) { double num2 = this._previousPosition.Value.X - this._previousKeyPosition.Value.X; double num3 = this._previousPosition.Value.Y - this._previousKeyPosition.Value.Y; double num4 = point3.X - position.X; double num5 = point3.Y - position.Y; double num6 = Math.Sqrt((num2 * num2) + (num3 * num3)); double num7 = Math.Sqrt((num4 * num4) + (num5 * num5)); num2 /= num6; num3 /= num6; num4 /= num7; num5 /= num7; double d = (num2 * num4) + (num3 * num5); double num9 = (num2 * num5) - (num4 * num3); double num10 = (Math.Acos(d) * 180.0) / 3.1415926535897931; if ((this._rotateEnabled && (num10 > 0.0)) && (num10 <= 180.0)) { if (num9 > 0.0) { this.AssociatedObject.RotateTransform.Angle += num10; } else { this.AssociatedObject.RotateTransform.Angle -= num10; } // //this.AssociatedObject.NotifyRotateTransformUpdated(); } } this._previousKeyPosition = new Point(position.X, position.Y); #region SCALECODE //SCALE CODE REMOVED /*if (this.m_bIsScaleEnabled && this.m_dPreviousDistance.HasValue) { double num11 = num / this.m_dPreviousDistance.Value; if ((((this.m_scaleTransform.ScaleX * num11) < base.AssociatedObject.MinScale) || ((this.m_scaleTransform.ScaleY * num11) < base.AssociatedObject.MinScale)) && (num11 < 1.0)) { this.m_scaleTransform.ScaleX = base.AssociatedObject.MinScale; this.m_scaleTransform.ScaleY = base.AssociatedObject.MinScale; } else if ((((this.m_scaleTransform.ScaleX * num11) > base.AssociatedObject.MaxScale) || ((this.m_scaleTransform.ScaleX * num11) > base.AssociatedObject.MaxScale)) && (num11 > 1.0)) { this.m_scaleTransform.ScaleX = base.AssociatedObject.MaxScale; this.m_scaleTransform.ScaleY = base.AssociatedObject.MaxScale; } else { this.m_scaleTransform.ScaleX *= num11; this.m_scaleTransform.ScaleY *= num11; } Point point6 = this.m_element.TranslatePoint(point, parent); this.m_translateTransform.X += point3.X - point6.X; this.m_translateTransform.Y += point3.Y - point6.Y; base.AssociatedObject.NotifyScaleTransformUpdated(); }*/ #endregion this._previousDistance = num; if (this._translateEnabled && this._previousPosition.HasValue) { this.AssociatedObject.TranslateTransform.X += point3.X - this._previousPosition.Value.X; this.AssociatedObject.TranslateTransform.Y += point3.Y - this._previousPosition.Value.Y; //Console.WriteLine("Moving " + (point3.X - this._previousPosition.Value.X)); //base.AssociatedObject.NotifyTranslateTransformUpdated(); } this._previousPosition = point3; } } else if (this._touchContacts.Count == 1) //specific version for rotation around a point { if (args.TouchContact != this._keyTouchContact) { return; //dont waste my time } UIElement parent = AssociatedObject.Parent as UIElement; if ((this._previousObjectParent != null) && (parent != _previousObjectParent)) { this._previousObjectParent = parent; parent = null; } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrameworkElement_TouchContactMove(object sender, TouchContactEventArgs e) { try { if (!IsRotateEnabled) { return; } if (!this._elementTouchContacts.ContainsKey(e.TouchContact.ID)) { if (e.TouchContact.CapturedElement != this.AssociatedObject) { e.TouchContact.Release(); e.TouchContact.Capture(this.AssociatedObject); } if (!this._elementTouchContacts.ContainsKey(e.TouchContact.ID)) { this._elementTouchContacts.Add(e.TouchContact.ID, e.TouchContact); } this._keyTouchContact = e.TouchContact; this._previousKeyPosition = null; this._previousPosition = null; this._previousObjectParent = null; } else if (e.TouchContact == this._keyTouchContact) { UIElement parent = AssociatedObject.Parent as UIElement; if ((this._previousObjectParent != null) && (parent != this._previousObjectParent)) { this._previousObjectParent = parent; parent = null; } if (parent != null) { Point point = new Point(0.0, 0.0); foreach (TouchContact contact in this._elementTouchContacts.Values) { Point point2 = contact.GetPosition(parent); point.X += point2.X; point.Y += point2.Y; } point.X /= (double)this._elementTouchContacts.Count; point.Y /= (double)this._elementTouchContacts.Count; Point position = this._keyTouchContact.GetPosition(parent); if ((this._previousPosition.HasValue) && (this._previousKeyPosition.HasValue)) { double num; double num2; double num3; double num4; if (this._elementTouchContacts.Count == 1) { Point point4 = AssociatedObject.getCentroid(); point4 = this.AssociatedObject.TranslatePoint(point4, parent); num = this._previousPosition.Value.X - point4.X; num2 = _previousPosition.Value.Y - point4.Y; num3 = point.X - point4.X; num4 = point.Y - point4.Y; } else { num = this._previousPosition.Value.X - this._previousKeyPosition.Value.X; num2 = this._previousPosition.Value.Y - this._previousKeyPosition.Value.Y; num3 = point.X - position.X; num4 = point.Y - position.Y; } double num5 = Math.Sqrt((num * num) + (num2 * num2)); double num6 = Math.Sqrt((num3 * num3) + (num4 * num4)); num /= num5; num2 /= num5; num3 /= num6; num4 /= num6; double d = (num * num3) + (num2 * num4); double num8 = (num * num4) - (num3 * num2); double num9 = (Math.Acos(d) * 180.0) / Math.PI; if ((_isRotateEnabled && (num9 > 0.0)) && (num9 <= 180.0)) { if (num8 > 0.0) { AssociatedObject.StartAngle -= num9; AssociatedObject.EndAngle -= num9; } else { AssociatedObject.StartAngle += num9; AssociatedObject.EndAngle += num9; } } } this._previousKeyPosition = new Point(position.X, position.Y); this._previousPosition = new Point(point.X, point.Y); } } } catch (Exception exc) { Console.WriteLine(exc); Console.WriteLine(exc.InnerException); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrameworkElement_TouchContactUp(object sender, TouchContactEventArgs e) { if (this._elementTouchContacts.ContainsKey(e.TouchContact.ID)) { this._elementTouchContacts.Remove(e.TouchContact.ID); } if (e.TouchContact == this._keyTouchContact) { if (this._elementTouchContacts.Count > 0) { this._keyTouchContact = this._elementTouchContacts.Last<KeyValuePair<int, TouchContact>>().Value; } else { this._keyTouchContact = null; } } _previousKeyPosition = null; _previousPosition = null; _previousObjectParent = null; }
/// <summary> /// /// </summary> /// <param name="src"></param> /// <param name="args"></param> private void AssociatedObject_TouchContactUp(object src, TouchContactEventArgs args) { if (args.TouchContact.CapturedElement == AssociatedObject) { _touchContacts.Remove(args.TouchContact.ID); args.TouchContact.Release(); } if (args.TouchContact == this._keyTouchContact) { if (_touchContacts.Count > 0) { //use the last touch contact as the new key. _keyTouchContact = _touchContacts.Last<KeyValuePair<int, TouchContact>>().Value; } else { _keyTouchContact = null; } } _previousDistance = 0; _previousObjectParent = null; _previousPosition = null; _previousKeyPosition = null; }
/// <summary> /// /// </summary> /// <param name="src"></param> /// <param name="args"></param> private void AssociatedObject_TouchContactDown(object src, TouchContactEventArgs args) { if (!_touchContacts.ContainsKey(args.TouchContact.ID)) { _touchContacts.Add(args.TouchContact.ID, args.TouchContact); args.TouchContact.Capture(this.AssociatedObject); _keyTouchContact = args.TouchContact; } }