AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Smart Tooltip function

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Trubbleguy



Joined: 20 Jan 2007
Posts: 96
Location: Melbourne

PostPosted: Sun Dec 06, 2009 7:19 am    Post subject: Smart Tooltip function Reply with quote

I have spent hours and hours trying to get a tooltip that is smooth and fluid when in use and finally made a function to do it reliably.
I hate it when a tooltip stays onscreen, well this fixes that nicely.

Sample Gui
Code:
;Usage   TT  = Tooltip label
;Usage   1  =  A_GUI label
;Usage   variable (no spaces can be in its name)  = Tooltip Control label

;Usage eg: TT_1_spin=Check this box to turn blah blah blah blah,    multiple lines can be created using `n

;TT for tooltip prefix_first Gui_variable to match control is "SPIN"   




#SingleInstance , Force

#include tooltip.ahk  ;the tooltip Function that does all the work.

CoordMode, ToolTip                       ;makes tooltip screen aware

OnMessage(0x200,"MouseOVER")             ;turn on Mousover detection (Put this in the Function code for permanent tooltips)

badchars=~,&,<,>,+,*,/,(,),-,:,\,.,`n    ;some known bad characters that variables hate

ex:=A_ScreenWidth-130  ;used to set Gui top RIght of screen, out of the way, but down far enough to close windows underneath

Gui, Margin ,0, 0
Gui, +AlwaysOnTop +BackgroundTrans
Gui, Add, checkbox,vspin checked%spin% x1 y5,Spin Name 2 UK
TT_1_spin=Check this box to turn`n   Parton, Dolly`n       Into`n   Dolly Parton`nwhen F2 is pressed
 
Gui, Add, checkbox,vsort x1 y+2,Sort Into Folders (F3)
TT_1_sort=Check to Enable F3 key to Move mixed `nkaraoke files Into folders using their DiskID`n`nSC8123-10-The Rose - Midler, Bette`n      moves to`n...\SC8123\SC8123-10-The Rose - Midler, Bette`n`nThe F3 Key is Disabled when Unchecked`nNB:   THIS DOES NOT SPIN THE NAME!!!!

Gui, Add, checkbox,vcase checked%case% x1 y+2,First letter UpperCase
TT_1_case=Makes the first letter of each word Uppercase

Gui, Add, button,xp y+1 gtrubbleguy.com vlogopic w120 h20,Trubbleguy.com
TT_1_logopic=Click on the file you want to spin`nIn its folder, and Press the F2 Key`n`nSC8123-10- The Rose - Midler, Bette.zip`n      will change to`nSC8123-10- Midler, Bette - The Rose.zip`n`nIf all files in folder need spinning`nHold CTRL + ALT down and tap F2 Key`n`nNB: This will only work, for the last 2 parts`nof the filename, Ignoring the   SC8123-10 `n`nClick button to open Trubbleguy.com

Gui, Add, Progress,xp y+1 wp h10 cBlue vMyProgress Range0-120000

gui, show ,x%ex% y20 AutoSize,%prgtitle%

return


Function:
tooltip.ahk
Code:

;tooltip.ahk

MOUSEOVER()
   {
   _tword=%A_GuiControl% ;make A_GuiControl a modifyable variable
   if TT_%A_Gui%_%_tword% = %_tips%
      return
   ControlGetpos,1x, 1y,1width,1Height,%_tword%
   MouseGetPos, OX, OY
   gx:=1X + 1Width
   gy:=1y + 1Height
   if OX between 1X and gx
      if OY between 1y and gy
         if _tword
            {
            StringReplace,_tword,_tword,%A_Space%,,all ;remove the Spaces so it can find the ToolTip
            _tip=  ;wipe old tip
            if _tword contains %badchars%
               loop,parse,badchars,csv
                  StringReplace,_tword,_tword,%A_LoopField%,,all
            _tips=TT_%A_Gui%_%_tword% ;get the ToolTips name
            if _tips             ;if it has data in it
               _tip:=TT_%A_Gui%_%_tword% ;get the ToolTip to display
            if _tip
               ToolTip %_tip% ;display it
            }
   settimer,removetool,100
   return
   
   ;############################## False end of Function code ##############################
   
   ;%%%%%%%%%% Subs below here work fine called from your main script, saves a lot of copying
   ;%%%%%%%%%% for some reason a subroutine can sit inside a Function and still work fine   
   
   ;##########################################################################################
   ;tag
   removetool: 
   ControlGetpos,1x, 1y,1width,1Height,%A_GuiControl%
   MouseGetPos, OX, OY   
   gx:=1X + 1Width
   gy:=1y + 1Height
   
   if OX between 1X and gx
      if OY between 1y and gy
         return  ;mouse is still in location, bomb out and return
         
   tooltip
   settimer,removetool,off
    return

   ;##########################################################################################
   ;tag
    trubbleguy.com:  ; for some reason a subroutine can sit inside a Function and still work
   run http://www.trubbleguy.com
   Return
   }  ;###############The real end of Function, while containing a handy sub i always use.
   

_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Sun Dec 06, 2009 8:20 am    Post subject: Reply with quote

Have you seen ToolTip() Question
Code:
#Include ToolTip.ahk
ex:=A_ScreenWidth-130  ;used to set Gui top RIght of screen, out of the way, but down far enough to close windows underneath

Gui, Margin ,0, 0
Gui, +AlwaysOnTop +BackgroundTrans
Gui, Add, checkbox,vspin checked%spin% x1 y5,Spin Name 2 UK
ToolTip(1,"Check this box to turn`n   Parton, Dolly`n       Into`n   Dolly Parton`nwhen F2 is pressed","","P1 AButton1")
 
Gui, Add, checkbox,vsort x1 y+2,Sort Into Folders (F3)
ToolTip(1,"Check to Enable F3 key to Move mixed `nkaraoke files Into folders using their DiskID`n`nSC8123-10-The Rose - Midler, Bette`n      moves to`n...\SC8123\SC8123-10-The Rose - Midler, Bette`n`nThe F3 Key is Disabled when Unchecked`nNB:   THIS DOES NOT SPIN THE NAME!!!!","","P1 AButton2")

Gui, Add, checkbox,vcase checked%case% x1 y+2,First letter UpperCase
ToolTip(1,"Makes the first letter of each word Uppercase","","P1 AButton3")

Gui, Add, button,xp y+1 vlogopic w120 h20,Trubbleguy.com
ToolTip(1,"Click on the file you want to spin`nIn its folder, and Press the F2 Key`n`nSC8123-10- The Rose - Midler, Bette.zip`n      will change to`nSC8123-10- Midler, Bette - The Rose.zip`n`nIf all files in folder need spinning`nHold CTRL + ALT down and tap F2 Key`n`nNB: This will only work, for the last 2 parts`nof the filename, Ignoring the   SC8123-10 `n`nClick button to open Trubbleguy.com","","P1 AButton4")

Gui, Add, Progress,xp y+1 wp h10 cBlue vMyProgress Range0-120000

gui, show ,x%ex% y20 AutoSize,%prgtitle%

return
GuiClose:
ToolTip()
ExitApp
;tooltip.ahk


There is also Add Tooltips to controls and ShowToolTip()
_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group