Jump to content

Homer Simpson Clock


Lakes
 Share

Recommended Posts

Thanks to UZE for help with the Transparency and Sizing.

The advanced version uses 20% processor time , which is a bit high for a clock, but not excessive, maybe someone will improve the drawing routine. ;)

The shadow checkbox is greyed out because my frazzled brain could`nt work out a way to toggle them on and off while keeping the correct position, just comment them out in the drawing routine if you don`t want them.

The context menu is a bit buggy if the processor is under high load, but works fine under normal operation, you can use the trayicon menu instead.

Everything is included in the Zip file

http://www.box.com/s/akoaa0bz6pgyq348n822

.

;
Basic version of the clock
; No Sizing, Transparency or Menus
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #include <Misc.au3>
    #include <WinAPI.au3>
  
    Opt("GUIOnEventMode", 1)
$Size = 600
$Wid  = $Size
$Hgt  = $Size
$Lx  = 247
$Ly  = 240
$Rx  = 353
$Ry  = 240
$HoursX = $Size/2
$HoursY = $Size/2
$MinsX = $Size/2
$MinsY = $Size/2
Global Const $deg = ACos(-1) / 180
Global $secs, $Mins, $Hours, $Angle = 6, $RightMatrix, $eX, $eY
Global $StringX, $StringY
$secscale = 0.6 ;make secs pointer smaller or larger
    $hGUI = GUICreate("Work", $Wid, $Wid, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
;   GUICtrlSetCursor(-1, 2)
If @OSBuild < 7600 Then WinSetTrans($hGUI,"", 0xFF) ; only use this if solid background
    GUISetState(@SW_SHOW)
    GUISetOnEvent(-3, "close")
  
  ; ===========================================
    _GDIPlus_Startup()

#region Window BckBuffer
    $graphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics($Wid, $Hgt, $graphics)
    $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
#EndRegion
$hPen1 = _GDIPlus_PenCreate(0xFF800010, 4)  ;Pem for Lines
    $bitmap1 = _GDIPlus_BitmapCreateFromGraphics($Wid, $Hgt, $graphics)
    $backbuffer1 = _GDIPlus_ImageGetGraphicsContext($bitmap1)
    $Homer = _GDIPlus_ImageLoadFromFile("Homer No Pupils.png")

$Eye  = _GDIPlus_ImageLoadFromFile("Eye.png")
$EyeW   = _GDIPlus_ImageGetWidth($Eye)
$EyeH  = _GDIPlus_ImageGetHeight($Eye)
$eX  = $EyeW/2
$eY  = $EyeH/2
  consolewrite($eX)
    $LeftMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($LeftMatrix, $Lx, $Ly)
    $RightMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($RightMatrix, $Rx, $Ry)
$HoursPointer  = _GDIPlus_ImageLoadFromFile("Hours Pointer.png") ;"Hours Pointer1.png"
    $HoursMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($HoursMatrix, $HoursX, $HoursY)

$MinsPointer  = _GDIPlus_ImageLoadFromFile("Mins Pointer.png") ;"Mins Pointer1.png"
    $MinsMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($MinsMatrix, $MinsX, $MinsY)

    $secPointer  = _GDIPlus_ImageLoadFromFile("Secs Pointer.png")
$secMatrix = _GDIPlus_MatrixCreate()
Global $rot_mid_x = $size / 2        ; set rotation point
Global $rot_mid_y = $size / 2
_GDIPlus_MatrixTranslate($secMatrix, $rot_mid_x, $rot_mid_y)  ; move to rotation point
; * eyes and secs pointer have an offset because they are rotated in the original image *
_GDIPlus_MatrixRotate($RightMatrix, @SEC  * 6 + 90 + 12)    ;start eyes at current Seconds
_GDIPlus_MatrixRotate($LeftMatrix,  @SEC  * 6 + 90 + 12)
_GDIPlus_MatrixRotate($HoursMatrix, @HOUR * 30 - 6)    ;                 current Hours
_GDIPlus_MatrixRotate($MinsMatrix,  @MIN  * 6  - 6)    ;                 current Minutes
_GDIPlus_MatrixRotate($secMatrix,  @SEC  * 6 + 90 - 12)  ;start pointer at current Seconds

$fs = 20
$cX = $Wid/2
$cY = $Hgt/2 -10
$cX1 = $cX + 10
$Cy1 = $cY + 20
$Lx  = $Wid/2
$Ly  = $Hgt/2
$Lx1 = $Wid/2
$Ly1 = $Hgt/2
Global Const $radius = $Hgt * 0.85
Global Const $cR = $radius * 0.42, $cR1 = $cR * 1.1
Global Const $cR2 = $cR * 0.86, $cR3 = $cR * 0.96
Global Const $cR4 = $cR * 0.9
  ; ==========================================
    
Do
        _GDIPlus_GraphicsClear($backbuffer, 0x00FFFFFF)
        _GDIPlus_GraphicsDrawImageRect($backbuffer1, $Homer, 0, 0, $Wid, $Hgt)     ;Homer Static Image
if $secs <> @SEC then
  Rotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, $Angle)
  Rotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, $Angle)
  Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
  Rotate($MinsMatrix, $MinsPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
  Rotate($secMatrix, $secPointer, $secScale, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, $Angle)
  $Secs = @SEC
Else
  Rotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)    ;no rotation, but image updated
  Rotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)
  Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
  Rotate($MinsMatrix, $MinsPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)  
  Rotate($secMatrix, $secPointer, $secScale, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
EndIF

If $Mins <> @MIN then
;  Rotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)
;  Rotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)
;  Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)  
  Rotate($MinsMatrix, $MinsPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, $Angle)  
  Rotate($secMatrix, $secPointer, $secScale, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
   $Mins = @MIN  
EndIF

If $Hours <> @HOUR then
  Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, $Angle)  ; put it infront of secs pointer
  Rotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)    ;no rotation, but image updated
  Rotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)
  Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, $Angle)
  Rotate($MinsMatrix, $MinsPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)  
  Rotate($secMatrix, $secPointer, $secScale, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)  
  $Hours = @HOUR
EndIF

        _GDIPlus_GraphicsDrawImageRect($backbuffer1, $bitmap, 0, 0, $Wid, $Hgt)
  _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap1, 0, 0, $Wid, $Hgt)
        Sleep(100)
