;By Max Reble (GtaSpider)
;V 1.0
;This softer is under Creative Commons License
;http://creativecommons.org/licenses/by/3.0/de/deed.en
;http://creativecommons.org/licenses/by/3.0/de/
;You are free to Share and to Remix
;But you must attribute the work in the manner specified by the author or licensor (Max Reble)
;...

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $b_Opt_GuiOnEventMode = 0
Global $bModernSplash_Created = False
Global $bModernSplash_Initiated = False
Global $PI = 3.14159265358979

Global $oModernSplash_Flash = ObjCreate("ShockwaveFlash.ShockwaveFlash")
Global $oModernSplash_AutoItError = ObjEvent("AutoIt.Error", "COMError")

Global $sModernSplash_Movie

Global $hModernSplash_Parent, $hModernSplash_ClientText, $hModernSplash_ClientText_Label, $hModernSplash_ClientTitle, _
		$hModernSplash_ClientTitle_Label, $hModernSplash_ClientTitle_Label_Build, $hModernSplash_Parent_Vid,$hModernSplash_Dummy, _
		$hModernSplash_Close,$hModernSplash_CallBack_Exit = ""

Func _ModernSplash_Create($sTitle, $sBuild = "", $sCallBack_Exit = "",$iCorners = 20, $sMovieFile = "", $sFont = "Arial")
	If Not $sMovieFile Then $sMovieFile = @ScriptDir & "\back.swf"
	If $sCallBack_Exit Then $hModernSplash_CallBack_Exit = $sCallBack_Exit
	$sModernSplash_Movie = $sMovieFile
	$hModernSplash_Parent = GUICreate($sTitle, 500, 300, -1, -1, $WS_POPUP)
	If $iCorners Then __GuiRoundCorners($hModernSplash_Parent, $iCorners, $iCorners, $iCorners, $iCorners)
	GUISetOnEvent(-3, "_ModernSplash_ExitGui")
	$FlashCtrl = GUICtrlCreateObj($oModernSplash_Flash, 0, 0, 500, 300)

	$hModernSplash_ClientText = GUICreate("ClientText", 100, 60, 60, 200, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $hModernSplash_Parent)
	GUISetOnEvent(-3, "_ModernSplash_ExitGui")
	GUISetBkColor(0xFFEC00)
	$hModernSplash_ClientText_Label = GUICtrlCreateLabel("", 0, 40, 120, 40)
	GUICtrlSetFont(-1, 10, 400, 0, $sFont)
	GUICtrlSetBkColor(-1, -2)


	$hModernSplash_ClientTitle = GUICreate("ClientTitle", 300, 110, 60, 90, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $hModernSplash_Parent)
	GUISetBkColor(0xFFEC00)
	GUISetOnEvent(-3, "_ModernSplash_ExitGui")
	$hModernSplash_ClientTitle_Label = GUICtrlCreateLabel($sTitle, 0, 0, 300, 49)
	GUICtrlSetFont(-1, 32,400,0,$sFont)
	$hModernSplash_ClientTitle_Label_Build = GUICtrlCreateLabel($sBuild, 20, 69, 300, 60)
	GUICtrlSetFont(-1, 16,400,0,$sFont)

	$hModernSplash_Dummy = GUICreate("Dummy", 500, 300, 0, 0, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $hModernSplash_Parent)
	GUISetBkColor(0xFFEC00)
	GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "__PrimaryDown")
	_WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientTitle, 0xFFEC00, 0)

	$hModernSplash_Close = GUICreate("ClientText", 40, 40, 450, 40, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $hModernSplash_Parent)
	GUISetBkColor(0xE2B100)
	_WinAPI_SetLayeredWindowAttributes($hModernSplash_Close, 0xE2B100, 255)
	GUICtrlCreateLabel("X",0,0,40,40)
	GUICtrlSetOnEvent(-1,"_ModernSplash_ExitGui")
	GUICtrlSetFont(-1,32,400,0,$sFont)

	Global $bModernSplash_Created = True
	Return True
EndFunc   ;==>_ModernSplash_Create


