Advertisement
Guest User

pButton Class By Hellbent

a guest
Jun 18th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     ;Custom Progress Buttons By Hellbent aka CivReborn
  3.    
  4.     Date Started: May 31st, 2018
  5.     Date of Last Edit: June 18th, 2018
  6.    
  7.     PasteBin Link: https://pastebin.com/GrtV6qfx
  8.    
  9.     Link To Video Tutorial: https://youtu.be/a2gmBUNYDgw
  10.    
  11.     Instructions to use:
  12.    
  13.     1: #Include this script in your script / **(or paste it in (not tested may have to move some things around))
  14.    
  15.     2: Call the pButton_StartUp() Function in your script
  16.    
  17.     3: Create New Buttons by First setting a global object Called "pButton"
  18.         ;pButton will be need to be an array of objects.
  19.        
  20.     4: Add your buttons by making your button a Progress_Button Class Object
  21.         ; Example
  22.             ;(see video for arg meanings and take notes/ or look over code to see what is needed).
  23.             ; pButton[1]:= New Progress_Button(args). In this method use array position as the Button_Name. ie. 1
  24.         ; Example 2
  25.             ; pButton.Push(New Progress_Button(args)). In this method, use pButton.Length()+1 as the Button_Name
  26.    
  27.     5:  Add the Button_Press() Method to any lable that is using a Progress_Button Class Button.
  28.         ;set it in a if statement to test if the statement returns a true or false
  29.        
  30.         ;Example
  31.             ;if(!pButton[A_GuiControl].Button_Press())
  32.                 return
  33.             ; your code that you want the button to do comes after the if statement
  34.             ; See video if you get stuck.
  35.            
  36.         ;Full Example
  37.             ;-----------------------------------
  38.             My_Label:
  39.                 if(!pButton[A_GuiControl].Button_Press())
  40.                     return
  41.                 a:=5
  42.                 b:=6
  43.                 c:=a+b
  44.                 msgbox,% c
  45.                 return
  46.             ;---------------------------------------           
  47. */
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.            ; Button Class
  55. ;------------------------------------------------------------------------------------------------
  56. ;------------------------------------------------------------------------------------------------
  57. ;------------------------------------------------------------------------------------------------
  58. global Press_active:=0,Hover_On:=0,Active_Button
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. pButton_StartUp(){
  66.     SetTimer,Watch_Hover,10
  67. }  
  68. Watch_Hover(){
  69.     global
  70.     if(Press_active=0){
  71.         if(Hover_On=0){
  72.             MouseGetPos,,,,ctrl,2
  73.             loop,% pButton.Length() {
  74.                 GuiControlGet,cName,% pButton[A_Index].Window_Name ":Name",% ctrl
  75.                 cut:=Strlen(cName)
  76.                 StringLeft,bName,cName,cut-2
  77.                 ;~ Loop,% pButton.Length()
  78.                     if(bname=pButton[A_Index].Button_Name){
  79.                         pButton[A_Index].Button_Hover_On()
  80.                         Hover_On:=1,Active_Button:=bname,win:=pButton[A_Index].Window_Name
  81.                         return
  82.                     }  
  83.             }
  84.         }else if(Hover_On=1){
  85.             MouseGetPos,,,,ctrl,2
  86.             GuiControlGet,cName,%win%:Name,% ctrl
  87.             cut:=Strlen(cName)
  88.             StringLeft,nBName,cName,cut-2
  89.             if(NbName!=Active_Button){
  90.                 pButton[Active_Button].Button_Hover_Off()
  91.                     Hover_On:=0,Active_Button:=""
  92.             }
  93.         }
  94.     }          
  95. }
  96.  
  97. Class Progress_Button   {
  98.         __New(Window_Name,Button_Name,Label,x,y,w,h,BC,TRC,TC1,TC2,TC3,Button_Text,Text_Offset:=0)
  99.             {
  100.                 This.Text_Offset:=Text_Offset
  101.                 This.Window_Name:=Window_Name
  102.                 This.Button_Name:=Button_Name
  103.                 This.Label:=Label
  104.                 This.Button_ID1:=Button_Name "_1"
  105.                 This.Button_ID2:=Button_Name "_2"
  106.                 This.Button_ID3:=Button_Name "_3"
  107.                 This.Button_ID4:=Button_Name "_4"
  108.                 This.Button_Text:=Button_Text
  109.                 This.X:=x
  110.                 This.Y:=y
  111.                 This.W:=w
  112.                 This.H:=h
  113.                 This.Bottom_Color:=BC
  114.                 This.Trim_Color:=TRC
  115.                 This.Top_Color_1:=TC1
  116.                 This.Top_Color_2:=TC2
  117.                 This.Top_Color_3:=TC3
  118.                 This.Add_Button()
  119.             }
  120.         Add_Button()
  121.             {
  122.                 global
  123.                 Gui,% This.Window_Name ":Add",Text,% "x" This.X " y" This.Y " w" This.W " h" This.H " v" This.Button_Name " g" This.Label
  124.                 Gui,% This.Window_Name ":Add",Progress,% "x" This.X " y" This.Y " w" This.W " h" This.H " Background" This.Bottom_Color " v" This.Button_ID1
  125.                 Gui,% This.Window_Name ":Add",Progress,% "x" This.X " y" This.Y " w" This.W-1 " h" This.H-1 " Background" This.Trim_Color " v" This.Button_ID2
  126.                 Gui,% This.Window_Name ":Add",Progress,% "x" This.X+1 " y" This.Y+1 " w" This.W-2 " h" This.H-2 " Background" This.Top_Color_1 " v" This.Button_ID3
  127.                 Gui,% This.Window_Name ":Add",Text,% "x" This.X+1 " y" This.Y+This.Text_Offset " w" This.W-2 " r1 Center BackgroundTrans v" This.Button_ID4,% This.Button_Text
  128.             }
  129.         Button_Press()
  130.             {
  131.                 global
  132.                 Press_Active:=1
  133.                 GuiControl,% This.Window_Name ":Move",% This.Button_ID4,% "x" This.X+1 " y" This.Y+1+This.Text_Offset
  134.                 sleep,-1
  135.                 GuiControl,% This.Window_Name ":Hide",This.Button_ID2
  136.                 GuiControl,% This.Window_Name ":+Background" This.Top_Color_3,% This.Button_ID3
  137.                 GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID1
  138.                 GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID3
  139.                 GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID4
  140.                 While(GetKeyState("LButton"))
  141.                     Sleep, 10
  142.                 MouseGetPos,,,,ctrl,2
  143.                 GuiControlGet,cName,1:Name,% ctrl
  144.                 cut:=Strlen(cName)
  145.                 StringLeft,bName,cName,cut-2
  146.                 if(bname=This.Button_Name)
  147.                     {
  148.                         GuiControl,% This.Window_Name ":Show",This.Button_ID2
  149.                         GuiControl,% This.Window_Name ":+Background" This.Top_Color_1,% This.Button_ID3
  150.                         GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID1
  151.                         GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID2
  152.                         GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID3
  153.                         GuiControl,% This.Window_Name ":Move",% This.Button_ID4,% "x" This.X " y" This.Y+This.Text_Offset
  154.                         GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID4
  155.                         %bName%.Button_Hover_On()
  156.                         Hover_On:=0
  157.                         Active_Button:=bname
  158.                         Press_Active:=0
  159.                         sleep,10
  160.                         return true
  161.                     }
  162.                 GuiControl,% This.Window_Name ":Show",This.Button_ID2
  163.                 GuiControl,% This.Window_Name ":Move",% This.Button_ID4,% "x" This.X " y" This.Y+This.Text_Offset
  164.                 GuiControl,% This.Window_Name ":+Background" This.Top_Color_1,% This.Button_ID3
  165.                 GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID1
  166.                 GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID2
  167.                 GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID3
  168.                 GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID4
  169.                 Hover_On:=0
  170.                 Press_Active:=0
  171.                 sleep,10
  172.                 return False
  173.             }
  174.         Button_Hover_On(){
  175.             global
  176.             GuiControl,% This.Window_Name ":+Background" This.Top_Color_2,% This.Button_ID3
  177.             GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID4
  178.         }
  179.         Button_Hover_Off()
  180.             {
  181.                 global
  182.                 GuiControl,% This.Window_Name ":+Background" This.Top_Color_1,% This.Button_ID3
  183.                 GuiControl,% This.Window_Name ":+Redraw",% This.Button_ID4
  184.             }
  185.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement