-
Notifications
You must be signed in to change notification settings - Fork 1
/
Overlay.ahk
129 lines (107 loc) · 3.15 KB
/
Overlay.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
class Overlay
{
_guiConfig := {}
__New()
{
this._guiConfig.Background := "202020"
this._guiConfig.Foreground := "white"
this._guiConfig.FontSize := 10
this._guiConfig.FontName := "Consolas"
this._guiConfig.Transparency := 200
this._guiConfig.Timeout := -1000 ; must be negative to ensure the timer is launched once only
}
_monitorGuisMap := [[]]
Show(texts*)
{
count := this.getMonitorCount()
Loop, %count%
{
index := A_Index
hwnd := this.guiCreate(texts)
if (!this._monitorGuisMap[index]) ; if the element is uninitialized
{
this._monitorGuisMap[index] := []
}
guis := this._monitorGuisMap[index]
Gui, Show, x0 y-3000 NoActivate
this.placeGuiBottomLeft(index, hwnd)
WinGetPos,,,, height, ahk_id %hwnd%
this.shiftGuis(guis, 0, -height)
guiIndex := guis.Push(hwnd)
this.guiSetupDestroyCallback(hwnd, guis, guiIndex, this._guiConfig.Timeout)
WinSet, Transparent, % this._guiConfig.Transparency, ahk_id %hwnd%
}
}
; negative number for only launching once
guiSetupDestroyCallback(hwnd, guis, guiIndex, timeout)
{
callback := ObjBindMethod(this, "guiDestroy", hwnd, guis, guiIndex)
SetTimer % callback, % timeout
}
guiDestroy(hwnd, guis, guiIndex)
{
Gui, %hwnd%:Destroy
guis.RemoveAt(guiIndex)
}
shiftGuis(guisList, offsetX, offsetY)
{
SetWinDelay, 0
for index, hwnd in guisList
{
WinGetPos, x, y,,, ahk_id %hwnd%
x += offsetX
y += offsetY
WinMove, ahk_id %hwnd%, , %x%, %y%
}
SetWinDelay, 100
}
placeGuiBottomLeft(monitorIndex, hwnd)
{
SetWinDelay, 0 ; default 100ms
SysGet, workspace, MonitorWorkArea, % monitorIndex
SysGet, name, Monitorname, % monitorIndex
WinGetPos, x, y, width, height, ahk_id %hwnd% ; get current gui dimension
offset := 50 ; extract this to config?
; position gui at the bottom left
newX := workspaceLeft + offset
newY := workspaceBottom - height - offset
WinMove, ahk_id %hwnd%, , %newX%, %newY%
SetWinDelay, 100
}
guiCreate(texts)
{
; first line second line
; line
; line
; line
Gui, New
Gui, -Caption +ToolWindow +LastFound +AlwaysOnTop +Hwndhwnd
Gui, %hwnd%:Default
Gui, Color, % this._guiConfig.Background
Gui, Font, % "c" . this._guiConfig.Foreground
for index, text in texts
{
if (index == texts.MinIndex())
{
Gui, Font, % "bold s" . this._guiConfig.FontSize, % this._guiConfig.FontName
Gui, Add, Text, Center , % text
}
else if (index == texts.MinIndex() + 1)
{
Gui, Font, % "norm s" . this._guiConfig.FontSize, % this._guiConfig.FontName
Gui, Add, Text, Center x+m , % text ; place on the right of the previous
}
else
{
Gui, Font, % "norm s" . this._guiConfig.FontSize, % this._guiConfig.FontName
Gui, Add, Text, Center xp y+m, % text ; place below the previous
}
}
return hwnd
}
getMonitorCount()
{
SysGet, count, 80 ; SM_CMONITORS
return count
}
}