Until 0
Func Rotate($Matrix, $Pointer, $scale, $midX, $midY, $Wid, $Hgt, $nAngle)
  _GDIPlus_MatrixRotate($Matrix, $nAngle, False)            
  _GDIPlus_GraphicsSetTransform ($backbuffer, $Matrix)
  _GDIPlus_GraphicsDrawImageRect($backbuffer, $Pointer, -$midX *$scale, -$midY * $scale, $Wid * $scale, $Hgt * $scale)
EndFunc
    Func close()
        _GDIPlus_MatrixDispose($LeftMatrix)
        _GDIPlus_MatrixDispose($RightMatrix)  
        _GDIPlus_MatrixDispose($SecMatrix)
        _GDIPlus_MatrixDispose($MinsMatrix)
        _GDIPlus_MatrixDispose($HoursMatrix)
        _GDIPlus_GraphicsDispose($graphics)
  _GDIPlus_PenDispose($hPen1)
        _WinAPI_DeleteObject($bitmap)
  _WinAPI_DeleteObject($bitmap1)
        _GDIPlus_GraphicsDispose($backbuffer)
        _GDIPlus_GraphicsDispose($backbuffer1)
        _GDIPlus_Shutdown()
        Exit
    EndFunc ;==>close
  ;

Advanced version with more features.

#NoTrayIcon
#include <Date.au3>
#Include <Timers.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <String.au3>
#include <GuiMenu.au3>
#include <Misc.au3>
$dll = DllOpen("user32.dll")
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode",1)
Opt ("trayMenuMode",1)
Global $hGUI, $hGraphics, $hBackbuffer_Rot, $hFG_Bitmap_Rot, $hPen1, $hPen2, $hPen3, $hPen4
Global $iWidth = 600, $iHeight = $iWidth, $iW = $iWidth, $iH = $iHeight
Global Const $minSize = $iWidth * 0.25
Global Const $maxSize = $iWidth * 1.5
Global Const $deg = ACos(-1) / 180
Global Const $radius = $iHeight * 0.85
Global Const $cR = $radius * 0.42, $cR1 = $cR * 1.1
Global Const $cR2 = $cR * 0.86, $cR3 = $cR * 0.96
Global Const $cR4 = $cR * 0.9
Global Const $tms = $iHeight / 20, $tmh = $iHeight * 0.725
Global $x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4, $x5, $x6, $y5, $y6, $tm
Global $ScreenDc, $dc, $tSize, $pSize, $tSource, $pSource, $tBlend, $pBlend, $tPoint, $pPoint, $gdibitmap
Global $Sec, $Min, $Hour
Global  $SliderGUI,$Trans, $Trans_Handle, $Size, $Size_Handle, $TransValue, $SizeValue
Global $T_Font, $T_Brush, $T_Format, $T_Family, $T_Layout, $T_String
Global $T_ShadowBrush, $T_ShadowFormat, $T_ShadowFamily, $T_ShadowFont, $T_hShadowFamily, $T_ShadowLayout
Global $T_Shadow_color, $T_tShadow, $T_Shadowtext ,$T_ShadowtLayout, $T_ShadowColor = 0xFFABA9BA
;
Global $Face, $ClockRing, $Homer, $EyeW, $EyeH, $LeftMatrix, $secscale, $scale, $FaceX, $FaceY, $Lx, $Ly
Global $Rx, $Ry, $HoursX, $HoursY, $MinsX, $MinsY, $LeftEye, $RightEye, $HoursPointer, $HoursMatrix
Global $shadHoursPointer, $shadHoursMatrix, $MinsPointer, $MinsMatrix, $shadMinsPointer, $shadMinsMatrix
Global $RightMatrix, $secPointer, $secMatrix, $rot_mid_x, $rot_mid_y, $secShadPointer, $secShadMatrix, $hMatrix
Global $Secs, $Mins, $Hours, $Eye, $eX, $eY, $Angle, $fs, $cX, $cY, $Cx1, $Cy1, $LineX, $LineY, $LineX1, $LineY1
Global $StringX, $StringY, $ElpsX, $ElpsY, $LnX, $LnY, $LnX1, $LnY1
Global $WinPos, $WinPosX, $WinPosY, $Alpha, $settingsDir, $PropGuiPos, $PropGuiX, $PropGuiY
Global $TransLabel, $sizeLabel, $BackCheck, $NumCheck, $DigiCheck, $RingCheck, $ShadCheck, $Check1
Global $BackGround, $ClockBackGround, $ClockTransBack, $exitItem, $PrefsItem, $Dfs
Global $Digitog = 1, $NumTog = 1
Global Enum $mProperties = 1000, $mHelp, $mExit
Global Const $WHEEL_DELTA = 120
$Angle = 6
;$Homer_scale = 0.5
;Ssize = 600
;$Lx  = $size * 0.41
;$Ly  = $size * 0.4
;$Rx  = $size * 0.59
Global $Lx  = 246
Global $Ly  = 239
Global $Rx  = 354
Global $Ry  = 239
Global $HoursX = $iWidth/2, $HoursY = $iHeight/2, $MinsX = $iWidth/2, $MinsY = $iHeight/2
Global $FaceX = $iWidth/2, $FaceY = $iHeight/2
Global $LineX  = $iWidth/2, $LineY  = $iHeight/2, $LineX1 = $iWidth/2, $LineY1 = $iHeight/2
Global $cX = $iWidth/2
Global $cY = $iHeight/2 -10
Global $cX1 = $cX + 10
Global $Cy1 = $cY + 20
$secscale = 0.6  ;make pointer smaller or larger
$Scale = 0.6
$fs = 20   ; Font Size
Global $title = "Homer Simpson Clock"
Opt("GUIOnEventMode", 1)
$settingsDir = @ScriptDir & "\clockSettings.ini"
If FileExists($settingsDir) Then
$WinPosX = IniRead($settingsDir, "Position",  "WinPosX",  "Error")
$WinPosY = IniRead($settingsDir, "Position",  "WinPosy",  "Error")
$iW   = IniRead($settingsDir, "Size",   "SizeW",  "Error")
$iH   = IniRead($settingsDir, "Size",   "SizeH",  "Error")
$Alpha   = IniRead($settingsDir, "Trans",   "Alpha",  "Error")
$PropGuiX = IniRead($settingsDir, "Properties", "PropGuiX", "Error")
$PropGuiY = IniRead($settingsDir, "Properties", "PropGuiY", "Error")
; ConsoleWrite("WinposX = " &$WinPosX &@CRLF &" WinPosY = " &$WinPosY &@CRLF &" SizeW = " &$iW &@CRLF &" SizeW = " &$iW &@CRLF &"Alpha = " &$Alpha &@CRLF)
Else
$WinPosX = -1
$WinPosY = -1
$iW   = 300
$Alpha  = 200
$PropGuiX  = 100
$PropGuiY  = 100
EndIf
; ====== Create Properties GUI but hide it =====================
$sliderGUI = GUICreate("Properties", 340, 145, $PropGuiX, $PropGuiY)
GUISetOnEvent($GUI_EVENT_CLOSE, "SliderGUIhide",$SliderGUI)
GUICtrlCreateLabel("Transparency",21, 8, 69, 17)    
$Trans = GUICtrlCreateSlider(10, 27, 210, 20)   
$Trans_Handle = GUICtrlGetHandle(-1)
GUICtrlSetLimit(-1, 255, 10)      ; change min/max value
GUICtrlSetData(-1, $Alpha)

