With how it is set up, be sure to make your slider variable and paired edit variable global.
Here is a little demo script
Code: Select all
#SingleInstance, Force
global Demo_Slider_1 , DS1Edit , pSlider := []
global Demo_Slider_2 , DS2Edit
global Demo_Slider_3 , DS3Edit
global Demo_Slider_4 , DS4Edit
Gui,1:+AlwaysOnTop -DPIScale
Gui,1:Color,333333
Gui,1:Font,s10 w600
Gui,1:Add,Button,x40 y10 w35 h17 -Theme vSub5 gAdjustSlider1,- 5
Gui,1:Add,Button,x80 y10 w35 h17 -Theme vSub1 gAdjustSlider1,- 1
Gui,1:Add,Edit,x125 y10 w50 h17 -E0x200 Center Disabled vDS1Edit ,5
Gui,1:Add,Button,x185 y10 w35 h17 -Theme vAdd1 gAdjustSlider1,+ 1
Gui,1:Add,Button,x225 y10 w35 h17 -Theme vAdd5 gAdjustSlider1,+ 5
pSlider[1]:= New Progress_Slider("1","Demo_Slider_1",30,35,240,20,-20,25,5,"D18F0B","FFFF00",1,"DS1Edit",1)
pSlider[2]:= New Progress_Slider("1","Demo_Slider_2",30,70,10,200,0,250,58,"080D60","0A17D8",1,"DS2Edit",1,1)
Gui,1:Add,Edit,x10 y280 w50 h17 -E0x200 Center Disabled vDS2Edit ,58
pSlider[3]:= New Progress_Slider("1","Demo_Slider_3",80,70,30,200,0,550,122,"555555","aaaaaa",1,"DS3Edit",0,1)
Gui,1:Add,Edit,x70 y280 w50 h17 -E0x200 Center Disabled vDS3Edit ,122
pSlider[4]:= New Progress_Slider("1","Demo_Slider_4",150,70,20,200,0,1250,158,,,1,"DS4Edit",1,1,0)
Gui,1:Add,Edit,x140 y280 w40 h17 -E0x200 Center Disabled vDS4Edit,158
Gui,1:Show, w300 , pSlider Demo `
return
GuiClose:
GuiContextMenu:
ExitApp
AdjustSlider1:
(A_GuiControl="Sub5")?(pSlider[1].Slider_Value-=5):(A_GuiControl="Sub1")?(pSlider[1].Slider_Value-=1):(A_GuiControl="Add1")?(pSlider[1].Slider_Value+=1):(A_GuiControl="Add5")?(pSlider[1].Slider_Value+=5)
(pSlider[1].Slider_Value > pSlider[1].End_Range)?(pSlider[1].SET_pSlider(pSlider[1].End_Range)):(pSlider[1].Slider_Value < pSlider[1].Start_Range)?(pSlider[1].SET_pSlider(pSlider[1].Start_Range)):(pSlider[1].SET_pSlider(pSlider[1].Slider_Value))
return
numpad1::
pSlider[1].SET_pSlider(-8)
return
class Progress_Slider {
__New(pSlider_GUI_NAME , pSlider_Control_ID , pSlider_X , pSlider_Y , pSlider_W , pSlider_H , pSlider_Range_Start , pSlider_Range_End , pSlider_Value:=0 , pSlider_Background_Color := "Black" , pSlider_Top_Color := "Red" , pSlider_Pair_With_Edit := 0 , pSlider_Paired_Edit_ID := "" , pSlider_Use_Tooltip := 0 , pSlider_Vertical := 0 , pSlider_Smooth := 1){
This.GUI_NAME:=pSlider_GUI_NAME
This.Control_ID:=pSlider_Control_ID
This.X := pSlider_X
This.Y := pSlider_Y
This.W := pSlider_W
This.H := pSlider_H
This.Start_Range := pSlider_Range_Start
This.End_Range := pSlider_Range_End
This.Slider_Value := pSlider_Value
This.Background_Color := pSlider_Background_Color
This.Top_Color := pSlider_Top_Color
This.Vertical := pSlider_Vertical
This.Smooth := pSlider_Smooth
This.Pair_With_Edit := pSlider_Pair_With_Edit
This.Paired_Edit_ID := pSlider_Paired_Edit_ID
This.Use_Tooltip := pSlider_Use_Tooltip
This.Add_pSlider()
}
Add_pSlider(){
Gui, % This.GUI_NAME ":Add" , Text , % "x" This.X " y" This.Y " w" This.W " h" This.H " hwndpSliderTriggerhwnd"
pSlider_Trigger := This.Adjust_pSlider.BIND( THIS )
GUICONTROL +G , %pSliderTriggerhwnd% , % pSlider_Trigger
if(This.Smooth=1&&This.Vertical=0)
Gui, % This.GUI_NAME ":Add" , Progress , % "x" This.X " y" This.Y " w" This.W " h" This.H " Background" This.Background_Color " c" This.Top_Color " Range" This.Start_Range "-" This.End_Range " v" This.Control_ID ,% This.Slider_Value
else if(This.Smooth=0&&This.Vertical=0)
Gui, % This.GUI_NAME ":Add" , Progress , % "x" This.X " y" This.Y " w" This.W " h" This.H " -Smooth Range" This.Start_Range "-" This.End_Range " v" This.Control_ID ,% This.Slider_Value
else if(This.Smooth=1&&This.Vertical=1)
Gui, % This.GUI_NAME ":Add" , Progress , % "x" This.X " y" This.Y " w" This.W " h" This.H " Background" This.Background_Color " c" This.Top_Color " Range" This.Start_Range "-" This.End_Range " Vertical v" This.Control_ID ,% This.Slider_Value
else if(This.Smooth=0&&This.Vertical=1)
Gui, % This.GUI_NAME ":Add" , Progress , % "x" This.X " y" This.Y " w" This.W " h" This.H " -Smooth Range" This.Start_Range "-" This.End_Range " Vertical v" This.Control_ID ,% This.Slider_Value
}
Adjust_pSlider(){
CoordMode,Mouse,Client
while(GetKeyState("LButton")){
MouseGetPos,pSlider_Temp_X,pSlider_Temp_Y
if(This.Vertical=0)
This.Slider_Value := Round((pSlider_Temp_X - This.X ) / ( This.W / (This.End_Range - This.Start_Range) )) + This.Start_Range
else
This.Slider_Value := Round(((pSlider_Temp_Y - This.Y ) / ( This.H / (This.End_Range - This.Start_Range) )) + This.Start_Range )* -1 + This.End_Range
if(This.Slider_Value > This.End_Range )
This.Slider_Value:=This.End_Range
else if(This.Slider_Value<This.Start_Range)
This.Slider_Value:=This.Start_Range
GuiControl,% This.GUI_NAME ":" ,% This.Control_ID , % This.Slider_Value
if(This.Pair_With_Edit=1)
GuiControl,% This.GUI_NAME ":" ,% This.Paired_Edit_ID , % This.Slider_Value
if(This.Use_Tooltip=1)
ToolTip , % This.Slider_Value
}
if(This.Use_Tooltip=1)
ToolTip,
}
SET_pSlider(NEW_pSlider_Value){
This.Slider_Value := NEW_pSlider_Value
GuiControl,% This.GUI_NAME ":" ,% This.Control_ID , % This.Slider_Value
if(This.Pair_With_Edit=1)
GuiControl,% This.GUI_NAME ":" ,% This.Paired_Edit_ID , % This.Slider_Value
}
}
Code: Select all
class Progress_Slider {
__New(pSlider_GUI_NAME , pSlider_Control_ID , pSlider_X , pSlider_Y , pSlider_W , pSlider_H , pSlider_Range_Start , pSlider_Range_End , pSlider_Value:=0 , pSlider_Background_Color := "Black" , pSlider_Top_Color := "Red" , pSlider_Pair_With_Edit := 0 , pSlider_Paired_Edit_ID := "" , pSlider_Use_Tooltip := 0 , pSlider_Vertical := 0 , pSlider_Smooth := 1){
This.GUI_NAME:=pSlider_GUI_NAME
This.Control_ID:=pSlider_Control_ID
This.X := pSlider_X
This.Y := pSlider_Y
This.W := pSlider_W
This.H := pSlider_H
This.Start_Range := pSlider_Range_Start
This.End_Range := pSlider_Range_End
This.Slider_Value := pSlider_Value
This.Background_Color := pSlider_Background_Color
This.Top_Color := pSlider_Top_Color
This.Vertical := pSlider_Vertical
This.Smooth := pSlider_Smooth
This.Pair_With_Edit := pSlider_Pair_With_Edit
This.Paired_Edit_ID := pSlider_Paired_Edit_ID
This.Use_Tooltip := pSlider_Use_Tooltip
This.Add_pSlider()
}
Add_pSlider(){
Gui, % This.GUI_NAME ":Add" , Text , % "x" This.X " y" This.Y " w" This.W " h" This.H " hwndpSliderTriggerhwnd"
pSlider_Trigger := This.Adjust_pSlider.BIND( THIS )
GUICONTROL +G , %pSliderTriggerhwnd% , % pSlider_Trigger
if(This.Smooth=1&&This.Vertical=0)
Gui, % This.GUI_NAME ":Add" , Progress , % "x" This.X " y" This.Y " w" This.W " h" This.H " Background" This.Background_Color " c" This.Top_Color " Range" This.Start_Range "-" This.End_Range " v" This.Control_ID ,% This.Slider_Value
else if(This.Smooth=0&&This.Vertical=0)
Gui, % This.GUI_NAME ":Add" , Progress , % "x" This.X " y" This.Y " w" This.W " h" This.H " -Smooth Range" This.Start_Range "-" This.End_Range " v" This.Control_ID ,% This.Slider_Value
else if(This.Smooth=1&&This.Vertical=1)
Gui, % This.GUI_NAME ":Add" , Progress , % "x" This.X " y" This.Y " w" This.W " h" This.H " Background" This.Background_Color " c" This.Top_Color " Range" This.Start_Range "-" This.End_Range " Vertical v" This.Control_ID ,% This.Slider_Value
else if(This.Smooth=0&&This.Vertical=1)
Gui, % This.GUI_NAME ":Add" , Progress , % "x" This.X " y" This.Y " w" This.W " h" This.H " -Smooth Range" This.Start_Range "-" This.End_Range " Vertical v" This.Control_ID ,% This.Slider_Value
}
Adjust_pSlider(){
CoordMode,Mouse,Client
while(GetKeyState("LButton")){
MouseGetPos,pSlider_Temp_X,pSlider_Temp_Y
if(This.Vertical=0)
This.Slider_Value := Round((pSlider_Temp_X - This.X ) / ( This.W / (This.End_Range - This.Start_Range) )) + This.Start_Range
else
This.Slider_Value := Round(((pSlider_Temp_Y - This.Y ) / ( This.H / (This.End_Range - This.Start_Range) )) + This.Start_Range )* -1 + This.End_Range
if(This.Slider_Value > This.End_Range )
This.Slider_Value:=This.End_Range
else if(This.Slider_Value<This.Start_Range)
This.Slider_Value:=This.Start_Range
GuiControl,% This.GUI_NAME ":" ,% This.Control_ID , % This.Slider_Value
if(This.Pair_With_Edit=1)
GuiControl,% This.GUI_NAME ":" ,% This.Paired_Edit_ID , % This.Slider_Value
if(This.Use_Tooltip=1)
ToolTip , % This.Slider_Value
}
if(This.Use_Tooltip=1)
ToolTip,
}
SET_pSlider(NEW_pSlider_Value){
This.Slider_Value := NEW_pSlider_Value
GuiControl,% This.GUI_NAME ":" ,% This.Control_ID , % This.Slider_Value
if(This.Pair_With_Edit=1)
GuiControl,% This.GUI_NAME ":" ,% This.Paired_Edit_ID , % This.Slider_Value
}
}