Example #1
0
        public bool GetTooltip(Vector2 windowMouseCoordinates, out string tooltip, out Rect screenRectPosition)
        {
            tooltip            = string.Empty;
            screenRectPosition = Rect.zero;

            VisualElement target = m_Panel.Pick(windowMouseCoordinates);

            if (target != null)
            {
                using (var tooltipEvent = TooltipEvent.GetPooled())
                {
                    tooltipEvent.target  = target;
                    tooltipEvent.tooltip = null;
                    tooltipEvent.rect    = Rect.zero;
                    target.SendEvent(tooltipEvent);

                    if (!string.IsNullOrEmpty(tooltipEvent.tooltip) && !tooltipEvent.isDefaultPrevented)
                    {
                        tooltip            = tooltipEvent.tooltip;
                        screenRectPosition = tooltipEvent.rect;
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #2
0
        internal static void SetTooltip(float mouseX, float mouseY)
        {
            //mouseX,mouseY are screen relative.
            GUIView view = GUIView.mouseOverView;

            if (view != null && view.visualTree != null && view.visualTree.panel != null)
            {
                var panel = view.visualTree.panel;

                // Pick expect view relative coordinates.
                VisualElement target = panel.Pick(new Vector2(mouseX, mouseY) - view.screenPosition.position);
                if (target != null)
                {
                    using (var tooltipEvent = TooltipEvent.GetPooled())
                    {
                        tooltipEvent.target  = target;
                        tooltipEvent.tooltip = null;
                        tooltipEvent.rect    = Rect.zero;
                        target.SendEvent(tooltipEvent);

                        if (!string.IsNullOrEmpty(tooltipEvent.tooltip) && !tooltipEvent.isDefaultPrevented)
                        {
                            Rect rect = tooltipEvent.rect;
                            rect.position += view.screenPosition.position; //SetMouseTooltip expects Screen relative coordinates.

                            GUIStyle.SetMouseTooltip(tooltipEvent.tooltip, rect);
                        }
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        ///     事件處理
        /// </summary>
        /// <param name="eveneType">事件類別</param>
        /// <param name="mouseEvent">滑鼠事件</param>
        public void HandleEvent(TooltipEvent eveneType, MouseEvent mouseEvent)
        {
            if (this.CurrentTransitionFunction == null)
            {
                throw new UnexpectedStateException();
            }

            var nextState = this.CurrentTransitionFunction.HandledEvent(eveneType, mouseEvent);

            this.StateTransition(nextState);
        }
Example #4
0
        /// <summary>
        ///     處理事件
        /// </summary>
        /// <param name="tooltipEvent">事件類別</param>
        /// <param name="mouseEvent">滑鼠事件</param>
        /// <returns>下一個狀態</returns>
        public TooltipState HandledEvent(TooltipEvent tooltipEvent, MouseEvent mouseEvent)
        {
            // 取得事件對應的處理函式
            if (!this.EventHandlers.TryGetValue(tooltipEvent, out var handler))
            {
                throw new UnexpectedEventException();
            }

            // 呼叫處理函式
            var nextState = handler(mouseEvent);

            return(nextState);
        }
Example #5
0
        /// <summary>
        ///     呼叫狀態處理含式
        /// </summary>
        /// <param name="anotherState">狀態</param>
        /// <param name="anotherEvent">事件類別</param>
        /// <param name="mouseEvent">滑鼠事件</param>
        /// <returns>回傳下一個狀態</returns>
        public TooltipState CallTransitionFunction(TooltipState anotherState, TooltipEvent anotherEvent,
                                                   MouseEvent mouseEvent)
        {
            // 取得狀態轉移函式
            if (!this.TransitionFunctions.TryGetValue(anotherState, out var transitionFunction))
            {
                throw new UnexpectedStateException();
            }

            // 呼叫狀態轉移函式
            var nextState = transitionFunction.HandledEvent(anotherEvent, mouseEvent);

            return(nextState);
        }
Example #6
0
        protected void OnTooltip(TooltipEvent evt)
        {
            // TODO: Better implementation that can be styled
            if (evt.target == titleContainer.Q("title-label"))
            {
                var typeData = NodeReflection.GetNodeType(Target.GetType());
                evt.tooltip = typeData?.Help;

                // Float the tooltip above the node title bar
                var bound = titleContainer.worldBound;
                bound.x       = 0;
                bound.y       = 0;
                bound.height *= -1;

                evt.rect = titleContainer.LocalToWorld(bound);
            }
        }
Example #7
0
 public void NotifyTooltipClose(TooltipEvent eventArgs)
 {
     OnTooltipClose?.Invoke(this, eventArgs);
 }
Example #8
0
 public void NotifyTooltipOpen(TooltipEvent eventArgs)
 {
     OnTooltipOpen?.Invoke(this, eventArgs);
 }