GUICtrlCreateLabel("Size", 21, 86, 24, 17)
$Size = GUICtrlCreateSlider(10, 106, 210, 20)
$Size_Handle = GUICtrlGetHandle(-1)
GUICtrlSetLimit(-1, 100, 10)      ; change min/max value
GUICtrlSetData(-1, $iW/6)
$BackCheck  = GUICtrlCreateCheckbox("BackGround" ,240, 14, 79, 20)
$NumCheck  = GUICtrlCreateCheckbox("Clock Numbers", 240, 94, 95, 20)
$DigiCheck  = GUICtrlCreateCheckbox("Digital Clock" ,240, 68, 81, 20)
$RingCheck  = GUICtrlCreateCheckbox("Clock Ring" ,240, 40, 75, 20)
$ShadCheck  = GUICtrlCreateCheckbox("Shadows"  ,240, 120, 77, 17)
GUICtrlSetState($BackCheck, $GUI_CHECKED)
GUICtrlSetState($NumCheck,  $GUI_CHECKED)
GUICtrlSetState($DigiCheck, $GUI_CHECKED)
GUICtrlSetState($shadCheck, $GUI_DISABLE)
GUICtrlSetOnEvent($BackCheck,  "_BackCheck")
GUICtrlSetOnEvent($NumCheck,  "_NumCheck")
GUICtrlSetOnEvent($DigiCheck, "_DigiCheck")
GUICtrlSetOnEvent($RingCheck, "_RingCheck")
GUICtrlSetOnEvent($ShadCheck, "_ShadCheck")
GUISetState(@SW_HIDE, $SliderGUI)
GUIRegisterMsg($WM_HSCROLL, "WM_H_Slider")
;==========================================
TraySetIcon(@ScriptDir &"\HomerSharp.ico")
$prefsitem   = TrayCreateItem("Preferences")
TrayItemSetOnEvent(-1,"Properties")
$exititem  = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"_Exit")
;===========================================
; Initialize GDI+
_GDIPlus_Startup()
$hGUI = GUICreate($title, $iWidth, $iHeight, $WinPosX, $WinPosY, 0, $WS_EX_LAYERED + $WS_EX_TOPMOST)
;If @OSBuild < 7600 Then WinSetTrans($hGui,"", 0xFF)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") ;Adjust Trans
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
;GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hFG_Bitmap_Rot = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
$hBackbuffer_Rot = _GDIPlus_ImageGetGraphicsContext($hFG_Bitmap_Rot)
$hPen1 = _GDIPlus_PenCreate(0xFF800010, 4)  ;Pem for Lines
Global $hBG_Bitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBG_Bitmap)
#Region Init Matrix
$ClockBackGround  = _GDIPlus_ImageLoadFromFile("Clock BackGnd.png")
$ClockTransBack  = _GDIPlus_ImageLoadFromFile("Clock TransBack.png")
    $ClockRing  = _GDIPlus_ImageLoadFromFile("Clock Ring.png")
$Homer   = _GDIPlus_ImageLoadFromFile("Homer No Pupils.png")
$Face    = _GDIPlus_ImageLoadFromFile("Face.png")

Global $BackGround  = $Homer
$Eye  = _GDIPlus_ImageLoadFromFile("Eye.png")
$EyeW   = _GDIPlus_ImageGetWidth($Eye)
$EyeH  = _GDIPlus_ImageGetHeight($Eye)
$eX   = $EyeW/2
$eY   = $EyeH/2
    $LeftMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($LeftMatrix, $Lx, $Ly)
    $RightMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($RightMatrix, $Rx, $Ry)
$HoursPointer  = _GDIPlus_ImageLoadFromFile("Hours Pointer.png")
    $HoursMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($HoursMatrix, $HoursX, $HoursY)

    $shadHoursPointer   = _GDIPlus_ImageLoadFromFile("Hours Pointer Shadow.png")
$shadHoursMatrix   = _GDIPlus_MatrixCreate()
Global $shadHoursX  = $HoursX - 3       ; set rotation point
Global $shadHoursY   = $HoursY - 3
_GDIPlus_MatrixTranslate($shadHoursMatrix, $shadHoursX, $shadHoursY) ; move to rotation point

$MinsPointer  = _GDIPlus_ImageLoadFromFile("Mins Pointer.png")
    $MinsMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($MinsMatrix, $MinsX, $MinsY)
    $shadMinsPointer   = _GDIPlus_ImageLoadFromFile("Mins Shadow Pointer.png")
$shadMinsMatrix   = _GDIPlus_MatrixCreate()
Global $shadMinsX  = $MinsX - 4     ; set rotation point
Global $shadMinsY   = $MinsY - 4
_GDIPlus_MatrixTranslate($shadMinsMatrix, $shadMinsX, $shadMinsY)  ; move to rotation point
    $secPointer   = _GDIPlus_ImageLoadFromFile("Secs Pointer.png")
$secMatrix  = _GDIPlus_MatrixCreate()
Global $rot_mid_x  = $iWidth / 2         ; set rotation point
Global $rot_mid_y = $iHeight / 2
_GDIPlus_MatrixTranslate($secMatrix, $rot_mid_x, $rot_mid_y)   ; move to rotation point

    $secShadPointer = _GDIPlus_ImageLoadFromFile("Secs Pointer Shadow.png")
