-
Notifications
You must be signed in to change notification settings - Fork 71
/
class_VSliderGUI.ahk
156 lines (124 loc) · 9.35 KB
/
class_VSliderGUI.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
Class VSliderGUI {
static bcolor := "090909" ;background color
static pcolor := "E9E9E9" ;progressbar color
static tcolor := "666666" ;text color
__New(guiName, width, height, tsize, iconOffsetx, iconOffsety, bradius, y, transtarget, timeToDecay, playSound := 1){
this.guiName := guiName
this.width := width
this.height := height
this.tsize := tsize
this.iconOffset := {"x": iconOffsetx, "y": iconOffsety}
this.bradius := bradius
this.y := y
this.transtarget := transtarget
this.timeToDecay := timeToDecay
this.playSound := playSound
this._registerGui()
this._addControls()
this._finaliseGui()
}
update(vol, icon){
if(!this.vanishTimer)
this.show(vol, icon)
GuiControl, , % this.vol.slider, % vol
GuiControl, , % this.vol.icon, % icon
this._tempTimer(this.vanishTimer, this.timeToDecay, -1)
if(this.playSound){
if(!this.testVolTimer)
this.testVolTimer := this._testVol.Bind(this)
this._tempTimer(this.testVolTimer, this.timeToDecay * 0.6, -1)
}
}
show(vol, icon){
GuiControl, , % this.vol.slider, % vol
GuiControl, , % this.vol.icon, % icon
WinGetPos, , , width, height, % "ahk_id " . this.hwnd ; Get GUI info
x := (A_ScreenWidth / 2) - (width / 2) ; Calculate true screen center
Gui, % this.hwnd ":Show"
, % "x" x
. " y" . this.y
. " NA"
WinSet, Region, % Format("0-0 w{1:d} h{2:d} r{3:d}-{3:d}"
, width
, height
, this.bradius) ; Apply rounded corners
, % "ahk_id " . this.hwnd
While(A_Index < 11
, (x := this._transmation(this.transtarget, 10, A_Index))){
Sleep, 1
WinSet, Transparent, % x, % "ahk_id " . this.hwnd
}
this.vanishTimer := this.hide.Bind(this)
this._tempTimer(this.vanishTimer, this.timeToDecay, -1)
}
hide(){
While(A_Index < 11)
, (x := this._transmation(this.transtarget, 10, 10 - A_Index)){
WinSet, Transparent, % x, % "ahk_id " . this.hwnd
Sleep, 1
}
WinSet, Transparent, 0, % "ahk_id " . this.hwnd
Gui, % this.hwnd . ":Hide"
this.vanishTimer := ""
}
_transmation(target, steps, x){
return, Floor(target / steps * x)
}
_testVol(){
SoundPlay, % A_WinDir . "\Media\Windows Background.wav"
this.testVolTimer := ""
}
_tempTimer(timer, period, prio){
SetTimer, % timer, % -Abs(period), % prio
}
; -- helper methods for creating the instances gui --
_registerGui(){
Gui, % this.guiName ":New" ; create GUI with needed options
, % "+Hwndhwnd +LastFound +ToolWindow +AlwaysOnTop -Caption -Disabled"
, this.guiName
this.hwnd := hwnd
DllCall("SetClassLong" ; Drop Shadow
, "UInt", this.hwnd
, "Int", -26
, "Int", DllCall("GetClassLong"
, "UInt", this.hwnd
, "Int", -26) | 0x20000)
Gui, % this.hwnd ":Color" ; setting background Color
, this.tcolor, this.tcolor
}
_addControls(){
Gui, % this.hwnd ":Add"
, Progress
, % "HwndVolSlider"
. " x" . -1
. " y" . -1
. " w" . this.width
. " h" . this.height
. " c" . this.pcolor
. " Background" this.bcolor
, 50
Gui, % this.hwnd ":Font"
, % "s" . this.tsize . " c" . this.tcolor
, Segoe MDL2 Assets
Gui, % this.hwnd ":Add"
, Text
, % "BackgroundTrans"
. " HwndVolIcon"
. " x" . this.iconOffset.x
. " y" . this.iconOffset.y
, % ""
Gui, % this.hwnd ":Margin", 0, 0
this.vol := {}
this.vol.slider := VolSlider
this.vol.icon := VolIcon
}
_finaliseGui(){
DetectHiddenWindows, On
Gui, % this.hwnd ":Show", Hide ; Pre-render GUI
WinSet, Transparent, 0, % "ahk_id " . this.hwnd ; Apply 0% transparency
}
; -- other methods --
__Delete(){
Gui, % this.hwnd . ":Destroy"
}
}