Gdi+ Tutorial [Part 5]

  • Tehe ich fands auch erst komisch :D

    Spoiler anzeigen
    [autoit]

    Select
    Case _IsPressed(25)
    $x -= 1
    Case _IsPressed(26)
    $y -= 1
    Case _IsPressed(27)
    $x += 1
    Case _IsPressed(28)
    $y += 1
    EndSelect

    [/autoit]


    Wenn du damit Pfeil-Oben und dann Pfeil-Rechts drückst ist rechts geblockt

    So hingegen nicht

    Spoiler anzeigen
    [autoit]

    Select
    Case _IsPressed(25)
    $x -= $movespeed
    Case _IsPressed(27)
    $x += $movespeed
    Case _IsPressed(26)
    $y -= $movespeed
    Case _IsPressed(28)
    $y += $movespeed
    EndSelect

    [/autoit]

    MfG Hellboy

    PS: Front- und Backbuffer gehören nun mal zu den Basics (oder?) find`s aber echt nett das mit den TuT`s :thumbup:

    MfG hellboy

    [autoit]

    Do
    _help($user)
    Until $questions = 0

    [/autoit]

    Meine Werke:
    Ste`s Web-Radio

  • ja schwer ist es nicht aber ich weiss irgendwie nicht wie ich das erlären soll...

    Bis jetzt hab ich einfach so gschrieben was mir in den Sinn kam aber ich hänge gerade so ein bisschen.

    mfg Ubuntu

  • Wenn's einer kann dann du ^^
    Nur Mut ;)

    Spoiler anzeigen

    Grundkenntnisse in: C++, JavaScript
    Sehr gute Kenntnisse: PHP, JAVA, C und näturlich AutoIt


    Klaviatur, Anhang UDF, GDI+ Mühle

    Zitat

    "Wenn einen um 20h der Pizzadienst anruft und fragt, ob man's nur vergessen hat und ob man das gleiche
    möchte wie immer -- dann sollte man sein Bestellverhalten evtl überdenken"

  • Und wieder ein neuer Teil.

    Viel Spass damit
    (besonders hellboy :D )

    Vielen Dank auch an name22 der ein Beispiel geschrieben hat.
    Ich hab jetzt geschrieben wir haben eins gemacht da ich es ganz schön verändern musste ;)
    Ich hoffe das ist OK.
    Ich werde auf jeden Fall im verlauf des Tutorials nochmal darauf zurück kommen :thumbup:

    Wens interessiert hier das Beispiel von name

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $iX = 50
    $iY = 50
    $vX = 2
    $vY = 1

    [/autoit] [autoit][/autoit] [autoit]

    $iSleep = 10

    [/autoit] [autoit][/autoit] [autoit]

    $bBuffering = True

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Back- und Frontbuffer", 400, 440)
    $cBuffering = GUICtrlCreateCheckbox("Buffering", 5, 355)
    $cLabel = GUICtrlCreateLabel("Wartezeit zwischen den Frames: " & $iSleep, 5, 390)
    $cFramerate = GUICtrlCreateSlider(5, 410, 200, 20)
    $cApply = GUICtrlCreateButton("OK", 220, 400)
    GUICtrlSetLimit($cFramerate, 100, 10)
    GUICtrlSetState($cBuffering, $GUI_CHECKED)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics(400, 400, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)

    [/autoit] [autoit][/autoit] [autoit]

    $hBrushWhite = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    OnAutoItExitRegister("_Exit")

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlSetOnEvent($cBuffering, "_Buffering")
    GUICtrlSetOnEvent($cApply, "_ApplySettings")

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep($iSleep)
    $iX += $vX
    $iY += $vY
    If $iX >= 380 Or $iX <= 0 Then $vX *= -1
    If $iY >= 325 Or $iY <= 0 Then $vY *= -1

    [/autoit] [autoit][/autoit] [autoit]

    Switch $bBuffering
    Case True
    _GDIPlus_GraphicsFillRect($hBuffer, 0, 0, 400, 350, $hBrushWhite)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $iX, $iY, 20, 20)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 400, 400)
    Case False
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, 400, 350, $hBrushWhite)
    _GDIPlus_GraphicsFillEllipse($hGraphic, $iX, $iY, 20, 20)
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Buffering()
    $bBuffering = BitXOR($bBuffering, 1)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ApplySettings()
    $iSleep = GUICtrlRead($cFramerate)
    GUICtrlSetData($cLabel, "Wartezeit zwischen den Frames: " & $iSleep)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BrushDispose($hBrushWhite)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit]

    Der ganze Text ist aber by me ^^


    mfg Ubuntu

  • Zitat

    da ich es ganz schön verändern musste ;)
    Ich hoffe das ist OK.


    Selbstverständlich ;) .
    Aber mir gefiel meine Variante mit BitXOR besser :P.

    [autoit]

    $bBuffering = not $bBuffering

    [/autoit][autoit]

    $bBuffering = BitXOR($bBuffering, 1)

    [/autoit]
  • Sieht zwar professioneller aus, ist aber für Änfänger unverständlich ^^

    mfg Ubuntu

    Ps: Ansonsten hast du den Code übrigends auch sehr anfängerunfreundlich gebaut :P
    (ist aber kein Problem ;) )

  • So ich hab jetzt noch mal eine verdeutlichung zur X und Y achse hinzugefügt.

    mfg Ubuntu

  • Bei einigen AutoIt-Codes ist die Formatierung sehr schlecht...
    Ich hab sie mal verbessert:

    Beispiel bewegliches Viereck(ohne Buffer)
    [autoit]

    #include <GuiConstants.au3>
    #include <GdiPlus.au3>;das include
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_end") ; die Funktion _end am Ende des Scriptes ausführen

    [/autoit] [autoit][/autoit] [autoit]

    $x = 0;x und y deklarieren
    $y = 0

    [/autoit] [autoit][/autoit] [autoit]

    $Gui = GUICreate("Beispiel", 179, 163, 100,100)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup() ;Gdi starten

    [/autoit] [autoit][/autoit] [autoit]

    $figur = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\figur.gif")
    $height = _GDIPlus_ImageGetHeight($figur)
    $width = _GDIPlus_ImageGetWidth($figur)
    $verhaelnis = $height / $width
    $graphic = _GDIPlus_GraphicsCreateFromHWND($Gui)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    Select
    Case _IsPressed(25)
    $x -= 1
    Case _IsPressed(26)
    $y -= 1
    Case _IsPressed(27)
    $x += 1
    Case _IsPressed(28)
    $y += 1
    EndSelect

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawImageRect($graphic,$figur,$x,$y,20,20 * $verhaelnis) ;die Figur wird an der neuen Position gezeichnet
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _end();die Exit funktion
    _GDIPlus_GraphicsDispose($graphic);Grafik Objekt freigeben
    _GDIPlus_ImageDispose($figur);Bild Objekt freigeben
    _GDIPlus_Shutdown();Ressourcen freigeben
    EndFunc

    [/autoit]
    Beispiel bewegliches Viereck mit Buffer
    [autoit]

    #include <GuiConstants.au3>
    #include <GdiPlus.au3>;das include
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_end") ; die Funktion _end am Ende des Scriptes ausführen

    [/autoit] [autoit][/autoit] [autoit]

    $x = 0;x und y deklarieren
    $y = 0

    [/autoit] [autoit][/autoit] [autoit]

    $Gui = GUICreate("Beispiel", 179, 163, 100,100)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup() ;Gdi starten

    [/autoit] [autoit][/autoit] [autoit]

    $figur = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\figur.gif")
    $bk = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\bk.jpg")
    $height = _GDIPlus_ImageGetHeight($figur)
    $width = _GDIPlus_ImageGetWidth($figur)
    $verhaelnis = $height / $width
    $graphic = _GDIPlus_GraphicsCreateFromHWND($Gui)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics(179, 163, $graphic)
    $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    Select
    Case _IsPressed(25) and not $x <= 0; ------------- geändert -------------
    $x -= 3
    Case _IsPressed(26) and not $y <= 0; ------------- geändert -------------
    $y -= 3
    Case _IsPressed(27) and $x <= 160; ------------- geändert -------------
    $x += 3
    Case _IsPressed(28) and $y <= 125; ------------- geändert -------------
    $y += 3
    EndSelect

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawImageRect($buffer,$bk,0,0,179, 163)
    _GDIPlus_GraphicsDrawImageRect($buffer,$figur,$x,$y,20,20 * $verhaelnis)
    _GDIPlus_GraphicsDrawImage($graphic, $bitmap, 0, 0)
    Sleep(30)

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _end();die Exit funktion
    _GDIPlus_GraphicsDispose($graphic);Grafik Objekt freigeben
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_ImageDispose($figur);Bild Objekt 1 freigeben
    _GDIPlus_ImageDispose($bk);Bild Objekt 2 freigeben
    _GDIPlus_Shutdown();Ressourcen freigeben
    EndFunc

    [/autoit]
    Code kommentiert
    [autoit]

    #include <GUIConstants.au3>
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $iX = 50
    $iY = 50
    $vX = 2
    $vY = 1

    [/autoit] [autoit][/autoit] [autoit]

    $iSleep = 10
    $bBuffering = True

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Buffer", 400, 440)
    $cBuffering = GUICtrlCreateCheckbox("Buffering", 5, 355)
    $cLabel = GUICtrlCreateLabel("Wartezeit zwischen den Frames: " & $iSleep, 5, 390)
    $cFramerate = GUICtrlCreateSlider(5, 410, 200, 20)
    $cApply = GUICtrlCreateButton("OK", 220, 400)
    $cSmooth = GUICtrlCreateButton("Smooth", 220, 400)
    GUICtrlSetLimit($cFramerate, 100, 10)
    GUICtrlSetState($cBuffering, $GUI_CHECKED)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $kreis = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\kreis.png")
    $weiss = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\weiss.jpg")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd);noramle Grafik erstellen
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics(400, 400, $hGraphic);Buffer erstellen Schritt 1...
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap);...und 2

    [/autoit] [autoit][/autoit] [autoit]

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    OnAutoItExitRegister("_Exit")

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlSetOnEvent($cBuffering, "_Buffering")
    GUICtrlSetOnEvent($cApply, "_ApplySettings")

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep($iSleep)
    $iX += $vX
    $iY += $vY
    If $iX >= 380 Or $iX <= 0 Then $vX *= -1
    If $iY >= 325 Or $iY <= 0 Then $vY *= -1

    [/autoit] [autoit][/autoit] [autoit]

    Switch $bBuffering
    Case True
    _GDIPlus_GraphicsDrawImageRect($hBuffer,$weiss, 0, 0, 400,350);mit Buffer
    _GDIPlus_GraphicsDrawImageRect($hBuffer,$kreis,$iX,$iY,20,20)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 400, 400)
    Case False
    _GDIPlus_GraphicsDrawImageRect($hGraphic,$weiss, 0, 0, 400,350);ohne Buffer
    _GDIPlus_GraphicsDrawImageRect($hGraphic,$kreis,$iX,$iY,20,20)
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Buffering()
    $bBuffering = not $bBuffering ;wenn der hacken angeklickt wurde kehrt dieser Befehl die Variable ins Gegenteil
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ApplySettings()
    $iSleep = GUICtrlRead($cFramerate)
    GUICtrlSetData($cLabel, "Wartezeit zwischen den Frames: " & $iSleep)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit]
    Code unkommentiert
    [autoit]

    #include <GUIConstants.au3>
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $iX = 50
    $iY = 50
    $vX = 2
    $vY = 1

    [/autoit] [autoit][/autoit] [autoit]

    $iSleep = 10
    $bBuffering = True

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Buffer", 400, 440)
    $cBuffering = GUICtrlCreateCheckbox("Buffering", 5, 355)
    $cLabel = GUICtrlCreateLabel("Wartezeit zwischen den Frames: " & $iSleep, 5, 390)
    $cFramerate = GUICtrlCreateSlider(5, 410, 200, 20)
    $cApply = GUICtrlCreateButton("OK", 220, 400)
    $cSmooth = GUICtrlCreateButton("Smooth", 220, 400)
    GUICtrlSetLimit($cFramerate, 100, 10)
    GUICtrlSetState($cBuffering, $GUI_CHECKED)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $kreis = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\kreis.png")
    $weiss = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\weiss.jpg")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics(400, 400, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    OnAutoItExitRegister("_Exit")

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlSetOnEvent($cBuffering, "_Buffering")
    GUICtrlSetOnEvent($cApply, "_ApplySettings")

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep($iSleep)
    $iX += $vX
    $iY += $vY
    If $iX >= 380 Or $iX <= 0 Then $vX *= -1
    If $iY >= 325 Or $iY <= 0 Then $vY *= -1

    [/autoit] [autoit][/autoit] [autoit]

    Switch $bBuffering
    Case True
    _GDIPlus_GraphicsDrawImageRect($hBuffer,$weiss, 0, 0, 400,350)
    _GDIPlus_GraphicsDrawImageRect($hBuffer,$kreis,$iX,$iY,20,20)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 400, 400)
    Case False
    _GDIPlus_GraphicsDrawImageRect($hGraphic,$weiss, 0, 0, 400,350)
    _GDIPlus_GraphicsDrawImageRect($hGraphic,$kreis,$iX,$iY,20,20)
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Buffering()
    $bBuffering = not $bBuffering
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ApplySettings()
    $iSleep = GUICtrlRead($cFramerate)
    GUICtrlSetData($cLabel, "Wartezeit zwischen den Frames: " & $iSleep)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit]


    Na ja, spart dir ne Arbeit von 1,5 min ^^

    Spoiler anzeigen

    Grundkenntnisse in: C++, JavaScript
    Sehr gute Kenntnisse: PHP, JAVA, C und näturlich AutoIt


    Klaviatur, Anhang UDF, GDI+ Mühle

    Zitat

    "Wenn einen um 20h der Pizzadienst anruft und fragt, ob man's nur vergessen hat und ob man das gleiche
    möchte wie immer -- dann sollte man sein Bestellverhalten evtl überdenken"

  • @Cartan & @staykawaynight:
    Schön das es noch jemanden interessiert.
    Dann werden auch neue Teile kommen ^^

    @Cartan:
    Danke :thumbup: werds morgen einbauen. (formatierung hat sich einmal zerschossen als ich alles per zurück wieder herstellen musste)

    mfg Ubuntu