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);
                        }
                    }
                }
            }
        }