Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WinAPI.au3>
- #include <GDIPlus.au3>
- #include <Misc.au3>
- #include <WindowsConstants.au3>
- HotKeySet("{Esc}", "_Exit")
- $hGUI = GUICreate("", 500, 500)
- $hGUI_DC = _WinAPI_GetDC($hGUI)
- $hBitmap = _WinAPI_CreateCompatibleBitmap($hGUI_DC, 500, 500)
- $hBitmapDC = _WinAPI_CreateCompatibleDC($hGUI_DC)
- _WinAPI_SelectObject($hBitmapDC, $hBitmap)
- GUISetState()
- _GDIPlus_Startup()
- $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hBitmapDC)
- $hBrush_Schwarz = _GDIPlus_BrushCreateSolid()
- $hBrush_Weiss = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
- $hPen_Schwarz = _GDIPlus_PenCreate()
- Dim $aPositionen[4][5] = [[0, 0, 50, 50, 1], _
- [200, 0, 50, 50, 1], _
- [0, 200, 50, 50, 1], _
- [200, 200, 50, 50, 1]]
- Global $iFPS, $hTimer = TimerInit(), $MaxFPS = 100, $iSleep = 10, $FPSWert, $hDll = DllOpen("user32.dll")
- While Sleep($iSleep)
- _GDIPlus_GraphicsFillRect($hGraphics, 0, 0, 500, 500, $hBrush_Weiss)
- ;Zeichnen
- For $x = 0 To UBound($aPositionen) - 1
- Switch $aPositionen[$x][4]
- Case 1
- _GDIPlus_GraphicsFillRect($hGraphics, $aPositionen[$x][0], $aPositionen[$x][1], $aPositionen[$x][2], $aPositionen[$x][3], $hBrush_Schwarz)
- Case 0
- _GDIPlus_GraphicsDrawRect($hGraphics, $aPositionen[$x][0], $aPositionen[$x][1], $aPositionen[$x][2], $aPositionen[$x][3], $hPen_Schwarz)
- EndSwitch
- Next
- _WinAPI_BitBlt($hGUI_DC, 0, 0, 500, 500, $hBitmapDC, 0, 0, $SRCCOPY)
- $iFPS += 1
- ;FPS Control
- $FPSWert = Int($iFPS / (TimerDiff($hTimer) / 1000))
- WinSetTitle($hGUI, "", "FPS:" & $FPSWert)
- If $FPSWert > $MaxFPS Then
- $iSleep += 5
- EndIf
- If $FPSWert < $MaxFPS Then
- $iSleep -= 5
- If $iSleep < 0 Then $iSleep = 0
- EndIf
- If Not _IsPressed("01", $hDll) Then ContinueLoop ;Wenn die Linke Maustaste nicht gedrückt wurde
- While _IsPressed("01", $hDll);Warten bis Maustaste losgelassen wird (sonst flackern die Quadrate)
- Sleep(10)
- WEnd
- $aCoords = GUIGetCursorInfo() ; Maus Koordinaten relativ zur GUI hohlen
- If @error Then ContinueLoop
- For $x = 0 To UBound($aPositionen) - 1 ;Prüfen ob Coordinaten sich in einem Dreieck befinden
- If _RectCollision($aCoords[0], $aCoords[1], 0, 0, $aPositionen[$x][0], $aPositionen[$x][1], $aPositionen[$x][2], $aPositionen[$x][3]) Then $aPositionen[$x][4] = Not $aPositionen[$x][4]
- Next
- WEnd
- Func _Exit()
- _GDIPlus_PenDispose($hPen_Schwarz)
- _GDIPlus_BrushDispose($hBrush_Schwarz)
- _GDIPlus_BrushDispose($hBrush_Weiss)
- _GDIPlus_GraphicsDispose($hGraphics)
- _GDIPlus_Shutdown()
- _WinAPI_ReleaseDC($hGUI, $hGUI_DC)
- _WinAPI_DeleteObject($hBitmap)
- _WinAPI_DeleteDC($hBitmapDC)
- DllClose($hDll)
- Exit
- EndFunc ;==>_Exit
- Func _RectCollision($iX1, $iY1, $iWidth1, $iHeight1, $iX2, $iY2, $iWidth2, $iHeight2)
- ;Author: Faweyr
- Return $iX1 + $iWidth1 > $iX2 And $iX1 < $iX2 + $iWidth2 And $iY1 + $iHeight1 > $iY2 And $iY1 < $iY2 + $iHeight2
- EndFunc ;==>_RectCollision
Advertisement
Add Comment
Please, Sign In to add comment