;~ AutoIt Version: 3.3.14.5
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <GDIPlus.au3>
Global Const $BACK_COLOR_RGB = 0x1E1F21
;~ Global Const $BACK_COLOR_ARGB = BitOR($BACK_COLOR_RGB, 0xFF000000)
Global Const $FORE_COLOR_RGB = 0xFFFFFF
Global Const $FORE_COLOR_ARGB = BitOR($FORE_COLOR_RGB, 0xFF000000)
Global Const $MAX_HOUR = 99
Global Const $TICK_SEC = 1000
Global Const $TICK_MIN = $TICK_SEC * 60
Global Const $TICK_HOUR = $TICK_MIN * 60
Global Enum $SW_ID, $SW_IDHOUR, $SW_IDMSEC, $SW_TIMER, $SW_HOUR, $SW_MIN, $SW_SEC, $SW_MSEC, $SW_TICKS, $SW_MAX
Global $g_idStart, $g_idPause, $g_aSW[$SW_MAX]
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
GUICreate("STOPWATCH", 500, 500, -1, -1, -1, BitOR($WS_EX_WINDOWEDGE, $WS_EX_COMPOSITED))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetBkColor($BACK_COLOR_RGB)
GUISetFont(16, Default, Default, "Courier New")
$g_aSW[$SW_ID] = GUICtrlCreateLabel("0:00", 60, 200, 380, 120, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, $FORE_COLOR_RGB)
GUICtrlSetFont(-1, 100)
$g_aSW[$SW_IDHOUR] = GUICtrlCreateLabel("", 120, 320, 40, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, $FORE_COLOR_RGB)
$g_aSW[$SW_IDMSEC] = GUICtrlCreateLabel("000", 360, 320, 40, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, $FORE_COLOR_RGB)
$g_idStart = GUICtrlCreateButton("START", 145, 350, 100, 50)
GUICtrlSetCursor(-1, 0)
GUICtrlSetBkColor(-1, $BACK_COLOR_RGB)
GUICtrlSetColor(-1, $FORE_COLOR_RGB)
GUICtrlSetOnEvent(-1, "_Start")
$g_idPause = GUICtrlCreateButton("PAUSE", 255, 350, 100, 50)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetCursor(-1, 0)
GUICtrlSetBkColor(-1, $BACK_COLOR_RGB)
GUICtrlSetColor(-1, $FORE_COLOR_RGB)
GUICtrlSetOnEvent(-1, "_Pause")
GUICtrlCreateButton("RESET", 200, 410, 100, 50)
GUICtrlSetCursor(-1, 0)
GUICtrlSetBkColor(-1, $BACK_COLOR_RGB)
GUICtrlSetColor(-1, $FORE_COLOR_RGB)
GUICtrlSetOnEvent(-1, "_Reset")
GUICtrlCreateButton("+1M", 10, 440, 70, 50)
GUICtrlSetCursor(-1, 0)
GUICtrlSetBkColor(-1, $BACK_COLOR_RGB)
GUICtrlSetColor(-1, $FORE_COLOR_RGB)
GUICtrlSetOnEvent(-1, "_Add")
GUICtrlCreateButton("+10M", 420, 440, 70, 50)
GUICtrlSetCursor(-1, 0)
GUICtrlSetBkColor(-1, $BACK_COLOR_RGB)
GUICtrlSetColor(-1, $FORE_COLOR_RGB)
GUICtrlSetOnEvent(-1, "_Add10")
GUICtrlCreatePic("", 10, 10, 480, 480)
GUICtrlSetState(-1, $GUI_DISABLE)
_GUICtrlPic_DrawEllipse(-1, 480, 480, 0, $FORE_COLOR_ARGB, 4)
GUISetState()
While Sleep(10)
WEnd
Func _Start()
GUICtrlSetState($g_idStart, $GUI_DISABLE)
GUICtrlSetState($g_idPause, $GUI_ENABLE)
$g_aSW[$SW_TIMER] = TimerInit()
AdlibRegister("_Stopwatch", 10)
EndFunc ;==>_Start
Func _Pause()
AdlibUnRegister("_Stopwatch")
$g_aSW[$SW_TIMER] = 0
$g_aSW[$SW_TICKS] = $g_aSW[$SW_HOUR] * $TICK_HOUR + $g_aSW[$SW_MIN] * $TICK_MIN + $g_aSW[$SW_SEC] * $TICK_SEC + $g_aSW[$SW_MSEC]
GUICtrlSetState($g_idStart, $GUI_ENABLE)
GUICtrlSetState($g_idPause, $GUI_DISABLE)
EndFunc ;==>_Pause
Func _Reset()
_Pause()
$g_aSW[$SW_TICKS] = 0
_Stopwatch()
EndFunc ;==>_Reset
Func _Add()
$g_aSW[$SW_TICKS] += $TICK_MIN
_Stopwatch()
EndFunc ;==>_Add
Func _Add10()
$g_aSW[$SW_TICKS] += $TICK_MIN * 10
_Stopwatch()
EndFunc ;==>_Add10
Func _Stopwatch()
Local $iTicks, $iHour, $iMin, $iSec
$iTicks = ($g_aSW[$SW_TIMER] ? Int(TimerDiff($g_aSW[$SW_TIMER])) : 0) + $g_aSW[$SW_TICKS]
$iHour = Int($iTicks / $TICK_HOUR)
$iTicks = Mod($iTicks, $TICK_HOUR)
$iMin = Int($iTicks / $TICK_MIN)
$iTicks = Mod($iTicks, $TICK_MIN)
$iSec = Int($iTicks / $TICK_SEC)
$g_aSW[$SW_MSEC] = Mod($iTicks, $TICK_SEC)
If $g_aSW[$SW_SEC] <> $iSec Or $g_aSW[$SW_MIN] <> $iMin Then
$g_aSW[$SW_MIN] = $iMin
$g_aSW[$SW_SEC] = $iSec
GUICtrlSetData($g_aSW[$SW_ID], StringFormat("%i:%02i", $g_aSW[$SW_MIN], $g_aSW[$SW_SEC]))
EndIf
If $g_aSW[$SW_HOUR] <> $iHour Then
$g_aSW[$SW_HOUR] = $iHour
If $g_aSW[$SW_HOUR] > $MAX_HOUR Then Return _Reset()
GUICtrlSetData($g_aSW[$SW_IDHOUR], $g_aSW[$SW_HOUR] ? StringFormat("%iH", $g_aSW[$SW_HOUR]) : "")
EndIf
GUICtrlSetData($g_aSW[$SW_IDMSEC], StringFormat("%03i", $g_aSW[$SW_MSEC]))
EndFunc ;==>_Stopwatch
Func _Exit()
Exit
EndFunc ;==>_Exit
Func _GUICtrlPic_DrawEllipse($idPic, $iWidth, $iHeight, $iBackColor, $iForeColor, $iPenWidth)
_GDIPlus_Startup()
Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetPixelOffsetMode($hGraphics, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
_GDIPlus_GraphicsClear($hGraphics, $iBackColor)
Local $hPen = _GDIPlus_PenCreate($iForeColor, $iPenWidth)
_GDIPlus_GraphicsDrawEllipse($hGraphics, $iPenWidth, $iPenWidth, $iWidth - $iPenWidth * 2, $iHeight - $iPenWidth * 2, $hPen)
Local $hXOR = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
Local $hPrevBitmap = GUICtrlSendMsg($idPic, $STM_SETIMAGE, 0, $hXOR)
If $hPrevBitmap Then _WinAPI_DeleteObject($hPrevBitmap)
_WinAPI_DeleteObject($hXOR)
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()
EndFunc ;==>_GUICtrlPic_DrawEllipse