Skip to content

Commit

Permalink
Tooltips are following the cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestPessimist committed Aug 13, 2023
1 parent d635894 commit 6c3b213
Showing 1 changed file with 68 additions and 21 deletions.
89 changes: 68 additions & 21 deletions lib/Tippy2.ahk
Original file line number Diff line number Diff line change
@@ -1,44 +1,91 @@
#Include _JXON.ahk
#SingleInstance


class T
{
static Tooltips := Map()
static TooltipTimerHwnd := ""

CurrentText := ""
LastText := ""
Duration := ""
fnOff := ""
WhichToolTip := ""
extraOffsetY := ""
Hwnd := ""
ToolTipHeight := ""
YOffset := ""

static ShowTooltipsFunc := T.LoopDisplayTooltips.Bind(this)

CurrentText := -1
Duration := -1
WhichToolTip := -1
ToolTipHeight := 0

LastText := -1
extraOffsetY := -1
YOffset := -1
Hwnd := -1

__New(
CurrentText,
Duration
Duration,
WhichTooltip
) {
this.CurrentText := CurrentText
this.Duration := Duration
this.WhichTooltip := WhichTooltip
}

LoopShowTooltips()
static LoopDisplayTooltips()
{
for k,v in T.tooltips
Critical
SetWinDelay -1

CoordMode("Mouse", "Screen")
MouseGetPos(&mouseX, &mouseY)

x := mouseX
y := mouseY

/*
Cases
- tooltip is new and was not shown before
- tooltip exists and was already shown
- tooltip exists and was already shown, but has changed text
- tooltip has expired and must not be shown anymore
*/



for k,tt in T.tooltips
{
tooltip( k . dbg(v), 10, 10, k)
x := x + 30*k
y := y + 10*k

if(!tt.AlreadyShown())
{
Tooltip( k . dbg(tt), x, y, k)
tt.Hwnd := WinExist("ahk_class tooltips_class32 ahk_pid " DllCall("GetCurrentProcessId"))
WinGetPos(,, &w, &h, "ahk_id " tt.Hwnd)
tt.ToolTipHeight := h
}
else
{
WinMove(x, y,,, tt.Hwnd)
}
}
}

ShowTooltip()
AlreadyShown()
{
return (this.Hwnd != -1)
}


static StartLoop()
{
; SetTimer(LoopShowTooltips, 10)
SetTimer(T.ShowTooltipsFunc, 1)

; TODO: use A_Tick count to set the time after which this tooltip should be off.
; in this way i dont have to store start and stop functions for each tooltip
}

static StopLoop()
{
SetTimer(T.ShowTooltipsFunc, 0)
}

/*
Technical: ToString is not needed because i'm using a JSON library to dump everything to string
Expand All @@ -47,12 +94,11 @@ class T



t1 := T("curr 1", 123)
t2 := T("curr 2", 456)
t1 := T("curr 1", 123, 16)
t2 := T("curr 2", 456, 10)

t.tooltips[16] := t1
t.tooltips[10] := t2

;msgbox dbg(T)

t1.CurrentText := "AAAAAAAAAAAAAAAAAA"
Expand All @@ -64,4 +110,5 @@ dbg(obj)
return JxonEncode(obj, 1)
}

;^j::T.
^j::T.StartLoop()
^k::T.StopLoop()

0 comments on commit 6c3b213

Please sign in to comment.