Skip to content

Instantly share code, notes, and snippets.

@fischgeek
Last active August 29, 2015 14:18
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fischgeek/00b7c78838f818fb446b to your computer and use it in GitHub Desktop.
CircleProgress.ahk
#Include Gdip.ahk
#Include CircleProgressClass.ahk
#SingleInstance, Force
SysGet, mon, MonitorWorkArea
thickness := 15
spacing := thickness*2
hrDiam := thickness+spacing
minDiam := hrDiam+spacing
secDiam := minDiam+spacing
yCoord := (monBottom-(spacing+secDiam))
progHour := new CircleProgressClass({X: spacing, Y: yCoord+spacing, BarDiameter: hrDiam, BarThickness: thickness, BarColor: "aa46749a", TextSize: thickness, TextFont: "Segoe UI Light", TextColor: "aa46749a"})
progMinute := new CircleProgressClass({X: thickness, Y: yCoord+thickness, BarDiameter: minDiam, BarThickness: thickness, BarColor: "aa46749a", BackgroundColor: 0})
progSecond := new CircleProgressClass({X: 0, Y: yCoord, BarDiameter: secDiam, BarThickness: thickness, BarColor: "aa46749a", BackgroundColor: 0})
SetTimer, updateTime, 500
return
updateTime:
{
FormatTime, hr,, h
FormatTime, day,, d`nMMM
progSecond.Update(A_Sec*1.7)
progMinute.Update(A_Min*1.7)
progHour.Update(hr*8.5, day)
return
}
Esc::ExitApp
class CircleProgressClass { ; http://ahkscript.org/boards/viewtopic.php?p=41794#p41794
static Version := 1.02, WebSite := "http://ahkscript.org/boards/viewtopic.php?p=41794#p41794"
__New(Options="") {
this.BarDiameter := (Options.HasKey("BarDiameter") = 1) ? Options.BarDiameter : 120
this.BarThickness := (Options.HasKey("BarThickness") = 1) ? Options.BarThickness : 25
this.BarColor := (Options.HasKey("BarColor") = 1) ? Options.BarColor : "ff22aa22"
this.BackgroundColor := (Options.HasKey("BackgroundColor") = 1) ? Options.BackgroundColor : "ffffffff"
this.TextColor := (Options.HasKey("TextColor") = 1) ? Options.TextColor : "ee000000"
this.TextSize := (Options.HasKey("TextSize") = 1) ? Options.TextSize : 11
this.TextRendering := (Options.HasKey("TextRendering") = 1) ? Options.TextRendering : 5
this.TextFont := (Options.HasKey("TextFont") = 1) ? Options.TextFont : "Arial"
this.TextStyle := (Options.HasKey("TextStyle") = 1) ? Options.TextStyle : "" ; you can use for example "Bold Italic"
this.X := (Options.HasKey("X") = 1) ? Options.X : Round(A_ScreenWidth/2-this.BarDiameter/2-this.BarThickness) ; centered is defualt
this.Y := (Options.HasKey("Y") = 1) ? Options.Y : Round(A_ScreenHeight/2-this.BarDiameter/2-this.BarThickness) ; centered is defualt
this.W := this.BarDiameter+this.BarThickness*2
Gui, New, +Hwndhwnd
Gui %hwnd%: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui %hwnd%: Show, NA
WinSet, ExStyle, +0x20, % "ahk_id " hwnd ; click through style
hbm := CreateDIBSection(this.W, this.W), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
pPen:=Gdip_CreatePen("0x" this.BarColor, this.BarThickness)
if (pPen = 0) { ; GDI+ is not started up - start it up now and shut it down in __Delete() automatically
pToken := Gdip_Startup()
pPen:=Gdip_CreatePen("0x" this.BarColor, this.BarThickness) ; call it again (with GDI+ started up now)
}
G := Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4)
if (this.BackgroundColor > 0) {
pBrush:=Gdip_BrushCreateSolid("0x" this.BackgroundColor)
}
this.hwnd := hwnd, this.hdc := hdc, this.obm := obm, this.hbm := hbm, this.pPen := pPen, this.pBrush := pBrush, this.G := G, this.pToken := pToken
}
Update(Percent=0, Text="") {
Gdip_GraphicsClear(this.G)
if (this.BackgroundColor > 0) {
Gdip_FillEllipse(this.G, this.pBrush, this.BarThickness, this.BarThickness, this.BarDiameter,this.BarDiameter)
}
if (Percent>0) {
Gdip_DrawArc(this.G, this.pPen, Round(this.BarThickness/2), Round(this.BarThickness/2), this.BarDiameter+this.BarThickness-1, this.BarDiameter+this.BarThickness-1, 270, Round(360/100*percent))
}
if (Text!="") {
Options := Trim("x0 y0 w" this.W " h" this.W " Center Vcenter r" this.TextRendering " s" this.TextSize " c" this.TextColor A_Space this.TextStyle)
Gdip_TextToGraphics(this.G, Text, Options, this.TextFont, this.BarDiameter, this.BarDiameter)
}
UpdateLayeredWindow(this.hwnd, this.hdc, this.X, this.Y, this.W, this.W)
}
Clear() { ; Just clears the graphics and updates layered window. Doesn't destroy object nor clear resources.
Gdip_GraphicsClear(this.G)
UpdateLayeredWindow(this.hwnd, this.hdc, this.X, this.Y, this.W, this.W)
}
__Delete() {
Gdip_DeletePen(this.pPen)
if (this.BackgroundColor > 0) {
Gdip_DeleteBrush(this.pBrush)
}
Gdip_DeleteGraphics(this.G)
SelectObject(this.hdc, this.obm)
DeleteObject(this.hbm)
DeleteDC(this.hdc)
if (this.pToken != "") { ; GDI+ was obviously automatically started up in __New(), and therefore shut it down automatically now
Gdip_Shutdown(this.pToken)
}
hwnd := this.hwnd
Gui %hwnd%: Destroy
}
}
CircleProgressCCleaner := new CircleProgressClass({y: 300, BackgroundColor: "ffeeeeee", BarColor: "ffaaaaaa", BarThickness: 10})
CircleProgressFirefox := new CircleProgressClass({y: 500, BackgroundColor: "ff000000", BarColor: "ffffc018", TextColor: "ffffc018", TextStyle: "Bold", BarThickness: 40, BarDiameter: 100})
Loop, 200 {
if (A_Index < 101)
CircleProgressCCleaner.Update(A_Index, "Downloading`nCCleaner`n`n" A_Index "% done")
CircleProgressFirefox.Update(A_Index/2, "Downloading`nFirefox`n`n" Round(A_Index/2) "% done")
Sleep, 50
}
return
CircleProgress := new CircleProgressClass()
Loop, 100 {
CircleProgress.Update(A_Index, "Downloading`nAutoHotkey.exe`n`n" A_Index "% done")
Sleep, 50
}
return
@fischgeek
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment