Esempio n. 1
0
        /// <summary>
        /// Creates new tooltip form for displaying given tooltip
        /// </summary>
        public static ToolTipForm CreateToolTipForm(string text)
        {
            IToolTipRenderer renderer = null;

            if (playerTooltipRenderer == null)
            {
                playerTooltipRenderer = new PlayerTooltipRenderer();
                battleTooltipRenderer = new BattleTooltipRenderer();
                mapTooltipRenderer    = new MapTooltipRenderer();
                textTooltipRenderer   = new TextTooltipRenderer();
            }

            if (text.StartsWith("#user#"))
            {
                playerTooltipRenderer.SetPlayerTooltipRenderer(text.Substring(6));
                renderer = playerTooltipRenderer;
            }
            else if (text.StartsWith("#battle#"))
            {
                battleTooltipRenderer.SetBattleTooltipRenderer(int.Parse(text.Substring(8)));
                renderer = battleTooltipRenderer;
            }
            else if (text.StartsWith("#map#"))
            {
                mapTooltipRenderer.SetMapTooltipRenderer(text.Substring(5));
                renderer = mapTooltipRenderer;
            }
            else
            {
                textTooltipRenderer.SetTextTooltipRenderer(text);
                renderer = textTooltipRenderer;
            }

            if (nt == null)
            {
                nt = new ToolTipForm(renderer);
            }
            else
            {
                nt.toolTipRenderer = renderer;
            }

            var size = nt.GetTooltipSize();

            if (size != null)
            {
                nt.Size   = size.Value;
                nt.active = true;
            }
            else
            {
                nt.active = false;
            }

            return(nt);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates new tooltip form for displaying given tooltip
        /// </summary>
        public static ToolTipForm CreateToolTipForm(string text)
        {
            IToolTipRenderer renderer = null;

            if (text.StartsWith("#user#"))
            {
                renderer = new PlayerTooltipRenderer(text.Substring(6));
            }
            else if (text.StartsWith("#battle#"))
            {
                renderer = new BattleTooltipRenderer(int.Parse(text.Substring(8)));
            }
            else if (text.StartsWith("#map#"))
            {
                renderer = new MapTooltipRenderer(text.Substring(5));
            }
            else
            {
                renderer = new TextTooltipRenderer(text);
            }

            var nt   = new ToolTipForm(renderer);
            var size = nt.GetTooltipSize();

            if (size != null)
            {
                nt.Size = size.Value;
            }
            else
            {
                nt.Dispose();
                return(null);
            }

            return(nt);
        }
Esempio n. 3
0
        private void RefreshToolTip(bool invalidate)
        {
            if (Program.MainWindow != null && Program.MainWindow.IsHandleCreated && !Program.CloseOnNext && Program.MainWindow.Visible && Program.MainWindow.WindowState != FormWindowState.Minimized)
            {
                var    control = MainWindow.Instance.GetHoveredControl();
                string text    = null;
                if (control != null)
                {
                    tooltips.TryGetValue(control, out text);
                }
                bool isWindowActive = Form.ActiveForm != null;
                //bool newTooltip = false; //to trigger position update for Method A

                if (lastText != text || lastVisible != Visible || lastActive != isWindowActive)
                {
                    if (tooltip != null)
                    {
                        tooltip.Visible = false;
                    }

                    if (!string.IsNullOrEmpty(text) && Visible && isWindowActive)
                    {
                        tooltip = ToolTipForm.CreateToolTipForm(text);
                        if (tooltip.IsDrawing)
                        {
                            tooltip.Visible = true;
                        }
                    }

                    lastText    = text;
                    lastVisible = visible;
                    lastActive  = isWindowActive;
                    //newTooltip = true; //trigger position update
                }

                if (tooltip != null && tooltip.Visible)
                {
                    //method B: tooltip remain stationary until user block the vision or when new tooltip is available
                    //var mp = System.Windows.Forms.Control.MousePosition;
                    //int tooltipLocationX = tooltip.Location.X;
                    //int tooltipLocationY = tooltip.Location.Y;
                    //if (mp.X > tooltipLocationX && mp.X < tooltipLocationX + tooltip.Width)
                    //{
                    //    if (mp.Y > tooltipLocationY && mp.Y < tooltipLocationY + tooltip.Height)
                    //    {
                    //        newTooltip = true;
                    //    }
                    //}
                    //if (Math.Abs(mp.X - tooltipLocationX) > 50 || Math.Abs(mp.Y - tooltipLocationY) > 50)
                    //{
                    //    newTooltip = true;
                    //}
                    //if (newTooltip) //set new position for new tooltip
                    //{
                    //    var point = MainWindow.Instance.PointToScreen(new Point(5, 5));
                    //    var scr = Screen.GetWorkingArea(new Point((int)point.X, (int)point.Y));

                    //    //need screen0's bounds because SetDesktopLocation is relative to screen0.
                    //    var scr1 = Screen.AllScreens[0].WorkingArea;
                    //    var scr1B = Screen.AllScreens[0].Bounds;

                    //    var nx = Math.Min(mp.X + 14 + scr1B.X - scr1.X, scr.Right - tooltip.Width - 2);
                    //    var ny = Math.Min(mp.Y + 14 + scr1B.Y - scr1.Y, scr.Bottom - tooltip.Height - 2);

                    //    var rect = new Rectangle(nx, ny, tooltip.Width, tooltip.Height);
                    //    if (rect.Contains(mp))
                    //    {
                    //        nx = mp.X - tooltip.Width - 8;
                    //        ny = mp.Y - tooltip.Height - 8;
                    //    }

                    //    SetWindowPos(tooltip.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_ToolTipOption);
                    //    tooltip.SetDesktopLocation(nx, ny);

                    //    var newSize = tooltip.GetTooltipSize();
                    //    if (newSize.HasValue && newSize.Value != tooltip.Size) tooltip.Size = newSize.Value;
                    //}
                    //end method B

                    //method A: tooltip follow mouse cursor everywhere it go
                    var mp = System.Windows.Forms.Control.MousePosition;

                    var point = MainWindow.Instance.PointToScreen(new Point(5, 5));
                    var scr   = Screen.GetWorkingArea(new Point((int)point.X, (int)point.Y));

                    //need screen0's bounds because SetDesktopLocation is relative to screen0.
                    var scr1  = Screen.AllScreens[0].WorkingArea;
                    var scr1B = Screen.AllScreens[0].Bounds;

                    var nx = Math.Min(mp.X + 14 + scr1B.X - scr1.X, scr.Right - tooltip.Width - 2);
                    var ny = Math.Min(mp.Y + 14 + scr1B.Y - scr1.Y, scr.Bottom - tooltip.Height - 2);

                    var rect = new Rectangle(nx, ny, tooltip.Width, tooltip.Height);
                    if (rect.Contains(mp))
                    {
                        nx = mp.X - tooltip.Width - 8;
                        ny = mp.Y - tooltip.Height - 8;
                    }

                    if (Environment.OSVersion.Platform != PlatformID.Unix)
                    {
                        SetWindowPos(tooltip.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_ToolTipOption); //refresh tooltip's Z-order to be on top
                    }
                    tooltip.SetDesktopLocation(nx, ny);

                    var newSize = tooltip.GetTooltipSize();
                    if (newSize.HasValue && newSize.Value != tooltip.Size)
                    {
                        tooltip.Size = newSize.Value;
                    }
                    //end method A

                    if (invalidate)
                    {
                        tooltip.Invalidate(true);
                    }
                }
            }
        }
        /// <summary>
        /// Creates new tooltip form for displaying given tooltip
        /// </summary>
        public static ToolTipForm CreateToolTipForm(string text)
        {
            IToolTipRenderer renderer = null;

            if (playerTooltipRenderer == null) 
            {
                playerTooltipRenderer = new PlayerTooltipRenderer();
                battleTooltipRenderer = new BattleTooltipRenderer();
                mapTooltipRenderer = new MapTooltipRenderer();
                textTooltipRenderer = new TextTooltipRenderer();
            }

            if (text.StartsWith ("#user#")) 
            {
                playerTooltipRenderer.SetPlayerTooltipRenderer (text.Substring (6));
                renderer = playerTooltipRenderer;
            } 
            else if (text.StartsWith ("#battle#")) 
            {
                battleTooltipRenderer.SetBattleTooltipRenderer (int.Parse (text.Substring (8)));
                renderer = battleTooltipRenderer;
            } 
            else if (text.StartsWith ("#map#")) 
            {
                mapTooltipRenderer.SetMapTooltipRenderer (text.Substring (5));
                renderer = mapTooltipRenderer;
            } 
            else 
            {
                textTooltipRenderer.SetTextTooltipRenderer (text);
                renderer = textTooltipRenderer;
            }

            if (nt == null)
                nt = new ToolTipForm (renderer);
            else
                nt.toolTipRenderer = renderer;

            var size = nt.GetTooltipSize();
            if (size != null) 
            {
                nt.Size = size.Value;
                nt.active = true;
            }
            else
                nt.active = false;

            return nt;
        }
        private void RefreshToolTip(bool invalidate) {
            if (Program.MainWindow != null && Program.MainWindow.IsHandleCreated && !Program.CloseOnNext && Program.MainWindow.Visible && Program.MainWindow.WindowState != FormWindowState.Minimized) {

                var control = MainWindow.Instance.GetHoveredControl();
                string text = null;
                if (control != null) tooltips.TryGetValue(control, out text);
                bool isWindowActive = Form.ActiveForm != null;
                //bool newTooltip = false; //to trigger position update for Method A

                if (lastText != text || lastVisible != Visible || lastActive != isWindowActive) {
                    if (tooltip != null)
                        tooltip.Visible = false;

                    if (!string.IsNullOrEmpty(text) && Visible && isWindowActive) {
                        tooltip = ToolTipForm.CreateToolTipForm(text);
                        if (tooltip.IsDrawing)
                            tooltip.Visible = true;
                    }

                    lastText = text;
                    lastVisible = visible;
                    lastActive = isWindowActive;
                    //newTooltip = true; //trigger position update
                }

                if (tooltip != null && tooltip.Visible) {
                    //method B: tooltip remain stationary until user block the vision or when new tooltip is available
                    //var mp = System.Windows.Forms.Control.MousePosition;
                    //int tooltipLocationX = tooltip.Location.X;
                    //int tooltipLocationY = tooltip.Location.Y;
                    //if (mp.X > tooltipLocationX && mp.X < tooltipLocationX + tooltip.Width)
                    //{
                    //    if (mp.Y > tooltipLocationY && mp.Y < tooltipLocationY + tooltip.Height)
                    //    {
                    //        newTooltip = true;
                    //    }
                    //}
                    //if (Math.Abs(mp.X - tooltipLocationX) > 50 || Math.Abs(mp.Y - tooltipLocationY) > 50)
                    //{
                    //    newTooltip = true;
                    //}
                    //if (newTooltip) //set new position for new tooltip
                    //{
                    //    var point = MainWindow.Instance.PointToScreen(new Point(5, 5));
                    //    var scr = Screen.GetWorkingArea(new Point((int)point.X, (int)point.Y));

                    //    //need screen0's bounds because SetDesktopLocation is relative to screen0.
                    //    var scr1 = Screen.AllScreens[0].WorkingArea;
                    //    var scr1B = Screen.AllScreens[0].Bounds;

                    //    var nx = Math.Min(mp.X + 14 + scr1B.X - scr1.X, scr.Right - tooltip.Width - 2);
                    //    var ny = Math.Min(mp.Y + 14 + scr1B.Y - scr1.Y, scr.Bottom - tooltip.Height - 2);

                    //    var rect = new Rectangle(nx, ny, tooltip.Width, tooltip.Height);
                    //    if (rect.Contains(mp))
                    //    {
                    //        nx = mp.X - tooltip.Width - 8;
                    //        ny = mp.Y - tooltip.Height - 8;
                    //    }

                    //    SetWindowPos(tooltip.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_ToolTipOption);
                    //    tooltip.SetDesktopLocation(nx, ny);

                    //    var newSize = tooltip.GetTooltipSize();
                    //    if (newSize.HasValue && newSize.Value != tooltip.Size) tooltip.Size = newSize.Value;
                    //} 
                    //end method B
                    
                    //method A: tooltip follow mouse cursor everywhere it go
                    var mp = System.Windows.Forms.Control.MousePosition;

                    var point = MainWindow.Instance.PointToScreen(new Point(5, 5));
                    var scr = Screen.GetWorkingArea(new Point((int)point.X, (int)point.Y));

                    //need screen0's bounds because SetDesktopLocation is relative to screen0.
                    var scr1 = Screen.AllScreens[0].WorkingArea;
                    var scr1B = Screen.AllScreens[0].Bounds;

                    var nx = Math.Min(mp.X + 14 + scr1B.X - scr1.X, scr.Right - tooltip.Width - 2);
                    var ny = Math.Min(mp.Y + 14 + scr1B.Y - scr1.Y, scr.Bottom - tooltip.Height - 2);

                    var rect = new Rectangle(nx, ny, tooltip.Width, tooltip.Height);
                    if (rect.Contains(mp))
                    {
                        nx = mp.X - tooltip.Width - 8;
                        ny = mp.Y - tooltip.Height - 8;
                    }

                    if (Environment.OSVersion.Platform != PlatformID.Unix)
                    {
                        SetWindowPos(tooltip.Handle, HWND_TOPMOST, 0, 0, 0,0, SWP_ToolTipOption); //refresh tooltip's Z-order to be on top
                    }
                    tooltip.SetDesktopLocation(nx, ny); 

                    var newSize = tooltip.GetTooltipSize();
                    if (newSize.HasValue && newSize.Value != tooltip.Size) tooltip.Size = newSize.Value;
                    //end method A

                    if (invalidate) tooltip.Invalidate(true);
                }
            }
        }