#include <GDIP.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "_Exit")

Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()

Global $iWidth = @DesktopWidth
Global $iHeight = @DesktopHeight
Global $iSize = 150
Global $fArea = 0.2

Global $hGui = GUICreate("Black Hole", $iWidth, $iHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0xABCDEF)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState()
_WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF, 255, 0x1)

Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFFABCDEF)

Global $hBrush = _CreateBrush()

GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")

_WinAPI_ShowCursor(False)
While 1
	_Draw()
	Sleep(10)
WEnd

Func _Draw()
	Local $aPos = MouseGetPos()
	$aPos[0] -= $iSize / 2
	$aPos[1] -= $iSize / 2
	_GDIPlus_GraphicsClear($hGfxBuffer, 0xFFABCDEF)

	Local $hBmp = _ScreenCapture_Capture("", $aPos[0], $aPos[1], $aPos[0] + $iSize, $aPos[1] + $iSize, False)
	Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
	_WinAPI_DeleteObject($hBmp)
	Local $hTexture = _GDIPlus_TextureCreate($hBitmap)
	_GDIPlus_BitmapDispose($hBitmap)

	$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iSize, $iSize, $hGraphics)
	Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

	Local $fScale = 1
	Local $hMatrix = _GDIPlus_MatrixCreate()

	_GDIPlus_GraphicsFillEllipse($hContext, 0, 0, $iSize, $iSize, $hTexture)
	_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)

	Local $fTmp = 0
	For $i = 2 To Floor($iSize / 2)
		$fTmp = $i * ($iSize * $fArea) / ($iSize / 2) * 2.6
		$fScale = (($iSize - $fTmp) / ($iSize - $i * 2))

		_GDIPlus_MatrixSetElements($hMatrix, 1, 0, 0, 1, 0, 0)
		_GDIPlus_MatrixTranslate($hMatrix, $iSize / 2, $iSize / 2)
		_GDIPlus_MatrixScale($hMatrix, $fScale, $fScale)
		_GDIPlus_MatrixRotate($hMatrix, $fScale)
		_GDIPlus_MatrixTranslate($hMatrix, -$iSize / 2, -$iSize / 2)
		_GDIPlus_GraphicsSetTransform($hContext, $hMatrix)
		_GDIPlus_GraphicsFillEllipse($hContext, $i, $i, $iSize - $i * 2, $iSize - $i * 2, $hTexture)
	Next

	_GDIPlus_MatrixSetElements($hMatrix, 1, 0, 0, 1, 0, 0)
	_GDIPlus_GraphicsSetTransform($hContext, $hMatrix)

	_GDIPlus_GraphicsFillRect($hContext, 0, 0, $iSize, $iSize, $hBrush)

	_GDIPlus_MatrixDispose($hMatrix)
	_GDIPlus_BrushDispose($hTexture)

	_GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBitmap, $aPos[0] - 1, $aPos[1] + 1)

	_GDIPlus_GraphicsDispose($hContext)
	_GDIPlus_BitmapDispose($hBitmap)
	_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
EndFunc   ;==>_Draw


Func _CreateBrush()
	Local $fTmp = $iSize * $fArea
	Local $hPath = _GDIPlus_PathCreate()
	_GDIPlus_PathAddEllipse($hPath, $fTmp, $fTmp, $iSize - $fTmp * 2, $iSize - $fTmp * 2)

	Local $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath)
	_GDIPlus_PathBrushSetCenterColor($hBrush, 0xFF000000)
	Local $aColor[2] = [1, 0x00000000]
	_GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aColor)
	_GDIPlus_PathBrushSetFocusScales($hBrush, 0.7, 0.7)
	_GDIPlus_PathBrushSetGammaCorrection($hBrush, True)
	_GDIPlus_PathDispose($hPath)

	Return $hBrush
EndFunc   ;==>_CreateBrush


Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
	_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

Func WM_ERASEBKGND($hWnd, $uMsgm, $wParam, $lParam)
	_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
	Return True
EndFunc   ;==>WM_ERASEBKGND

Func _Exit()
	_WinAPI_ShowCursor(True)
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_GraphicsDispose($hGfxBuffer)
	_GDIPlus_BitmapDispose($hBmpBuffer)
	_GDIPlus_GraphicsDispose($hGraphics)
	_GDIPlus_Shutdown()
	Exit
EndFunc   ;==>_Exit