$secShadMatrix   = _GDIPlus_MatrixCreate()
Global $shad_rot_mid_x  = $iWidth / 2  - 5        ; set rotation point
Global $shad_rot_mid_y  = $iHeight / 2 - 5
_GDIPlus_MatrixTranslate($secShadMatrix , $shad_rot_mid_x, $shad_rot_mid_y)  ; move to rotation point
; * eyes and secs pointer have an offset because they are rotated in the original image *
;start eyes at current Seconds
_GDIPlus_MatrixRotate($RightMatrix, @SEC  * 6 + 90 + 24)  
_GDIPlus_MatrixRotate($LeftMatrix,  @SEC  * 6 + 90 + 24)
;current Hours
_GDIPlus_MatrixRotate($shadHoursMatrix, @HOUR * 30 + (@MIN / 2))
_GDIPlus_MatrixRotate($HoursMatrix, @HOUR * 30 + (@MIN / 2))  
;current Minutes
_GDIPlus_MatrixRotate($shadMinsMatrix,  @MIN * 6 + (@SEC / 10))
_GDIPlus_MatrixRotate($MinsMatrix,  @MIN * 6 + (@SEC / 10))  
;start pointer at current Seconds
_GDIPlus_MatrixRotate($secShadMatrix,  @SEC  * 6 + 90 - 12)
_GDIPlus_MatrixRotate($secMatrix,  @SEC  * 6 + 90 - 12) 
#endregion
; _WinAPI_UpdateLayeredWindow parameters
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", $iWidth)
DllStructSetData($tSize, "Y", $iHeight)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
;Global $alpha = 200
Global $alpha_steps = 5
Global $size_steps = 10
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $alpha)
DllStructSetData($tBlend, "Format", 1)
GuiSetState()
GUIRegisterMsg($WM_NCHITTEST,   "WM_NCHITTEST") ;Drag Window
GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") ;Adjust Trans
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
$ScreenDc = _WinAPI_GetDC($hGUI)
$gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hFG_Bitmap_Rot)
$dc = _WinAPI_CreateCompatibleDC($ScreenDc)
_WinAPI_SelectObject($dc, $gdibitmap)
; Using antialiasing
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer_Rot, 2)
;DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hBackbuffer_Rot, "int", 3)
Global $font = "Comic Sans MS"
; ================ Digital Time Fontinit =======================
$Dfs = 32
  $T_Font = "Verdana"
  $T_Brush = _GDIPlus_BrushCreateSolid(0xFF008080)
  $T_Format = _GDIPlus_StringFormatCreate()
  $T_Family = _GDIPlus_FontFamilyCreate($T_Font)
  $T_Font   = _GDIPlus_FontCreate ($T_Family, $Dfs, 3)
  $T_Layout = _GDIPlus_RectFCreate(0, 0, $iWidth, $Dfs * 2)
;shadow
;$T_Fontoffset = 5
$T_ShadowBrush = _GDIPlus_BrushCreateSolid($T_ShadowColor)
$T_ShadowFormat = _GDIPlus_StringFormatCreate()
$T_ShadowFamily = _GDIPlus_FontFamilyCreate("Verdana")
$T_ShadowFont = _GDIPlus_FontCreate($T_ShadowFamily, $Dfs, 3)
$T_ShadowLayout = _GDIPlus_RectFCreate(0, 0, $iWidth, $Dfs * 2)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
AdlibRegister("Ticker", 50)
Global $timer = 100
GUIRegisterMsg($WM_TIMER, "Draw") ;$WM_TIMER = 0x0113
DllCall("User32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $timer, "int", 0)
While Sleep(100000000)
WEnd
Func Draw()
     _GDIPlus_GraphicsClear($hBackbuffer, 0x00000000)
     _GDIPlus_GraphicsClear($hBackbuffer_Rot, 0x00000000)

_GDIPlus_GraphicsDrawImage($hBackbuffer, $BackGround, 0, 0)
;   ============== Analog Clock =============  
HomerTime()
;   ============== Digital Time =============
If $DigiTog = 1 then DrawDigital()
; ============== Draw Clock Face Numbers =======
If $NumTog = 1 then DrawNumbers()
; ============== Pointer Continous Rotation ==========
;Pointer_Test()
;=======================================================

;   =========  Update layered Window  ============================
; creates an empty bitmap with the new size, This bitmap will be used for the transparent GUI.
    Local $hBmp = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int",  0x0026200A, "ptr", 0, "int*", 0)
    $hBmp = $hBmp[6]
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBmp)
    _GDIPlus_GraphicsDrawImageRect($hContext, $hBG_Bitmap, 0, 0, $iW, $iH)
    _GDIPlus_GraphicsDrawImageRect($hContext, $hFG_Bitmap_Rot, 0, 0, $iW, $iH)
    $gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
    _WinAPI_SelectObject($dc, $gdibitmap)
    DllStructSetData($tSize, "X", $iW)
    DllStructSetData($tSize, "Y", $iH)
; ConsoleWrite($iW &@CRLF)
    _WinAPI_UpdateLayeredWindow($hGUI, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 2)
    _WinAPI_DeleteObject($gdibitmap)
    _WinAPI_RedrawWindow($hGUI)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BitmapDispose($hBmp)
EndFunc
;=================================================================
;================ Draw Clock Face Numbers =========================
Func DrawNumbers()
    For $i = 0 To 11
  $StringX = -$fs / 2 + $cX + Cos(-45 + $i * 29.7 * $deg)  * $cR
  $StringY = -$fs / 2 + $cY + Sin(-45 + $i * 29.7 * $deg)  * $cR
  $ElpsX = -$fs / 2 + $cX + Cos($i * 29.7 * $deg)  * $cR1
  $ElpsY = -$fs / 2 + $cY + Sin($i * 29.7 * $deg)  * $cR1
;    _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $ElpsX + 8 , $ElpsY + 8 , 8, 8,  $hPen1)
        _GDIPlus_GraphicsDrawString($hBackbuffer, $i + 1, $StringX, $StringY, "Comic Sans MS", $fs)
#cs
  $LnX = -$fs / 2 + $cX1 + Cos(-45 + $i * 29.7 * $deg) * $cR2
  $LnY = -$fs / 2 + $cY1 + Sin(-45 + $i * 29.7 * $deg) * $cR2
  $LnX1 = -$fs / 2 + $cX1 + Cos(-45 + $i * 29.7 * $deg) * $cR3
  $LnY1 = -$fs / 2 + $cY1 + Sin(-45 + $i * 29.7 * $deg) * $cR3
     _GDIPlus_GraphicsDrawLine($hBackbuffer, $LnX, $LnY,  $LnX1, $LnY1,  $hPen1)
#ce
    Next
