Need a multi-line tool tip function? The string parameter can even handle newlines '\n'.
sync on
corner = 4
do
cls
if inkey$() = "1" then corner = 1
if inkey$() = "2" then corner = 2
if inkey$() = "3" then corner = 3
if inkey$() = "4" then corner = 4
drawToolTip("This is a really cool\ntool tip function.\nComplete with newline switches!", mousex(), mousey(), corner)
sync
loop
REM ============================================
REM Draws a tool tip box. The string may contain
REM any number of '\n' (newline) switches.
REM The 'corner' parameter states where the tool
REM tip should be draw in relation to the given
REM [X, Y] coordinates.
REM Corner 1 = top right
REM Corner 2 = top left
REM Corner 3 = bottom right
REM Corner 4 = bottom left
REM ============================================
function drawToolTip(s$, x, y, corner)
maxWidth = 0
lines = 0
b = 0
for i = 2 to len(s$)
if mid$(s$,i-1)+mid$(s$,i) = "\n" or i = len(s$)
t$ = left$(s$, i-((i<len(s$))*2))
t$ = right$(t$, len(t$)-b)
b = i
inc i
inc lines
w = text width(t$)
if w > maxWidth then maxWidth = w
endif
next i
if corner = 2 || corner = 4 then ox = -(maxWidth+6)
if corner = 3 || corner = 4 then oy = lines*-16
rem tooltip background
ink rgb(228,219,195),0
box x+ox, y+oy, x+maxWidth+6+ox, y+lines*16+oy
ink 0,0
b = 0
row = 0
for i = 2 to len(s$)
if mid$(s$,i-1)+mid$(s$,i) = "\n" or i = len(s$)
t$ = left$(s$, i-((i<len(s$))*2))
text x+3+ox, y+row*16+oy, right$(t$, len(t$)-b)
b = i
inc i
inc row
endif
next i
rem tooltip outline
box x+ox, y+oy, x+ox+1, y+lines*16+oy
box x+maxWidth+5+ox, y+oy, x+maxWidth+6+ox, y+lines*16+oy
box x+ox, y+oy, x+maxWidth+6+ox, y+oy+1
box x+ox, y+lines*16+oy-1, x+maxWidth+6+ox, y+lines*16+oy
endfunction
"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke