private void Update()
 {
     if (Input.touchCount > 0 || Input.GetMouseButton(0))
     {
         Tap?.Invoke();
     }
 }
 protected override void OnMouseUp(MouseButtonEventArgs e)
 {
     base.OnMouseUp(e);
     if (Tap != null &&
         _tapped)
     {
         Tap.Invoke(this, new GestureEventArgs(new System.Windows.Point(), e.GetPosition(this))
         {
             OriginalSource = e.OriginalSource
         });
         _tapped = false;
     }
 }
Example #3
0
        private void TapTimer_Expired()
        {
            if (Mode == TouchMode.Normal)
            {
                if (TapCount == 1)
                {
                    Tap?.Invoke(this, null);
                }
                else if (TapCount >= 2)
                {
                    DoubleTap?.Invoke(this, null);
                }

                TapCount = 0;
            }
        }
Example #4
0
        private void UpdateTouchState()
        {
            var position = ViewportAdapter.PointToScreen(InputManager.TouchPosition());

            if (BoundingRectangle().Intersects(new Rectangle(position, Vector2.One.ToPoint())))
            {
                if (InputManager.TouchDown())
                {
                    _touchedDown = true;
                    TouchStarted?.Invoke(this, position);
                }
                else if (InputManager.TouchUp() && _touchedDown)
                {
                    _touchedDown = false;
                    Tap?.Invoke(this, position);
                    Action?.Invoke(this, position);
                }
            }
            else
            {
                _touchedDown = false;
            }
        }
    private void Update()
    {
        if (Input.GetButton("Fire1"))
        {
            if (startTouchPosition == Vector2.zero)
            {
                startTouchPosition = (Vector2)Input.mousePosition;
            }
        }
        else if (Input.GetButtonUp("Fire1"))
        {
            if (Vector2.Distance((Vector2)Input.mousePosition, startTouchPosition) > 10)
            {
                MovePlayer((Vector2)Input.mousePosition - startTouchPosition);
            }
            else
            {
                Tap.Invoke();
            }

            startTouchPosition = Vector2.zero;
        }
    }
Example #6
0
 /// <summary>
 /// Raises the <see cref="Tap"/> event.
 /// </summary>
 /// <param name="touchID">The unique identifier of the touch which caused the tap.</param>
 /// <param name="fingerID">The unique identifier of the finger which caused the tap.</param>
 /// <param name="x">The normalized x-coordinate of the tap.</param>
 /// <param name="y">The normalized y-coordinate of the tap.</param>
 protected virtual void OnTap(Int64 touchID, Int64 fingerID, Single x, Single y)
 {
     Tap?.Invoke(this, touchID, fingerID, x, y);
 }
Example #7
0
        internal void ProcessUp(int id, Vector2 position, DateTime time)
        {
            TouchElement element;

            if (!_elements.TryGetValue(id, out element))
            {
                return;
            }

            Vector2 move = position - element.Position;

            element.Position       = position;
            element.LockedListener = null;

            _elements.Remove(id);

            _gesture.GestureType       = GestureType.Up;
            _gesture.Origin            = element.Origin;
            _gesture.Position          = position;
            _gesture.PointerCapturedBy = element.LockedListener;
            _gesture.TouchId           = id;
            _gesture.Offset            = move;
            _gesture.Time = time;

            OnGesture();

            if (element.LockedGesture == GestureType.HoldStart)
            {
                _gesture.GestureType = GestureType.HoldCancel;
                OnGesture();
            }

            if (!_gesture.Handled)
            {
                if (element.LockedGesture == GestureType.None)
                {
                    if ((element.Origin - element.Position).Length() < MinDragSize && (DateTime.Now - element.DownTime).TotalMilliseconds < HoldStartTimeInMs)
                    {
                        bool doubleTap = false;

                        if (_lastTap.HasValue)
                        {
                            if ((element.Position - _lastTap.Value.Position).Length() < DoubleTapSize)
                            {
                                _gesture.GestureType = GestureType.DoubleTap;

                                OnGesture();

                                doubleTap = true;

                                if (_gesture.Handled)
                                {
                                    _lastTap = null;
                                    return;
                                }
                            }
                        }

                        _gesture.GestureType = GestureType.Tap;
                        OnGesture();

                        Tap?.Invoke(_gesture.TouchId, _gesture.Position);

                        if (!_gesture.Handled)
                        {
                            if (doubleTap)
                            {
                                _lastTap = null;
                            }
                            else
                            {
                                _lastTap = new LastTap()
                                {
                                    Position = _gesture.Position,
                                    Time     = 0
                                };
                            }
                        }
                    }
                }
            }

            TouchUp?.Invoke(id, position);
        }
Example #8
0
 protected virtual void OnMapLongTouch(MapLongTouchEventArgs e)
 {
     Tap?.Invoke(this, e);
 }
