Advertisement
Guest User

gdip buttons test

a guest
Jun 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance,Force
  2.  
  3.  
  4. #Include,Hellbents gdip.ahk
  5.  
  6.  
  7.  
  8. OnExit,GuiClose
  9. ;~ gui,1:add,button,x300 y200 w100 h30 ,button 4
  10. OnMessage(0x201,"Window_Clicks"),OnMessage(0x200,"Window_Hover")
  11. winval:={X:0,Y:0,W:1220,H:500,Name1:1,Name2:2,Smoothing:4,Options1:"+AlwaysOnTop -DPIScale",Options2:"+Parent1 +AlwaysOnTop -Caption +LastFound -DPIScale",Title:"Simple Clicker v2",x_Offset:3,y_Offset:26,BackGround:"171717"} ;171717
  12. global Btn:={},Current:=""
  13. global Window:=New Window(winval)
  14.  
  15. /*  Button Prototype
  16.                             ;This shows every value and meaning in a button setup object
  17.    
  18.    
  19.     Button_Prototype := {  
  20.    
  21.     X:                  10,         ;The X position of the button on the gui
  22.     Y:                  10,         ;The Y position of the button on the gui
  23.     W:                  150,        ;The Width of the button in px (size drawn and size on the gui)        
  24.     H:                  30,         ;The Height of the button in px (size drawn and size on the gui)
  25.  
  26.  
  27.     }
  28. */
  29.  
  30. ;~ Button_1:={X:10,Y:10,W:150,H:30,C11:"000000",C12:"33ff33",C13:"222222",C21:"000000",C22:"33ff33",C23:"343434",C31:"000000",C32:"000000",C33:"272727",Text:"Button " Btn.Length()+1,Smoothing:1,Options:" vCenter s14 r5 cff33ff33 Center",Options2:"vCenter s14 r5 cff33ff33 Center Underline",Options3:"x1 y1 vCenter s14 r5 cff33ff33 Center Underline",Font:"Arial Black"}
  31. ;~ Btn[Btn.Length()+1]:=New Button_Class_1(Button_1)
  32.  
  33. x:=10
  34. Loop 5
  35. {
  36.     y:=10
  37.     Loop 5
  38.         {
  39.             Button_1:={X:x,Y:y,W:150,H:30,C11:"000000",C12:"33ff33",C13:"222222",C21:"000000",C22:"33ff33",C23:"0066aa",C31:"000000",C32:"000000",C33:"272727",Text:"Button " Btn.Length()+1,Smoothing:1,Options:" vCenter s14 r5 cff33ff33 Center",Options2:"vCenter s14 r5 cff33ff33 Center Underline",Options3:"x1 y1 vCenter s14 r5 cff33ff33 Center Underline",Font:"Arial Black"}
  40.             Btn[Btn.Length()+1]:=New Button_Class_1(Button_1)
  41.             y+=40
  42.         }
  43.     x+=160     
  44. }
  45. Button_1:={X:x,Y:y,W:250,H:50,C11:"000000",C12:"33ff33",C13:"222222",C21:"000000",C22:"33ff33",C23:"ff0000",C31:"000000",C32:"000000",C33:"eeeeee",Text:"Button " Btn.Length()+1,Smoothing:1,Options:" vCenter s14 r5 cff33ff33 Center",Options2:"vCenter s14 r5 cff000000 Center Underline",Options3:"x1 y1 vCenter s14 r5 cff33ff33 Center Underline",Font:"Arial Black"}
  46.     Btn[Btn.Length()+1]:=New Button_Class_1(Button_1)
  47. Button_1:={X:10,Y:y+=60,W:250,H:50,C11:"000000",C12:"777777",C13:"222222",C21:"000000",C22:"777777",C23:"ff0000",C31:"000000",C32:"000000",C33:"eeeeee",Text:"Button " Btn.Length()+1,Smoothing:1,Options:" vCenter s14 r5 cff33ff33 Center",Options2:"vCenter s14 r5 cff000000 Center Underline",Options3:"x1 y1 vCenter s14 r5 cff33ff33 Center Underline",Font:"Arial Black"}
  48.     Btn[Btn.Length()+1]:=New Button_Class_1(Button_1)  
  49. global Ready:=1
  50. return
  51. GuiClose:
  52. GuiEscape:
  53. *^ESC::
  54.     Loop,% btn.Length()
  55.         btn[A_Index].Button_ShutDown()
  56.     window.Shutdown()
  57.     ExitApp
  58.    
  59. Class Button_Class_1
  60.     {
  61.         __New(Settings)
  62.             {
  63.                 for k, v in settings
  64.                     This[k]:=v
  65.                 This.Bitmap_1:=This.Create_Bitmaps(This.C11,This.C12,This.C13,This.Options)
  66.                 This.Bitmap_2:=This.Create_Bitmaps(This.C21,This.C22,This.C23,This.Options2)
  67.                 This.Bitmap_3:=This.Create_Bitmaps(This.C31,This.C32,This.C33,This.Options3)
  68.                 This.Draw_Buttons(This.Bitmap_1)
  69.             }
  70.         Create_Bitmaps(c1,c2,c3,o)
  71.             {
  72.                 pBitmap:=Gdip_CreateBitmap(This.W,This.H)
  73.                 G := Gdip_GraphicsFromImage(pBitmap)
  74.                 Gdip_SetSmoothingMode(G,This.Smoothing)
  75.                 brush1:=New_Brush(c1)
  76.                 brush2:=New_Brush(c2)
  77.                 brush3:=New_Brush(c3)
  78.                 brush4:=Gdip_CreateLineBrushFromRect(0, 0, this.w, this.h,0x33ffffff, 0x77000000,1)
  79.                
  80.                 Gdip_FillRectangle(G,brush1,0,0,This.W,This.H)
  81.                 Gdip_FillRectangle(G,brush2,0,0,This.W-1,This.H-1)
  82.                 Gdip_FillRectangle(G,brush3,1,1,This.W-2,This.H-2)
  83.                 Gdip_FillRectangle(G,brush4,2,2,This.W-4,This.H-4)
  84.                 Gdip_TextToGraphics(G,This.Text,o,This.Font, This.W, This.H)
  85.                 Gdip_DeleteBrush(brush1)
  86.                 Gdip_DeleteBrush(brush2)
  87.                 Gdip_DeleteBrush(brush3)
  88.                 Gdip_DeleteBrush(brush4)
  89.                 Gdip_DeleteGraphics(G)
  90.                 return pBitmap
  91.             }
  92.         Draw_Buttons(bitmap)
  93.             {
  94.                 Gdip_DrawImage(Window.G,bitmap,This.X,This.Y,This.W,This.H)
  95.                 Window.Update()
  96.             }
  97.         Button_Hover() 
  98.             {
  99.                 Tooltip,
  100.                 tip_counter:=1
  101.                 this.Draw_Buttons(This.Bitmap_2)
  102.                 Mousegetpos,tx,ty
  103.                 While(tx >= This.x &&tx <= (This.x+This.W)&& ty >= This.Y && ty <= This.Y+This.H)
  104.                     {
  105.                         Mousegetpos,tx,ty
  106.                         if(GetKeyState("LButton"))
  107.                             Window_Clicks()
  108.                         if(++Tip_Counter=30000)
  109.                             {
  110.                                 Tip_Counter:=1
  111.                                 Tooltip,% "This button is at x:" This.X " and y:" This.Y
  112.                             }
  113.                     }  
  114.                 this.Draw_Buttons(This.Bitmap_1)
  115.                 Tooltip,
  116.             }
  117.         Button_Press()
  118.             {
  119.                 Tooltip,
  120.                 this.Draw_Buttons(This.Bitmap_3)
  121.                 While(GetKeyState("LButton"))
  122.                     sleep,10
  123.                 ;~ gosub,Tray_tips
  124.                 this.Draw_Buttons(This.Bitmap_1)
  125.                 Window_Hover()
  126.             }
  127.         Button_ShutDown()
  128.             {
  129.                 Gdip_DisposeImage(This.Bitmap_1)
  130.                 Gdip_DisposeImage(This.Bitmap_2)
  131.                 Gdip_DisposeImage(This.Bitmap_3)
  132.             }
  133.     }
  134.  
  135. Class Window
  136.     {
  137.         ;~ __New(x,y,w,h,name1,name2,smoothing,options1,options2,title,x_offset,y_offset,Background)
  138.         __New(winval)
  139.             {
  140.                 for k, v in winval
  141.                     This[k]:=v
  142.                 if(This.Name1!=""){
  143.                     Gui,% This.Name1 ": " This.Options1
  144.                     Gui,% This.Name1 ": Show",% "w" This.W " h" This.H, % This.Title
  145.                 }
  146.                 This.Layered_Window_SetUp()
  147.             }
  148.         Draw_Background()
  149.             {
  150.                 This.Background_Brush:=New_Brush(This.Background)
  151.                 Gdip_FillRectangle(This.G,This.Background_Brush,This.X-1,This.Y-1,This.W+2,This.H+2)
  152.             }
  153.         UpDate()
  154.             {
  155.                 UpdateLayeredWindow(This.hwnd,This.hdc,This.X,This.Y,This.W,This.H)
  156.             }
  157.         Shutdown()
  158.             {
  159.                 SelectObject(This.hdc,This.obm)
  160.                 DeleteObject(This.hbm)
  161.                 DeleteDC(This.hdc)
  162.                 gdip_deleteGraphics(This.g)
  163.                 Gdip_Shutdown(This.pToken)
  164.             }
  165.         Layered_Window_SetUp()
  166.             {
  167.                 This.Token:=Gdip_Startup()
  168.                 Gui,% This.Name2 ": +E0x80000 +LastFound " This.Options2
  169.                 Gui,% This.Name2 ":Show",% "x" This.X " y" This.Y " w" This.W " h" This.H " NA"
  170.                 This.hwnd:=winExist()
  171.                 This.hbm := CreateDIBSection(This.W,This.H)
  172.                 This.hdc := CreateCompatibleDC()
  173.                 This.obm := SelectObject(This.hdc,This.hbm)
  174.                 This.G := Gdip_GraphicsFromHDC(This.hdc)
  175.                 Gdip_SetSmoothingMode(This.G,This.Smoothing)
  176.                 This.Draw_Background()
  177.                 This.UpDate()
  178.             }
  179.     }
  180. Window_Clicks()
  181.     {
  182.         if(Ready=1){
  183.             Coordmode,Mouse,client
  184.             MouseGetPos,tx,ty
  185.             Loop,% Btn.Length()
  186.                 {
  187.                     if(tx >= Btn[A_Index].x &&tx <= (Btn[A_Index].x+Btn[A_Index].W)&& ty >= Btn[A_Index].Y && ty <= Btn[A_Index].Y+Btn[A_Index].H)
  188.                         Current:=A_Index,Btn[A_Index].Button_Press()
  189.                 }
  190.             }  
  191.     }
  192. Window_Hover()
  193.     {
  194.        
  195.         if(Winactive(Window.title)&&Ready=1){
  196.             Coordmode,Mouse,client
  197.             MouseGetPos,tx,ty
  198.             Loop,% Btn.Length()
  199.                 {
  200.                     if(tx >= Btn[A_Index].x &&tx <= (Btn[A_Index].x+Btn[A_Index].W)&& ty >= Btn[A_Index].Y && ty <= Btn[A_Index].Y+Btn[A_Index].H)
  201.                         Btn[A_Index].Button_Hover()
  202.                 }
  203.         }      
  204.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement