Ejemplo n.º 1
0
        /// <summary>
        /// Handles the touch down event.
        /// </summary>
        /// <param name="e">Touch event arguments.</param>
        /// <returns>Touch event arguments.</returns>
        protected override void OnTouchDown(TouchEventArgs e)
        {
            var x = e.Touches[0].X;
            var y = e.Touches[0].Y;

            //e.GetPosition(this.Parent, 0, out int x, out int y);
            // Global coordinates to local coordinates
            GHIElectronics.TinyCLR.UI.Glide.Geom.Point localPoint = new GHIElectronics.TinyCLR.UI.Glide.Geom.Point(x - Rect.X, y - Rect.Y);

            if (_knob.Contains(localPoint))
            {
                _dragging = true;
                Invalidate();

                if (_touchThread == null || (_touchThread != null && !_touchThread.IsAlive))
                {
                    //GlideTouch.IgnoreAllEvents = true;
                    _touchThread          = new Thread(TouchThread);
                    _touchThread.Priority = ThreadPriority.Highest;
                    _touchThread.Start();
                }

                //e.StopPropagation();
                return;
            }

            if (Rect.Contains(x, y))
            {
                _lastTouchX = x;
                _lastTouchY = y;
                RenderKnob(new Point(x, y));
                //e.StopPropagation();
            }
            var evt  = new RoutedEvent("TouchDownEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler));
            var args = new RoutedEventArgs(evt, this);

            //this.Click?.Invoke(this, args);

            e.Handled = args.Handled;

            if (this.Parent != null)
            {
                this.Invalidate();
            }
            //return e;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the touch up event.
        /// </summary>
        /// <param name="e">Touch event arguments.</param>
        /// <returns>Touch event arguments.</returns>
        protected override void OnTouchUp(TouchEventArgs e)
        {
            var x = e.Touches[0].X;
            var y = e.Touches[0].Y;

            //e.GetPosition(this.Parent, 0, out int x, out int y);
            GHIElectronics.TinyCLR.UI.Glide.Geom.Point localPoint = new GHIElectronics.TinyCLR.UI.Glide.Geom.Point(x - Rect.X, y - Rect.Y);

            if (_knob.Contains(localPoint))
            {
                if (_dragging)
                {
                    _dragging = false;
                    Invalidate();
                    //e.StopPropagation();
                }
            }
            else
            {
                if (_dragging)
                {
                    _dragging = false;
                    Invalidate();
                }
            }
            //return e;
            var evt  = new RoutedEvent("TouchUpEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler));
            var args = new RoutedEventArgs(evt, this);

            //this.Click?.Invoke(this, args);

            e.Handled = args.Handled;

            //this.isPressed = false;

            if (this.Parent != null)
            {
                this.Invalidate();
            }
        }