#cs
For $i = 0 to 60
  $LnX = -$fs / 2 + $cX1 + Cos(-40 + $i * 6 * $deg) * $cR2
  $LnY = -$fs / 2 + $cY1 + Sin(-40 + $i * 6 * $deg) * $cR2
  $LnX1 = -$fs / 2 + $cX1 + Cos(-40 + $i * 6 * $deg) * $cR3
  $LnY1 = -$fs / 2 + $cY1 + Sin(-40 + $i * 6  * $deg) * $cR3
     _GDIPlus_GraphicsDrawLine($hBackbuffer, $LnX, $LnY,  $LnX1, $LnY1,  $hPen1)
Next
#ce
    _GDIPlus_GraphicsDrawLine($hBackbuffer, $LineX - $cR4, $LineY,  $LineX1 - $cR4 + 35, $LineY1,  $hPen1)  ;Left line
_GDIPlus_GraphicsDrawLine($hBackbuffer, $LineX + $cR4, $LineY,  $LineX1 + $cR4 - 35, $LineY1,  $hPen1) ;Right Line
    _GDIPlus_GraphicsDrawLine($hBackbuffer, $LineX, $LineY - $cR4,  $LineX1, $LineY1 - $cR4 + 35,  $hPen1) ;Top Line
_GDIPlus_GraphicsDrawLine($hBackbuffer, $LineX, $LineY + $cR4,  $LineX1, $LineY1 + $cR4 - 35,  $hPen1) ;Bottom Line
EndFunc
; ================== Draw the digital time =============================
Func DrawDigital()
  Local $sString, $aSize, $S_Size, $FontOffset = 3, $FxOffset = 0.77, $FyOffSet = 350
  ;   WinSetTitle($hGui, "", $title & @HOUR & ":" & @MIN & ":" & @SEC)
  $sString = StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC)
;ShadowTime
   $S_Size   = _GDIPlus_GraphicsMeasureString($hBackbuffer, $sString, $T_Font, $T_Layout, $T_Format)
  DllStructSetData($T_ShadowLayout, "X", (DllStructGetData($S_Size[0], "Width")* $FxOffset + $FontOffset))    
  DllStructSetData($T_ShadowLayout, "Y", (DllStructGetData($S_Size[0], "Height")+ $FyOffSet + $FontOffset)) 
  _GDIPlus_GraphicsDrawStringEx($hBackbuffer, $sString, $T_ShadowFont, $T_ShadowLayout, $T_ShadowFormat, $T_ShadowBrush)
;Time
  $aSize   = _GDIPlus_GraphicsMeasureString($hBackbuffer, $sString, $T_Font, $T_Layout, $T_Format)
  DllStructSetData($T_Layout, "X", (DllStructGetData($aSize[0], "Width")* $FxOffset))      ; Middle of Window
  DllStructSetData($T_Layout, "Y", (DllStructGetData($aSize[0], "Height")+ $FyOffSet ))   ; Clock at Top
_GDIPlus_GraphicsDrawStringEx($hBackbuffer, $sString, $T_Font, $T_Layout, $T_Format, $T_Brush)
EndFunc
;============== Draw Homer Clock =====================
Func HomerTime()
  if $secs <> @SEC then
  Rotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, $Angle)
  Rotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, $Angle)
  ;Hours
  Rotate($shadHoursMatrix, $shadHoursPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, ($Angle/60)/12)
  Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, ($Angle/60)/12)
  ;Mins
  Rotate($shadMinsMatrix, $shadMinsPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, $Angle/60)  
  Rotate($MinsMatrix, $MinsPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, $Angle/60)
  ;Secs
  Rotate($secShadMatrix, $secShadPointer, $secScale, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, $Angle)
  Rotate($secMatrix, $secPointer, $secScale, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, $Angle)
  $Secs = @SEC
Else
  NoRotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)      ;no rotation, but image updated
  NoRotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)      ;This is to stop the image flashing
  ;Hours
  NoRotate($shadHoursMatrix, $shadHoursPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 0)
  NoRotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 0)
  ;Mins
  NoRotate($shadMinsMatrix, $shadMinsPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 0)
  Rotate($MinsMatrix, $MinsPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 0)
  ;Secs
  NoRotate($secShadMatrix, $secShadPointer, $secScale, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 0)
  NoRotate($secMatrix, $secPointer, $secScale, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 0)
EndIF
EndFunc
;==================================================
Func Rotate($Matrix, $Pointer, $scale, $midX, $midY, $iWidth, $iHeight, $nAngle)
  _GDIPlus_MatrixRotate($Matrix, $nAngle, False)            
  _GDIPlus_GraphicsSetTransform ($hbackbuffer_Rot, $Matrix)
  _GDIPlus_GraphicsDrawImageRect($hbackbuffer_Rot, $Pointer, -$midX *$scale, -$midY * $scale, $iWidth * $scale, $iHeight * $scale)  
EndFunc
Func NoRotate($Matrix, $Pointer, $scale, $midX, $midY, $iWidth, $iHeight, $nAngle)
  _GDIPlus_GraphicsSetTransform ($hbackbuffer_Rot, $Matrix)
  _GDIPlus_GraphicsDrawImageRect($hbackbuffer_Rot, $Pointer, -$midX *$scale, -$midY * $scale, $iWidth * $scale, $iHeight * $scale)
EndFunc

;Continuous Rotation of all Clock Pointers
Func Pointer_test()
  Rotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, 2)
  Rotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, 2)
  Rotate($shadHoursMatrix, $shadHoursPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 0.1)
  Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 0.1)
  Rotate($shadMinsMatrix, $shadMinsPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 0.4)
  Rotate($MinsMatrix, $MinsPointer, 1, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 0.4)
  Rotate($secShadMatrix, $secShadPointer, $secScale, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 2)  
  Rotate($secMatrix, $secPointer, $secScale, $rot_mid_x, $rot_mid_y, $iWidth, $iHeight, 2)
