#RequireAdmin
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=mona.ico
#AutoIt3Wrapper_Outfile=PhotoViewer.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Description=Kleiner Bildbetrachter
#AutoIt3Wrapper_Res_Fileversion=1.1.4.6
#AutoIt3Wrapper_Res_LegalCopyright=© by Ritzelrocker04
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_Res_Field=Compiled by|Ritzelrocker04
#AutoIt3Wrapper_Res_Field=Original Name|AutoIt PhotoViewer
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ComboConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <Misc.au3>
#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)

OnAutoItExitRegister("_quit")
_GDIPlus_Startup()

FileInstall('autoit9_wall.jpg', @TempDir & "\autoit9_wall.jpg", 1)
Global $Msg, $tartpic = @TempDir & "\autoit9_wall.jpg"
Global $ourcePath, $path, $PicList, $how = 1, $PicSwitchTime = 1000, $tepPic = 0
Global $hGraphics, $hImage, $hBrush_Grey, $iX, $iY, $iW, $iH
;$sVersion = "0.36 " wird erst nach dem kompilieren wirksam.
Global $sTitle = "AutoIt PhotoViewer ", $sDate = "28.09.2013 ", $sVersion = FileGetVersion(@ScriptFullPath)
Global $sMsgUpdate = '%s\n\nDer Nutzer wählt einen beliebigen Ordner' _
		 & '\nmit den Bilddateien (*.jpg), die Anzahl der Bilder\nim Ordner sind noch unbekannt.\n\n' _
		 & 'Der kleine Bildbetrachter ermittelt Anzahl, Bezeichnung\ndes Bildermaterials und erstellt eine Bilderpräsentation.' _
		 & '\n\nDie Bilder können in einzelnen Schritten\nvorwärts, rückwärts oder als Diashow betrachtet werden.\n' _
		 & 'Die Bildwechselzeit ist einstellbar und\neine laufende Diashow kann unterbrochen werden.' _
		 & '\n\nVersion:\t%s\nBuild:\t%s\n\nCopyright: © 2013 by Ritzelrocker04\n\nAutor:\nRitzelrocker04 / RR04' _
		 & '\nritzelrocker04.bplaced.net\n\nWeiter zur Homepage ?'

Global $hGui = GUICreate($sTitle, 1000, 618)

#region ### Group Präsentation ###
Global $pic = GUICtrlCreatePic($tartpic, 10, 10, 660, 500)
Global $lblLabel = GUICtrlCreateLabel(StringFormat('%s', $sTitle), 20, 520, 640, 22, $SS_CENTER)
GUICtrlSetFont(-1, 11, 400, 0, "Arial")
#endregion ### Group Präsentation ###

#region ### Group Information ###
GUICtrlCreateLabel('', 680, 10, 310, 360)
GUICtrlSetBkColor(-1, 0xCBCBCB)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $iptInfo[4]
For $i = 0 To 3
	$iptInfo[$i] = GUICtrlCreateInput("", 700, 60 + $i * 80, 270, 22, $ES_READONLY)
	GUICtrlSetBkColor(-1, 0xffffff); 0x000000 ; 0xffffff ; 0xCBCBCB
Next
#endregion ### Group Information ###

