public override void HoveringUpdate(NVRHand hand, float forTime)
 {
     base.HoveringUpdate(hand, forTime);
     OnHovering.Invoke();
 }
예제 #2
0
        /// <summary>
        /// GUI部品を更新する。
        /// </summary>
        /// <param name="mouse">マウス。</param>
        /// <param name="pointX">マウスの相対X座標。</param>
        /// <param name="pointY">マウスの相対Y座標。</param>
        public virtual void Update(Mouse mouse = null, int?pointX = null, int?pointY = null)
        {
            if (mouse == null)
            {
                LeftJudge = (false, (0, 0));

                LongClickCounter.Stop();
                LongClickCounter.Reset();

                Dragging = false;
                return;
            }

            if (!pointX.HasValue || !pointY.HasValue)
            {
                MousePoint = (mouse.Point.x - X, mouse.Point.y - Y);
            }
            else
            {
                MousePoint = (pointX.Value - X, pointY.Value - Y);
            }

            var outSide = IsOutSide();

            if (!outSide)
            {
                OnHovering?.Invoke(this, new MouseClickEventArgs(MousePoint.x, MousePoint.y));
                if (!Hovering)
                {
                    OnMouseEnter?.Invoke(this, new MouseClickEventArgs(MousePoint.x, MousePoint.y));
                    Hovering = true;
                }
            }
            else
            {
                if (Hovering)
                {
                    OnMouseLeave?.Invoke(this, new MouseClickEventArgs(MousePoint.x, MousePoint.y));
                    Hovering = false;
                }
            }

            if (mouse.IsPushedButton(MouseButton.Left))
            {
                // マウス初回クリック処理
                if (!outSide)
                {
                    LeftJudge = (true, MousePoint);
                    LongClickCounter?.Start();
                    OnMouseDown?.Invoke(this, new MouseClickEventArgs(MousePoint.x, MousePoint.y));
                }
            }
            else if (mouse.IsPushingButton(MouseButton.Left))
            {
                // マウスが要素内をクリックしてるかどうかの判定
                if (LeftJudge.Item1)
                {
                    if (outSide)
                    {
                        LeftJudge = (false, MousePoint);
                        OnMouseUp?.Invoke(this, new MouseClickEventArgs(MousePoint.x, MousePoint.y));
                        LongClickCounter.Stop();
                        LongClickCounter.Reset();
                    }
                    else
                    {
                        LongClickCounter?.Tick();
                        if (LongClickCounter.State == TimerState.Stopped)
                        {
                            // ロングタップ
                            LeftJudge = (false, MousePoint);
                            OnMouseUp?.Invoke(this, new MouseClickEventArgs(MousePoint.x, MousePoint.y));
                            if (!Dragging)
                            {
                                LongClicked?.Invoke(this, new MouseClickEventArgs(MousePoint.x, MousePoint.y));
                            }
                            LongClickCounter.Stop();
                            LongClickCounter.Reset();

                            Dragging = false;
                        }
                    }
                }
            }
            else if (mouse.IsLeftButton(MouseButton.Left))
            {
                // クリック判定
                if (LeftJudge.Item1)
                {
                    if (!Dragging)
                    {
                        Clicked?.Invoke(this, new MouseClickEventArgs(MousePoint.x, MousePoint.y));
                    }
                    OnMouseUp?.Invoke(this, new MouseClickEventArgs(MousePoint.x, MousePoint.y));
                }
                LongClickCounter.Stop();
                LongClickCounter.Reset();

                Dragging = false;
            }

            foreach (var item in Child)
            {
                item.Update(mouse, MousePoint.x, MousePoint.y);
            }
        }