• Hallo Leute,

    vielleicht seid ihr auch begeisterte "Rubic Cuber" (Zauberwürfel). ;)
    Ich jedenfalls bin es und habe mir überlegt, dass ich gerne mal
    die Zeit messen möchte, in der ich einen Cube lösen kann. Was
    würde sich dort nicht eher anbieten, als einen Timer zu programmiern. :)
    Das habe ich in die Tat umgesetzt und werde euch das Ergebnis
    jetzt hier präsentieren.

    Was kann der CubeTimer?

    • Zeit messen :P
    • Wertungen anzeigen (Gut, Mittel, Schlecht)
    • Wertungen selbst einstellen


    Todo:

    • Bestzeiten
    • Durchnittszeiten


    Screenshots:

    [Blockierte Grafik: http://www.abload.de/thumb/screenshot1h25n.jpg][Blockierte Grafik: http://www.abload.de/thumb/screenshot2v1h3.jpg]

    Code
    [autoit]


    #cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.2.0
    Author: qixx (http://www.autoit.de)
    Credits:

    #ce ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    #include <Timers.au3>
    #include <misc.au3>
    #include <GuiListView.au3>
    #include <GuiListBox.au3>
    #include <GuiImageList.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <EditConstants.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global $MinRed = IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "MinRed", 2)
    Global $SecRed = IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "SecRed", 0) ;Ab 2 Minuten ist das Icon Rot
    Global $MinYellow = IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "MinYellow", 1)
    Global $SecYellow = IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "SecYellow", 5) ;Ab 1 Minuten und 5 Sekunden ist das Icon Gelb

    [/autoit] [autoit][/autoit] [autoit]

    If IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "Splash", "1") = "1" Then
    SplashImageOn("Cube Timer", @ScriptDir & "\images\splash.jpg", 460, 267, -1, -1, 3)
    Sleep(3000)
    SplashOff()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $MainGUI = GUICreate("CubeTimer", 510, 202, -1, -1, $WS_POPUP)
    GUISetBkColor(0xFFFFFF)
    GUICtrlCreatePic(@ScriptDir & "\images\bg.jpg", 0, 0, 510, 202)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $LabelTime = GUICtrlCreateLabel("00:00.000", 32, 72, 252, 65)
    GUICtrlSetFont(-1, 45, 800, 0, "Arial Narrow")
    GUICtrlSetColor(-1, 0x34b0ff)
    GUICtrlCreatePic(@ScriptDir & "\images\logo.jpg", 1, 1, 335, 69, -1, $GUI_WS_EX_PARENTDRAG)
    $SettingsButton = GUICtrlCreatePic(@ScriptDir & "\images\settings.jpg", 465, 6, 10, 10)
    $MinimizeButton = GUICtrlCreatePic(@ScriptDir & "\images\line.jpg", 479, 6, 10, 10)
    $ExitButton = GUICtrlCreatePic(@ScriptDir & "\images\x.jpg", 493, 6, 10, 10)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel("", 335, 1, 125, 20, -1, $GUI_WS_EX_PARENTDRAG)

    [/autoit] [autoit][/autoit] [autoit]

    $List = GUICtrlCreateListView("", 336, 24, 165, 149, 0x00200000)
    _GUICtrlListView_InsertColumn($List, 0, "Datum", 80)
    _GUICtrlListView_InsertColumn($List, 1, "Zeit", 64)
    $Nr = IniReadSection(@AppDataDir & "\CubeTimer.ct", "CubeTimer Times")
    If IsArray($Nr) Then
    For $i = 1 To $Nr[0][0]
    GUICtrlCreateListViewItem(IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Times", "Time" & $i, ""), $List)
    $AnalysString = StringSplit(IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Times", "Time" & $i, ""), "|")
    _Analysieren($AnalysString[2], $i - 1)
    Next
    EndIf
    $ButtonClear = GUICtrlCreateLabel(" Liste leeren", 428, 176, 73, 15)
    GUICtrlSetBkColor(-1, 0x34b0ff)
    GUICtrlSetColor(-1, 0xffffff)
    GUICtrlCreateLabel("Starten und Stoppen mit 'Leertaste'", 82, 142, 175, 17)
    GUICtrlSetColor(-1, 0xcccccc)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $SettingsGUI = GUICreate("Einstellungen", 162, 178, -1, -1, $WS_POPUP)
    GUISetBkColor(0xFFFFFF)
    GUICtrlCreatePic(@ScriptDir & "\images\sbg.jpg", 0, 0, 162, 178)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateLabel("Einstellungen", 8, 5, 146, 17, -1, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xcccccc)

    [/autoit] [autoit][/autoit] [autoit]

    ;Grün
    GUICtrlCreateLabel("", 8, 24, 20, 20)
    GUICtrlSetBkColor(-1, 0x00FF00)
    GUICtrlCreateInput("00", 32, 24, 25, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
    GUICtrlCreateLabel(":", 58, 24, 4, 22)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlCreateInput("00", 64, 24, 25, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
    GUICtrlCreateLabel(".", 91, 27, 8, 22)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlCreateInput("000", 96, 24, 33, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))

    [/autoit] [autoit][/autoit] [autoit]

    ;Gelb
    GUICtrlCreateLabel("", 8, 48, 20, 20)
    GUICtrlSetBkColor(-1, 0xFFFF00)
    $sYellowMinInput = GUICtrlCreateInput("01", 32, 48, 25, 21, $ES_NUMBER)
    GUICtrlCreateLabel(":", 58, 48, 8, 22)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
    GUICtrlSetColor(-1, 0x000000)
    $sYellowSecInput = GUICtrlCreateInput("30", 64, 48, 25, 21, $ES_NUMBER)
    GUICtrlCreateLabel(".", 91, 52, 8, 22)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlCreateInput("000", 96, 48, 33, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))

    [/autoit] [autoit][/autoit] [autoit]

    ;Rot
    GUICtrlCreateLabel("", 8, 72, 20, 20)
    GUICtrlSetBkColor(-1, 0xFF0000)
    $sRedMinInput = GUICtrlCreateInput("02", 32, 72, 25, 21, $ES_NUMBER)
    GUICtrlCreateLabel(":", 58, 72, 8, 22)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
    GUICtrlSetColor(-1, 0x000000)
    $sRedSecInput = GUICtrlCreateInput("30", 64, 72, 25, 21, $ES_NUMBER)
    GUICtrlCreateLabel(".", 91, 74, 8, 22)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlCreateInput("000", 96, 72, 33, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))

    [/autoit] [autoit][/autoit] [autoit]

    ;Anderes
    $sCheckESC = GUICtrlCreateCheckbox("Mit ESC Beenden", 8, 104, 105, 17)
    If IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "EndESC", "1") = "1" Then
    GUICtrlSetState($sCheckESC, $GUI_CHECKED)
    Else
    GUICtrlSetState($sCheckESC, $GUI_UNCHECKED)
    EndIf
    $sCheckSplash = GUICtrlCreateCheckbox("Bild beim Starten anzeigen", 8, 120, 145, 17)
    If IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "Splash", "1") = "1" Then
    GUICtrlSetState($sCheckSplash, $GUI_CHECKED)
    Else
    GUICtrlSetState($sCheckSplash, $GUI_UNCHECKED)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $sOk = GUICtrlCreateLabel(" Ok", 40, 152, 41, 15)
    GUICtrlSetBkColor(-1, 0x34b0ff)
    GUICtrlSetColor(-1, 0xffffff)
    $sCancel = GUICtrlCreateLabel(" Abbrechen", 88, 152, 65, 15)
    GUICtrlSetBkColor(-1, 0x34b0ff)
    GUICtrlSetColor(-1, 0xffffff)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($List, 0xFF0000, 16, 16)) ;Rot
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($List, 0xFFFF00, 16, 16)) ;Gelb
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($List, 0x00FF00, 16, 16)) ;Grün
    _GUICtrlListView_SetImageList($List, $hImage, 1)

    [/autoit] [autoit][/autoit] [autoit]

    If IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "EndESC", "1") = "1" Then
    HotKeySet("{ESC}", "_Exit")
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Func _Timer()

    [/autoit] [autoit][/autoit] [autoit]

    Local $starttime = _Timer_Init(), $Min = 0
    While 1
    Sleep(10)
    $time = StringSplit(_Timer_Diff($starttime), ".")
    $Sec = StringTrimRight($time[1], 3) - 60 * $Min

    [/autoit] [autoit][/autoit] [autoit]

    If $Sec = "" Then $Sec = 0
    If $Sec = "60" Then
    $Min = $Min + 1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If StringLen($Min) = 1 Then $Min = "0" & $Min
    If StringLen($Sec) = 1 Then $Sec = "0" & $Sec
    $ElapsedTime = $Min & ":" & $Sec & "." & StringTrimLeft($time[1], StringLen($time[1]) - 3)
    GUICtrlSetData($LabelTime, $ElapsedTime)
    If $Sec > 0 Then
    If _IsPressed(20) Then
    GUICtrlCreateListViewItem(@MDAY & "." & @MON & "." & @YEAR & "|" & $ElapsedTime, $List)
    ClipPut(@AppDataDir & "\CubeTimer.ct")
    For $i = 1 To _GUICtrlListView_GetItemCount($List)
    IniWrite(@AppDataDir & "\CubeTimer.ct", "CubeTimer Times", "Time" & $i, _GUICtrlListView_GetItemText($List, $i - 1, 0) & "|" & _GUICtrlListView_GetItemText($List, $i - 1, 1))
    Next
    _Analysieren($ElapsedTime, _GUICtrlListView_GetItemCount($List) - 1)
    MsgBox(0, "Deine Zeit", "Deine erreichte Zeit: " & $ElapsedTime)
    ExitLoop
    EndIf
    EndIf
    WEnd
    EndFunc ;==>_Timer

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc ;==>_Exit

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Analysieren($String, $Position)
    ;Farbicon eintragen
    ;Return 0 = Rot
    ;Return 1 = Gelb
    ;Return 2 = Grün

    [/autoit] [autoit][/autoit] [autoit]

    $Analysis = StringSplit($String, ":.")
    For $i = 0 To 9
    If $Analysis[1] = "0" & $i Then $Analysis[1] = $i
    Next
    For $i = 0 To 9
    If $Analysis[2] = "0" & $i Then $Analysis[2] = $i
    Next

    [/autoit] [autoit][/autoit] [autoit]

    If $Analysis[1] >= $MinRed Then
    If $Analysis[2] >= $SecRed Then
    _GUICtrlListView_SetItemImage($List, $Position, 0)
    Return 0
    Else
    If $Analysis[1] >= $MinYellow Then
    If $Analysis[2] >= $SecYellow Then
    _GUICtrlListView_SetItemImage($List, $Position, 1)
    Return 1
    Else
    _GUICtrlListView_SetItemImage($List, $Position, 2)
    Return 2
    EndIf
    EndIf
    EndIf
    Else
    If $Analysis[1] >= $MinYellow Then
    If $Analysis[2] >= $SecYellow Then
    _GUICtrlListView_SetItemImage($List, $Position, 1)
    Return 1
    Else
    _GUICtrlListView_SetItemImage($List, $Position, 2)
    Return 2
    EndIf
    Else
    _GUICtrlListView_SetItemImage($List, $Position, 2)
    Return 2
    EndIf
    EndIf
    EndFunc ;==>_Analysieren

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case -3
    _Exit()
    Case $ButtonClear
    For $i = 0 To _GUICtrlListView_GetItemCount($List) - 1
    _GUICtrlListView_DeleteItem(GUICtrlGetHandle($List), 0)
    Next
    IniDelete(@AppDataDir & "\CubeTimer.ct", "CubeTimer Times")

    [/autoit] [autoit][/autoit] [autoit]

    Case $SettingsButton
    GUICtrlSetData($sRedMinInput, $MinRed)
    GUICtrlSetData($sRedSecInput, $SecRed)
    GUICtrlSetData($sYellowMinInput, $MinYellow)
    GUICtrlSetData($sYellowSecInput, $SecYellow)
    $pos = WinGetPos($MainGUI)
    WinMove($SettingsGUI, "", $pos[0] + 10, $pos[1] + 10)
    GUISetState(@SW_SHOW, $SettingsGUI)

    [/autoit] [autoit][/autoit] [autoit]

    Case $MinimizeButton
    GUISetState(@SW_MINIMIZE)

    [/autoit] [autoit][/autoit] [autoit]

    Case $ExitButton
    _Exit()

    [/autoit] [autoit][/autoit] [autoit]

    Case $sOk
    $MinRed = GUICtrlRead($sRedMinInput)
    $SecRed = GUICtrlRead($sRedSecInput)
    $MinYellow = GUICtrlRead($sYellowMinInput)
    $SecYellow = GUICtrlRead($sYellowSecInput)

    [/autoit] [autoit][/autoit] [autoit]

    IniWrite(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "MinRed", $MinRed)
    IniWrite(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "SecRed", $SecRed)
    IniWrite(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "MinYellow", $MinYellow)
    IniWrite(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "SecYellow", $SecYellow)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    If GUICtrlRead($sCheckESC) = $GUI_CHECKED Then
    HotKeySet("{ESC}", "_Exit")
    IniWrite(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "EndESC", "1")
    Else
    HotKeySet("{ESC}")
    IniWrite(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "EndESC", "0")
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If GUICtrlRead($sCheckSplash) = $GUI_CHECKED Then
    IniWrite(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "Splash", "1")
    Else
    IniWrite(@AppDataDir & "\CubeTimer.ct", "CubeTimer Settings", "Splash", "0")
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To _GUICtrlListView_GetItemCount($List) - 1
    _GUICtrlListView_DeleteItem(GUICtrlGetHandle($List), 0)
    Next
    $Nr = IniReadSection(@AppDataDir & "\CubeTimer.ct", "CubeTimer Times")
    If IsArray($Nr) Then
    For $i = 1 To $Nr[0][0]
    GUICtrlCreateListViewItem(IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Times", "Time" & $i, ""), $List)
    $AnalysString = StringSplit(IniRead(@AppDataDir & "\CubeTimer.ct", "CubeTimer Times", "Time" & $i, ""), "|")
    If StringLen($AnalysString[2]) = 1 Then $AnalysString[2] = "0" & $AnalysString[2]
    _Analysieren($AnalysString[2], $i - 1)
    Next
    EndIf
    GUISetState(@SW_HIDE, $SettingsGUI)
    WinActivate($MainGUI)

    [/autoit] [autoit][/autoit] [autoit]

    Case $sCancel
    GUISetState(@SW_HIDE, $SettingsGUI)
    WinActivate($MainGUI)

    [/autoit] [autoit][/autoit] [autoit]

    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    If _IsPressed(20) And WinActive($MainGUI) Then ;Leertaste
    _Timer()
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    If StringLen(GUICtrlRead($sRedMinInput)) > 2 Then
    GUICtrlSetData($sRedMinInput, StringTrimRight(GUICtrlRead($sRedMinInput), StringLen(GUICtrlRead($sRedMinInput)) - 2))
    EndIf
    If StringLen(GUICtrlRead($sRedSecInput)) > 2 Then
    GUICtrlSetData($sRedSecInput, StringTrimRight(GUICtrlRead($sRedSecInput), StringLen(GUICtrlRead($sRedSecInput)) - 2))
    EndIf
    If StringLen(GUICtrlRead($sYellowMinInput)) > 2 Then
    GUICtrlSetData($sYellowMinInput, StringTrimRight(GUICtrlRead($sYellowMinInput), StringLen(GUICtrlRead($sYellowMinInput)) - 2))
    EndIf
    If StringLen(GUICtrlRead($sYellowSecInput)) > 2 Then
    GUICtrlSetData($sYellowSecInput, StringTrimRight(GUICtrlRead($sYellowSecInput), StringLen(GUICtrlRead($sYellowSecInput)) - 2))
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit]

    Im Anhang sind die Bilder und der Code als .au3.


    MfG
    qixx