Global $iptSourcePath = GUICtrlCreateInput("", 10, 562, 660, 22, $ES_READONLY)
GUICtrlCreateLabel("Die Zeit in Sekunden bis zum Bildwechsel.", 680, 425, 310, 17, $SS_CENTER)
Global $cmbSwitchTime = GUICtrlCreateCombo("3", 680, 445, 310, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
GUICtrlSetData(-1, "2|4|5|6", "3")
Global $btnLeft = GUICtrlCreateButton("<", 680, 390, 150, 25)
Global $btnRight = GUICtrlCreateButton(">", 840, 390, 150, 25)
Global $btnShow = GUICtrlCreateButton("Show starten", 680, 480, 150, 25)
GUICtrlSetState($btnShow, $GUI_FOCUS)
Global $btnShowCancel = GUICtrlCreateButton("Show beenden", 840, 480, 150, 25)
;~ Show beenden beendet nicht das Programm !
GUICtrlSetState($btnShowCancel, $GUI_DISABLE)
GUICtrlCreateLabel("Den Bildpfad auswählen.", 680, 540, 310, 17, $SS_CENTER)
Global $btnFolder = GUICtrlCreateButton("...", 680, 560, 310, 25)

#region ### StatusBar ###
Global $tatusBar = _GUICtrlStatusBar_Create($hGui)
Global $tatusBar_PartsWidth[2] = [900, -1]
_GUICtrlStatusBar_SetParts($tatusBar, $tatusBar_PartsWidth)
_GUICtrlStatusBar_SetText($tatusBar, $sTitle & 'v' & $sVersion, 0)
_GUICtrlStatusBar_SetMinHeight($tatusBar, 20)
#endregion ### StatusBar ###

GUISetState(@SW_SHOW)

AdlibRegister("_clock", 1000)

While True
	$Msg = GUIGetMsg()
	Switch $Msg
		Case -3
			If MsgBox(64 + 4, $sTitle _
					 & ' UpdateCheck', StringFormat($sMsgUpdate, $sTitle, $sVersion, $sDate)) = 6 Then _
					ShellExecute("http://ritzelrocker04.bplaced.net/")
			FileDelete($tartpic)
			Exit

		Case $btnFolder
			$path = FileSelectFolder('Bitte das Bildverzeichnis auswählen :', '', 6, $ourcePath, $hGui)
			If StringRight($path, 1) <> '\' Then $path &= '\'
			$ourcePath = $path
			GUICtrlSetData($iptSourcePath, $path)

			$PicList = _FileListToArray($path, "*.jpg")
			If @error = 1 Or @error = 4 Then
				MsgBox(16, "Error", "Keine Dateien oder Ordner gefunden.")
				Exit
			EndIf

			GUICtrlSetData($iptInfo[0], StringFormat('Bilder gesamt : %i', $PicList[0]))

		Case $btnLeft, $btnRight, $btnShow
			_specialEvents()
	EndSwitch
WEnd

;~ Vor Verwendung eines der drei Events den Pfad prüfen.
Func _specialEvents()
	If $path <> '' Then
		Switch $Msg
			Case $btnLeft
				;i $btnLeft
				$tepPic -= 1
				If $tepPic < 1 Then $tepPic = $PicList[0]
				_picStep()

			Case $btnRight
				;i $btnRight
				$tepPic += 1
				If $tepPic > $PicList[0] Then $tepPic = 1
				_picStep()

			Case $btnShow
				;i $btnShow
				GUICtrlSetState($btnShowCancel, $GUI_ENABLE)
				$PicSwitchTime *= GUICtrlRead($cmbSwitchTime)

				Do
					GUICtrlSetData($iptInfo[1], StringFormat('Aktuelles Bild : %i', $how))
					_setImageProportion($path & $PicList[$how])
					GUICtrlSetData($lblLabel, StringFormat('%s', $PicList[$how]))
					_PicSwitchTime($PicSwitchTime)
					$how += 1
				Until $how > $PicList[0]

				;i Startbild anzeigen
				GUICtrlSetImage($pic, $tartpic)
				GUICtrlSetState($btnShowCancel, $GUI_DISABLE)

				;i Hinweis Ende der Show
				GUICtrlSetData($lblLabel, "Fertig - Ende der Bilderschau !")
				MsgBox(64, "Fertig", "Ende der Bilderschau !")
				For $i = 0 To 3
					GUICtrlSetData($iptInfo[$i], '')
				Next
				GUICtrlSetData($iptSourcePath, '')
				GUICtrlSetData($lblLabel, StringFormat('%s', $sTitle))
				$PicSwitchTime = 1000
				$path = ''
				$how = 1
		EndSwitch
	Else
		MsgBox(64, "Eingaben", "Bitte erst den Bildpfad eingeben.")
	EndIf
EndFunc   ;==>_specialEvents

Func _picStep()
	GUICtrlSetData($iptInfo[1], StringFormat('Aktuelles Bild : %i', $tepPic))
	GUICtrlSetImage($pic, $path & $PicList[$tepPic])
	GUICtrlSetData($lblLabel, StringFormat('%s', $PicList[$tepPic]))
	_setImageProportion($path & $PicList[$tepPic])
EndFunc   ;==>_picStep

Func _PicSwitchTime($time)
	Local $tstart = TimerInit()
	While TimerDiff($tstart) < $time
		;i Mit Ende-Taste oder Button "Show beenden" die Show vorzeitig beenden.
		If GUIGetMsg() = $btnShowCancel Or _IsPressed("23") Then $how = $PicList[0] + 1
	WEnd
EndFunc   ;==>_PicSwitchTime

; #_setImageProportion# =========================================================================================================
; Title .........: 	_setImageProportion
; AutoIt Version : 	v3.3.8.1 oder höher
; Language ......: 	Deutsch
; Description ...: 	Bilder in einer anderen Größe darstellen, bei gleicher Proportion
; Note ..........: 	Verwendung von GDIPLUS, einpassen der Bilder in einen vorgegebenen Rahmen.
; Author(s) .....: 	Ritzelrocker04
; Homepage ......:	http://ritzelrocker04.bplaced.net/
; ===============================================================================================================================
Func _setImageProportion($var)
	$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
	Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(660, 500, $hGraphics)
	Local $hBitmapContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

	$hImage = _GDIPlus_ImageLoadFromFile($var)
	Local $width = _GDIPlus_ImageGetWidth($hImage)
	Local $height = _GDIPlus_ImageGetHeight($hImage)

	GUICtrlSetData($iptInfo[2], StringFormat('Bildformat: %ipx  x  %ipx', $width, $height))
	GUICtrlSetData($iptInfo[3], StringFormat('Bildverhältnis:  %.3f', $width / $height))

	$hBrush_Grey = _GDIPlus_BrushCreateSolid(0xFFCBCBCB)
	_GDIPlus_GraphicsFillRect($hBitmapContext, 0, 0, 660, 500, $hBrush_Grey)

	$iH = 640 * $height / $width
	$iY = 10 + (480 - $iH) / 2
	$iX = 10
	$iW = 640
	If $iH > 480 Then
		$iW = 480 / ($height / $width)
		$iX = 10 + (640 - $iW) / 2
		$iY = 10
		$iH = 480
	EndIf

;~  Das Bild einpassen.
;~ _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, $iX, $iY, $iW, $iH)
	_GDIPlus_GraphicsDrawImageRect($hBitmapContext, $hImage, $iX, $iY, $iW, $iH)
	_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 10, 10, 660, 500)
EndFunc   ;==>_setImageProportion

Func _clock()
	Local $clock = _DateTimeFormat(_NowCalc(), 5)
	_GUICtrlStatusBar_SetText($tatusBar, @TAB & $clock, 1)
EndFunc   ;==>_clock

Func _quit()
	_GDIPlus_GraphicsDispose($hGraphics)
	_GDIPlus_BrushDispose($hBrush_Grey)
	_GDIPlus_ImageDispose($hImage)
	_GDIPlus_Shutdown()
EndFunc   ;==>_quit
; Ende
