-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathclass_WindowFader.ahk
79 lines (57 loc) · 1.87 KB
/
class_WindowFader.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
class WindowFader {
__New(hwnd) {
this.speed := 6.0
this.isFadeIn := true
this.interval := 1
this.hwnd := hwnd
this.alpha := 0.0
; Tick() has an implicit parameter "this" which is a reference to
; the object, so we need to create a function which encapsulates
; "this" and the method to call:
this.timer := ObjBindMethod(this, "_tick")
}
fadeIn() {
this.isFadeIn := true
this._startTimer()
}
fadeOut() {
this.isFadeIn := false
this._startTimer()
}
_startTimer() {
; KNOWN LIMITATION: SetTimer requires a plain variable reference.
timer := this.timer
SetTimer % timer, % this.interval
this.lastTime := A_TickCount
}
_stopTimer() {
; To turn off the timer, we must pass the same object as before:
timer := this.timer
SetTimer % timer, Off
}
; In this example, the timer calls this method:
_tick() {
delta := (A_TickCount - this.lastTime) / 1000.0
this.lastTime := A_TickCount
if (this.isFadeIn and this.alpha > 1.0) {
this.alpha := 1.0
this._stopTimer()
}
if ( !this.isFadeIn and this.alpha <= 0.0 ) {
this.alpha := 0.0
this._stopTimer()
}
if (this.alpha > 0.0) {
WinShow, % "ahk_id " this.hwnd
}
if (this.alpha <= 0.0) {
WinHide, % "ahk_id " this.hwnd
}
; Apply animation curve
val := sin( this.alpha * 1.57079632679 ) * 256
WinSet, Transparent, % val, % "ahk_id " this.hwnd
step := delta * this.speed
step := this.isFadeIn ? step : -step
this.alpha += step
}
}