Gdi+ Tutorial [Part 5]

  • Nochmals Danke für das Lob.

    Die einführung in die Spieleentwicklung wird auch eher kurz sein da ja jedes Spiel eine andere "Engine" hat.

    mfg Ubuntu

  • Super vielen Dank für das Tut :D
    Habe ich mir schon seit längerem gewünscht.
    Es ist auch gut das du direkt am Anfang anfängst da ich noch nie mir GDI PLus in berührung gekommen bin und jetzt damit anfange

    Weiter so ! :)

    clonker

  • Da ich keinen neuen Thread aufmachen wollte, schreib ich das hier rein:

    GDI+ Tut: Auf einem transparentem Fenster zeichnen:

    Script
    [autoit]

    #include <GDIPlus.au3>

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

    Opt("GUIOnEventMode", 1)

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

    Global $hWnd, $hGraphic, $hBitmap, $backbuffer
    Global $ScreenDc, $dc, $tSize, $pSize, $tSource, $pSource, $tBlend, $pBlend, $tPoint, $pPoint, $gdibitmap
    Global $title = "GDI+ Beispiel: Transparentes Fenster", _
    $width = 150, _
    $height = 150

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

    _StartUp()

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

    _GDIPlus_GraphicsDrawRoundedRect($backbuffer, 0, 0, $width - 1, $height - 1, 15)

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

    _UpDate()

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

    While 1
    Sleep(100)
    WEnd

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

    Func _StartUp()
    $hWnd = GUICreate($title, $width, $height, -1, -1, 0x80000000, BitOR(0x00000080, 0x00080000, 0x00000008))
    GUISetOnEvent(-3, "_ShutDown")
    GUISetState()

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

    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $backbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)

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

    $ScreenDc = _WinAPI_GetDC($hWnd)
    $dc = _WinAPI_CreateCompatibleDC($ScreenDc)

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

    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $width)
    DllStructSetData($tSize, "Y", $height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", 255)
    DllStructSetData($tBlend, "Format", 1)
    $tPoint = DllStructCreate($tagPOINT)
    $pPoint = DllStructGetPtr($tPoint)
    DllStructSetData($tPoint, "X", 0)
    DllStructSetData($tPoint, "Y", 0)
    EndFunc

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

    Func _ShutDown()
    _WinAPI_DeleteDC($dc)
    _WinAPI_ReleaseDC($hWnd, $ScreenDc)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hWnd)
    Exit
    EndFunc

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

    Func _UpDate()
    $gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_SelectObject($dc, $gdibitmap)
    _WinAPI_UpdateLayeredWindow($hWnd, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 2)
    _WinAPI_DeleteObject($gdibitmap)
    EndFunc

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

    Func _GDIPlus_GraphicsDrawRoundedRect($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius = 30, $Pen = "")
    _GDIPlus_GraphicsDrawArc($hGraphics, $iX, $iY, $iRadius, $iRadius, 180, 90, $Pen)
    _GDIPlus_GraphicsDrawArc($hGraphics, $iX + $iWidth - $iRadius, $iY, $iRadius, $iRadius, 270, 90, $Pen)
    _GDIPlus_GraphicsDrawArc($hGraphics, $iX, $iY + $iHeight - $iRadius, $iRadius, $iRadius, 90, 90, $Pen)
    _GDIPlus_GraphicsDrawArc($hGraphics, $iX + $iWidth - $iRadius, $iY + $iHeight - $iRadius, $iRadius, $iRadius, 360, 90, $Pen)

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

    _GDIPlus_GraphicsDrawLine($hGraphics, $iX + $iRadius / 2, $iY, $iX + $iWidth - $iRadius / 2, $iY, $Pen)
    _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY + $iRadius / 2, $iX, $iY + $iHeight - $iRadius / 2, $Pen)
    _GDIPlus_GraphicsDrawLine($hGraphics, $iX + $iRadius / 2, $iY + $iHeight, $iX + $iWidth - $iRadius / 2, $iY + $iHeight, $Pen)
    _GDIPlus_GraphicsDrawLine($hGraphics, $iX + $iWidth, $iY + $iRadius / 2, $iX + $iWidth, $iY + $iHeight - $iRadius / 2, $Pen)
    EndFunc

    [/autoit]

    Das gute daran, auf einem transparentem Fenster zu zeichnen ist, dass man nicht immer neuzeichnen muss.
    Das heißt:
    Wenn man am Anfang vom Script, nach dem Aufruf von _StartUp() was in den Buffer zeichnet, bleibt das solange am Bildschirm, bis man die Graphic mit _GDIPlus_GraphicsClear($backbuffer, 0x00000000) leert, oder das Script beendet.

    Zitat

    [Heute, 11:39] Raupi: Soll ich es dir machen?
    [Heute, 11:47] BugFix: "Soll ich es dir machen? " - also Raupi !! bitte nicht so öffentlich :rofl:

    Zitat

    [Heute, 11:51] BugFix: und ich werde es mir jetzt machen - das Mittagessen :P

    AMsg UDF v1.00.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%
    OwnStyle UDF Version 1.10.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%

    Einmal editiert, zuletzt von H2112 (30. Mai 2010 um 11:22)

  • @All:
    Danke für das Lob, freut mich wenn ich euch helfen könnte. :)

    @H1221:
    Wenns passt werde ich das vielleicht noch aufnehmen.
    (Natürlich nur wenn du willst und natürlich wüdest du dann auch in den Cedits stehen.)

    mfg Ubuntu

  • @All:
    @H1221:
    Wenns passt werde ich das vielleicht noch aufnehmen.
    (Natürlich nur wenn du willst und natürlich wüdest du dann auch in den Cedits stehen.)

    Natürlich darfst du das übernehmen, habs ja nur deswegen geschrieben. ;)

    Zitat

    [Heute, 11:39] Raupi: Soll ich es dir machen?
    [Heute, 11:47] BugFix: "Soll ich es dir machen? " - also Raupi !! bitte nicht so öffentlich :rofl:

    Zitat

    [Heute, 11:51] BugFix: und ich werde es mir jetzt machen - das Mittagessen :P

    AMsg UDF v1.00.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%
    OwnStyle UDF Version 1.10.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%

  • Neuer Teil ist hochgeladen.

    Hat jemand Lust ein mini Tut über den Buffer zu schreiben ?

    mfg Ubuntu

  • Sehr schön
    was mich auch noch interressieren würde ist , wie man einen farbverlauf erstellt und coole buttons

  • Mit der GDIP.au3

    Spoiler anzeigen
    [autoit]


    Func _GDIPlus_BrushCreateLinear($iX1, $iY1, $iX2, $iY2, $iARGB1 = 0xFF000000, $iARGB2 = 0xFFFFFFFF)
    Local $aResult, $start, $end, $sPoint, $ePoint

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

    $start = DllStructCreate("int X;int Y")
    DllStructSetData($start, "X", $iX1)
    DllStructSetData($start, "Y", $iY1)
    $sPoint = DllStructGetPtr($start)

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

    $end = DllStructCreate("int X;int Y")
    DllStructSetData($end, "X", $iX2)
    DllStructSetData($end, "Y", $iY2)
    $ePoint = DllStructGetPtr($end)

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

    $aResult = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushI", "ptr", $sPoint, "ptr", $ePoint, "int", $iARGB1, "int", $iARGB2, "int", 0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)

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

    Return SetError(0, $aResult[0], $aResult[6])
    EndFunc ;==>_GDIPlus_BrushCreateLinear

    [/autoit]


    Ich glaub das war aus der GDIP.au3, sonst ist es auch nur anderer Funktionsname

  • das sieht gut aus :D
    nur was mir grad aufälllt
    das

    [autoit]

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

    [/autoit]


    hat bei doodle jump n bug verursacht
    ich bevorzuge es seit damals so

    [autoit]


    If _IsPressed(25) Then $x -= 1
    If _IsPressed(26) Then $y -= 1
    If _IsPressed(27) Then $x += 1
    If _IsPressed(28) Then $y += 1

    [/autoit]

    und
    @H2112
    das kann ich gut gebrauchen Danke :thumbup:

  • Mir ist nur aufgefalen das zwei Tasten gleichzietig nicht aktzeptiert werden.
    (Was auch logisch ist)

    Aber ich werds ändern.

    mfg Ubuntu

  • yxyx: Bei Select

    Edit in Post #1: Einige formatierungen wiederhergestellt die irgendwie verloren gegangen sind.

    mfg Ubuntu

  • Zitat

    Mir ist nur aufgefalen das zwei Tasten gleichzietig nicht aktzeptiert werden.
    (Was auch logisch ist)

    Naja wie mans braucht , bei Spielen wie Pokemon,Zelda,usw... ist es sogar ganz gut das nicht beide Tasten gleichzeitig akzeptiert werden ;)
    Wenn man die Func so aufstellt das erst x x kommt und dann y y ist es übrigens noch besser ;)

    Spoiler anzeigen
    [autoit]

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

    [/autoit]

    MfG Hellboy


    PS: Wann kommt die Buffereinführung ? :S

    MfG hellboy

    [autoit]

    Do
    _help($user)
    Until $questions = 0

    [/autoit]

    Meine Werke:
    Ste`s Web-Radio

  • @hellboy:
    Wieso ist das so besser :huh:
    Ist halt nur anders.

    Buffer kommen morgen oder übermorgen.

    Ich hab nicht so wirklich viel lust auf das Thema aber gut.
    Einer muss es ja machen ;)

    mfg Ubuntu