Example #9
0
 public virtual void OnTap()
 {
     Tap?.Invoke();
 }
Example #10
0
        private void OnMouseStuff(object sender, MouseEventArgs args)
        {
            if (args.RoutedEvent == UIElement.MouseUpEvent ||
                (args.RoutedEvent == UIElement.MouseLeftButtonDownEvent && args.Source == null) ||
                (args.RoutedEvent == UIElement.MouseMoveEvent && args.Source == null && args.LeftButton == MouseButtonState.Released))
            {
                MultitouchWindow.RemoveMouseListener(_attachedElement, OnMouseStuff);

                if (!_downpoint.ContainsKey(-1))
                {
                    return;
                }

                //if (args.OriginalSource != _attachedElement) return;

                args.Handled = true;

                Point  current = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);
                Vector jitter  = Point.Subtract(current, _downpoint[-1]);
                if (jitter.Length < Threshold)
                {
                    if (Tap != null)
                    {
                        Tap.Invoke(_attachedElement, new TapEventArgs(args.MouseDevice, jitter));
                    }

                    if (args.Timestamp - _lasttap < DoubleTapDelay.TotalMilliseconds && DoubleTap != null)
                    {
                        DoubleTap.Invoke(_attachedElement, new TapEventArgs(args.MouseDevice, jitter));
                    }

                    if (_attachedElement is Control)
                    {
                        ((Control)_attachedElement).RaiseEvent(
                            new MouseButtonEventArgs(args.MouseDevice, args.Timestamp,
                                                     ((MouseButtonEventArgs)args).ChangedButton)
                        {
                            RoutedEvent = Control.MouseDoubleClickEvent
                        });
                    }

                    _lasttap = args.Timestamp;
                }
            }
            else if (args.RoutedEvent == UIElement.MouseDownEvent)
            {
                MultitouchWindow.AddMouseListener(_attachedElement, OnMouseStuff);
                _downpoint[-1] = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);
            }
            else if (args.RoutedEvent == UIElement.MouseMoveEvent)
            {
                if (!_downpoint.ContainsKey(-1))
                {
                    return;
                }

                Point current = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);
                if (Point.Subtract(current, _downpoint[-1]).Length > Threshold)
                {
                    _downpoint.Remove(-1);
                }
            }
        }
Example #11
0
        private void OnStylusStuff(object sender, StylusEventArgs args)
        {
            if (args.RoutedEvent == UIElement.StylusUpEvent ||
                (args.RoutedEvent == UIElement.StylusDownEvent && args.Source == null) ||
                (args.RoutedEvent == UIElement.StylusMoveEvent && args.Source == null && args.InAir))
            {
                MultitouchWindow.RemoveStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);

                if (!_downpoint.ContainsKey(args.StylusDevice.Id))
                {
                    return;
                }

                //if (args.OriginalSource != _attachedElement) return;

                args.Handled = true;

                Point  current = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);
                Vector jitter  = Point.Subtract(current, _downpoint[args.StylusDevice.Id]);
                if (jitter.Length < Threshold)
                {
                    if (Tap != null)
                    {
                        Tap.Invoke(_attachedElement, new TapEventArgs(args.StylusDevice, jitter));
                    }

                    if (_button != null)
                    {
                        _button.SetValue(TapBehavior.IsPressedProperty, true);
                        _button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                        ExecuteCommandSource(_button);
                    }

                    if ((args.Timestamp - _lasttap) < DoubleTapDelay.TotalMilliseconds && DoubleTap != null)
                    {
                        DoubleTap.Invoke(_attachedElement, new TapEventArgs(args.StylusDevice, jitter));
                    }

                    if (_attachedElement is Control)
                    {
                        ((Control)_attachedElement).RaiseEvent(
                            new MouseButtonEventArgs(Mouse.PrimaryDevice, args.Timestamp,
                                                     MouseButton.Left, args.StylusDevice)
                        {
                            RoutedEvent = Control.MouseDoubleClickEvent
                        });
                    }

                    _lasttap = args.Timestamp;
                }
            }
            else if (args.RoutedEvent == UIElement.StylusDownEvent)
            {
                MultitouchWindow.AddStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);
                _downpoint[args.StylusDevice.Id] = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);

                if (_button != null)
                {
                    _button.SetValue(TapBehavior.IsPressedProperty, true);
                }
            }
            else if (args.RoutedEvent == UIElement.StylusMoveEvent)
            {
                if (!_downpoint.ContainsKey(args.StylusDevice.Id))
                {
                    return;
                }

                Point current = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);
                if (Point.Subtract(current, _downpoint[args.StylusDevice.Id]).Length > Threshold)
                {
                    _downpoint.Remove(args.StylusDevice.Id);

                    if (_button != null)
                    {
                        _button.SetValue(TapBehavior.IsPressedProperty, false);
                    }
                }
            }
        }
