Jump to content

Highly configurable random screensaver


E1M1
 Share

Recommended Posts

What you guys think of my new screensaver?

Usage.

1. compile

2. name *.exe to *.scr

3. choose 1 of ini files below

4. run *.scr file

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WinAPI.au3>

Dim $aWords, $aFonts, $minh, $minw, $maxw, $maxh, $minr, $maxr, $ming, $maxg, $minb, $maxb, $minWords, $maxWords
#Region ### START Koda GUI section ### Form=
If $cmdline[0] > 0 Then
    If $cmdline[1] = "/S" Then
        Saver()
        Exit
    EndIf
EndIf

Func SettingsGet()
    $aWords = IniRead(@ScriptDir & "\saver.ini", "settings", "words", "-1")
    $aFonts = IniRead(@ScriptDir & "\saver.ini", "settings", "fonts", "-1")
    $minh = IniRead(@ScriptDir & "\saver.ini", "settings", "minh", "-1")
    $minw = IniRead(@ScriptDir & "\saver.ini", "settings", "minw", "-1")
    $maxw = IniRead(@ScriptDir & "\saver.ini", "settings", "maxh", "-1")
    $maxh = IniRead(@ScriptDir & "\saver.ini", "settings", "maxh", "-1")
    $minr = IniRead(@ScriptDir & "\saver.ini", "settings", "minr", "-1")
    $maxr = IniRead(@ScriptDir & "\saver.ini", "settings", "maxr", "-1")
    $ming = IniRead(@ScriptDir & "\saver.ini", "settings", "ming", "-1")
    $maxg = IniRead(@ScriptDir & "\saver.ini", "settings", "maxg", "-1")
    $minb = IniRead(@ScriptDir & "\saver.ini", "settings", "minb", "-1")
    $maxb = IniRead(@ScriptDir & "\saver.ini", "settings", "maxb", "-1")
    $minWords = IniRead(@ScriptDir & "\saver.ini", "settings", "minWords", "-1")
    $maxWords = IniRead(@ScriptDir & "\saver.ini", "settings", "maxWords", "-1")
EndFunc   ;==>SettingsGet

Func SettingsPut()
    IniWrite(@ScriptDir & "\saver.ini", "settings", "words", $aWords)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "fonts", $aFonts)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "minh", $minh)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "minw", $minw)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "maxh", $maxh)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "maxh", $maxh)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "minr", $minr)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "maxr", $maxr)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "ming", $ming)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "maxg", $maxg)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "minb", $minb)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "maxb", $maxb)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "maxWords", $maxWords)
    IniWrite(@ScriptDir & "\saver.ini", "settings", "minWords", $minWords)
EndFunc   ;==>SettingsPut

ConfGUI()
Func ConfGUI()
    SettingsGet()
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Settings", 627, 387, 192, 114)
    GUICtrlCreateTab(0, 0, 625, 385)
    GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
    $TabSheet1 = GUICtrlCreateTabItem("General")
    $Group1 = GUICtrlCreateGroup("Words", 8, 24, 609, 345)
    $Label3 = GUICtrlCreateLabel("Min height", 16, 56, 53, 17)
    $Input1 = GUICtrlCreateInput($minh, 80, 48, 121, 21)
    $Label4 = GUICtrlCreateLabel("Max height", 16, 88, 56, 17)
    $Input2 = GUICtrlCreateInput($maxh, 80, 80, 121, 21)
    $Label5 = GUICtrlCreateLabel("Min width", 16, 120, 49, 17)
    $Input3 = GUICtrlCreateInput($minw, 80, 112, 121, 21)
    $Label6 = GUICtrlCreateLabel("Max width", 16, 152, 52, 17)
    $Input4 = GUICtrlCreateInput($maxw, 80, 144, 121, 21)
    $Label7 = GUICtrlCreateLabel("Min Red", 240, 48, 44, 17)
    $Label8 = GUICtrlCreateLabel("Max Red", 240, 72, 47, 17)
    $Label9 = GUICtrlCreateLabel("Min Green", 240, 96, 53, 17)
    $Label10 = GUICtrlCreateLabel("Max Green", 240, 120, 56, 17)
    $Label11 = GUICtrlCreateLabel("Min Blue", 240, 144, 45, 17)
    $Label12 = GUICtrlCreateLabel("Max Blue", 240, 168, 48, 17)
    $Label13 = GUICtrlCreateLabel("Min Words", 240, 190, 60, 17)
    $Label14 = GUICtrlCreateLabel("Max Words", 240, 212, 60, 17)
    $Input5 = GUICtrlCreateInput($minr, 312, 48, 121, 21)
    $Input6 = GUICtrlCreateInput($maxr, 312, 72, 121, 21)
    $Input7 = GUICtrlCreateInput($ming, 312, 96, 121, 21)
    $Input8 = GUICtrlCreateInput($maxg, 312, 120, 121, 21)
    $Input9 = GUICtrlCreateInput($minb, 312, 144, 121, 21)
    $Input10 = GUICtrlCreateInput($maxb, 312, 168, 121, 21)
    $Input11 = GUICtrlCreateInput($minWords, 312, 190, 121, 21)
    $Input11 = GUICtrlCreateInput($maxWords, 312, 212, 121, 21)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $TabSheet2 = GUICtrlCreateTabItem("Words")
    $Edit2 = GUICtrlCreateEdit(StringReplace($aWords, ",", @CRLF), 8, 40, 617, 345)
    $Label2 = GUICtrlCreateLabel("Enter 1 word per line", 8, 24, 101, 17)
    $TabSheet3 = GUICtrlCreateTabItem("Font")
    $Edit1 = GUICtrlCreateEdit(StringReplace($aFonts, ",", @CRLF), 8, 40, 617, 345)
    $Label1 = GUICtrlCreateLabel("Enter 1 font per line", 8, 24, 101, 17)
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                $aWords = StringReplace(GUICtrlRead($Edit2), @CRLF, ",")
                $aFonts = StringReplace(GUICtrlRead($Edit1), @CRLF, ",")
                $minh = GUICtrlRead($Input1)
                $minw = GUICtrlRead($Input3)
                $maxw = GUICtrlRead($Input4)
                $maxh = GUICtrlRead($Input2)
                $minr = GUICtrlRead($Input5)
                $maxr = GUICtrlRead($Input6)
                $ming = GUICtrlRead($Input7)
                $maxg = GUICtrlRead($Input8)
                $minb = GUICtrlRead($Input9)
                $maxb = GUICtrlRead($Input10)
                SettingsPut()
                Exit

        EndSwitch
    WEnd