Func _ModernSplash_Initiate($sText)
	HotKeySet("{ESC}","_ModernSplash_CheckExit")
	If Not $bModernSplash_Created Then Return SetError(1, 0, 0)
	Global $b_Opt_GuiOnEventMode = Opt("GuiOnEventMode", 1)
	With $oModernSplash_Flash
		.Movie = $sModernSplash_Movie
		.wmode = "opaque"
		.allowScriptAccess = "Always"
	EndWith
	_WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientTitle, 0xFFEC00, 0)
	_WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientText, 0xFFEC00, 0)
	WinSetTrans($hModernSplash_Parent, "", 0)
	GUISetState(@SW_SHOW, $hModernSplash_Parent)
	GUISetState(@SW_SHOW, $hModernSplash_ClientText)
	GUISetState(@SW_SHOW, $hModernSplash_ClientTitle)
	GUISetState(@SW_SHOW, $hModernSplash_Dummy)
	GUISetState(@SW_SHOW, $hModernSplash_Close)
	Local $i

	For $i = 0 To 255 Step 15
		WinSetTrans($hModernSplash_Parent, "", $i)
		ControlMove($hModernSplash_ClientTitle, "", $hModernSplash_ClientTitle_Label, 20 - (20 * $i / 255), 0)
		ControlMove($hModernSplash_ClientTitle, "", $hModernSplash_ClientTitle_Label_Build, 20 - (20 * $i / 255), 50 + (20 - (20 * $i / 255)))
		_WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientTitle, 0xFFEC00, $i)
		Sleep(Sin((90 * $i / 255) * ($PI / 180)) * 30)
	Next
	ControlMove($hModernSplash_ClientTitle, "", $hModernSplash_ClientTitle_Label, 0, 0)
	ControlMove($hModernSplash_ClientTitle, "", $hModernSplash_ClientTitle_Label_Build, 0, 50)
	_WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientTitle, 0xFFEC00, 255)
	Global $bModernSplash_Initiated = True
	_ModernSplash_AddText($sText, True)
	Return True
EndFunc   ;==>_ModernSplash_Initiate

Func _ModernSplash_CheckExit()
	Switch WinGetHandle("")
		Case $hModernSplash_ClientText, $hModernSplash_ClientTitle, $hModernSplash_Close,$hModernSplash_Dummy,$hModernSplash_Parent
			_ModernSplash_ExitGui()
	EndSwitch
EndFunc


Func _ModernSplash_DeInitiate()
	If Not $bModernSplash_Initiated Then Return SetError(1, 0, 0)
	HotKeySet("{ESC}")
	_ModernSplash_AddText("", False, True)
	Local $i
	For $i = 255 To 0 Step -15
		WinSetTrans($hModernSplash_Parent, "", $i)
		_WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientTitle, 0xFFEC00, $i)
		_WinAPI_SetLayeredWindowAttributes($hModernSplash_Close, 0xE2B100, $i)
		Sleep(10)
	Next
	GUIDelete($hModernSplash_ClientText)
	GUIDelete($hModernSplash_ClientTitle)
	GUIDelete($hModernSplash_Parent)
	Global $bModernSplash_Created = False
	Global $bModernSplash_Initiated = False
	Opt("GuiOnEventMode", $b_Opt_GuiOnEventMode)

EndFunc   ;==>_ModernSplash_DeInitiate

Func _ModernSplash_ExitGui()
	_ModernSplash_DeInitiate()
	If $hModernSplash_CallBack_Exit Then Call($hModernSplash_CallBack_Exit)
EndFunc


Func _ModernSplash_AddText($sText, $bFirst = False, $bLast = False)
	Local $i
	If Not $bModernSplash_Initiated Then Return SetError(1, 0, 0)
	If Not $bFirst Then
		For $i = 255 To 0 Step -20
			_WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientText, 0xFFEC00, $i)
			ControlMove($hModernSplash_ClientText, "", $hModernSplash_ClientText_Label, 0, 20 - (20 - (20 * $i / 255)))
			Sleep(Sin((90 * $i / 255) * ($PI / 180)) * 10)
		Next
		_WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientText, 0xFFEC00, 0)
	EndIf
	If Not $bLast Then
		GUICtrlSetData($hModernSplash_ClientText_Label, $sText)
		For $i = 0 To 255 Step 15
			_WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientText, 0xFFEC00, $i)
			ControlMove($hModernSplash_ClientText, "", $hModernSplash_ClientText_Label, 0, 40 - (20 * $i / 255))
			Sleep(Sin((90 * $i / 255) * ($PI / 180)) * 30)
		Next
		_WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientText, 0xFFEC00, 255)
	EndIf
EndFunc   ;==>_ModernSplash_AddText


Func __GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3) ; thanks gafrost
	Local $XS_pos, $XS_ret, $XS_ret2
	$XS_pos = WinGetPos($h_win)
	$XS_ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $XS_pos[2], "long", $XS_pos[3], "long", $i_x3, "long", $i_y3)
	If $XS_ret[0] Then
		$XS_ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $XS_ret[0], "int", 1)
	EndIf
EndFunc   ;==>__GuiRoundCorners

Func __PrimaryDown()
	_SendMessage($hModernSplash_Parent, $WM_SYSCOMMAND, 0xF012, 0);SC_DRAGMOVE
EndFunc   ;==>__PrimaryDown