From 6c3b2133bcffe3dc5146fce84f22eff62deac736 Mon Sep 17 00:00:00 2001 From: TheBestPessimist Date: Sun, 13 Aug 2023 15:12:01 +0300 Subject: [PATCH] Tooltips are following the cursor --- lib/Tippy2.ahk | 89 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 21 deletions(-) diff --git a/lib/Tippy2.ahk b/lib/Tippy2.ahk index 673200e..fbecb9a 100644 --- a/lib/Tippy2.ahk +++ b/lib/Tippy2.ahk @@ -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 @@ -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" @@ -64,4 +110,5 @@ dbg(obj) return JxonEncode(obj, 1) } -;^j::T. +^j::T.StartLoop() +^k::T.StopLoop()