Example #12
0
 protected virtual void OnTap(TapEventArgs e)
 {
     Tap?.Invoke(this, e);
 }
Example #13
0
        public event Action <LoadUIElement> Tap;           // when this is tapped, share is tapped, or delete is tapped

        public LoadUIElement(String filePath) : base()
        {
            this.filePath = filePath;

            this.Orientation     = StackOrientation.Horizontal; //
            this.BackgroundColor = Color.Black;                 // Stylistic choices
            this.HeightRequest   = 50;                          //


            // Make a new label initialized with the song name

            Label songLabel = new Label
            {
                Text                    = FileUtilities.SongNameFromFilePath(filePath), // Make sure it displays the name of song
                FontSize                = 20,                                           //*
                BackgroundColor         = Color.Black,                                  //*
                TextColor               = Color.White,                                  //* Stylistic choices
                HorizontalTextAlignment = TextAlignment.Start,                          //*
                HorizontalOptions       = LayoutOptions.StartAndExpand,                 //*
                VerticalOptions         = LayoutOptions.CenterAndExpand,                //*
                InputTransparent        = true,                                         // Ensures the user can't tap on label instead of main body of this object
                Margin                  = new Thickness(17.0, 0.0)
            };


            // Make a button that lets user delete this object's song
            Button deleteButton = new Button
            {
                Text              = "DELETE",
                TextColor         = Color.Red,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.End,
                Margin            = 7
            };

            // Make a button that prompts user to share this song
            Button shareButton = new Button
            {
                Text              = "SHARE",
                TextColor         = Color.Blue,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.End,
                Margin            = 22
            };

            this.Children.Add(songLabel);       //
            this.Children.Add(shareButton);     // Add visual elements to this object
            this.Children.Add(deleteButton);    //


            // Ensure that gestures on the delete button, share button and rest of object are handled by public events

            deleteButton.Clicked += (s, e) => { DeleteClicked.Invoke(this); };
            shareButton.Clicked  += (s, e) => { ShareClicked.Invoke(this); };


            TapGestureRecognizer tgr = new TapGestureRecognizer()
            {
                Command = new Command(() => { Tap.Invoke(this); })
            };

            this.GestureRecognizers.Add(tgr);
        }
Example #14
0
 protected virtual void OnTap(bool tapped)
 {
     Tap?.Invoke(this, tapped);
 }
Example #15
0
        public MiniGrid(int semitoneShift) : base()
        {
            this.semitoneShift = semitoneShift;

            //No grid spacing
            this.ColumnSpacing   = 0;
            this.RowSpacing      = 0;
            this.BackgroundColor = Color.Black;
            //Using GridUnitType.Star means the squares will split the grid in half horizontally and vertically
            this.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            this.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                                // Add in column definitions
            this.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            this.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });                                                                                            // Add in row definitions

            // Add in boxviews
            topLeft = new BoxView {
                BackgroundColor = NoNotesColor
            };
            topRight = new BoxView {
                BackgroundColor = NoNotesColor
            };
            bottomLeft = new BoxView {
                BackgroundColor = NoNotesColor
            };
            bottomRight = new BoxView {
                BackgroundColor = NoNotesColor
            };

            this.Children.Add(topLeft, 0, 0);
            this.Children.Add(topRight, 1, 0);
            this.Children.Add(bottomLeft, 0, 1);
            this.Children.Add(bottomRight, 1, 1);

            //When created the top left boxview will cover the whole grid
            Grid.SetColumnSpan(topLeft, 2);
            Grid.SetRowSpan(topLeft, 2);

            // Give the grid a tapGesture recognizer
            TapGestureRecognizer tgr = new TapGestureRecognizer()
            {
                Command = new Command(delegate()
                {
                    Tap.Invoke(this);
                })
            };

            //Add recognizer to the grid itself and each of the boxes
            this.GestureRecognizers.Add(tgr);
            topLeft.GestureRecognizers.Add(tgr);
            topRight.GestureRecognizers.Add(tgr);
            bottomLeft.GestureRecognizers.Add(tgr);
            bottomRight.GestureRecognizers.Add(tgr);
        }
Example #16
0
 /// <summary>
 /// Raises the <see cref="Tap"/> event.
 /// </summary>
 /// <param name="fingerID">A value which identifies the finger which was tapped.</param>
 /// <param name="x">The x-coordinate at which the finger was tapped.</param>
 /// <param name="y">The y-coordinate at which the finger was tapped.</param>
 protected virtual void OnTap(Int64 fingerID, Single x, Single y) =>
 Tap?.Invoke(this, fingerID, x, y);