Nach langer Pause hab ich mich mal wieder mit GDI+ gespielt.
viel Vergnügen!
autoit.de/wcf/attachment/15295/
Spoiler anzeigen
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]Global $iWidth = 500
Global $iHeight = 400
Global $iStyle = $GUI_SS_DEFAULT_GUI, $iExStyle = 0, $iX = -1, $iY = -1
If MsgBox(4, "Fullscreen?", "Fullscreen?") = 6 Then
$iWidth = @DesktopWidth
$iHeight = @DesktopHeight
$iStyle = $WS_POPUP
$iExStyle = $WS_EX_TOPMOST
$iX = 0
$iY = 0
_WinAPI_ShowCursor(False)
EndIf
Global $iPlanes = 16
Global $iLines = 32
Global $iCount = $iPlanes * $iLines
Global $fPersp = 0.04
Global $fSpeed = 0.2
Global $hMatrix_Speed = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix_Speed, 0, $fSpeed)
Global $tWarp_V = DllStructCreate("float[8];")
Global $pWarp_V = DllStructGetPtr($tWarp_V)
DllStructSetData($tWarp_V, 1, 0, 1)
DllStructSetData($tWarp_V, 1, $iHeight, 2)
DllStructSetData($tWarp_V, 1, 0, 3)
DllStructSetData($tWarp_V, 1, 0, 4)
DllStructSetData($tWarp_V, 1, ($iWidth / 2) - ($iWidth * $fPersp), 5)
DllStructSetData($tWarp_V, 1, ($iHeight / 2) + ($iHeight * $fPersp), 6)
DllStructSetData($tWarp_V, 1, ($iWidth / 2) - ($iWidth * $fPersp), 7)
DllStructSetData($tWarp_V, 1, ($iHeight / 2) - ($iHeight * $fPersp),
Global $tWarp_H = DllStructCreate("float[8];")
Global $pWarp_H = DllStructGetPtr($tWarp_H)
DllStructSetData($tWarp_H, 1, $iWidth, 1)
DllStructSetData($tWarp_H, 1, $iHeight, 2)
DllStructSetData($tWarp_H, 1, 0, 3)
DllStructSetData($tWarp_H, 1, $iHeight, 4)
DllStructSetData($tWarp_H, 1, ($iWidth / 2) + ($iWidth * $fPersp), 5)
DllStructSetData($tWarp_H, 1, ($iHeight / 2) + ($iHeight * $fPersp), 6)
DllStructSetData($tWarp_H, 1, ($iWidth / 2) - ($iWidth * $fPersp), 7)
DllStructSetData($tWarp_H, 1, ($iHeight / 2) + ($iHeight * $fPersp),
Global $tData = DllStructCreate("int Count; ptr Points; ptr Types;")
Global $pData = DllStructGetPtr($tData)
Global $tData_P = DllStructCreate("float[" & $iCount * 2 & "]")
Global $pData_P = DllStructGetPtr($tData_P)
Global $tData_T = DllStructCreate("ubyte[" & $iCount & "]")
Global $pData_T = DllStructGetPtr($tData_T)
DllStructSetData($tData, "Count", $iCount)
DllStructSetData($tData, "Points", $pData_P)
DllStructSetData($tData, "Types", $pData_T)
Global $tPoints_V = DllStructCreate("float[" & $iCount * 2 & "];")
Global $pPoints_V = DllStructGetPtr($tPoints_V)
For $j = 0 To $iLines - 1
DllStructSetData($tPoints_V, 1, Random(-300, 300), $j * 2 + 1)
DllStructSetData($tPoints_V, 1, 0, $j * 2 + 2)
Next
For $i = 1 To $iPlanes - 1
For $j = 0 To $iLines - 1
DllStructSetData($tPoints_V, 1, _CalcNewPoint(DllStructGetData($tPoints_V, 1, (($i - 1) * $iLines + $j) * 2 + 1)), ($i * $iLines + $j) * 2 + 1)
DllStructSetData($tPoints_V, 1, $i, ($i * $iLines + $j) * 2 + 2)
Next
Next
Global $tPoints_H = DllStructCreate("float[" & $iCount * 2 & "];")
Global $pPoints_H = DllStructGetPtr($tPoints_H)
For $j = 0 To $iLines - 1
DllStructSetData($tPoints_H, 1, Random(-300, 300), $j * 2 + 1)
DllStructSetData($tPoints_H, 1, 0, $j * 2 + 2)
Next
For $i = 1 To $iPlanes - 1
For $j = 0 To $iLines - 1
DllStructSetData($tPoints_H, 1, _CalcNewPoint(DllStructGetData($tPoints_H, 1, (($i - 1) * $iLines + $j) * 2 + 1)), ($i * $iLines + $j) * 2 + 1)
DllStructSetData($tPoints_H, 1, $i, ($i * $iLines + $j) * 2 + 2)
Next
Next
Global $tWarped_H = DllStructCreate("float[" & $iCount * 2 & "];")
Global $pWarped_H = DllStructGetPtr($tWarped_H)
Global $tWarped_V = DllStructCreate("float[" & $iCount * 2 & "];")
Global $pWarped_V = DllStructGetPtr($tWarped_V)
Global $hGui = GUICreate("GDI+ Script by Eukalyptus", $iWidth, $iHeight, $iX, $iY, $iStyle, $iExStyle)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
Global $hDC = _WinAPI_GetDC($hGui)
Global $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
Global $hBmpTmp = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
_WinAPI_DeleteObject($hBMP)
$hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmpTmp)
_GDIPlus_BitmapDispose($hBmpTmp)
Global $hCDC = _WinAPI_CreateCompatibleDC($hDC)
Global $hOBJ = _WinAPI_SelectObject($hCDC, $hBMP)
Global $hGfxBuffer = _GDIPlus_GraphicsCreateFromHDC($hCDC)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)
Global $hPen = _GDIPlus_PenCreate(0xFF005500, 1)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_PAINT")
GUISetState()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]While 1
Select
Case _IsPressed("25")
_Move_H(0.5)
Case _IsPressed("27")
_Move_H(-0.5)
Case _IsPressed("26")
_Move_V(0.5)
Case _IsPressed("28")
_Move_V(-0.5)
EndSelect
_Draw()
Sleep(10)
WEnd
Func _Move_H($fMove)
Local $hMatrix = _GDIPlus_MatrixCreate()
DllCall($ghGDIPDll, "uint", "GdipShearMatrix", "hwnd", $hMatrix, "float", $fMove, "float", 0, "int", 0)
DllCall($ghGDIPDll, "uint", "GdipTransformMatrixPoints", "hwnd", $hMatrix, "ptr", $pPoints_H, "int", $iCount)
_GDIPlus_MatrixDispose($hMatrix)
EndFunc ;==>_Move_H
Func _Move_V($fMove)
Local $hMatrix = _GDIPlus_MatrixCreate()
DllCall($ghGDIPDll, "uint", "GdipShearMatrix", "hwnd", $hMatrix, "float", $fMove, "float", 0, "int", 0)
DllCall($ghGDIPDll, "uint", "GdipTransformMatrixPoints", "hwnd", $hMatrix, "ptr", $pPoints_V, "int", $iCount)
_GDIPlus_MatrixDispose($hMatrix)
EndFunc ;==>_Move_V
Func _CalcNewPoint($fOld)
Local $fTmp
Do
$fTmp = Random(-30, 30)
Until Abs($fOld + $fTmp) < 300; And Abs($fX + $fTmp) > 10
Return $fOld + $fTmp
EndFunc ;==>_CalcNewPoint
Func _Draw()
DllCall($ghGDIPDll, "uint", "GdipTransformMatrixPoints", "hwnd", $hMatrix_Speed, "ptr", $pPoints_H, "int", $iCount)
DllCall($ghGDIPDll, "uint", "GdipTransformMatrixPoints", "hwnd", $hMatrix_Speed, "ptr", $pPoints_V, "int", $iCount)
If DllStructGetData($tPoints_H, 1, 2) >= 1 Then
Local $fX, $fTmp
DllCall("kernel32.dll", "none", "RtlMoveMemory", "ptr", $pPoints_H + ($iLines * 8), "ptr", $pPoints_H, "ulong_ptr", DllStructGetSize($tPoints_H) - ($iLines * 8))
For $i = 1 To $iLines
DllStructSetData($tPoints_H, 1, _CalcNewPoint(DllStructGetData($tPoints_H, 1, ($i - 1) * 2 + 1)), ($i - 1) * 2 + 1)
DllStructSetData($tPoints_H, 1, 0, ($i - 1) * 2 + 2)
Next
DllCall("kernel32.dll", "none", "RtlMoveMemory", "ptr", $pPoints_V + ($iLines * 8), "ptr", $pPoints_V, "ulong_ptr", DllStructGetSize($tPoints_V) - ($iLines * 8))
For $i = 1 To $iLines
DllStructSetData($tPoints_V, 1, _CalcNewPoint(DllStructGetData($tPoints_V, 1, ($i - 1) * 2 + 1)), ($i - 1) * 2 + 1)
DllStructSetData($tPoints_V, 1, 0, ($i - 1) * 2 + 2)
Next
EndIf
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
Local $hPath_Temp = $aResult[2]
DllCall($ghGDIPDll, "uint", "GdipAddPathLine2", "hwnd", $hPath_Temp, "ptr", $pPoints_V, "int", $iCount)
Local $fOff = DllStructGetData($tPoints_H, 1, 2)
[/autoit] [autoit][/autoit] [autoit]DllCall($ghGDIPDll, "uint", "GdipGetPathData", "hwnd", $hPath_Temp, "ptr", $pData)
[/autoit] [autoit][/autoit] [autoit]Local $fX1, $fY1, $fX2, $fY2
For $i = 1 To $iLines
$fX1 = DllStructGetData($tData_P, 1, ($iLines + $i - 1) * 2 + 1)
$fY1 = DllStructGetData($tData_P, 1, ($iLines + $i - 1) * 2 + 2)
$fX2 = DllStructGetData($tData_P, 1, ($i - 1) * 2 + 1)
$fY2 = DllStructGetData($tData_P, 1, ($i - 1) * 2 + 2)
DllStructSetData($tData_P, 1, $fX1 + ($fX2 - $fX1) * $fOff, ($i - 1) * 2 + 1)
DllStructSetData($tData_P, 1, $fY1 + ($fY2 - $fY1) * $fOff, ($i - 1) * 2 + 2)
Next
$aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath2", "ptr", $pData_P, "ptr", $pData_T, "int", $iCount, "int", 0, "int*", 0)
Local $hPath_V = $aResult[5]
DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPath_V, "hwnd", 0, "ptr", $pWarp_V, "int", 4, "float", -50, "float", 2, "float", 100, "float", $iPlanes, "int", 0, "float", 0)
[/autoit] [autoit][/autoit] [autoit]DllCall($ghGDIPDll, "uint", "GdipResetPath", "hwnd", $hPath_Temp)
DllCall($ghGDIPDll, "uint", "GdipAddPathLine2", "hwnd", $hPath_Temp, "ptr", $pPoints_H, "int", $iCount)
DllCall($ghGDIPDll, "uint", "GdipGetPathData", "hwnd", $hPath_Temp, "ptr", $pData)
[/autoit] [autoit][/autoit] [autoit]For $i = 1 To $iLines
$fX1 = DllStructGetData($tData_P, 1, ($iLines + $i - 1) * 2 + 1)
$fY1 = DllStructGetData($tData_P, 1, ($iLines + $i - 1) * 2 + 2)
$fX2 = DllStructGetData($tData_P, 1, ($i - 1) * 2 + 1)
$fY2 = DllStructGetData($tData_P, 1, ($i - 1) * 2 + 2)
DllStructSetData($tData_P, 1, $fX1 + ($fX2 - $fX1) * $fOff, ($i - 1) * 2 + 1)
DllStructSetData($tData_P, 1, $fY1 + ($fY2 - $fY1) * $fOff, ($i - 1) * 2 + 2)
Next
$aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath2", "ptr", $pData_P, "ptr", $pData_T, "int", $iCount, "int", 0, "int*", 0)
Local $hPath_H = $aResult[5]
DllCall($ghGDIPDll, "uint", "GdipWarpPath", "hwnd", $hPath_H, "hwnd", 0, "ptr", $pWarp_H, "int", 4, "float", -50, "float", 2, "float", 100, "float", $iPlanes, "int", 0, "float", 0)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]DllCall($ghGDIPDll, "uint", "GdipGetPathPoints", "hwnd", $hPath_H, "ptr", $pWarped_H, "int", $iCount)
DllCall($ghGDIPDll, "uint", "GdipGetPathPoints", "hwnd", $hPath_V, "ptr", $pWarped_V, "int", $iCount)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFF040008)
For $i = $iPlanes - 2 To 0 Step -1
_GDIPlus_PenSetWidth($hPen, _CalcPenW(DllStructGetData($tPoints_H, 1, ($i * $iLines) * 2 + 2), $iPlanes, 2))
_GDIPlus_PenSetColor($hPen, BitOR(BitShift(0xFF - ($i * 0xFF / $iPlanes), -24), BitShift(0xFF - ($i * 0xFF / $iPlanes), -16), ($i * 0xFF / $iPlanes)))
For $j = 0 To $iLines - 1
$fX1 = DllStructGetData($tWarped_H, 1, ($i * $iLines + $j) * 2 + 1)
$fY1 = DllStructGetData($tWarped_V, 1, ($i * $iLines + $j) * 2 + 2)
$fX2 = DllStructGetData($tWarped_H, 1, (($i + 1) * $iLines + $j) * 2 + 1)
$fY2 = DllStructGetData($tWarped_V, 1, (($i + 1) * $iLines + $j) * 2 + 2)
DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $hGfxBuffer, "handle", $hPen, "float", $fX1, "float", $fY1, "float", $fX2, "float", $fY2)
Next
Next
DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath_V)
DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath_H)
DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath_Temp)
_WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $hCDC, 0, 0, 0x00CC0020)
EndFunc ;==>_Draw
Func _CalcPenW($fVal, $iRange, $iMax)
Local $fW = (Log($iRange * 2) - Log($fVal + 1)) * $iMax
Return $fW
EndFunc ;==>_CalcPenW
Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
_WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $hCDC, 0, 0, 0x00CC0020)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_PAINT
Func _Exit()
_GDIPlus_MatrixDispose($hMatrix_Speed)
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGfxBuffer)
_WinAPI_SelectObject($hCDC, $hOBJ)
_WinAPI_DeleteObject($hBMP)
_WinAPI_DeleteDC($hCDC)
_WinAPI_ReleaseDC($hGui, $hDC)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>_Exit
E
Edit.: sollte nun auch auf älteren AutoIt Versionen laufen...