/// <summary> /// Prepares a control to be tilted by setting up a plane projection and /// some event handlers. /// </summary> /// <param name="element">The control that is to be tilted.</param> /// <param name="centerDelta">Delta between the element's center and the /// tilt container's.</param> /// <returns>true if successful; false otherwise.</returns> /// <remarks> /// This method is conservative; it will fail any attempt to tilt a /// control that already has a projection on it. /// </remarks> private static bool PrepareControlForTilt(FrameworkElement element, Point centerDelta, Pointer p) { // Prevents interference with any existing transforms if (element.Projection != null || (element.RenderTransform != null && element.RenderTransform.GetType() != typeof(MatrixTransform))) { return(false); } _originalCacheMode[element] = element.CacheMode; element.CacheMode = new BitmapCache(); TranslateTransform transform = new TranslateTransform(); transform.X = centerDelta.X; transform.Y = centerDelta.Y; element.RenderTransform = transform; PlaneProjection projection = new PlaneProjection(); projection.GlobalOffsetX = -1 * centerDelta.X; projection.GlobalOffsetY = -1 * centerDelta.Y; element.Projection = projection; element.PointerMoved += TiltEffect_PointerMoved; element.PointerReleased += TiltEffect_PointerReleased; element.PointerCaptureLost += TiltEffect_PointerCaptureLost; element.CapturePointer(p); return(true); }
static bool PrepareControlForTilt(FrameworkElement element, Point centerDelta) #endif { // Prevents interference with any existing transforms if (element.Projection != null || (element.RenderTransform != null && element.RenderTransform.GetType() != typeof(MatrixTransform))) { return(false); } OriginalCacheMode[element] = element.CacheMode; element.CacheMode = new BitmapCache(); var transform = new TranslateTransform { X = centerDelta.X, Y = centerDelta.Y }; element.RenderTransform = transform; var projection = new PlaneProjection { GlobalOffsetX = -1 * centerDelta.X, GlobalOffsetY = -1 * centerDelta.Y }; element.Projection = projection; #if WINDOWS_STORE element.PointerMoved += TiltEffect_PointerMoved; element.PointerReleased += TiltEffect_PointerReleased; element.PointerCaptureLost += TiltEffect_PointerCaptureLost; element.CapturePointer(p); #elif WINDOWS_PHONE element.ManipulationDelta += TiltEffectDelta; element.ManipulationCompleted += TiltEffectCompleted; #endif return(true); }
void frameworkElement_PointerPressed(object sender, PointerRoutedEventArgs e) { if (Convert.ToBoolean(_supportedContacts.TouchPresent) && (_numActiveContacts > _supportedContacts.Contacts)) { Debug.WriteLine("Number of contacts exceeds the number supported by the device."); return; } PointerPoint pt = e.GetCurrentPoint(_frameworkElement); var state = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.LeftControl); if (e.Pointer.PointerDeviceType == PointerDeviceType.Pen || (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down) { return; } if (_currentContacts.ContainsKey(pt.PointerId)) { return; } _frameworkElement.CapturePointer(e.Pointer); if (!_currentPointers.Any(p => p.PointerId == e.Pointer.PointerId)) { _currentPointers.Add(e.Pointer); } _currentContacts[pt.PointerId] = pt; _startContacts[pt.PointerId] = pt; ++_numActiveContacts; fireAdded(e.Pointer, e); e.Handled = true; }
//! @brief handle the user starting to drive private void PointerPressed(object sender, PointerRoutedEventArgs args) { Windows.UI.Input.PointerPoint pointer = args.GetCurrentPoint(null); if (pointer.Properties.IsLeftButtonPressed) { m_initialPoint = new Point(pointer.RawPosition.X - m_translateTransform.X, pointer.RawPosition.Y - m_translateTransform.Y); args.Handled = true; m_puckControl.CapturePointer(args.Pointer); } }
private void SliderContainer_PointerPressed(object sender, PointerRoutedEventArgs e) { if (sliderContainer == null) { return; } e.Handled = true; isPressed = true; UpdateVisualState(); try { sliderContainer.CapturePointer(e.Pointer); } catch (Exception) { } if (Orientation == Orientation.Vertical) { if (verticalThumb == null || verticalTemplate == null) { return; } double trackHeight = verticalTemplate.ActualHeight - verticalThumb.ActualHeight; if (trackHeight <= layoutEpsilon) { return; } Point position; try { position = e.GetCurrentPoint(verticalTemplate).Position; } catch (Exception) { return; } double fraction = 1.0 - (position.Y - verticalThumb.ActualHeight / 2.0) / trackHeight; double newValue = fraction * (Maximum - Minimum) + Minimum; RoundAndSetValue(newValue); } else { if (horizontalThumb == null || horizontalTemplate == null) { return; } double trackWidth = horizontalTemplate.ActualWidth - horizontalThumb.ActualWidth; if (trackWidth <= layoutEpsilon) { return; } Point position; try { position = e.GetCurrentPoint(horizontalTemplate).Position; } catch (Exception) { return; } double fraction = (position.X - horizontalThumb.ActualWidth / 2.0) / trackWidth; double newValue = fraction * (Maximum - Minimum) + Minimum; RoundAndSetValue(newValue); } }
public void OnPointerDown(FrameworkElement uie, PointerRoutedEventArgs e) { FrameworkElement parent = VisualTreeHelper.GetParent(uie) as FrameworkElement; this._adjustCanvasCoordinates = (parent != null && parent.GetType() == typeof(Canvas)); this._startPos = e.GetCurrentPoint(null); uie.PointerReleased += this.OnPointerReleased; uie.PointerMoved += this.OnPointerMoved; uie.PointerCaptureLost += this.OnLostCapture; uie.CapturePointer(e.Pointer); }
private void HandlePointerPressed(Object sender, PointerRoutedEventArgs args) { // Check to see if this kind of device is being ignored if (!IsValidDevice(args.Pointer.PointerDeviceType)) { return; } System.Diagnostics.Debug.WriteLine("PointerPressed - {0}, {1}", args.Pointer.PointerId, args.Pointer.PointerDeviceType); // Capturing the pointer to follow it as it strays outside the element _eventSourceElement.CapturePointer(args.Pointer); }
private void CapturePointer( Pointer pointer) { if (null == pointer) { throw new ArgumentNullException(nameof(pointer)); } FrameworkElement nativeElement = this.FrameworkElement; if (null != nativeElement) { this._isPointerCaptured = nativeElement.CapturePointer(pointer); } }
//! @brief handle the user starting to calibrate private void OnPointerPressed(object sender, PointerRoutedEventArgs args) { Windows.UI.Input.PointerPoint pointer = args.GetCurrentPoint(m_calibrateRotationRoot); if (pointer.Properties.IsLeftButtonPressed) { if (m_sphero != null) { m_sphero.SetHeading(0); m_sphero.SetBackLED(1.0f); } m_calibrateElement.CapturePointer(args.Pointer); args.Handled = true; // Show rings m_ringOuter.Visibility = Visibility.Visible; m_ringMiddle.Visibility = Visibility.Visible; m_ringInner.Visibility = Visibility.Visible; m_fingerPoint.Visibility = Visibility.Visible; } }
void OnPointerPressed(object sender, PointerRoutedEventArgs e) { // todo: add pinch gesture support. downPos = e.GetCurrentPoint(this.element).Position; element.CapturePointer(e.Pointer); }
static bool PrepareControlForTilt(FrameworkElement element, Point centerDelta) #endif { // Prevents interference with any existing transforms if (element.Projection != null || (element.RenderTransform != null && element.RenderTransform.GetType() != typeof(MatrixTransform))) { return false; } OriginalCacheMode[element] = element.CacheMode; element.CacheMode = new BitmapCache(); var transform = new TranslateTransform {X = centerDelta.X, Y = centerDelta.Y}; element.RenderTransform = transform; var projection = new PlaneProjection {GlobalOffsetX = -1*centerDelta.X, GlobalOffsetY = -1*centerDelta.Y}; element.Projection = projection; #if WINDOWS_STORE element.PointerMoved += TiltEffect_PointerMoved; element.PointerReleased += TiltEffect_PointerReleased; element.PointerCaptureLost += TiltEffect_PointerCaptureLost; element.CapturePointer(p); #elif WINDOWS_PHONE element.ManipulationDelta += TiltEffectDelta; element.ManipulationCompleted += TiltEffectCompleted; #endif return true; }