Advertisement
Stewie410

MaterialDesign_CompileTests.ahk

Aug 22nd, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Script Information ===========================================================
  2. ; Name:         Material Design
  3. ; Description:  Material Design UI for AutoHotkey
  4. ; AHK Version:  1.1.26.01 (Unicode 32-bit)
  5. ; OS Version:   Windows 2000+
  6. ; Language:     English (United States)
  7. ; Author:       Weston Campbell <westoncampbell@gmail.com>
  8. ; Filename:     MaterialDesign.ahk
  9. ; ==============================================================================
  10. ;
  11. ; Modified By:  u/stewie5410
  12. ; Date:         2019-08-21
  13. ; Purpose:      Compile and Run, learning, testing
  14.  
  15. ; Revision History =============================================================
  16. ; Revision 1 (2018-05-11)
  17. ; * Initial release
  18. ; ==============================================================================
  19.  
  20. ; Auto-Execute =================================================================
  21. #SingleInstance, Force ; Allow only one running instance of script
  22. #Persistent ; Keep the script permanently running until terminated
  23. #NoEnv ; Avoid checking empty variables for environment variables
  24. #Warn ; Enable warnings to assist with detecting common errors
  25. #NoTrayIcon ; Disable the tray icon of the script
  26. SetWorkingDir, % A_ScriptDir ; Set the working directory of the script
  27. SetBatchLines, -1 ; The speed at which the lines of the script are executed
  28. SendMode, Input ; The method for sending keystrokes and mouse clicks
  29. DetectHiddenWindows, On ; The visibility of hidden windows by the script
  30. SetWinDelay, -1 ; The delay to occur after modifying a window
  31. SetControlDelay, -1 ; The delay to occur after modifying a control
  32. OnExit("OnUnload") ; Run a subroutine or function when exiting the script
  33.  
  34. ; Includes
  35. #Include %A_ScriptDir%
  36. return ; End automatic execution
  37. ; ==============================================================================
  38.  
  39. ; Labels =======================================================================
  40. GuiEscape:
  41. GuiClose:
  42. ExitSub:
  43.     ExitApp ; Terminate the script unconditionally
  44. return
  45. ; ==============================================================================
  46.  
  47. ; Functions ====================================================================
  48. OnLoad() {
  49.     Global ; Assume-global mode
  50.     Static Init := OnLoad() ; Call function
  51.  
  52.     ; Instantiate required files
  53.     IfNotExist, "images\"
  54.         {
  55.             FileCreateDir, images\
  56.             FileInstall, images\MenuActiveBg.png, images\MenuActiveBg.png, 1
  57.             FileInstall, images\MenuBackground.png, images\MenuBackground.png, 1
  58.             FileInstall, images\MenuDivider.png, images\MenuDivider.png, 1
  59.             FileInstall, images\MenuIconExit.png, images\MenuIconExit.png, 1
  60.             FileInstall, images\MenuIconSettings.png, images\MenuIconSettings.png, 1
  61.             FileInstall, images\MenuIconStar.png, images\MenuIconStar.png, 1
  62.             FileInstall, images\MenuLineToolbarShadow.png, images\MenuLineToolbarShadow.png, 1
  63.             FileInstall, images\MenuShadow.png, images\MenuShadow.png, 1
  64.             FileInstall, images\ToolbarBg.png, images\ToolbarBg.png, 1
  65.             FileInstall, images\ToolbarLinkHover.png, images\ToolbarLinkHover.png, 1
  66.             FileInstall, images\ToolbarLinkNormal.png, images\ToolbarLinkNormal.png, 1
  67.             FileInstall, images\ToolbarMenuHover.png, images\ToolbarMenuHover.png, 1
  68.             FileInstall, images\ToolbarMenuNormal.png, images\ToolbarMenuNormal.png, 1
  69.             FileInstall, images\ToolbarShadow.png, images\ToolbarShadow.png, 1
  70.         }
  71.     IfNotExist, "fonts\"
  72.         {
  73.             FileCreateDir, fonts\
  74.             FileInstall, fonts\Product Sans Regular.ttf, fonts\Product Sans Regular.ttf, 1
  75.             FileInstall, fonts\Roboto-Regular.ttf, fonts\Roboto-Regular.ttf, 1
  76.             FileInstall, fonts\Roboto-Medium.ttf, fonts\Roboto-Medium.ttf, 1
  77.         }
  78.  
  79.     /*
  80.     ; Create Missing Directories
  81.     IfNotExist, images\
  82.         FileCreateDir, images\
  83.     IfNotExist, fonts\
  84.         FileCreateDir fonts\
  85.     ; Create Missing Files
  86.     if (!FileExist("images\MenuActiveBg.png"))
  87.         FileInstall, images\MenuActiveBg.png, images\MenuActiveBg.png, 1
  88.     if (!FileExist("images\MenuBackground.png"))
  89.         FileInstall, images\MenuBackground.png, images\MenuBackground.png, 1
  90.     if (!FileExist("images\MenuDivider.png"))
  91.         FileInstall, images\MenuDivider.png, images\MenuDivider.png, 1
  92.     if (!FileExist("images\MenuIconExit.png"))
  93.         FileInstall, images\MenuIconExit.png, images\MenuIconExit.png, 1
  94.     if (!FileExist("images\MenuIconSettings.png"))
  95.         FileInstall, images\MenuIconSettings.png, images\MenuIconSettings.png, 1
  96.     if (!FileExist("images\MenuIconStar.png"))
  97.         FileInstall, images\MenuIconStar.png, images\MenuIconStar.png, 1
  98.     if (!FileExist("images\MenuLineToolbarShadow.png"))
  99.         FileInstall, images\MenuLineToolbarShadow.png, images\MenuLineToolbarShadow.png, 1
  100.     if (!FileExist("images\MenuShadow.png"))
  101.         FileInstall, images\MenuShadow.png, images\MenuShadow.png, 1
  102.     if (!FileExist("images\ToolbarBg.png"))
  103.         FileInstall, images\ToolbarBg.png, images\ToolbarBg.png, 1
  104.     if (!FileExist("images\ToolbarLinkHover.png"))
  105.         FileInstall, images\ToolbarLinkHover.png, images\ToolbarLinkHover.png, 1
  106.     if (!FileExist("images\ToolbarLinkNormal.png"))
  107.         FileInstall, images\ToolbarLinkNormal.png, images\ToolbarLinkNormal.png, 1
  108.     if (!FileExist("images\ToolbarMenuHover.png"))
  109.         FileInstall, images\ToolbarMenuHover.png, images\ToolbarMenuHover.png, 1
  110.     if (!FileExist("images\ToolbarMenuNormal.png"))
  111.         FileInstall, images\ToolbarMenuNormal.png, images\ToolbarMenuNormal.png, 1
  112.     if (!FileExist("images\ToolbarShadow.png"))
  113.         FileInstall, images\ToolbarShadow.png, images\ToolbarShadow.png, 1
  114.     if (!FileExist("fonts\Product Sans Regular.ttf"))
  115.         FileInstall, fonts\Product Sans Regular.ttf, fonts\Product Sans Regular.ttf, 1
  116.     if (!FileExist("fonts\Roboto-Regular.ttf"))
  117.         FileInstall, fonts\Roboto-Regular.ttf, fonts\Roboto-Regular.ttf, 1
  118.     if (!FileExist("fonts\Roboto-Medium.ttf"))
  119.         FileInstall, fonts\Roboto-Medium.ttf, fonts\Roboto-Medium.ttf, 1
  120.     */
  121.  
  122.     Menu, Tray, Tip, Material Design
  123.  
  124.     DllCall("Gdi32.dll\AddFontResourceEx", "Str", "fonts\Product Sans Regular.ttf", "UInt", 0x10, "UInt", 0)
  125.     DllCall("Gdi32.dll\AddFontResourceEx", "Str", "fonts\Roboto-Regular.ttf", "UInt", 0x10, "UInt", 0)
  126.     DllCall("Gdi32.dll\AddFontResourceEx", "Str", "fonts\Roboto-Medium.ttf", "UInt", 0x10, "UInt", 0)
  127. }
  128.  
  129. OnUnload(ExitReason, ExitCode) {
  130.     Global ; Assume-global mode
  131.  
  132.     DllCall("Gdi32.dll\RemoveFontResourceEx", "Str", "fonts\Product Sans Regular.ttf", "UInt", 0x10, "UInt", 0)
  133.     DllCall("Gdi32.dll\RemoveFontResourceEx", "Str", "fonts\Roboto-Regular.ttf", "UInt", 0x10, "UInt", 0)
  134.     DllCall("Gdi32.dll\RemoveFontResourceEx", "Str", "fonts\Roboto-Medium.ttf", "UInt", 0x10, "UInt", 0)
  135.  
  136.     /*
  137.     ; Remove no-longer-necessary files
  138.     if %A_IsCompiled%
  139.         {
  140.             IfExist, images\
  141.                 FileRemoveDir, images\, 1
  142.             IfExist, fonts\
  143.                 FileRemoveDir, fonts\, 1
  144.         }
  145.     */
  146. }
  147.  
  148. GuiCreate() {
  149.     Global ; Assume-global mode
  150.     Static Init := GuiCreate() ; Call function
  151.  
  152.     ; For setting initial placement of controls
  153.     ParentWidth := 800
  154.     ParentHeight := 600
  155.  
  156.     ; Parent -------------------------------------------------------------------
  157.     Gui, Parent: +Resize +LastFound +HWNDhParent +MinSize640x480
  158.     Gui, Parent: Margin, 0, 0
  159.     Gui, Parent: Color, FFFFFF
  160.  
  161.     ; Toolbar ------------------------------------------------------------------
  162.     Gui, Toolbar: +ParentParent +HWNDhToolbar -Caption -Border
  163.     Gui, Toolbar: Margin, 0, 0
  164.     Gui, Toolbar: Color, FFFFFF
  165.     Gui, Toolbar: Add, Picture, x0 y0 w%ParentWidth% h64 +HWNDhToolbarBg, images\ToolbarBg.png
  166.     Gui, Toolbar: Add, Picture, x12 y8 w48 h48 +HWNDhToolbarMenuNormal, images\ToolbarMenuNormal.png
  167.     Gui, Toolbar: Add, Picture, x12 y8 w48 h48 +HWNDhToolbarMenuHover Hidden1, images\ToolbarMenuHover.png
  168.     Gui, Toolbar: Add, Picture, % "x" (ParentWidth-60) " y" 8 " w" 48 " h" 48 " +HWNDhToolbarLinkNormal", images\ToolbarLinkNormal.png
  169.     Gui, Toolbar: Add, Picture, % "x" (ParentWidth-60) " y" 8 " w" 48 " h" 48 " +HWNDhToolbarLinkHover Hidden1", images\ToolbarLinkHover.png
  170.     Gui, Toolbar: Add, Text, % "x" 80 " y" 0 " w" (ParentWidth-140) " h" 64 " +HWNDhToolbarTitle +0x200 +BackgroundTrans", Application
  171.     Gui, Toolbar: Font, s16.5 cFFFFFF w400 q4, Product Sans
  172.     GuiControl, Toolbar: Font, % hToolbarTitle
  173.  
  174.     ; Body ---------------------------------------------------------------------
  175.     Gui, Body: +ParentParent +HwndhBody -Caption -Border
  176.     Gui, Body: Margin, 0, 0
  177.     Gui, Body: Color, FFFFFF
  178.     Gui, Body: Add, Picture, x0 y0 w%ParentWidth% h12 +HWNDhToolbarShadow, images\ToolbarShadow.png
  179.     Gui, Body: Add, Text, % "x" 24 " y" 24 " w" (ParentWidth-48) " h" (ParentHeight-112) " +HWNDhBodyText +BackgroundTrans", Hello World!
  180.     Gui, Body: Font, s10 c212121, Roboto
  181.     GuiControl, Body: Font, % hBodyText
  182.  
  183.     ; MainMenu -----------------------------------------------------------------
  184.     Gui, MainMenu: +ParentParent +HwndhMainMenu +AlwaysOnTop -Caption -Border
  185.     Gui, MainMenu: Margin, 0, 0
  186.     Gui, MainMenu: Color, FFFFFF
  187.     Gui, MainMenu: Add, Picture, x0 y0 w260 h12 +HWNDhMenuShadow, images\MenuShadow.png
  188.     Gui, MainMenu: Add, Picture, % "x" 0 " y" 12 " w" 260 " h" (ParentHeight-76) " +HWNDhMenuBackground", images\MenuBackground.png
  189.     Gui, MainMenu: Add, Picture, x0 y15 w259 h42 +HWNDhMenuHover, images\MenuActiveBg.png
  190.     Gui, MainMenu: Add, Picture, x0 y15 w259 h42 +HWNDhMenuActive, images\MenuActiveBg.png
  191.  
  192.     MenuItem := []
  193.     MenuItem[1] := {Icon: "images\MenuIconStar.png", Text: "Item 1"}
  194.     MenuItem[2] := {Icon: "images\MenuIconStar.png", Text: "Item 2"}
  195.     MenuItem[3] := {Icon: "images\MenuIconStar.png", Text: "Item 3"}
  196.     MenuItem[4] := {Icon: "images\MenuIconStar.png", Text: "Item 4"}
  197.     MenuItem[5] := {Icon: "images\MenuIconStar.png", Text: "Item 5"}
  198.     MenuItem[6] := {}
  199.     MenuItem[7] := {Icon: "images\MenuIconSettings.png", Text: "Settings"}
  200.     MenuItem[8] := {}
  201.     MenuItem[9] := {Icon: "images\MenuIconExit.png", Text: "Exit"}
  202.  
  203.     Gui, MainMenu: Font, s10 c212121, Roboto Medium
  204.         For Key, Value In MenuItem {
  205.             PrevKey := Key-1
  206.  
  207.             If (Key = 1) {
  208.                 yPos := 15
  209.                 Gui, MainMenu: Add, Picture, x0 y%yPos% w56 h42 +BackgroundTrans +HWNDhMenuItemIcon%Key%, % MenuItem[Key].Icon
  210.                 Gui, MainMenu: Add, Text, x56 y%yPos% w199 h42 +BackgroundTrans +0x200 +HWNDhMenuItemText%Key%, % MenuItem[Key].Text
  211.             } Else {
  212.                 GuiControlGet, MenuPos, Pos, % hMenuItemText%PrevKey%
  213.                 yPos := MenuPosY + MenuPosH
  214.  
  215.                 If (MenuItem[Key].Text = "") { ; Divider
  216.                     Gui, MainMenu: Add, Picture, x0 y%yPos% w259 h15 +HWNDhMenuItemText%Key% +BackgroundTrans, images\MenuDivider.png
  217.                 } Else {
  218.                     Gui, MainMenu: Add, Picture, x0 y%yPos% w56 h42 +BackgroundTrans +HWNDhMenuItemIcon%Key%, % MenuItem[Key].Icon
  219.                     Gui, MainMenu: Add, Text, x56 y%yPos% w199 h42 +BackgroundTrans +0x200 +HWNDhMenuItemText%Key%, % MenuItem[Key].Text
  220.                 }
  221.             }
  222.         }
  223.     Gui, MainMenu: Font
  224.  
  225.     Gui, Toolbar: Show, x0 y0 w%ParentWidth% h64
  226.     Gui, Body: Show, x0 y64 w%ParentWidth% h%ParentHeight%
  227.     Gui, MainMenu: Show, % "Hide x" 0 " y" 64 " w" 260 " h" ParentHeight-64
  228.     WinSet, Top,, ahk_id %hMainMenu%
  229.     Gui, Parent: Show, w%ParentWidth% h%ParentHeight%, Material Design
  230. }
  231.  
  232. ParentGuiSize(GuiHwnd, EventInfo, Width, Height) {
  233.     Global ; Assume-global mode
  234.  
  235.     If (ErrorLevel = 1) { ; Window minimized
  236.         return
  237.     }
  238.  
  239.     WinMove, ahk_id %hToolbar%,, 0, 0, % Width, 64
  240.     GuiControl, MoveDraw, % hToolbarBg, x0 y0 w%Width% h64
  241.     GuiControl, MoveDraw, % hToolbarLinkNormal, % "x" (Width-60) " y" 8 " w" 48 " h" 48
  242.     GuiControl, MoveDraw, % hToolbarLinkHover, % "x" (Width-60) " y" 8 " w" 48 " h" 48
  243.     GuiControl, MoveDraw, % hToolbarTitle, % "x" 80 " y" 0 " w" (Width-140) " h" 64
  244.  
  245.     WinMove, ahk_id %hBody%,, 0, 64, % Width, % (Height-64)
  246.     GuiControl, MoveDraw, % hToolbarShadow, x0 y0 w%Width% h12
  247.     GuiControl, MoveDraw, % hBodyText, % "x" 24 " y" 24 " w" (Width-48) " h" (Height-112)
  248.  
  249.     WinMove, ahk_id %hMainMenu%,, 0, 64, 260, % (Height-64)
  250.     GuiControl, MoveDraw, % hMenuBackground, % "x" 0 " y" 12 " w" 260 " h" (Height-76)
  251. }
  252.  
  253. WM_EXITSIZEMOVE(wParam, lParam, Msg, Hwnd) {
  254.     Global ; Assume-global mode
  255.     Static Init := OnMessage(0x0232, "WM_EXITSIZEMOVE")
  256.  
  257.     WinSet, Redraw,, ahk_id %hToolbar%
  258.     WinSet, Redraw,, ahk_id %hBody%
  259.     WinSet, Redraw,, ahk_id %hMainMenu%
  260.     WinSet, Redraw,, ahk_id %hParent%
  261. }
  262.  
  263. WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
  264.     Global ; Assume-global mode
  265.     Static Init := OnMessage(0x0200, "WM_MOUSEMOVE")
  266.     Static Hover := 0
  267.     Static Curr := ""
  268.  
  269.     IsMainMenu := DllCall("IsWindowVisible", "UInt", WinExist("ahk_id " hMainMenu))
  270.  
  271.     MouseGetPos,,,, MouseCtrl, 2
  272.     MouseGetPos,,,, MouseWin, 3
  273.  
  274.     GuiControlGet, MouseCtrl, Pos, % MouseCtrl
  275.  
  276.     VarSetCapacity(TME, 16, 0)
  277.     NumPut(16, TME, 0)
  278.     NumPut(2, TME, 4) ; TME_LEAVE
  279.     NumPut(MouseWin, TME, 8)
  280.  
  281.     DllCall("User32.dll\TrackMouseEvent", "UInt", &TME)
  282.  
  283.     If (MouseCtrl = hToolbarMenuHover || MouseCtrl = hToolbarLinkHover) {
  284.         return
  285.     }
  286.  
  287.     GuiControl, % "Toolbar: " (MouseCtrl = hToolbarMenuNormal ? "Show" : "Hide"), % hToolbarMenuHover
  288.     GuiControl, % "Toolbar: " (MouseCtrl = hToolbarLinkNormal ? "Show" : "Hide"), % hToolbarLinkHover
  289.  
  290.     If (MouseWin = hMainMenu) {
  291.         If (MouseCtrlH = 42) {
  292.             GuiControl, MainMenu: MoveDraw, % hMenuHover, % "x" 0 " y" MouseCtrlY " w" 259 " h" 42
  293.             Hover := 1, Curr := MouseCtrlY
  294.         } Else {
  295.             GuiControl, MainMenu: MoveDraw, % hMenuHover, % "x" 0 " y" 0 " w" 0 " h" 0
  296.             Hover := 0, Curr := ""
  297.         }
  298.     }
  299. }
  300.  
  301. WM_LBUTTONUP(wParam, lParam, Msg, Hwnd) {
  302.     Global ; Assume-global mode
  303.     Static Init := OnMessage(0x0202, "WM_LBUTTONUP")
  304.  
  305.     If (MouseCtrl = hToolbarMenuHover) {
  306.         Gui, % "MainMenu: " (IsMainMenu ? "Hide" : "Show")
  307.     }
  308.  
  309.     If (MouseCtrl = hToolbarLinkHover) {
  310.         Run, https://autohotkey.com/
  311.     }
  312.  
  313.     If (MouseWin = hMainMenu) {
  314.         If (MouseCtrlH = 42) {
  315.             GuiControl, MainMenu: MoveDraw, % hMenuActive, % "y" MouseCtrlY
  316.         }
  317.     }
  318.  
  319.     If (IsMainMenu = 1 && MouseWin <> hMainMenu) {
  320.         If (MouseCtrl = hToolbarMenuHover) {
  321.             return
  322.         }
  323.  
  324.         Gui, MainMenu: Hide
  325.     }
  326.  
  327.     If (IsMainMenu) {
  328.         If (MouseCtrl = hMenuItemIcon1 || MouseCtrl = hMenuItemText1) {
  329.             GuiControl,, % hBodyText, Page 1
  330.         } Else If (MouseCtrl = hMenuItemIcon2 || MouseCtrl = hMenuItemText2) {
  331.             GuiControl,, % hBodyText, Page 2
  332.         } Else If (MouseCtrl = hMenuItemIcon3 || MouseCtrl = hMenuItemText3) {
  333.             GuiControl,, % hBodyText, Page 3
  334.         } Else If (MouseCtrl = hMenuItemIcon4 || MouseCtrl = hMenuItemText4) {
  335.             GuiControl,, % hBodyText, Page 4
  336.         } Else If (MouseCtrl = hMenuItemIcon5 || MouseCtrl = hMenuItemText5) {
  337.             GuiControl,, % hBodyText, Page 5
  338.         } Else If (MouseCtrl = hMenuItemIcon7 || MouseCtrl = hMenuItemText7) {
  339.             GuiControl,, % hBodyText, Settings
  340.         } Else If (MouseCtrl = hMenuItemIcon9 || MouseCtrl = hMenuItemText9) {
  341.             ExitApp
  342.         }
  343.  
  344.         Gui, MainMenu: Hide
  345.     }
  346. }
  347.  
  348. WM_MOUSELEAVE(wParam, lParam, Msg, Hwnd) {
  349.     Global ; Assume-global mode
  350.     Static Init := OnMessage(0x2A3, "WM_MOUSELEAVE")
  351.  
  352.     GuiControl, Toolbar: Hide, % hToolbarMenuHover
  353.     GuiControl, Toolbar: Hide, % hToolbarLinkHover
  354.     GuiControl, MainMenu: MoveDraw, % hMenuHover, % "x" 0 " y" 0 " w" 0 " h" 0
  355. }
  356. ; ==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement