Exemple #1
0
        /// <summary>
        /// Handler for holding the button.
        /// </summary>
        private void StartHoldingHandler(object?state)
        {
            _holdingTimer?.Dispose();
            _holdingTimer = null;
            _holdingState = ButtonHoldingState.Started;

            Holding?.Invoke(this, new ButtonHoldingEventArgs {
                HoldingState = ButtonHoldingState.Started
            });
        }
Exemple #2
0
        private void _DispatcherTimer_Tick(object sender, object e)
        {
            // コントローラー入力をチェック
            foreach (var controller in UINavigationController.UINavigationControllers.Take(1))
            {
                var currentInput = controller.GetCurrentReading();

                // ボタンを離した瞬間を検出
                var pressing = RequiredUINavigationButtonsHelper.ToUINavigationButtons(currentInput.RequiredButtons)
                               | OptionalUINavigationButtonsHelper.ToUINavigationButtons(currentInput.OptionalButtons);

//                var trigger = pressing & (_PrevPressingButtons ^ pressing);
                var released = _PrevPressingButtons & (_PrevPressingButtons ^ pressing);

                if (released != UINavigationButtons.None)
                {
                    Pressed?.Invoke(this, released);
                }

                // ホールド入力の検出
                UINavigationButtons holdingButtons = UINavigationButtons.None;
                foreach (var target in __InputDetectTargets)
                {
                    if (pressing.HasFlag(target))
                    {
                        if (!_ProcessedHoldingButtons.HasFlag(target))
                        {
                            var time = _ButtonHold[target] += __InputPollingInterval;

                            if (time > __HoldDetectTime)
                            {
                                holdingButtons           |= target;
                                _ProcessedHoldingButtons |= target;
                            }
                        }
                    }
                    else
                    {
                        _ButtonHold[target]      = TimeSpan.Zero;
                        _ProcessedHoldingButtons = (((UINavigationButtons)0) ^ target) & _ProcessedHoldingButtons;
                    }
                }

                if (holdingButtons != UINavigationButtons.None)
                {
                    Holding?.Invoke(this, holdingButtons);
                }

                // トリガー検出用に前フレームの入力情報を保存
                _PrevPressingButtons = pressing;
            }
        }
Exemple #3
0
        /// <summary>
        /// Handler for releasing the button.
        /// </summary>
        protected void HandleButtonReleased()
        {
            if (_debounceTime.Ticks > 0 && !IsPressed)
            {
                return;
            }

            _debounceStartTicks = DateTime.UtcNow.Ticks;
            _holdingTimer?.Dispose();
            _holdingTimer = null;

            IsPressed = false;

            ButtonUp?.Invoke(this, new EventArgs());
            Press?.Invoke(this, new EventArgs());

            if (IsHoldingEnabled && _holdingState == ButtonHoldingState.Started)
            {
                _holdingState = ButtonHoldingState.Completed;
                Holding?.Invoke(this, new ButtonHoldingEventArgs {
                    HoldingState = ButtonHoldingState.Completed
                });
            }

            if (IsDoublePressEnabled)
            {
                if (_lastPress == DateTime.MinValue.Ticks)
                {
                    _lastPress = DateTime.UtcNow.Ticks;
                }
                else
                {
                    if (DateTime.UtcNow.Ticks - _lastPress <= _doublePressTicks)
                    {
                        DoublePress?.Invoke(this, new EventArgs());
                    }

                    _lastPress = DateTime.MinValue.Ticks;
                }
            }
        }
Exemple #4
0
 public void OnHolding()
 {
     Holding?.Invoke();
 }
 internal void RaiseHolding(HoldingRoutedEventArgs args)
 {
     Holding?.Invoke(this, args);
 }