EndFunc
; ============= Handle the WM_NCHITTEST message  ===============
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
Local $hMenu, $Win, $WinX, $WinY, $mX, $mY
if $hWnD = $hGUI and _IsPressed (01) then Return $HTCAPTION
if $hWnd = $hGUI and _IsPressed (02) then
; ConsoleWrite($GUI &" HIT!! "&@CRLF)
$hMenu = _GUICtrlMenu_CreatePopup ()
_GUICtrlMenu_InsertMenuItem ($hMenu, 0, "Properties", $mProperties)
_GUICtrlMenu_InsertMenuItem ($hMenu, 1, "Help", $mHelp)
_GUICtrlMenu_InsertMenuItem ($hMenu, 3, "", 0)
_GUICtrlMenu_InsertMenuItem ($hMenu, 3, "Exit", $mExit)
_GUICtrlMenu_TrackPopupMenu ($hMenu, $hGUI, -1,-1 ,1,0 )
_GUICtrlMenu_DestroyMenu ($hMenu)
Return True
endif
EndFunc
;==================================================================
; =========  Handle WM_COMMAND messages for Context Menu=======================
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Switch $iwParam
  Case $mProperties
   Properties()
  Case $mHelp
  SplashTextOn("Help", "Size = Cntrl & Mouse Wheel" &@CRLF &"Alpha = Alt + Mouse Wheel" &@CRLF, 250, 60, 100, 300, 32, "", 10)
  Sleep(3000)
  SplashOff()
   Case $mExit
_Exit()
EndSwitch
EndFunc   ;==>WM_COMMAND
;=============================================================
Func Properties()
   GUISetState(@SW_SHOW, $SliderGUI)
EndFunc
Func SliderGUIhide()
GUISetState(@SW_HIDE, $SliderGUI)
EndFunc
; ============ Read CheckBoxes ==============
Func _BackCheck()
$Check1 = GUICtrlRead($BackCheck)
If $Check1 = $GUI_CHECKED Then
  $BackGround = $Homer
  GUICtrlSetState($RingCheck, $GUI_UNCHECKED)
ElseIf $Check1 = $GUI_UNCHECKED Then
  $BackGround = $ClockTransBack
EndIf
EndFunc
Func _RingCheck()
$Check1 = GUICtrlRead($RingCheck)
If $Check1 = $GUI_CHECKED Then
  $BackGround = $Homer
  GUICtrlSetState($BackCheck, $GUI_UNCHECKED)  
ElseIf $Check1 = $GUI_UNCHECKED Then
  $BackGround = $Face
EndIf
EndFunc
Func _NumCheck()
$Check1 = GUICtrlRead($NumCheck)
If $Check1 = $GUI_CHECKED Then
   $NumTog = 1
  Else
   $NumTog = 0
Endif
EndFunc
Func _DigiCheck()
$Check1 = GUICtrlRead($DigiCheck)
If $Check1 = $GUI_CHECKED Then
   $DigiTog = 1
  Else
   $DigiTog = 0
Endif
EndFunc
Func _ShadCheck()
;not used at this time
EndFunc
; ===========================================
; ============ React to slider movement ========================
Func WM_H_Slider($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    If $lParam = $Trans_Handle Then
        $Alpha = GUICtrlRead($Trans)
        DllStructSetData($tBlend, "Alpha", $Alpha)       ; Set Alpha (Transparency) Level
        DllStructSetData($tBlend, "Format", 1)
        ToolTip($TransValue)
    EndIf
    If $lParam = $Size_Handle Then
        $SizeValue = GUICtrlRead($Size)
        $iW = $iWidth * $SizeValue * 0.01
        $iH = $iHeight * $SizeValue * 0.01
    EndIf
Return "GUI_RUNDEFMSG"
EndFunc
;===============================================================
; MouseWheel for Win Trans
Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam)
  Local $mouseData, $n1
      $mouseData = _WinAPI_HiWord($wParam) ;/ $WHEEL_DELTA  ;= 1 or -1
Select
;WM_MOUSEWHEEL = 0x020A
Case WinActive($hGUI)
  If $mouseData > 0  Then     ; Scroll Up
  
   If $iW + $size_steps <= 600 and _Ispressed(12) then
    $iW += $size_steps  ;wheel and ALT key  ;Set Clock Size
    $iH += $size_steps  
   EndIF
   If $alpha + $alpha_steps <= 255 and _IsPressed(11) Then ;wheel and CTRL key
    $alpha += $alpha_steps
    DllStructSetData($tBlend, "Alpha", $alpha)        ; Set Alpha (Transparency) Level
    DllStructSetData($tBlend, "Format", 1)
   EndIF
  Else ;wheel down
  
  If $iW + $size_steps > 0  and _Ispressed(12) then
   $iW -= $size_steps  ;wheel and ALT key
   $iH -= $size_steps  
  EndIF

   If $alpha - $alpha_steps > 0 and _IsPressed(11) Then
    $alpha -= $alpha_steps
    DllStructSetData($tBlend, "Alpha", $alpha)        ; Set Alpha (Transparency) Level
    DllStructSetData($tBlend, "Format", 1)
   Endif
  EndIf
   ConsoleWrite($alpha & @CRLF)
EndSelect
EndFunc ;==>WM_MOUSEWHEEL
Func Ticker()
    $sec = @SEC * 6 - 90
    $min = @MIN * 6 + (@SEC * 0.10) - 90
    $Hour = @HOUR * 30 + (@MIN * 0.50) - 90
EndFunc
Func _SaveSettings()
$WinPos = WinGetPos($title)
$WinPosX  = $WinPos[0]
$WinPosY  = $WinPos[1]
$PropGuiPos  = WingetPos("Properties")
$PropGuiX  = $PropGuiPos[0]
$PropGuiY  = $PropGuiPos[1]
IniWrite($settingsDir, "Position",  "WinPosX" ,$WinPosX)
IniWrite($settingsDir, "Position",  "WinPosy" ,$WinPosY)
IniWrite($settingsDir, "Size",   "SizeW"  ,$iW)
IniWrite($settingsDir, "Size",   "SizeH"  ,$iH)
IniWrite($settingsDir, "Trans",  "Alpha"  ,$Alpha)
IniWrite($settingsDir, "Properties", "PropGuiX" ,$PropGuiX)
IniWrite($settingsDir, "Properties", "PropGuiY" ,$PropGuiY)
EndFunc
Func _Exit()
_SaveSettings()
    AdlibUnRegister("Ticker")
    GUIRegisterMsg($WM_TIMER, "")
    GUIRegisterMsg($WM_GETMINMAXINFO, "")
    GUIRegisterMsg($WM_SIZE, "")
    GUIRegisterMsg($WM_ERASEBKGND, "")
    GUIRegisterMsg($WM_SIZING, "")
