I modified it to work on multiple controls at the same time. Now you should be able to use:
Code:
Fade.in(Channel, "Power On", ChannelTitle, "Welcome to Aaron's YouTube Television", VolumeText, "Volume")
Fade.out(Channel, ChannelTitle, VolumeText)
Code:
background_color := 0x000000
text_color := 0xFF0000
fade := new Text_fader(text_color, background_color)
text1 := "Original text."
text2 := "Replacement text."
Gui, Color, %background_color%
Gui, Add, Text, c%text_color% w100 vtext_control1
Gui, Add, Text, c%text_color% w100 vtext_control2
Gui, Add, Text, c%text_color% w100 vtext_control3
Gui, Add, Button, gfade_in, Fade in text.
Gui, Add, Button, gfade_to, Fade to text.
Gui, Add, Button, gfade_out, Fade out text.
Gui, Show
return
fade_in:
fade.in(text_control1, text1, text_control2, text2, text_control3, text1)
return
fade_to:
fade.to(text_control1, text2, text_control2, text1, text_control3, text2)
return
fade_out:
fade.out(text_control1, text_control2, text_control3)
return
GuiClose:
GuiEscape:
ExitApp
class Text_fader {
__New(text_color = 0x000000, background_color = 0xf0f0f0, step = 5) {
global Color
this.text_color := new Color(text_color)
this.background_color := new Color(background_color)
this.step := step
this.fade_color := new Color
}
to(ByRef control1, new_text1, ByRef control2 = "nil", new_text2 = "", ByRef control3 = "nil", new_text3 = "") {
this.out(control1, control2, control3)
this.in(control1, new_text1, control2, new_text2, control3, new_text3)
}
out(ByRef control1, ByRef control2 = "nil", ByRef control3 = "nil") {
percent = 100
while percent > 0
{
percent -= this.step
for k, v in ["R", "G", "B"]
this.fade_color[v] := Round(this.background_color[v] + ((this.text_color[v] - this.background_color[v]) * (percent / 100)))
GuiControl, % "+C" . (percent <= 0 ? this.background_color.hex : this.fade_color.hex), control1
GuiControl, MoveDraw, control1
if (control2 != "nil")
{
GuiControl, % "+C" . (percent <= 0 ? this.background_color.hex : this.fade_color.hex), control2
GuiControl, MoveDraw, control2
}
if (control3 != "nil")
{
GuiControl, % "+C" . (percent <= 0 ? this.background_color.hex : this.fade_color.hex), control3
GuiControl, MoveDraw, control3
}
Sleep, 1
}
}
in(ByRef control1, new_text1, ByRef control2 = "nil", new_text2 = "", ByRef control3 = "nil", new_text3 = "") {
percent = 0
while percent < 100
{
percent += this.step
for k, v in ["R", "G", "B"]
this.fade_color[v] := Round(this.background_color[v] + ((this.text_color[v] - this.background_color[v]) * (percent / 100)))
GuiControl, % "+C" . (percent >= 100 ? this.text_color.hex : this.fade_color.hex), control1
GuiControl,, control1, %new_text1%
if (control2 != "nil")
{
GuiControl, % "+C" . (percent >= 100 ? this.text_color.hex : this.fade_color.hex), control2
GuiControl,, control2, %new_text2%
}
if (control3 != "nil")
{
GuiControl, % "+C" . (percent >= 100 ? this.text_color.hex : this.fade_color.hex), control3
GuiControl,, control3, %new_text3%
}
Sleep, 1
}
}
}
;modified color class from the AHK_L help file
class Color
{
__New(aRGB = 0x000000) {
this.RGB := aRGB
}
__Get(aName) {
if (aName = "R")
return (this.RGB >> 16) & 255
if (aName = "G")
return (this.RGB >> 8) & 255
if (aName = "B")
return this.RGB & 255
if (aName = "hex")
{
format_setting := A_FormatInteger
SetFormat, IntegerFast, h
hex := SubStr(this.RGB + 0, 3)
SetFormat, IntegerFast, %format_setting%
while StrLen(hex) < 6
hex := "0" . hex
return, "0x" . hex
}
}
__Set(aName, aValue) {
if aName in R,G,B
{
aValue &= 255
if (aName = "R")
this.RGB := (aValue << 16) | (this.RGB & ~0xff0000)
else if (aName = "G")
this.RGB := (aValue << 8) | (this.RGB & ~0x00ff00)
else ; (aName = "B")
this.RGB := aValue | (this.RGB & ~0x0000ff)
return aValue
}
}
}
I know that in AHK_L you can make functions accept a variable number of parameters, but I can't figure out how to do that with ByRef variables, and using ByRef variables is the only way I could get it to control the GUI. So for now it only accepts up to 3 controls at a time, but if you need more I can edit it to make it accept more.
[Edit]I just found out that you can pass the control variable names as strings instead of using ByRef. I'll post a better version when I get it working.[/Edit]