EndFunc   ;==>ConfGUI

Func max($a, $b)
    If $a > $b Then
        Return $b
    Else
        Return $a
    EndIf
EndFunc   ;==>max

Func _KeyProc($nCode, $wParam, $lParam)
    If $wParam = $WM_KEYDOWN Then
      Exit
    EndIf
EndFunc   ;==>_KeyProc

Func Saver()
    SettingsGet()
    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)

    $aWords = StringSplit($aWords, ",")
    $aFonts = StringSplit($aFonts, ",")
    $w = @DesktopWidth
    $h = @DesktopHeight
    $Form1 = GUICreate("Screen Saver", $w, $h, 0, 0, $WS_POPUP)
    GUISetCursor(16, 1)
    GUISetBkColor(0x000000)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $x = MouseGetPos(0)
    $y = MouseGetPos(1)

    While 1
        $loop = Random($minWords, $maxWords, 1)
        For $i = 1 To $loop
            $rndw = Random($minw, $maxw, 1)
            $rndh = Random($minh, $maxh, 1)
            $rndx = Random(-$rndw + 10, $w - 20, 1)
            $rndy = Random(-$rndh + 10, $h - 20, 1)
            $word = $aWords[Random(1, $aWords[0], 1)]
            ConsoleWrite(GUICtrlCreateLabel($word, $rndx, $rndy, $rndw, $rndh) & @CRLF)
            $rndr = Hex(Random($minr, $maxr, 1), 2)
            $rndg = Hex(Random($ming, $maxg, 1), 2)
            $rndb = Hex(Random($minb, $maxb, 1), 2)
            GUICtrlSetColor(-1, "0x" & $rndr & $rndg & $rndb)
            $fontsizex = $rndw / StringLen($word)
            $fontsizey = max($fontsizex, $rndh * .80)
            GUICtrlSetFont(-1, $fontsizey, Random(0, 800, 1), Random(0, 14, 1), $aFonts[Random(1, $aFonts[0], 1)])
            GUICtrlSetBkColor(-1, -2)
            If MouseGetPos(0) <> $x Or MouseGetPos(1) <> $y Then Exit
        Next
        For $i = 0 To $loop + 3
            GUICtrlDelete($i)
            If MouseGetPos(0) <> $x Or MouseGetPos(1) <> $y Then Exit
        Next
    WEnd
EndFunc   ;==>Saver

saver.ini

[settings]
minw=9
minh=12
maxw=100
maxh=50
minr=0
maxr=0
ming=50
maxg=255
minb=0
maxb=0
fonts=Arial,Bernard MT,Blackadder ITC,Bodoni MT Poster,Bradley Hand ITC,Broadway,Brush Script MT,Castellar,Curlz MT,Terminal
words=1,0
minWords=9999
maxWords=10000

saver.ini

[settings]
minw=11
minh=11
maxw=12
maxh=12
minr=0
maxr=0
ming=50
maxg=255
minb=0
maxb=0
fonts=Terminal
words=1,0
minWords=9999
maxWords=10000
Edited by E1M1

edited

Link to comment
Share on other sites

Why is it in help and support?

Oops, wanted to post it in example scripts. Probably forgot to select right forum.

Could moderators or administrators move it to example scripts please? I'am really sorry for poting it in wrong place.

Edited by E1M1

edited

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...