_WinAPI_DeleteDC($dc)
    _WinAPI_ReleaseDC($hGUI, $ScreenDc)

    ; Clean up GDI+ resources
    _GDIPlus_BitmapDispose($hFG_Bitmap_Rot)
    _GDIPlus_GraphicsDispose($hBackbuffer_Rot)
    _GDIPlus_GraphicsDispose($hGraphics)
  _GDIPlus_FontDispose    ($T_Font  )
  _GDIPlus_FontFamilyDispose  ($T_Family)
  _GDIPlus_StringFormatDispose($T_Format)
  _GDIPlus_BrushDispose ($T_Brush)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_MatrixDispose($shadHoursMatrix)
    _GDIPlus_MatrixDispose($shadMinsMatrix)
    _GDIPlus_MatrixDispose($secShadMatrix )
    _GDIPlus_BitmapDispose($hFG_Bitmap_Rot)
DllClose($dll)
GUIRegisterMsg($WM_COMMAND, "")
GUIRegisterMsg($WM_CONTEXTMENU, "")
    ; Uninitialize GDI+
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc
Enjoy! :) Edited by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Its should save settings on exit, see the for UEZ excellent examples. :)

I would edit the first post to correct his name, but the forum software deletes all the includes from the listings... ;)

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Nice work Lakes - I really like it :)

Good idea with the moving eyes...

Br,

UZE UEZ ;)

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Nice work Lakes - I really like it Posted Image

Good idea with the moving eyes...

Br,

UZE UEZ Posted Image

:)

You can buy an actual clock like that, thats where the idea came from. ;)

Edited by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Cool clock!

I just had to "fix" the eyes to follow the beer instead of rotation arbitrarily, cuz I'm a nut for geometry.

I un-rotate the eyes every time before I rotate them, so that I can rotate them to an absolute degree instead of a delta. There is probably a better way to do this, but I just did this quickly to see how it would come out.

Here's the code:

; Basic version of the clock
; No Sizing, Transparency or Menus

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <WinAPI.au3>

Opt("GUIOnEventMode", 1)
$Size = 600
$Wid  = $Size
$Hgt  = $Size

$Lx = 247
$Ly = 240

$Rx = 353
$Ry = 240

$HoursX = $Size/2
$HoursY = $Size/2
$MinsX = $Size/2
$MinsY = $Size/2

Global Const $deg = ACos(-1) / 180
Global $secs, $Mins, $Hours, $Angle = 6, $RightMatrix, $eX, $eY
Global $StringX, $StringY

Dim $LeftEyeRot[60]=[34, 41, 47, 53, 59, 64, 69, 73, 78, 82, 87, 91, 95, 99, 103, 107, 111, 115, 119, 123, 126, 130, 134, 138, 141, 145, 149, 153, 157, 161, 164, 168, 172, 176, 180, 184, 189, 193, 197, 202, 207, 211, 217, 222, 228, 234, 241, 248, 257, 266, 277, 289, 302, 317, 331, 345, 357, 8, 18, 26]
Dim $RightEyeRot[60]=[325, 333, 341, 351, 2, 14, 28, 42, 57, 70, 82, 93, 102, 111, 118, 125, 131, 137, 142, 148, 152, 157, 162, 166, 170, 175, 179, 183, 187, 191, 195, 198, 202, 206, 210, 214, 218, 221, 225, 229, 233, 236, 240, 244, 248, 252, 256, 260, 264, 268, 272, 277, 281, 286, 290, 295, 300, 306, 312, 318]

$secscale = 0.6 ;make secs pointer smaller or larger

$hGUI = GUICreate("Work", $Wid, $Wid, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
;GUICtrlSetCursor(-1, 2)
If @OSBuild < 7600 Then WinSetTrans($hGUI,"", 0xFF) ; only use this if solid background
GUISetState(@SW_SHOW)
GUISetOnEvent(-3, "close")

;===========================================
_GDIPlus_Startup()

#region Window BckBuffer
$graphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($Wid, $Hgt, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
#EndRegion

$hPen1 = _GDIPlus_PenCreate(0xFF800010, 4) ;Pem for Lines

$bitmap1 = _GDIPlus_BitmapCreateFromGraphics($Wid, $Hgt, $graphics)
$backbuffer1 = _GDIPlus_ImageGetGraphicsContext($bitmap1)
$Homer = _GDIPlus_ImageLoadFromFile("Homer No Pupils.png")

$Eye = _GDIPlus_ImageLoadFromFile("Eye.png")
$EyeW  = _GDIPlus_ImageGetWidth($Eye)
$EyeH = _GDIPlus_ImageGetHeight($Eye)
$eX = $EyeW/2
$eY = $EyeH/2

$LeftMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($LeftMatrix, $Lx, $Ly)
$RightMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($RightMatrix, $Rx, $Ry)

$HoursPointer  = _GDIPlus_ImageLoadFromFile("Hours Pointer.png") ;"Hours Pointer1.png"
$HoursMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($HoursMatrix, $HoursX, $HoursY)

$MinsPointer  = _GDIPlus_ImageLoadFromFile("Mins Pointer.png") ;"Mins Pointer1.png"
$MinsMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($MinsMatrix, $MinsX, $MinsY)

$secPointer = _GDIPlus_ImageLoadFromFile("Secs Pointer.png")
$secMatrix = _GDIPlus_MatrixCreate()
Global $rot_mid_x = $size / 2 ; set rotation point
Global $rot_mid_y = $size / 2
_GDIPlus_MatrixTranslate($secMatrix, $rot_mid_x, $rot_mid_y)  ; move to rotation point

; * eyes and secs pointer have an offset because they are rotated in the original image *
$secs=@Sec
_GDIPlus_MatrixRotate($RightMatrix, $RightEyeRot[$Secs] + 90 + 12) ;start eyes at current Seconds
_GDIPlus_MatrixRotate($LeftMatrix,  $LeftEyeRot[$Secs] + 90 + 12)
_GDIPlus_MatrixRotate($HoursMatrix, @HOUR * 30 - 6)  ;               current Hours  
_GDIPlus_MatrixRotate($MinsMatrix,  @MIN  * 6  - 6)  ;               current Minutes
_GDIPlus_MatrixRotate($secMatrix,  @SEC  * 6 + 90 - 12)  ;start pointer at current Seconds


$fs = 20
$cX = $Wid/2
$cY = $Hgt/2 -10
$cX1 = $cX + 10
$Cy1 = $cY + 20

$Lx  = $Wid/2
$Ly  = $Hgt/2
$Lx1 = $Wid/2
$Ly1 = $Hgt/2

Global Const $radius = $Hgt * 0.85
Global Const $cR = $radius * 0.42, $cR1 = $cR * 1.1
Global Const $cR2 = $cR * 0.86, $cR3 = $cR * 0.96
Global Const $cR4 = $cR * 0.9
  ; ==========================================

Do
_GDIPlus_GraphicsClear($backbuffer, 0x00FFFFFF)
_GDIPlus_GraphicsDrawImageRect($backbuffer1, $Homer, 0, 0, $Wid, $Hgt) ;Homer Static Image

if $secs <> @SEC then
;Reverse previous rotation
Rotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, -1 * $LeftEyeRot[$secs])
Rotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, -1 * $RightEyeRot[$secs])

