#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here ;coded by UEZ build 2018-02-14 ;the Hilfiker / MobaTime Swiss Railway Clock ;the Hilfiker / MobaTime Swiss Railway Clock ;coded by UEZ build 2018-02-16 ;thanks to Eukalyptus for the _CreateBrushedAluminum() function! #pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico") #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so /pe /rm #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3" #AutoIt3Wrapper_UseX64=n #include #include #include #include _GDIPlus_Startup() Global $hGUI, $iFPS = 0, $iShowFPS = 0, $bExit Global Const $iW = 500, $iH = $iW, $sTitle = "GDI+ clock" ;~ Global Const $fRad = ACos(-1) / 180, $fDeg = 180 / ACos(-1), Global Const $iTimer = 30 Global $hDC, $hCanvas, $hBitmap_Clock, $fDiameter, $hDC_backbuffer AutoItSetOption("GUIOnEventMode", 1) GDIPlus_GoogleClock() AutoItSetOption("GUIOnEventMode", 0) _GDIPlus_Shutdown() Func GDIPlus_GoogleClock() $bExit = False $hGUI = GUICreate($sTitle, $iW, $iH, -1, -1, -1, $WS_EX_TOPMOST) GUISetBkColor(0xFF000000, $hGUI) GUISetState(@SW_SHOW, $hGUI) ;~ GUISetCursor(16, 1) ;create canvas elements $hDC = _WinAPI_GetDC($hGUI) Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Local Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) _GDIPlus_GraphicsSetSmoothingMode($hCanvas, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) $fDiameter = $iW $hBitmap_Clock = GenerateClockBg($fDiameter) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit_About") GUIRegisterMsg($WM_TIMER, "Draw") ;$WM_TIMER = 0x0113 DllCall("User32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $iTimer, "int", 0) Do If $bExit Then ExitLoop Until Not Sleep(100) ;release resources GUIRegisterMsg($WM_TIMER, "") GUIDelete($hGUI) EndFunc ;==>GDIPlus_GoogleClock Func Draw() _GDIPlus_GraphicsDrawImageRect($hCanvas, $hBitmap_Clock, 0, 0, $fDiameter, $fDiameter) UpdateClock($hCanvas, $fDiameter) ; aiguiile _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hDC_backbuffer, 0, 0, $SRCCOPY) EndFunc ;==>Draw Func _Exit_About() $bExit = True EndFunc ;==>_Exit_About Func UpdateClock($hGfx, $fDiameter) ;~ $Font_Color = "0xFF000000" ;~ $Back_Color = "0xFFFFFFFF" $Font_Color = "0xFFFFFFFF" $Back_Color = "0xFF000000" $Font = "Arial" $fRadius = $fDiameter / 2 $pourAffiMinute = 30 / 100 ; $pourAffiSeconde = 50 / 100 If $pourAffiSeconde > (80 / 100) Then $pourAffiSeconde = 80 / 100 ; EndIf $hDrawPen_Color = $Font_Color Local $hDrawPen = _GDIPlus_PenCreate($Back_Color, 1) Local $hBrush = _GDIPlus_BrushCreateSolid($Back_Color) ;~ _GDIPlus_GraphicsDrawEllipse($hGfx, 10, 10, $fDiameter - 20, $fDiameter - 20 , $hDrawPen) _GDIPlus_GraphicsFillEllipse($hGfx, 10, 10, $fDiameter - 20, $fDiameter - 20, $hBrush) _GDIPlus_BrushDispose($hBrush) $hBrush = _GDIPlus_BrushCreateSolid(StringReplace($hDrawPen_Color, "0x", "0xFF")) Local $iWidth1 = $fDiameter * 0.0026667, $iHeight1 = $fDiameter / 30, $iWidth12 = $iWidth1, _ $iWidth2 = $iWidth1, $iHeight2 = $fDiameter / 45, $iWidth22 = $iWidth2 ;~ $fPosY = $fDiameter * 0.083333, $fPosY = $fRadius * (0.855 - $pourAffiSeconde) $clockSec = @SEC $clockMin = @MIN _GDIPlus_GraphicsTranslateTransform($hGfx, $fRadius, $fRadius) _GDIPlus_GraphicsRotateTransform($hGfx, -6) _GDIPlus_GraphicsTranslateTransform($hGfx, -$fRadius, -$fRadius) ;~ trait secondes For $i = 0 To 59 _GDIPlus_GraphicsTranslateTransform($hGfx, $fRadius, $fRadius) _GDIPlus_GraphicsRotateTransform($hGfx, 6) _GDIPlus_GraphicsTranslateTransform($hGfx, -$fRadius, -$fRadius) $valSeconde = $clockSec + 15 - $i If $valSeconde < 0 Then $valSeconde += 60 ElseIf $valSeconde > 59 Then $valSeconde -= 60 EndIf Switch Mod($valSeconde, 5) Case 0 _GDIPlus_GraphicsFillRect($hGfx, $fRadius - $iWidth1, $fPosY, $iWidth1, $iHeight1, $hBrush) Case Else _GDIPlus_GraphicsFillRect($hGfx, $fRadius - $iWidth1, $fPosY, $iWidth2, $iHeight2, $hBrush) EndSwitch Next _GDIPlus_GraphicsResetTransform($hGfx) ;~ ;trait minutes $fPosY = $fRadius * (0.87 - $pourAffiMinute) _GDIPlus_GraphicsTranslateTransform($hGfx, $fRadius, $fRadius) _GDIPlus_GraphicsRotateTransform($hGfx, -6) _GDIPlus_GraphicsTranslateTransform($hGfx, -$fRadius, -$fRadius) For $i = 0 To 59 _GDIPlus_GraphicsTranslateTransform($hGfx, $fRadius, $fRadius) _GDIPlus_GraphicsRotateTransform($hGfx, 6) _GDIPlus_GraphicsTranslateTransform($hGfx, -$fRadius, -$fRadius) $valMinute = @MIN + 15 - $i If $valMinute < 0 Then $valMinute += 60 ElseIf $valMinute > 59 Then $valMinute -= 60 EndIf Switch Mod($valMinute, 5) Case 0 _GDIPlus_GraphicsFillRect($hGfx, $fRadius - $iWidth1, $fPosY, $iWidth1, $iHeight1, $hBrush) Case Else _GDIPlus_GraphicsFillRect($hGfx, $fRadius - $iWidth1, $fPosY, $iWidth2, $iHeight2, $hBrush) EndSwitch Next _GDIPlus_GraphicsResetTransform($hGfx) ;~ chiffres $Width = 100 $Height = 60 $Fontsize = 50 $FontStyle = 01 $xPos = ($fRadius - ($Width / 2)) $yPos = ($fRadius - ($Height / 2)) Local $Brush_FontColor = _GDIPlus_BrushCreateSolid($Font_Color) Local $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate($Font) $hFont = _GDIPlus_FontCreate($hFamily, $Fontsize, $FontStyle) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) Local $tLayout = _GDIPlus_RectFCreate($xPos, $yPos, $Width, $Height) _GDIPlus_GraphicsDrawStringEx($hGfx, StringFormat("%02s", @HOUR), $hFont, $tLayout, $hFormat, $Brush_FontColor) ;sone zoom Local $hPath1 = _GDIPlus_PathCreate() _GDIPlus_PathAddLine($hPath1, $fDiameter - ($fRadius * (0.855 - $pourAffiSeconde)), $fRadius + $Height * 0.5, $fRadius + $Width + 0, $fRadius + $Height * 0.5) _GDIPlus_PathAddArc($hPath1, ($fRadius + ($Width * 3 / 7)), $fRadius - $Height * 0.5, ($Height * 1.0), ($Height * 1.0), 90, 90) _GDIPlus_PathAddArc($hPath1, ($fRadius + ($Width * 3 / 7)), $fRadius - $Height * 0.5, ($Height * 1.0), ($Height * 1.0), 180, 90) _GDIPlus_PathAddLine($hPath1, $fRadius + $Width + 0, $fRadius - $Height * 0.5, $fDiameter - ($fRadius * (0.855 - $pourAffiSeconde)), $fRadius - $Height * 0.5) Local Const $hPen = _GDIPlus_PenCreate(StringReplace($hDrawPen_Color, "0x", "0xFF"), 2) _GDIPlus_GraphicsDrawPath($hGfx, $hPath1, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_PathDispose($hPath1) $Width = 30 $Height = 25 $Fontsize = 15 $FontStyle = 0 $xCenter = ($fRadius - ($Width / 2)) $yCenter = ($fRadius - ($Height / 2)) Local $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate($Font) $hFont = _GDIPlus_FontCreate($hFamily, $Fontsize, $FontStyle) $hFontShowMinute = _GDIPlus_FontCreate($hFamily, 20, 1) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) ;Chiffres des minutes For $i = 0 To 59 $valMinute = $clockMin + 15 - $i If $valMinute < 0 Then $valMinute += 60 ElseIf $valMinute > 59 Then $valMinute -= 60 EndIf $Text = StringFormat("%02s", $valMinute) If $i < 11 Or $i > 19 Then If Mod($valMinute, 5) = 0 Then $x = $xCenter - (Cos(_Radian((6 * $i) + 90)) * $fRadius * $pourAffiMinute) $y = $yCenter - (Sin(_Radian((6 * $i) + 90)) * $fRadius * $pourAffiMinute) Local $tLayout = _GDIPlus_RectFCreate($x, $y, $Width, $Height) _GDIPlus_GraphicsDrawStringEx($hGfx, $Text, $hFont, $tLayout, $hFormat, $Brush_FontColor) EndIf ElseIf $i = 15 Then ;~ position 15 $x = $xCenter + ($fRadius * ($pourAffiMinute - 3 / 100)) $y = $yCenter Local $tLayout = _GDIPlus_RectFCreate($x, $y, 40, 30) _GDIPlus_GraphicsDrawStringEx($hGfx, $Text, $hFontShowMinute, $tLayout, $hFormat, $Brush_FontColor) EndIf Next ;Chiffres des secondes For $i = 0 To 59 $valSeconde = $clockSec + 15 - $i If $valSeconde < 0 Then $valSeconde += 60 ElseIf $valSeconde > 59 Then $valSeconde -= 60 EndIf If Mod($valSeconde, 5) = 0 Then $x = $xCenter - (Cos(_Radian((6 * $i) + 90)) * $fRadius * ($pourAffiSeconde + 2 / 100)) $y = $yCenter - (Sin(_Radian((6 * $i) + 90)) * $fRadius * ($pourAffiSeconde + 2 / 100)) $Text = StringFormat("%02s", $valSeconde) Local $tLayout = _GDIPlus_RectFCreate($x, $y, $Width, $Height) _GDIPlus_GraphicsDrawStringEx($hGfx, $Text, $hFont, $tLayout, $hFormat, $Brush_FontColor) EndIf Next ;Release created objects _GDIPlus_PenDispose($hDrawPen) _GDIPlus_FontDispose($hFont) _GDIPlus_FontDispose($hFontShowMinute) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($Brush_FontColor) _GDIPlus_BrushDispose($hBrush) EndFunc ;==>UpdateClock Func GenerateClockBg($fDiameter) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($fDiameter, $fDiameter) Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGfx, 4) _GDIPlus_GraphicsSetPixelOffsetMode($hGfx, 4) _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 4) _GDIPlus_GraphicsClear($hGfx, 0xFF000000) _GDIPlus_GraphicsDispose($hGfx) Return $hBitmap EndFunc ;==>GenerateClockBg