Sprenger120

GDI und _WinAPI_BitLit Beispiel (4 Quadrate)

Apr 26th, 2011
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.85 KB | None | 0 0
  1. #include <WinAPI.au3>
  2. #include <GDIPlus.au3>
  3. #include <Misc.au3>
  4. #include <WindowsConstants.au3>
  5. HotKeySet("{Esc}", "_Exit")
  6.  
  7. $hGUI = GUICreate("", 500, 500)
  8.  
  9. $hGUI_DC = _WinAPI_GetDC($hGUI)
  10.  
  11. $hBitmap = _WinAPI_CreateCompatibleBitmap($hGUI_DC, 500, 500)
  12. $hBitmapDC = _WinAPI_CreateCompatibleDC($hGUI_DC)
  13.  
  14. _WinAPI_SelectObject($hBitmapDC, $hBitmap)
  15.  
  16. GUISetState()
  17.  
  18. _GDIPlus_Startup()
  19. $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hBitmapDC)
  20. $hBrush_Schwarz = _GDIPlus_BrushCreateSolid()
  21. $hBrush_Weiss = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
  22. $hPen_Schwarz = _GDIPlus_PenCreate()
  23.  
  24.  
  25.  
  26.  
  27. Dim $aPositionen[4][5] = [[0, 0, 50, 50, 1], _
  28.         [200, 0, 50, 50, 1], _
  29.         [0, 200, 50, 50, 1], _
  30.         [200, 200, 50, 50, 1]]
  31.  
  32.  
  33.  
  34. Global $iFPS, $hTimer = TimerInit(), $MaxFPS = 100, $iSleep = 10, $FPSWert, $hDll = DllOpen("user32.dll")
  35.  
  36. While Sleep($iSleep)
  37.     _GDIPlus_GraphicsFillRect($hGraphics, 0, 0, 500, 500, $hBrush_Weiss)
  38.  
  39.     ;Zeichnen
  40.     For $x = 0 To UBound($aPositionen) - 1
  41.         Switch $aPositionen[$x][4]
  42.             Case 1
  43.                 _GDIPlus_GraphicsFillRect($hGraphics, $aPositionen[$x][0], $aPositionen[$x][1], $aPositionen[$x][2], $aPositionen[$x][3], $hBrush_Schwarz)
  44.             Case 0
  45.                 _GDIPlus_GraphicsDrawRect($hGraphics, $aPositionen[$x][0], $aPositionen[$x][1], $aPositionen[$x][2], $aPositionen[$x][3], $hPen_Schwarz)
  46.         EndSwitch
  47.     Next
  48.     _WinAPI_BitBlt($hGUI_DC, 0, 0, 500, 500, $hBitmapDC, 0, 0, $SRCCOPY)
  49.  
  50.     $iFPS += 1
  51.     ;FPS Control
  52.     $FPSWert = Int($iFPS / (TimerDiff($hTimer) / 1000))
  53.     WinSetTitle($hGUI, "", "FPS:" & $FPSWert)
  54.     If $FPSWert > $MaxFPS Then
  55.         $iSleep += 5
  56.     EndIf
  57.     If $FPSWert < $MaxFPS Then
  58.         $iSleep -= 5
  59.         If $iSleep < 0 Then $iSleep = 0
  60.     EndIf
  61.  
  62.     If Not _IsPressed("01", $hDll) Then ContinueLoop ;Wenn die Linke Maustaste nicht gedrückt wurde
  63.     While _IsPressed("01", $hDll);Warten bis Maustaste losgelassen wird   (sonst flackern die Quadrate)
  64.         Sleep(10)
  65.     WEnd
  66.     $aCoords = GUIGetCursorInfo() ; Maus Koordinaten relativ zur GUI hohlen
  67.     If @error Then ContinueLoop
  68.  
  69.     For $x = 0 To UBound($aPositionen) - 1 ;Prüfen ob Coordinaten sich in einem Dreieck befinden
  70.         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]
  71.     Next
  72.  
  73. WEnd
  74.  
  75.  
  76. Func _Exit()
  77.     _GDIPlus_PenDispose($hPen_Schwarz)
  78.     _GDIPlus_BrushDispose($hBrush_Schwarz)
  79.     _GDIPlus_BrushDispose($hBrush_Weiss)
  80.     _GDIPlus_GraphicsDispose($hGraphics)
  81.     _GDIPlus_Shutdown()
  82.     _WinAPI_ReleaseDC($hGUI, $hGUI_DC)
  83.     _WinAPI_DeleteObject($hBitmap)
  84.     _WinAPI_DeleteDC($hBitmapDC)
  85.     DllClose($hDll)
  86.     Exit
  87. EndFunc   ;==>_Exit
  88.  
  89. Func _RectCollision($iX1, $iY1, $iWidth1, $iHeight1, $iX2, $iY2, $iWidth2, $iHeight2)
  90.     ;Author: Faweyr
  91.     Return $iX1 + $iWidth1 > $iX2 And $iX1 < $iX2 + $iWidth2 And $iY1 + $iHeight1 > $iY2 And $iY1 < $iY2 + $iHeight2
  92. EndFunc   ;==>_RectCollision
Advertisement
Add Comment
Please, Sign In to add comment