Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Script Information ===========================================================
- ; Name: Material Design
- ; Description: Material Design UI for AutoHotkey
- ; AHK Version: 1.1.26.01 (Unicode 32-bit)
- ; OS Version: Windows 2000+
- ; Language: English (United States)
- ; Author: Weston Campbell <westoncampbell@gmail.com>
- ; Filename: MaterialDesign.ahk
- ; ==============================================================================
- ;
- ; Modified By: u/stewie5410
- ; Date: 2019-08-21
- ; Purpose: Compile and Run, learning, testing
- ; Revision History =============================================================
- ; Revision 1 (2018-05-11)
- ; * Initial release
- ; ==============================================================================
- ; Auto-Execute =================================================================
- #SingleInstance, Force ; Allow only one running instance of script
- #Persistent ; Keep the script permanently running until terminated
- #NoEnv ; Avoid checking empty variables for environment variables
- #Warn ; Enable warnings to assist with detecting common errors
- #NoTrayIcon ; Disable the tray icon of the script
- SetWorkingDir, % A_ScriptDir ; Set the working directory of the script
- SetBatchLines, -1 ; The speed at which the lines of the script are executed
- SendMode, Input ; The method for sending keystrokes and mouse clicks
- DetectHiddenWindows, On ; The visibility of hidden windows by the script
- SetWinDelay, -1 ; The delay to occur after modifying a window
- SetControlDelay, -1 ; The delay to occur after modifying a control
- OnExit("OnUnload") ; Run a subroutine or function when exiting the script
- ; Includes
- #Include %A_ScriptDir%
- return ; End automatic execution
- ; ==============================================================================
- ; Labels =======================================================================
- GuiEscape:
- GuiClose:
- ExitSub:
- ExitApp ; Terminate the script unconditionally
- return
- ; ==============================================================================
- ; Functions ====================================================================
- OnLoad() {
- Global ; Assume-global mode
- Static Init := OnLoad() ; Call function
- ; Instantiate required files
- IfNotExist, "images\"
- {
- FileCreateDir, images\
- FileInstall, images\MenuActiveBg.png, images\MenuActiveBg.png, 1
- FileInstall, images\MenuBackground.png, images\MenuBackground.png, 1
- FileInstall, images\MenuDivider.png, images\MenuDivider.png, 1
- FileInstall, images\MenuIconExit.png, images\MenuIconExit.png, 1
- FileInstall, images\MenuIconSettings.png, images\MenuIconSettings.png, 1
- FileInstall, images\MenuIconStar.png, images\MenuIconStar.png, 1
- FileInstall, images\MenuLineToolbarShadow.png, images\MenuLineToolbarShadow.png, 1
- FileInstall, images\MenuShadow.png, images\MenuShadow.png, 1
- FileInstall, images\ToolbarBg.png, images\ToolbarBg.png, 1
- FileInstall, images\ToolbarLinkHover.png, images\ToolbarLinkHover.png, 1
- FileInstall, images\ToolbarLinkNormal.png, images\ToolbarLinkNormal.png, 1
- FileInstall, images\ToolbarMenuHover.png, images\ToolbarMenuHover.png, 1
- FileInstall, images\ToolbarMenuNormal.png, images\ToolbarMenuNormal.png, 1
- FileInstall, images\ToolbarShadow.png, images\ToolbarShadow.png, 1
- }
- IfNotExist, "fonts\"
- {
- FileCreateDir, fonts\
- FileInstall, fonts\Product Sans Regular.ttf, fonts\Product Sans Regular.ttf, 1
- FileInstall, fonts\Roboto-Regular.ttf, fonts\Roboto-Regular.ttf, 1
- FileInstall, fonts\Roboto-Medium.ttf, fonts\Roboto-Medium.ttf, 1
- }
- /*
- ; Create Missing Directories
- IfNotExist, images\
- FileCreateDir, images\
- IfNotExist, fonts\
- FileCreateDir fonts\
- ; Create Missing Files
- if (!FileExist("images\MenuActiveBg.png"))
- FileInstall, images\MenuActiveBg.png, images\MenuActiveBg.png, 1
- if (!FileExist("images\MenuBackground.png"))
- FileInstall, images\MenuBackground.png, images\MenuBackground.png, 1
- if (!FileExist("images\MenuDivider.png"))
- FileInstall, images\MenuDivider.png, images\MenuDivider.png, 1
- if (!FileExist("images\MenuIconExit.png"))
- FileInstall, images\MenuIconExit.png, images\MenuIconExit.png, 1
- if (!FileExist("images\MenuIconSettings.png"))
- FileInstall, images\MenuIconSettings.png, images\MenuIconSettings.png, 1
- if (!FileExist("images\MenuIconStar.png"))
- FileInstall, images\MenuIconStar.png, images\MenuIconStar.png, 1
- if (!FileExist("images\MenuLineToolbarShadow.png"))
- FileInstall, images\MenuLineToolbarShadow.png, images\MenuLineToolbarShadow.png, 1
- if (!FileExist("images\MenuShadow.png"))
- FileInstall, images\MenuShadow.png, images\MenuShadow.png, 1
- if (!FileExist("images\ToolbarBg.png"))
- FileInstall, images\ToolbarBg.png, images\ToolbarBg.png, 1
- if (!FileExist("images\ToolbarLinkHover.png"))
- FileInstall, images\ToolbarLinkHover.png, images\ToolbarLinkHover.png, 1
- if (!FileExist("images\ToolbarLinkNormal.png"))
- FileInstall, images\ToolbarLinkNormal.png, images\ToolbarLinkNormal.png, 1
- if (!FileExist("images\ToolbarMenuHover.png"))
- FileInstall, images\ToolbarMenuHover.png, images\ToolbarMenuHover.png, 1
- if (!FileExist("images\ToolbarMenuNormal.png"))
- FileInstall, images\ToolbarMenuNormal.png, images\ToolbarMenuNormal.png, 1
- if (!FileExist("images\ToolbarShadow.png"))
- FileInstall, images\ToolbarShadow.png, images\ToolbarShadow.png, 1
- if (!FileExist("fonts\Product Sans Regular.ttf"))
- FileInstall, fonts\Product Sans Regular.ttf, fonts\Product Sans Regular.ttf, 1
- if (!FileExist("fonts\Roboto-Regular.ttf"))
- FileInstall, fonts\Roboto-Regular.ttf, fonts\Roboto-Regular.ttf, 1
- if (!FileExist("fonts\Roboto-Medium.ttf"))
- FileInstall, fonts\Roboto-Medium.ttf, fonts\Roboto-Medium.ttf, 1
- */
- Menu, Tray, Tip, Material Design
- DllCall("Gdi32.dll\AddFontResourceEx", "Str", "fonts\Product Sans Regular.ttf", "UInt", 0x10, "UInt", 0)
- DllCall("Gdi32.dll\AddFontResourceEx", "Str", "fonts\Roboto-Regular.ttf", "UInt", 0x10, "UInt", 0)
- DllCall("Gdi32.dll\AddFontResourceEx", "Str", "fonts\Roboto-Medium.ttf", "UInt", 0x10, "UInt", 0)
- }
- OnUnload(ExitReason, ExitCode) {
- Global ; Assume-global mode
- DllCall("Gdi32.dll\RemoveFontResourceEx", "Str", "fonts\Product Sans Regular.ttf", "UInt", 0x10, "UInt", 0)
- DllCall("Gdi32.dll\RemoveFontResourceEx", "Str", "fonts\Roboto-Regular.ttf", "UInt", 0x10, "UInt", 0)
- DllCall("Gdi32.dll\RemoveFontResourceEx", "Str", "fonts\Roboto-Medium.ttf", "UInt", 0x10, "UInt", 0)
- /*
- ; Remove no-longer-necessary files
- if %A_IsCompiled%
- {
- IfExist, images\
- FileRemoveDir, images\, 1
- IfExist, fonts\
- FileRemoveDir, fonts\, 1
- }
- */
- }
- GuiCreate() {
- Global ; Assume-global mode
- Static Init := GuiCreate() ; Call function
- ; For setting initial placement of controls
- ParentWidth := 800
- ParentHeight := 600
- ; Parent -------------------------------------------------------------------
- Gui, Parent: +Resize +LastFound +HWNDhParent +MinSize640x480
- Gui, Parent: Margin, 0, 0
- Gui, Parent: Color, FFFFFF
- ; Toolbar ------------------------------------------------------------------
- Gui, Toolbar: +ParentParent +HWNDhToolbar -Caption -Border
- Gui, Toolbar: Margin, 0, 0
- Gui, Toolbar: Color, FFFFFF
- Gui, Toolbar: Add, Picture, x0 y0 w%ParentWidth% h64 +HWNDhToolbarBg, images\ToolbarBg.png
- Gui, Toolbar: Add, Picture, x12 y8 w48 h48 +HWNDhToolbarMenuNormal, images\ToolbarMenuNormal.png
- Gui, Toolbar: Add, Picture, x12 y8 w48 h48 +HWNDhToolbarMenuHover Hidden1, images\ToolbarMenuHover.png
- Gui, Toolbar: Add, Picture, % "x" (ParentWidth-60) " y" 8 " w" 48 " h" 48 " +HWNDhToolbarLinkNormal", images\ToolbarLinkNormal.png
- Gui, Toolbar: Add, Picture, % "x" (ParentWidth-60) " y" 8 " w" 48 " h" 48 " +HWNDhToolbarLinkHover Hidden1", images\ToolbarLinkHover.png
- Gui, Toolbar: Add, Text, % "x" 80 " y" 0 " w" (ParentWidth-140) " h" 64 " +HWNDhToolbarTitle +0x200 +BackgroundTrans", Application
- Gui, Toolbar: Font, s16.5 cFFFFFF w400 q4, Product Sans
- GuiControl, Toolbar: Font, % hToolbarTitle
- ; Body ---------------------------------------------------------------------
- Gui, Body: +ParentParent +HwndhBody -Caption -Border
- Gui, Body: Margin, 0, 0
- Gui, Body: Color, FFFFFF
- Gui, Body: Add, Picture, x0 y0 w%ParentWidth% h12 +HWNDhToolbarShadow, images\ToolbarShadow.png
- Gui, Body: Add, Text, % "x" 24 " y" 24 " w" (ParentWidth-48) " h" (ParentHeight-112) " +HWNDhBodyText +BackgroundTrans", Hello World!
- Gui, Body: Font, s10 c212121, Roboto
- GuiControl, Body: Font, % hBodyText
- ; MainMenu -----------------------------------------------------------------
- Gui, MainMenu: +ParentParent +HwndhMainMenu +AlwaysOnTop -Caption -Border
- Gui, MainMenu: Margin, 0, 0
- Gui, MainMenu: Color, FFFFFF
- Gui, MainMenu: Add, Picture, x0 y0 w260 h12 +HWNDhMenuShadow, images\MenuShadow.png
- Gui, MainMenu: Add, Picture, % "x" 0 " y" 12 " w" 260 " h" (ParentHeight-76) " +HWNDhMenuBackground", images\MenuBackground.png
- Gui, MainMenu: Add, Picture, x0 y15 w259 h42 +HWNDhMenuHover, images\MenuActiveBg.png
- Gui, MainMenu: Add, Picture, x0 y15 w259 h42 +HWNDhMenuActive, images\MenuActiveBg.png
- MenuItem := []
- MenuItem[1] := {Icon: "images\MenuIconStar.png", Text: "Item 1"}
- MenuItem[2] := {Icon: "images\MenuIconStar.png", Text: "Item 2"}
- MenuItem[3] := {Icon: "images\MenuIconStar.png", Text: "Item 3"}
- MenuItem[4] := {Icon: "images\MenuIconStar.png", Text: "Item 4"}
- MenuItem[5] := {Icon: "images\MenuIconStar.png", Text: "Item 5"}
- MenuItem[6] := {}
- MenuItem[7] := {Icon: "images\MenuIconSettings.png", Text: "Settings"}
- MenuItem[8] := {}
- MenuItem[9] := {Icon: "images\MenuIconExit.png", Text: "Exit"}
- Gui, MainMenu: Font, s10 c212121, Roboto Medium
- For Key, Value In MenuItem {
- PrevKey := Key-1
- If (Key = 1) {
- yPos := 15
- Gui, MainMenu: Add, Picture, x0 y%yPos% w56 h42 +BackgroundTrans +HWNDhMenuItemIcon%Key%, % MenuItem[Key].Icon
- Gui, MainMenu: Add, Text, x56 y%yPos% w199 h42 +BackgroundTrans +0x200 +HWNDhMenuItemText%Key%, % MenuItem[Key].Text
- } Else {
- GuiControlGet, MenuPos, Pos, % hMenuItemText%PrevKey%
- yPos := MenuPosY + MenuPosH
- If (MenuItem[Key].Text = "") { ; Divider
- Gui, MainMenu: Add, Picture, x0 y%yPos% w259 h15 +HWNDhMenuItemText%Key% +BackgroundTrans, images\MenuDivider.png
- } Else {
- Gui, MainMenu: Add, Picture, x0 y%yPos% w56 h42 +BackgroundTrans +HWNDhMenuItemIcon%Key%, % MenuItem[Key].Icon
- Gui, MainMenu: Add, Text, x56 y%yPos% w199 h42 +BackgroundTrans +0x200 +HWNDhMenuItemText%Key%, % MenuItem[Key].Text
- }
- }
- }
- Gui, MainMenu: Font
- Gui, Toolbar: Show, x0 y0 w%ParentWidth% h64
- Gui, Body: Show, x0 y64 w%ParentWidth% h%ParentHeight%
- Gui, MainMenu: Show, % "Hide x" 0 " y" 64 " w" 260 " h" ParentHeight-64
- WinSet, Top,, ahk_id %hMainMenu%
- Gui, Parent: Show, w%ParentWidth% h%ParentHeight%, Material Design
- }
- ParentGuiSize(GuiHwnd, EventInfo, Width, Height) {
- Global ; Assume-global mode
- If (ErrorLevel = 1) { ; Window minimized
- return
- }
- WinMove, ahk_id %hToolbar%,, 0, 0, % Width, 64
- GuiControl, MoveDraw, % hToolbarBg, x0 y0 w%Width% h64
- GuiControl, MoveDraw, % hToolbarLinkNormal, % "x" (Width-60) " y" 8 " w" 48 " h" 48
- GuiControl, MoveDraw, % hToolbarLinkHover, % "x" (Width-60) " y" 8 " w" 48 " h" 48
- GuiControl, MoveDraw, % hToolbarTitle, % "x" 80 " y" 0 " w" (Width-140) " h" 64
- WinMove, ahk_id %hBody%,, 0, 64, % Width, % (Height-64)
- GuiControl, MoveDraw, % hToolbarShadow, x0 y0 w%Width% h12
- GuiControl, MoveDraw, % hBodyText, % "x" 24 " y" 24 " w" (Width-48) " h" (Height-112)
- WinMove, ahk_id %hMainMenu%,, 0, 64, 260, % (Height-64)
- GuiControl, MoveDraw, % hMenuBackground, % "x" 0 " y" 12 " w" 260 " h" (Height-76)
- }
- WM_EXITSIZEMOVE(wParam, lParam, Msg, Hwnd) {
- Global ; Assume-global mode
- Static Init := OnMessage(0x0232, "WM_EXITSIZEMOVE")
- WinSet, Redraw,, ahk_id %hToolbar%
- WinSet, Redraw,, ahk_id %hBody%
- WinSet, Redraw,, ahk_id %hMainMenu%
- WinSet, Redraw,, ahk_id %hParent%
- }
- WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
- Global ; Assume-global mode
- Static Init := OnMessage(0x0200, "WM_MOUSEMOVE")
- Static Hover := 0
- Static Curr := ""
- IsMainMenu := DllCall("IsWindowVisible", "UInt", WinExist("ahk_id " hMainMenu))
- MouseGetPos,,,, MouseCtrl, 2
- MouseGetPos,,,, MouseWin, 3
- GuiControlGet, MouseCtrl, Pos, % MouseCtrl
- VarSetCapacity(TME, 16, 0)
- NumPut(16, TME, 0)
- NumPut(2, TME, 4) ; TME_LEAVE
- NumPut(MouseWin, TME, 8)
- DllCall("User32.dll\TrackMouseEvent", "UInt", &TME)
- If (MouseCtrl = hToolbarMenuHover || MouseCtrl = hToolbarLinkHover) {
- return
- }
- GuiControl, % "Toolbar: " (MouseCtrl = hToolbarMenuNormal ? "Show" : "Hide"), % hToolbarMenuHover
- GuiControl, % "Toolbar: " (MouseCtrl = hToolbarLinkNormal ? "Show" : "Hide"), % hToolbarLinkHover
- If (MouseWin = hMainMenu) {
- If (MouseCtrlH = 42) {
- GuiControl, MainMenu: MoveDraw, % hMenuHover, % "x" 0 " y" MouseCtrlY " w" 259 " h" 42
- Hover := 1, Curr := MouseCtrlY
- } Else {
- GuiControl, MainMenu: MoveDraw, % hMenuHover, % "x" 0 " y" 0 " w" 0 " h" 0
- Hover := 0, Curr := ""
- }
- }
- }
- WM_LBUTTONUP(wParam, lParam, Msg, Hwnd) {
- Global ; Assume-global mode
- Static Init := OnMessage(0x0202, "WM_LBUTTONUP")
- If (MouseCtrl = hToolbarMenuHover) {
- Gui, % "MainMenu: " (IsMainMenu ? "Hide" : "Show")
- }
- If (MouseCtrl = hToolbarLinkHover) {
- Run, https://autohotkey.com/
- }
- If (MouseWin = hMainMenu) {
- If (MouseCtrlH = 42) {
- GuiControl, MainMenu: MoveDraw, % hMenuActive, % "y" MouseCtrlY
- }
- }
- If (IsMainMenu = 1 && MouseWin <> hMainMenu) {
- If (MouseCtrl = hToolbarMenuHover) {
- return
- }
- Gui, MainMenu: Hide
- }
- If (IsMainMenu) {
- If (MouseCtrl = hMenuItemIcon1 || MouseCtrl = hMenuItemText1) {
- GuiControl,, % hBodyText, Page 1
- } Else If (MouseCtrl = hMenuItemIcon2 || MouseCtrl = hMenuItemText2) {
- GuiControl,, % hBodyText, Page 2
- } Else If (MouseCtrl = hMenuItemIcon3 || MouseCtrl = hMenuItemText3) {
- GuiControl,, % hBodyText, Page 3
- } Else If (MouseCtrl = hMenuItemIcon4 || MouseCtrl = hMenuItemText4) {
- GuiControl,, % hBodyText, Page 4
- } Else If (MouseCtrl = hMenuItemIcon5 || MouseCtrl = hMenuItemText5) {
- GuiControl,, % hBodyText, Page 5
- } Else If (MouseCtrl = hMenuItemIcon7 || MouseCtrl = hMenuItemText7) {
- GuiControl,, % hBodyText, Settings
- } Else If (MouseCtrl = hMenuItemIcon9 || MouseCtrl = hMenuItemText9) {
- ExitApp
- }
- Gui, MainMenu: Hide
- }
- }
- WM_MOUSELEAVE(wParam, lParam, Msg, Hwnd) {
- Global ; Assume-global mode
- Static Init := OnMessage(0x2A3, "WM_MOUSELEAVE")
- GuiControl, Toolbar: Hide, % hToolbarMenuHover
- GuiControl, Toolbar: Hide, % hToolbarLinkHover
- GuiControl, MainMenu: MoveDraw, % hMenuHover, % "x" 0 " y" 0 " w" 0 " h" 0
- }
- ; ==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement