Hilfe bei GDI+

  • Ich hab für mich ne kleine GDI+ Übeung gemacht, naja, die Übung stellt sich als Schwieriger dar als ich Dachte.

    Und zwar, hatte ich vor sowas wie einen "Abspann" zu machen, viele ma chen sicherlich ein kleinen Spiel mit AutoIt und da kann man sowas dan schonmal brauchen, aber nicht nur für Spiele.
    Meine Idee war, man hat eine .txt Datei, mit sämtlichen namen und Infos welche Angezeigt werde sollen.
    Soweit so gut, das einlessen, kein thema, mit GDI+ das eingelessene Zeichnen, geht auch.
    Aber ich bekomm es nicht hin, dass mir das gezeichnete von Oben nach Unten oder Unten Nach oben (Erstmal von Oben nach Unten) verschoben wird.

    Das ganze sieht momentan so aus

    GDI+ Abspann.au3
    [autoit]


    #include <file.au3>
    #include <Array.au3>
    ;~
    Global $Creator[1] = [_FileCountLines(@ScriptDir & '\Creator.txt')]
    Global $fSize = 20
    Global $iStyle = 0
    Global $iUnit = 2
    Global $Speed = 50
    Global $Distance[1] = [0]
    ;~
    Global $hGUI
    Global $Size = WinGetClientSize($hGUI)
    ;~
    For $d = 1 To $Creator[0]
    _ArrayInsert($Distance, $d, $d * $fSize)
    Next
    ;~
    For $i = 1 To $Creator[0]
    _ArrayInsert($Creator, $i, FileReadLine('Creator.txt', $i))
    Next
    ;~
    ;~ _ArrayDisplay($Creator)
    ;~ _ArrayDisplay($Distance)
    ;~ _ArrayDisplay($Draw)
    ;~
    Func _LastWord($hGUI)
    ;~ $Size[0] = Breite(X) des Fensters
    ;~ $Size[1] = Höhe(Y) des Fensters
    Local $Size = WinGetClientSize($hGUI)
    Local $i = 0,$a = 1
    Local $Progress = GUICtrlCreateProgress(0, $Size[1] - 20, $Size[0], 20)
    ;~
    $hStringFormat = _GDIPlus_StringFormatCreate()
    $hFormat = _GDIPlus_StringFormatSetAlign($hStringFormat, 1)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hFamily = _GDIPlus_FontFamilyCreate('Arial')
    $hFont = _GDIPlus_FontCreate($hFamily, $fSize, $iStyle, $iUnit)
    ;~
    Do
    GUICtrlSetData($Progress, Floor($i / $Size[1]))
    $tLayout = _GDIPlus_RectFCreate($Size[0] / 2 - 100,$i, 300, $Size[1])
    If $i = $Distance[$a-1] Then
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $Creator[$a], $hFont, $tLayout, $hFormat, $hBrush)
    $a = $a +1
    EndIf
    ;~
    $i = $i + 1
    Sleep($Speed)
    Until $i = $Size[1]
    EndFunc ;==>_LastWord

    [/autoit]
    Test.au3
    [autoit]


    #include <GuiConstants.au3>
    #include <Constants.au3>
    #include <WindowsConstants.au3>
    #include <StaticConstants.au3>
    #include <GdiPlus.au3>
    #include 'GDI+ Game Abspann.au3'
    ;~
    OnAutoItExitRegister("_end")
    Global $width = 1000, $height = 500
    ;~
    _GDIPlus_Startup()
    ;~
    $hGui = GUICreate('Test', $width, $height, -1, -1)
    GUISetState(@SW_SHOW, $hGUI)
    ;~
    _LastWord($hGui)
    ;~
    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd
    ;~
    Func _end()
    _GDIPlus_Shutdown()
    EndFunc ;==>_end

    [/autoit]
    Creator.txt


    Das ist bisjetz dass was ich hinbekommen habe, leider weiss ich nicht weiter und hoffe Ihr versteht was ich da vorhabe.
    Erfräulich währen Denk anstösse, oder Möglichkeiten, wie mein Vorhaben vorranschreiten kann und nicht jetz schon zum Scheitern Verurteilt ist.

    Greez
    Skilkor


    **Edit 1**
    Die Progressbar hab ich mal so eingebaut, und nicht grossartig RICHTIG bearbeitet, da es eine Idee war und ich mich kenne, wenn ich es nicht gleich reinbaue, vergess ichs wieder X(

    Einmal editiert, zuletzt von Skilkor (13. Februar 2013 um 16:50)

  • Da wohl niemand helfen mag oder weiss auch nicht.
    Hab ich mal viel rumgetestet...
    Ergibniss:
    Mein fehler was, jede zeile der Datei in ein Array als einzelnes Element zu Speichern.

    Denkfehler
    [autoit]


    For $i = 1 To $Count[0]
    _ArrayInsert($Creator, $i, FileReadLine('Creator.txt', $i))
    Next

    [/autoit]


    Wenn ich dass zu

    Lösung
    [autoit]


    Global $Creator = FileRead('Creator.txt')

    [/autoit]


    abändere ab ich somit die volle Datei drin (Was ich nicht wusste, Zeilen Umbrüche werden mit _GDIPlus_GraphicsDrawStringEx auch Angezeigt)

    Nun aber habe ich das Problem, es Flakert unnormal.
    Hier mal der neue Code

    GDI+ Abspann
    [autoit]


    #include <file.au3>
    #include <Array.au3>
    Global $Count[1] = [_FileCountLines(@ScriptDir & '\Creator.txt')]
    Global $fSize = 20
    Global $iStyle = 0
    Global $iUnit = 2
    Global $Speed = 20
    Global $Distance[1] = [0]
    Global $Creator = FileRead('Creator.txt')
    ;~
    For $d = 1 To $Count[0]
    _ArrayInsert($Distance, $d, $d *1.2 * $fSize)
    Next
    ;~
    Func _LastWord($hGUI)
    Local $Size = WinGetClientSize($hGUI)
    Local $Progress = GUICtrlCreateProgress(0, $Size[1] - 20, $Size[0], 20)
    ;;~
    For $i = 0 To $Size[1] + $Distance[$Count[0]]
    $hStringFormat = _GDIPlus_StringFormatCreate()
    _GDIPlus_StringFormatSetAlign($hStringFormat, 1)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFAFA)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hFamily = _GDIPlus_FontFamilyCreate('Arial')
    $hFont = _GDIPlus_FontCreate($hFamily, $fSize, $iStyle, $iUnit)
    ;;~
    $bGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    _GDIPlus_GraphicsFillRect($bGraphic, 0, 0, $Size[0], $Size[1] - 40)
    ;;~
    $tLayout = _GDIPlus_RectFCreate($Size[0] / 2 - 150, $i -$Distance[$Count[0]], 300, $Distance[$Count[0]])
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $Creator, $hFont, $tLayout, $hStringFormat, $hBrush)
    Sleep($Speed)
    _GDIPlus_GraphicsClear($hGraphic)
    Next
    ;;~
    EndFunc ;==>_LastWord

    [/autoit]


    Das Flakern kommt von Zeile 33, nur ohne diese wird das ganze ne Fette Wurst :pinch:
    Die Progress (Welche ich noch nicht richtig bearbeitet habe) wird öminöserweisse überschrieben, dass _GDIPlus_GraphicsFillRect auf Zeile 28 Zieht da dann leider auch nicht ;( (Wieso :?: )

    Ich Experimentiere weiter, aber hoffe inständig darauf dass jemand mir beim Flakern helfen kann.

    Greez
    Skilkor

  • Um das Flackern zu vermeiden, benutzt man normalerweise einen sogenannten Doublebuffer (Oder auch Backbuffer).

    Spoiler anzeigen
    [autoit]


    #include <file.au3>
    #include <Array.au3>
    #include <GDIPlus.au3>

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

    _GDIPlus_Startup()

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

    HotKeySet("{F1}", "_ToggleBuffer")
    Opt("GUIOnEventMode", True)

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

    $iGUIWidth = 250
    $iGUIHeight = 250
    $bUseBuffer = True
    $iRectWH = 50
    $sMainTitle = "UseBuffer: "

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

    MsgBox(0, "", "Toggle the buffer with F1!")

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

    $hGUI = GUICreate($sMainTitle & $bUseBuffer, $iGUIWidth, $iGUIHeight)
    GUISetOnEvent(-3, "_Shutdown")
    GUISetState()

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

    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)

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

    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iGUIWidth, $iGUIHeight, $hGraphics)
    $hBufferOrigin = _GDIPlus_ImageGetGraphicsContext($hBitmap)

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

    $hBrushX = _GDIPlus_BrushCreateSolid(0x889999FF)
    $hBrushY = _GDIPlus_BrushCreateSolid(0x88FF9999)

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

    $iXPos = 0
    $iYPos = 0

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

    $iXCalc = +1
    $iYCalc = +1

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

    $hBuffer = $hBufferOrigin

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

    While True
    _GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)

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

    If $iXPos + $iRectWH >= $iGUIWidth Then $iXCalc = -1
    If $iXPos <= 0 Then $iXCalc = +1
    $iXPos += $iXCalc

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

    If $iYPos + $iRectWH >= $iGUIHeight Then $iYCalc = -1
    If $iYPos <= 0 Then $iYCalc = +1
    $iYPos += $iYCalc

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

    _GDIPlus_GraphicsFillRect($hBuffer, $iXPos, 0, $iRectWH, $iGUIHeight, $hBrushX)
    _GDIPlus_GraphicsFillRect($hBuffer, 0, $iYPos, $iGUIWidth, $iRectWH, $hBrushY)

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

    If $bUseBuffer Then _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iGUIWidth, $iGUIHeight)

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

    WEnd

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

    Func _ToggleBuffer()
    $bUseBuffer = Not $bUseBuffer
    Switch $bUseBuffer
    Case True
    $hBuffer = $hBufferOrigin
    Case False
    $hBuffer = $hGraphics
    EndSwitch
    WinSetTitle($hGUI, "", $sMainTitle & $bUseBuffer)
    EndFunc ;==>_ToggleBuffer

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

    Func _Shutdown()
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_GraphicsDispose($hBufferOrigin)
    _GDIPlus_ImageDispose($hBitmap)
    _GDIPlus_BrushDispose($hBrushX)
    _GDIPlus_BrushDispose($hBrushY)
    _GDIPlus_Shutdown()

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

    Exit
    EndFunc

    [/autoit]

    chess

  • Hier meine Variante von 2011:

    Spoiler anzeigen
    [autoit]


    #AutoIt3Wrapper_Run_Obfuscator=y
    #Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
    #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3"
    #AutoIt3Wrapper_UseUpx=y
    #AutoIt3Wrapper_UPX_Parameters=--brute --crp-ms=999999 --all-methods --all-filters
    #include <Array.au3>
    #include <GuiConstantsEx.au3>
    #include <GDIPlus.au3>
    #include <Misc.au3>

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

    Opt('MustDeclareVars', 1)

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

    Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
    Local $width = 800, $height = 600
    ; Create GUI
    $hGUI = GUICreate("GDI+ Vertical Scroller by UEZ", $width, $height)
    If @OSBuild < 7600 Then WinSetTrans($hGui,"", 0xFF)
    GUISetState()

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

    ; Draw a string
    _GDIPlus_Startup ()
    Local $hGfx = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    $hBrush = _GDIPlus_BrushCreateSolid (0xFF00007F)
    Local $hBmp_About = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGfx)
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBmp_About)
    _GDIPlus_GraphicsClear($hCtxt, 0xFFFFFFFF)
    _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)
    DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hCtxt, "int", 4)

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

    ;~ Local $tRectF = _GDIPlus_RectFCreate(0, 0, $width / 5, $height / 5)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $ver = "v0.98 Build 2010-12-09 Beta"

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

    Local $aText[26][9] = [ _
    ["AUTOIT", 0, 0, "Arial Black", 40], _
    ["Windows Screenshooter", 0, 0, "Comic Sans MS", 48], _
    [$ver, 0, 0, "Comic Sans MS", 24], _
    [" ", 0, 0, "Arial", 50], _
    ["Main Code", 0, 0, "Verdana", 30], _
    ["by", 0, 0, "Times New Roman", 40], _
    ["UEZ", 0, 0, "Arial Black", 150], _
    [" ", 0, 0, "Arial", 20], _
    ["Additional Code by:", 0, 0, "Georgia", 24], _
    ["(Alphabetical Order)", 0, 0, "Tahoma", 14], _
    [" ", 0, 0, "Arial", 20], _
    ["Authenticity", 0, 0, "Arial", 32], _
    ["eukalyptus", 0, 0, "Arial", 32], _
    ["Montfrooij", 0, 0, "Arial", 32], _
    ["taietel", 0, 0, "Arial", 32], _
    ["Ward", 0, 0, "Arial", 32], _
    ["Yashied", 0, 0, "Arial", 32], _
    [" ", 0, 0, "Arial", 100], _
    ["Thanks to:", 0, 0, "Tunga", 40], _
    [" ", 0, 0, "Arial", 20], _
    ["Firelight Technologies for fmod.dll", 0, 0, "Palatino Linotype", 32], _
    [" ", 0, 0, "Arial", 32], _
    ["Anne Haessig for the chip tune:", 0, 0, "MV Boli", 32], _
    ["DaZzLed", 0, 0, "Impact", 32], _
    [" ", 0, 0, "Arial", 120], _
    ["Press ESC to quit", 0, 0, "Latha", 30]]

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

    Local $tLayout = _GDIPlus_RectFCreate (0, 0, 0, 0), $aInfo
    Local $y = $height, $dy = 0, $sy = 0
    For $z = 0 To UBound($aText) - 1
    $aText[$z][1] = _GDIPlus_FontFamilyCreate($aText[$z][3]) ;$hFamily
    $aText[$z][2] = _GDIPlus_FontCreate($aText[$z][1], $aText[$z][4]) ;$hFont
    $aInfo = _GDIPlus_GraphicsMeasureString($hGfx, $aText[$z][0], $aText[$z][2], $tLayout, $hFormat)
    $aText[$z][5] = Floor(DllStructGetData($aInfo[0], "Width"))
    $aText[$z][6] = Floor(DllStructGetData($aInfo[0], "Height"))
    $aText[$z][7] = Floor($width / 2 - ($aText[$z][5] / 2))
    $aText[$z][8] = Floor($y + $dy + $sy)
    $sy += $aText[$z][6]
    Next
    ;~ _ArrayDisplay($aText)
    Local $speed = 1
    Local $dll = DllOpen("user32.dll")
    While Not _IsPressed("1B", $dll) * Sleep(10)
    _GDIPlus_GraphicsClear($hCtxt, 0xFFFFFFFF)
    For $z = 0 To UBound($aText) - 1
    If $aText[$z][8] < $height And $aText[$z][8] > -$aText[$z][6] Then
    $tLayout = _GDIPlus_RectFCreate ($aText[$z][7], $aText[$z][8], 0, 0)
    _GDIPlus_GraphicsDrawStringEx($hCtxt, $aText[$z][0], $aText[$z][2], $tLayout, $hFormat, $hBrush)
    EndIf
    $aText[$z][8] -= $speed
    Next
    _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp_About, 0, 0, $width, $height)
    If $aText[UBound($aText) - 1][8] < -$aText[UBound($aText) - 1][6] * 2.5 Then ExitLoop
    WEnd
    DllClose($dll)
    For $z = 0 To UBound($aText) - 1
    _GDIPlus_FontDispose($aText[$z][2])
    _GDIPlus_FontFamilyDispose($aText[$z][1])
    Next
    $tLayout = ""
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_BitmapDispose($hBmp_About)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_GraphicsDispose($hGfx)
    GUIDelete($hGUI)
    Exit

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (13. Februar 2013 um 17:52)

  • Is ja ganz hübsch :D
    Wer die Spielerrei mag ^^
    Hab mich versucht auf das mindeste zu beschränken ^^ und soweit eig das erreicht :D
    Hat noch das eine oder andere problemchem aber wird schon mit meiner Version :D
    Aber schon krass was die Spiellerei an zeilen verschlingt ^^ deines 101 Zeilen, meines 53 mit Func beschreibung (Welche 11 Zeilen ausmacht)