;Do current rotation
$Secs = @SEC
Rotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, $LeftEyeRot[$secs])
Rotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, $RightEyeRot[$secs])
Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
Rotate($MinsMatrix, $MinsPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
Rotate($secMatrix, $secPointer, $secScale, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, $Angle)
Else
Rotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0) ;no rotation, but image updated
Rotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)
Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
Rotate($MinsMatrix, $MinsPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
Rotate($secMatrix, $secPointer, $secScale, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
EndIF

If $Mins <> @MIN then
; Rotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)
; Rotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)
; Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
Rotate($MinsMatrix, $MinsPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, $Angle)
Rotate($secMatrix, $secPointer, $secScale, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
$Mins = @MIN
EndIF

If $Hours <> @HOUR then
Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, $Angle)  ; put it infront of secs pointer
Rotate($LeftMatrix,  $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0) ;no rotation, but image updated
Rotate($RightMatrix, $Eye, 1, $eX, $eY, $EyeW, $EyeH, 0)
Rotate($HoursMatrix, $HoursPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, $Angle)
Rotate($MinsMatrix, $MinsPointer, 1, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
Rotate($secMatrix, $secPointer, $secScale, $rot_mid_x, $rot_mid_y, $Wid, $Hgt, 0)
$Hours = @HOUR
EndIF

_GDIPlus_GraphicsDrawImageRect($backbuffer1, $bitmap, 0, 0, $Wid, $Hgt)
_GDIPlus_GraphicsDrawImageRect($graphics, $bitmap1, 0, 0, $Wid, $Hgt)
Sleep(100)
Until 0

Func Rotate($Matrix, $Pointer, $scale, $midX, $midY, $Wid, $Hgt, $nAngle)
_GDIPlus_MatrixRotate($Matrix, $nAngle, False)
_GDIPlus_GraphicsSetTransform ($backbuffer, $Matrix)
_GDIPlus_GraphicsDrawImageRect($backbuffer, $Pointer, -$midX *$scale, -$midY * $scale, $Wid * $scale, $Hgt * $scale)
EndFunc

Func close()
_GDIPlus_MatrixDispose($LeftMatrix)
_GDIPlus_MatrixDispose($RightMatrix)
_GDIPlus_MatrixDispose($SecMatrix)
_GDIPlus_MatrixDispose($MinsMatrix)
_GDIPlus_MatrixDispose($HoursMatrix)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_PenDispose($hPen1)
_WinAPI_DeleteObject($bitmap)
_WinAPI_DeleteObject($bitmap1)
_GDIPlus_GraphicsDispose($backbuffer)
_GDIPlus_GraphicsDispose($backbuffer1)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>close
;

And only if you're morbidly curious, here is the code I wrote to generate the rotation arrays:

#region Math Functions
;Have some Pi!
Global Const $pi = 3.14159265358979

;Find the angle of a point relative to the origin
Func GetAnglePO($x, $y)
Select
Case $x > 0
If $y >= 0 Then
Return ATan($y / $x)
Else
Return ATan($y / $x) + 2 * $pi
EndIf
Case $x = 0
If $y = 0 Then
Return 0
ElseIf $y > 0 Then
Return $pi / 2
Else
Return 3 * $pi / 2
EndIf
Case $x < 0
Return ATan($y / $x) + $pi
EndSelect
EndFunc

;Find the angle of a point relative to the first point
Func GetAnglePP($x1, $y1, $x2, $y2)
Return GetAnglePO($x2 - $x1, $y2 - $y1)
EndFunc
#endregion

#Region Graphics Data
;Graphical Artifact Constants - these don't change unless the graphics files are altered/replaced
;The (x,y) for the point the second hand spins around
$SecHandCenterX=300
$SecHandCenterY=300
;the distance from the spin point of the second hand to the "Target", AKA the center of the beer bottle
$SecHandLen=137
;the (x,y) for the center of the eye on the left
$LeftEyeX=247
$LeftEyeY=240
;the (x,y) for the center of the eye on the right
$RightEyeX=353
$RightEyeY=240
#endregion

;Arrays to hold the rotations for all 60 seconds
Dim $LeftEyeRot[60],$RightEyeRot[60]

ConsoleWrite("Secs"&@TAB&"Hand"&@TAB&"LEye"&@TAB&"REye"&@CRLF)
for $secs=0 to 59
;Figure the (x,y) coordinates for the Target
$sechandrad=$pi*($secs-15)/30
$sechanddeg=$sechandrad*180/$pi
$sechandx=$SecHandCenterX+$SecHandLen*Cos($sechandrad)
$sechandy=$SecHandCenterY+$SecHandLen*Sin($sechandrad)
;Find the Angle for the Left Eye, change to degrees, rotate so that 0 is straight up
$lefteyerad=GetAnglePP($lefteyex,$lefteyey,$sechandx,$sechandy)
$LeftEyeDeg=$lefteyerad*180/$pi
$LeftEyeRot[$secs]=mod(int($LeftEyeDeg+90),360)
;Find the Angle for the Right Eye, change to degrees, rotate so that 0 is straight up
$righteyerad=GetAnglePP($righteyex,$righteyey,$sechandx,$sechandy)
$RightEyeDeg=$RightEyeRad*180/$pi
$RightEyeRot[$secs]=mod(int($RightEyeDeg+90),360)
;debug
ConsoleWrite($secs & @TAB & $Secs * 6 & @TAB & $LeftEyeRot[$secs] & @TAB & $RightEyeRot[$Secs] & @CRLF)
Next

;Left Eye Array ready for Cut'n'Paste
ConsoleWrite("Dim $LeftEyeRot[60]=[")
for $secs=0 to 59
ConsoleWrite($LeftEyeRot[$secs])
If $secs<59 Then ConsoleWrite(", ")
Next
ConsoleWrite("]" & @CRLF)

;Right Eye Array ready for Cut'n'Paste
ConsoleWrite("Dim $RightEyeRot[60]=[")
for $secs=0 to 59
ConsoleWrite($RightEyeRot[$secs])
If $secs<59 Then ConsoleWrite(", ")
Next
ConsoleWrite("]" & @CRLF)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...