コード例 #1
0
        void OnTapStarted(TapData data)
        {
            if (effect?.IsDisabled ?? true)
            {
                return;
            }

            IsCanceled = false;
            HandleTouch(TouchStatus.Started, TouchInteractionStatus.Started);
        }
コード例 #2
0
        void OnGestureEnded(TapData data)
        {
            if (effect?.IsDisabled ?? true)
            {
                return;
            }

            HandleTouch(effect?.Status == TouchStatus.Started ? TouchStatus.Completed : TouchStatus.Canceled, TouchInteractionStatus.Completed);
            IsCanceled   = true;
            tapCompleted = true;
        }
コード例 #3
0
        private void ProcessActiveContact(TouchpadEventArgs eventArgs)
        {
            // If we're not inside an active 'tap', instantiate one.
            if (currentTap == null)
            {
                currentTap = new TapData(Constants.MaxContacts);
            }

            bool wasActive = currentTap.InstantaneousActiveContacts[eventArgs.ContactIndex];

            currentTap.InstantaneousActiveContacts[eventArgs.ContactIndex] = true;

            // If we were previously active, add the distance from the last X/Y
            // to this new one to the total distance in the tap object.
            if (wasActive)
            {
                uint previousX = currentTap.PreviousXValues[eventArgs.ContactIndex];
                uint previousY = currentTap.PreviousYValues[eventArgs.ContactIndex];

                double positionDelta = Math.Sqrt(Math.Pow((double)eventArgs.X - previousX, 2) + Math.Pow((double)eventArgs.Y - previousY, 2));
                currentTap.TotalContactDistances[eventArgs.ContactIndex] += positionDelta;
            }

            currentTap.MaximumActiveContacts = Math.Max(currentTap.InstantaneousActiveContacts.Count(ac => ac), currentTap.MaximumActiveContacts);
            currentTap.MaximumPressure       = Math.Max(currentTap.MaximumPressure, eventArgs.Pressure);

            currentTap.PreviousXValues[eventArgs.ContactIndex] = eventArgs.X;
            currentTap.PreviousYValues[eventArgs.ContactIndex] = eventArgs.Y;

            if (eventArgs.Pressure >= config.TapTriggerThreshold)
            {
                currentTap.TapThresholdMet = true;
            }

            // If we're not minimized, update the form values
            if (WindowState != FormWindowState.Minimized &&
                (!lastActiveContactUiUpdates[eventArgs.ContactIndex].HasValue || (DateTime.Now - lastActiveContactUiUpdates[eventArgs.ContactIndex].Value).TotalMilliseconds >= 50))
            {
                ActiveContactDisplay contactDisplay = activeContactDisplays[eventArgs.ContactIndex];

                contactDisplay.Active   = true;
                contactDisplay.Pressure = eventArgs.Pressure;
                contactDisplay.X        = eventArgs.X;
                contactDisplay.Y        = eventArgs.Y;

                lastActiveContactUiUpdates[eventArgs.ContactIndex] = DateTime.Now;
            }
        }
コード例 #4
0
        void OnGestureAborted(TapData data)
        {
            if (effect?.IsDisabled ?? true)
            {
                return;
            }

            if (tapCompleted || longTapStarted)
            {
                tapCompleted   = false;
                longTapStarted = false;
                return;
            }

            HandleTouch(TouchStatus.Canceled, TouchInteractionStatus.Completed);
            IsCanceled = true;
        }
コード例 #5
0
        protected override async Task OnInitializedAsync()
        {
            var state = await AuthState;

            Message     = string.Empty;
            StatusClass = string.Empty;
            try
            {
                Response = await UserGraphService.SetTapAsync(state.User.Identity.Name);
            }
            catch (System.Exception ex)
            {
                StatusClass = "alert-danger";
                Message     = "An error occurred while setting the temporary access password for you.";
            }
            await base.OnInitializedAsync();
        }
コード例 #6
0
        private void HandleContactEnd(object sender, TouchpadEventArgs e)
        {
            // If the tap object is null, just bail out
            if (currentTap == null)
            {
                return;
            }

            currentTap.InstantaneousActiveContacts[e.ContactIndex] = false;
            int currentActiveContacts = currentTap.InstantaneousActiveContacts.Count(ac => ac);

            // Has the tap ended?
            if (currentActiveContacts == 0)
            {
                DateTime tapEnd = DateTime.Now;

                // Okay, was this *really* a tap?
                // We need to validate by checking the total duration, whether the pressure threshold was met,
                // and if the distance was within the maximum range.
                if ((tapEnd - currentTap.Start).TotalMilliseconds <= config.MaxTapMilliseconds &&
                    currentTap.TapThresholdMet &&
                    currentTap.TotalContactDistances.Max() <= config.MaxTapDeltaPosition)
                {
                    // If it was a single-finger tap, inject a left click.
                    if (currentTap.MaximumActiveContacts == 1)
                    {
                        SendLeftClick();
                    }
                    // If it was a double-finger tap, inject a right click.
                    else if (currentTap.MaximumActiveContacts == 2)
                    {
                        SendRightClick();
                    }
                    else if (currentTap.MaximumActiveContacts == 3)
                    {
                        SendMiddleClick();
                    }
                }

                // Store reference to previous tap. Will probably need this later
                // if we want to add in support for double-tap-and-drag.
                previousTap = currentTap;

                // Clear out current tap, for it is over and done
                currentTap = null;

                // If we're not minimized, update form values
                if (WindowState != FormWindowState.Minimized)
                {
                    // Update previous tap display
                    previousMaxPressureLabel.Text  = previousTap.MaximumPressure.ToString();
                    previousDurationLabel.Text     = ((int)(tapEnd - previousTap.Start).TotalMilliseconds).ToString();
                    previousMaxDistanceLabel.Text  = ((int)previousTap.TotalContactDistances.Max()).ToString();
                    previousContactCountLabel.Text = previousTap.MaximumActiveContacts.ToString();

                    previousMaxPressureLabel.ForeColor = previousTap.MaximumPressure >= config.TapTriggerThreshold
                        ? Color.DarkGreen
                        : Color.DarkRed;
                    previousDurationLabel.ForeColor = (tapEnd - previousTap.Start).TotalMilliseconds < config.MaxTapMilliseconds
                        ? Color.DarkGreen
                        : Color.DarkRed;
                    previousMaxDistanceLabel.ForeColor = previousTap.TotalContactDistances.Max() < config.MaxTapDeltaPosition
                        ? Color.DarkGreen
                        : Color.DarkRed;
                    previousContactCountLabel.ForeColor = previousTap.MaximumActiveContacts >= 1 && previousTap.MaximumActiveContacts <= 3
                        ? Color.Green
                        : Color.DarkRed;
                }
            }

            if (WindowState != FormWindowState.Minimized)
            {
                ActiveContactDisplay contactDisplay = activeContactDisplays[e.ContactIndex];

                contactDisplay.Active   = false;
                contactDisplay.Pressure = 0;
                contactDisplay.X        = 0;
                contactDisplay.Y        = 0;
            }
        }
コード例 #7
0
 private void OnPreciseTap(TapData tapData)
 {
 }