Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name:RulerPP
- Version 1.1 (Mon March 02, 2015)
- Created: Sat January 31, 2015
- Author: tidbit
- Credit:
- Hotkeys:
- esc --- Quit
- Description:
- A multi-use ruler program. Designed using the worst code ever written.
- TO DO:
- get Vertical fully working.
- */
- ; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
- #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
- ; #Warn ; Enable warnings to assist with detecting common errors.
- SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
- SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
- #SingleInstance, force
- #maxThreadsPerHotkey, 2
- _name_=
- _version_=1.0 (date)
- _created_=date
- _author_=tidbit ([email protected])
- _credit_=
- _info_=
- onexit, DIE
- Width:=A_ScreenWidth
- Height:=A_ScreenHeight
- clickthrough:=0 ; not used right now
- snapping:=0 ; set to 0 for no snapping, otherwise the number you want it to snap to.
- ; wholeScreenTicks:=0 ; [NOT IMPLEMENTED. TOO LAZY TO FIX]
- global vert:=0 ; sue me.
- global coordsRuler ; sue me again.
- ; used for ruler mode
- ; [x, y, w, h, color, border color]
- ; leave border color blank for no border.
- coordsRuler:=[[7,250,250,50,0x77ff0000,0x77ffffff] ; main window
- ,[0,0,8,50,0x55ffffff,""] ; move bar
- ,[100,0,3,50,0xff00ffff,""] ; slider
- ,[242,0,8,50,0x55ffffff,""] ; resize bar
- ,[0,0,15,10,0x770000ff,""]] ; settings
- ; coordsRuler:=[[270,250,5,100, 0x9900ffff]
- ; ,[250,250,width//2,100,0x33ff0000]]
- ; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
- Gui, +hwndMYHWND -Caption +E0x80000 +AlwaysOnTop +ToolWindow +OwnDialogs
- ; Gui, +hwndMYHWND -Caption +E0x20 +E0x80000 +AlwaysOnTop +ToolWindow +OwnDialogs
- pToken:=Gdip_Startup()
- hbm :=CreateDIBSection(Width, Height)
- hdc :=CreateCompatibleDC()
- obm :=SelectObject(hdc, hbm)
- G :=Gdip_GraphicsFromHDC(hdc)
- Gdip_SetSmoothingMode(G, 4)
- ; WinSet_Click_Through(MYHWND)
- Gui, Show, NA
- gosub, mainStuff
- return
- tooltipOff:
- toolTip
- return
- /*
- ~lbutton up::
- mouseGetPos, x, y
- if ((x>=coordsRuler[5,1]+crx
- && x<=coordsRuler[5,1]+crx+coordsRuler[5,3])
- && (y>=coordsRuler[5,2]+cry
- && y<=coordsRuler[5,2]+cry+coordsRuler[5,4]))
- {
- clickthrough:=!clickthrough
- msgbox hi %clickthrough%
- ; coordsRuler[3,5]:=((clickthrough=1) ? 0xff0000ff ? 0xffff4400)
- ; Gui, % ((clickthrough=1) ? "+E0x20" : "-E0x20")
- ; drawControls(coordsRuler, G)
- ; drawTicks(crx, cry, 2, ((wholeScreenTicks=1) ? -1 : coordsRuler[2,4]), abs(arr[1]), tickCount, G)
- ; UpdateLayeredWindow(MYHWND, hdc, 0, 0, Width, Height)
- }
- return
- */
- $~lbutton::
- mainStuff:
- ; critical
- ; needed for the first showing.
- tickCount:=coordsRuler[1,3]//coordsRuler[3,1]
- ; calculate the offset of where you clicked inside the control.
- ; that way it doesn't jump when you go to drag it.
- mouseGetPos, x, y
- crx:=coordsRuler[1,1]
- cry:=coordsRuler[1,2]
- offx:=x-crx ; calculate the offset of where you clicked inside the control
- offy:=y-cry ; calculate the offset of where you clicked inside the control
- ; UIObj 1 = main window
- ; UIObj 2 = move
- ; UIObj 3 = slider
- ; UIObj 4 = resize
- ; UIObj 5 = button 1
- UIObj:=0 ; nothing
- for k, arr in coordsRuler
- {
- if (a_index=1)
- continue
- if (vert=0)
- xoff:=arr[1], yoff:=arr[2], w:=arr[3], h:=arr[4]
- else
- xoff:=arr[2], yoff:=arr[1], w:=arr[4], h:=arr[3]
- if ((x>=xoff+crx && x<=xoff+w+crx)
- && (y>=yoff+cry && y<=yoff+h+cry))
- {
- UIObj:=k ; return the item clicked.
- ; break
- }
- }
- ; if (clickthrough=1)
- ; continue
- if (UIObj=5)
- vert:=!vert
- if (UIObj=2) ; move bar
- {
- while (getKeyState("Lbutton", "P"))
- {
- mouseGetPos, x, y
- coordsRuler[1,1]:=x-offx
- coordsRuler[1,2]:=y-offy
- drawControls(coordsRuler, G)
- if (snapping>0)
- drawTicks(coordsRuler[1,1], coordsRuler[1,2], 1, coordsRuler[3,4], snapping, coordsRuler[1,3]//snapping, G, 0x66ffffff, 0)
- drawTicks(coordsRuler[1,1], coordsRuler[1,2], 2, ((wholeScreenTicks=1) ? -1 : coordsRuler[3,4]), abs(coordsRuler[3,1]), tickCount, G)
- UpdateLayeredWindow(MYHWND, hdc, 0, 0, Width, Height)
- ; toolTip, % "x: " coordsRuler[1,1] "`n---`n" st_printArr(coordsRuler)
- }
- settimer, tooltipOff, -2000
- ; return
- }
- if (UIObj=3) ; slider bar
- {
- if (vert=0)
- offx:=x-coordsRuler[3,1]
- , banana:=crx
- else
- offx:=x-coordsRuler[3,2]
- , banana:=cry
- while (getKeyState("Lbutton", "P"))
- {
- tickCount:=coordsRuler[1,3]//abs(coordsRuler[3,1])
- mouseGetPos, x, y
- if (vert=1)
- {
- x:=y
- toolTip % abs(coordsRuler[3,1]) " (" round(coordsRuler[3,1]/coordsRuler[1,3]*100,1) "%)", % crx+coordsRuler[1,4], % coordsRuler[3,1]+cry
- }
- else
- toolTip % abs(coordsRuler[3,1]) " (" round(coordsRuler[3,1]/coordsRuler[1,3]*100,1) "%)", % coordsRuler[3,1]+crx, % cry-22
- if (snapping>0)
- {
- ; toolTip, % crx " - " x-crx " - " mod(x-crx, snapping),,,2
- if (mod(x-banana, snapping)=0)
- coordsRuler[3,1]:=x-banana
- }
- else
- coordsRuler[3,1]:=x-banana
- ; tooltip, % x ", " tickCount "`n---`n" st_printArr(coordsRuler),,,2
- if (coordsRuler[3,1]<=1)
- coordsRuler[3,1]:=1
- if (coordsRuler[3,1]>=coordsRuler[1,3])
- coordsRuler[3,1]:=coordsRuler[1,3]
- drawControls(coordsRuler, G)
- if (snapping>0)
- drawTicks(crx, cry, 1, coordsRuler[3,4], snapping, coordsRuler[1,3]//snapping, G,0x66ffffff, 0)
- drawTicks(crx, cry, 2, ((wholeScreenTicks=1) ? -1 : coordsRuler[3,4]), abs(coordsRuler[3,1]), tickCount, G)
- UpdateLayeredWindow(MYHWND, hdc, 0, 0, Width, Height)
- }
- settimer, tooltipOff, -2000
- ; return
- }
- if (UIObj=4) ; resize bar
- {
- ; if (vert=0)
- offw:=coordsRuler[1,3]
- offh:=coordsRuler[1,4]
- ; else
- ; offw:=coordsRuler[1,4]
- while (getKeyState("Lbutton", "P"))
- {
- mouseGetPos, x, y
- tickCount:=coordsRuler[1,3]//abs(coordsRuler[3,1])
- if (vert=0)
- coordsRuler[1,3]:=x-offx+offw-crx
- else
- coordsRuler[1,3]:=y-cry
- ; the border is 2px. 2*2=4. but then we need 1 more for some reason.
- coordsRuler[4,1]:=coordsRuler[1,3]-coordsRuler[3,3]-5
- drawControls(coordsRuler, G)
- if (snapping>0)
- drawTicks(coordsRuler[1,1], coordsRuler[1,2], 1, coordsRuler[3,4], snapping, coordsRuler[1,3]//snapping, G, 0x66ffffff, 0)
- drawTicks(crx, cry, 2, ((wholeScreenTicks=1) ? -1 : coordsRuler[3,4]), abs(coordsRuler[3,1]), tickCount, G)
- UpdateLayeredWindow(MYHWND, hdc, 0, 0, Width, Height)
- }
- }
- drawControls(coordsRuler, G)
- if (snapping>0)
- drawTicks(coordsRuler[1,1], coordsRuler[1,2], 1, coordsRuler[2,4], snapping, coordsRuler[1,3]//snapping, G, 0x66ffffff, 0)
- ; msgbox % coordsRuler[1,2]
- drawTicks(coordsRuler[1,1], coordsRuler[1,2], 2, ((wholeScreenTicks=1) ? -1 : coordsRuler[3,4]), abs(coordsRuler[3,1]), tickCount, G)
- ; drawTicks(crx
- ; , cry
- ; , 2
- ; , ((wholeScreenTicks=1) ? -1 : coordsRuler[3,4])
- ; , abs(coordsRuler[3,1])
- ; , tickCount, G)
- UpdateLayeredWindow(MYHWND, hdc, 0, 0, Width, Height)
- Gdip_DeleteBrush(pBrush)
- return
- /*
- j::
- ; random, r, 40,250
- ; coordsRuler[2,1]:=r
- ; drawControls(coordsRuler, G)
- ; drawTicks(coordsRuler[1,1], coordsRuler[1,2], 2, ((wholeScreenTicks=1) ? -1 : coordsRuler[2,4]), abs(coordsRuler[2,1]), coordsRuler[1,3]//coordsRuler[2,1], G)
- ; UpdateLayeredWindow(MYHWND, hdc, 0, 0, Width, Height)
- tooltip % "aaaaaa" (st_printArr(coordsRuler))
- ; Gui, % ((clickthrough:=!clickthrough) ? "+E0x20" : "-E0x20")
- return
- */
- drawControls(byref contArr, G)
- {
- Gdip_GraphicsClear(G)
- basex:=contArr[1,1]
- basey:=contArr[1,2]
- offx:=0
- offy:=0
- ; ypos:=0
- for k,arr in contArr
- {
- if (a_index>1)
- {
- if (vert=0)
- offx:=arr[1], offy:=0
- else
- offx:=0, offy:=arr[1]
- ; msgbox % arr[2]
- }
- pBrush:=Gdip_BrushCreateSolid(arr[5])
- Gdip_FillRectangle(G
- , pBrush
- , abs(basex+offx)
- , abs(basey+offy)
- , (vert=0) ? arr[3] : arr[4]
- , (vert=0) ? arr[4] : arr[3])
- Gdip_DeleteBrush(pBrush)
- if (arr[6]!="")
- {
- pPen:=Gdip_CreatePen(arr[6], 2)
- Gdip_DrawRectangle(G
- , pPen
- , abs(basex+offx)
- , abs(basey+offy)
- , (vert=0) ? arr[3] : arr[4]
- , (vert=0) ? arr[4] : arr[3])
- Gdip_DeletePen(pPen)
- }
- }
- }
- drawTicks(x, y, w, h, spacing, tickCount, G, color="0xccffffff", text=1)
- {
- ; if (spacing<w)
- ; return 0
- if (vert=0)
- banana:=w
- else
- banana:=w, w:=h, h:=banana
- step:=spacing
- fname=Verdana ; Font name, one that's on your OS.
- fsize=14 ; Font size, like in MS Word or whatever.
- font:=Gdip_FontCreate(ff, fsize, 1)
- ff:=Gdip_FontFamilyCreate(fname)
- j:=0
- ; y:=((h=-1) ? 0 : y)
- ; h:=((h=-1) ? A_ScreenHeight : h)
- loop, %tickCount%
- {
- if (spacing<w)
- break
- pBrush:=Gdip_BrushCreateSolid(color)
- Gdip_FillRectangle(G, pBrush, x+((vert=0) ? spacing : 0), y+((vert=0) ? 0 : spacing), w, h)
- Gdip_DeleteBrush(pBrush)
- options:=(vert=0)
- ? "x" x+spacing " y" ((mod(a_index, 2)=1) ? (y, j:=0) : (y+15, j:=1)) ; why "j"? no idea.
- : "x" x " y" y+spacing
- if (step>=20 && text=1)
- Gdip_TextToGraphics(G, spacing, options " c" substr(color, 3) " s" fsize, fname)
- spacing+=step
- }
- options:=(vert=0)
- ? "x" coordsRuler[1,1]+coordsRuler[1,3] " y" ((j=0) ? y+15 : y)
- : "x" x " y" coordsRuler[1,2]+coordsRuler[1,3]
- Gdip_TextToGraphics(G, coordsRuler[1,3], options " c" substr(color, 3) " s" fsize, fname)
- Gdip_DeleteFont(font)
- Gdip_DeleteFontFamily(ff)
- }
- st_printArr(array, depth=5, indentLevel="")
- {
- for k,v in Array
- {
- list.= indentLevel "[" k "]"
- if (IsObject(v) && depth>1)
- list.="`n" st_printArr(v, depth-1, indentLevel . " ")
- Else
- list.=" => " v
- list.="`n"
- }
- return rtrim(list)
- }
- esc::
- DIE:
- critical
- SelectObject(hdc, obm)
- DeleteObject(hbm)
- DeleteDC(hdc)
- Gdip_DeleteGraphics(G)
- Gdip_DeleteBrush(pBrush)
- Gdip_DisposeImage(pB)
- Gdip_Shutdown(pToken)
- exitapp
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement