;Coded by UEZ 2009
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GDIPlus.au3>

Global Const $width = 640
Global Const $height = 480
Global Const $pi_div_180 = 4 * ATan(1) / 180
Global $graphics, $backbuffer, $bitmap, $Pen, $arrTxt1, $arrTxt2, $fontsize_txt1, $fontsize_txt2
Global $hBrush, $hFamily1, $hFamily2, $hFont1, $hFont2, $hFormat, $tLayout1, $tLayout2
Global $x1, $x2, $y1, $y2, $a, $b
Global  $i = 0, $j = 360, $m = 0, $n = 0
Global $radius_x, $radius_y
Global $title = "GDI+ Beispiel"

Opt("GUIOnEventMode", 1)
$hwnd = GUICreate($title, $width, $height, -1, -1, BitOR($WS_SYSMENU,$WS_DLGFRAME,$WS_POPUP))
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState()

_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 2)

$hBrush = _GDIPlus_BrushCreateSolid(0)
_GDIPlus_BrushSetSolidColor($hBrush, 0xFFF0F0F0)

$fontsize_txt1 = 48
$fontsize_txt2 = 24

$radius_x1 = ($width * 0.45) * 0.95
$radius_y1 = ($height * 0.45) * 0.95
$radius_x2 = ($width * 0.45) * 0.45
$radius_y2 = ($height * 0.45) * 0.45
$text1 = " Rotating Letters"
$text2 = " By UEZ ;-)"
$arrTxt1 = StringSplit($text1, "")
$arrTxt2 = StringSplit($text2, "")
Dim $arrX1[UBound($arrTxt1)]
Dim $arrY1[UBound($arrTxt1)]
Dim $arrX2[UBound($arrTxt2)]
Dim $arrY2[UBound($arrTxt2)]

$hFormat = _GDIPlus_StringFormatCreate()
$hFamily1 = _GDIPlus_FontFamilyCreate("Arial")
$hFamily2 = _GDIPlus_FontFamilyCreate("Comic Sans MS")
$hFont1 = _GDIPlus_FontCreate($hFamily1, $fontsize_txt1, 2)
$hFont2 = _GDIPlus_FontCreate($hFamily2, $fontsize_txt2, 2)
$tLayout1 = _GDIPlus_RectFCreate(0, 0)
$tLayout2 = _GDIPlus_RectFCreate(0, 0)
$a = 360 / (UBound($arrTxt1) - 1)
$b = 360 / (UBound($arrTxt2) - 1)

Do
	_GDIPlus_GraphicsClear($backbuffer, 0x90000000)
	For $x = 1 To UBound($arrTxt1) - 1
		$x1 = $width * 0.45 + Cos(($i + $m) * $pi_div_180) * $radius_x1
		$y1 = $height * 0.45 + Sin(($i + $m) * $pi_div_180) * $radius_y1 - $fontsize_txt1 / 4
		$arrX1[$x] = $x1
		$arrY1[$x] = $y1
		DllStructSetData($tLayout1, "x", $arrX1[$x])
		DllStructSetData($tLayout1, "y", $arrY1[$x])
		_GDIPlus_GraphicsDrawStringEx($backbuffer, $arrTxt1[$x], $hFont1, $tLayout1, $hFormat, $hBrush)
		$m += $a
	Next

	For $x = 1 To UBound($arrTxt2) - 1
		$x2 = $width * 0.45 + Cos(($j + $n) * $pi_div_180) * $radius_x2
		$y2 = $height * 0.45 + Sin(($j + $n) * $pi_div_180) * $radius_y2 - $fontsize_txt2 / 4
		$arrX2[$x] = $x2
		$arrY2[$x] = $y2
		DllStructSetData($tLayout2, "x", $arrX2[$x])
		DllStructSetData($tLayout2, "y", $arrY2[$x])
		_GDIPlus_GraphicsDrawStringEx($backbuffer, $arrTxt2[$x], $hFont2, $tLayout2, $hFormat, $hBrush)
		$n += $b
	Next

	_GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
	$i += 1
	If $i >= 360 Then
		$i = 0
		$m = 0
	EndIf
	$j -= 2
	If $j <= 0 Then
		$j = 360
		$n = 0
	EndIf
Until False * Not Sleep(30)

Func _GDIPlus_BrushSetSolidColor($hBrush, $iARGB = 0xFF000000)
	Local $aResult
	$aResult = DllCall($ghGDIPDll, "int", "GdipSetSolidFillColor", "hwnd", $hBrush, "int", $iARGB)
	If @error Then Return SetError(@error, @extended, 0)
	Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_BrushSetSolidColor

Func Close()
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_FontDispose($hFont1)
	_GDIPlus_FontDispose($hFont2)
	_GDIPlus_FontFamilyDispose($hFamily1)
	_GDIPlus_FontFamilyDispose($hFamily2)
	_GDIPlus_StringFormatDispose($hFormat)
	_GDIPlus_GraphicsDispose($backbuffer)
	_GDIPlus_BitmapDispose($bitmap)
	_GDIPlus_GraphicsDispose($graphics)
	_GDIPlus_Shutdown()
	WinClose($hwnd)
	Exit
EndFunc
