Jump to content

GDI+


UEZ
 Share

Recommended Posts

Here a modification (fast and dirty) from monoceres' GDI+ demo:

#include <GUIConstantsEx.au3>
#include <GDIplus.au3>

Global Const $width = 600
Global Const $height = 400
Global Const $pi = 3.14159265358979323
Global $title = "GDI+"
Global $aPoints[4][2]


; Build your GUI here
Opt("GUIOnEventMode", 1)
$hwnd = GUICreate($title, $width, $height)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
GUISetState()

; Load your GDI+ resources here:
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
$brush = _GDIPlus_BrushCreateSolid(0x1A000000) ;triangle fader
$hBrush = _GDIPlus_BrushCreateSolid (0x7FAFAFAF)
$font_size = 32
$hFormat = _GDIPlus_StringFormatCreate ()
$hFamily = _GDIPlus_FontFamilyCreate ("Arial")
$hFont = _GDIPlus_FontCreate ($hFamily, $font_size, 2)

$text = "GDI+ Demo" & @LF & @LF & _
            "Triangle coded by monoceres" & @LF & @LF & _
            "Vertical scroller by UEZ" & @LF & @LF & @LF & _
            "Greetings to all forum " & @LF  & _
            "Members at " & @LF & @LF & _
            "www.autoitscript.com"
            
$j = $height / 4

_AntiAlias($backbuffer, 4)
$inc = 0

Global $Polygon_Size = Random(80, 120, 1)
Global $Polygon_X = Random(0, $width - $Polygon_Size, 1)
Global $Polygon_Y = Random(0, $height - $Polygon_Size, 1)

Global $Polygon_Xdir = 1
Global $Polygon_ydir = 1

Global $x1, $x2, $x3, $y1, $y2, $y3

Global $Polygon_Speed = 1.2

_GDIPlus_GraphicsClear($backbuffer)
Do
    $inc += 0.02
    _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $width, $height, $brush)
    
    $Polygon_X += $Polygon_Xdir
    $Polygon_Y += $Polygon_ydir
    
    $Polygon_Size = 2.5 * (Tan($inc / 1.5) / Cos($inc * $pi / 180) + 1) * 100 + 50 ;triangle size
       
    $red = ((Sin(1 * $inc / 1) + 1) / 2) * 256
    $green = ((Sin(2 * $inc / 1) + 1) / 2) * 256
    $blue = ((Sin(3 * $inc / 1) + 1) / 2) * 256
    
    $Pen = _GDIPlus_PenCreate("0x7F" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2), 6) ;pen format and size
    $x1 = Cos($inc * $Polygon_Speed) * $Polygon_Size + $Polygon_X
    $y1 = Sin($inc * $Polygon_Speed) * $Polygon_Size + $Polygon_Y
    
    $x2 = Cos($inc * $Polygon_Speed + 2 * $pi / 3) * $Polygon_Size + $Polygon_X
    $y2 = Sin($inc * $Polygon_Speed + 2 * $pi / 3) * $Polygon_Size + $Polygon_Y
    
    $x3 = Cos($inc * $Polygon_Speed + 4 * $pi / 3) * $Polygon_Size + $Polygon_X
    $y3 = Sin($inc * $Polygon_Speed + 4 * $pi / 3) * $Polygon_Size + $Polygon_Y

    $aPoints[0][0] = 3
    $aPoints[1][0] = $x1
    $aPoints[1][1] = $y1
    $aPoints[2][0] = $x2
    $aPoints[2][1] = $y2
    $aPoints[3][0] = $x3
    $aPoints[3][1] = $y3
        
    For $i = 1 To $aPoints[0][0]
        If $aPoints[$i][1] >= $height Then
            $Polygon_ydir = -1
        ElseIf $aPoints[$i][1] <= 0 Then
;~             ConsoleWrite("meh!" & @CRLF)
            $Polygon_ydir = 1
        EndIf
        If $aPoints[$i][0] >= $width Then
            $Polygon_Xdir = -1
        ElseIf $aPoints[$i][0] <= 0 Then
            $Polygon_Xdir = 1
        EndIf
    Next

    _GDIPlus_GraphicsDrawPolygon($backbuffer, $aPoints, $Pen)
        
    $tLayout = _GDIPlus_RectFCreate (1 / $width, $height + $j, 0, 0)
    _GDIPlus_GraphicsDrawStringEx ($backbuffer, $text, $hFont, $tLayout, $hFormat, $hBrush)
    $j -= 0.75
    If $height + $j < 0 - (StringLen($text) * 5) Then $j = $height / 4
    
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
    _GDIPlus_PenDispose($Pen)
    Sleep(1)
Until False

Func close()
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose($brush)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc ;==>close

Func _AntiAlias($hGraphics, $mode)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", $mode)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc ;==>_AntiAlias

@monoceres: thanks for sharing knowledge :)

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

That's damn sexy...

Add a custom Music track and it would take me back to the days of assembler demos. :o

It is too late to do this...Maybe tomorrow :)

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@monoceres: if I had more time I would do more on learning GDI+ stuff :)

Here with audio:

#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_run_after=upx.exe --best --compress-resources=1 "%out%"
#include <GUIConstantsEx.au3>
#include <GDIplus.au3>
Opt("GUIOnEventMode", 1)
Opt('MustDeclareVars', 1)
Global Const $width = 600
Global Const $height = 400
Global Const $pi = 3.14159265358979323
Global $title = "GDI+"
Global $aPoints[4][2]
Global $Polygon_Size = Random(80, 120, 1)
Global $Polygon_X = Random(0, $width - $Polygon_Size, 1)
Global $Polygon_Y = Random(0, $height - $Polygon_Size, 1)

Global $Polygon_Xdir = 1
Global $Polygon_ydir = 1

Global $x1, $x2, $x3, $y1, $y2, $y3

Global $Polygon_Speed = 1.2

Global $hwnd, $graphics, $bitmap, $backbuffer, $brush, $hBrush, $font_size, $hFormat, $hFamily, $hFont, $text, $j, $inc, $red, $green, $blue, $Pen, $tLayout

Global $Init, $VolLevel, $string, $load, $VolLevel, $Volume, $bassdll

Play_Audio()

; Build your GUI here

$hwnd = GUICreate($title, $width, $height)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
GUISetState()

; Load your GDI+ resources here:
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
$brush = _GDIPlus_BrushCreateSolid(0x1A000000) ;triangle fader
$hBrush = _GDIPlus_BrushCreateSolid (0x7FAFAFAF)
$font_size = 32
$hFormat = _GDIPlus_StringFormatCreate ()
$hFamily = _GDIPlus_FontFamilyCreate ("Arial")
$hFont = _GDIPlus_FontCreate ($hFamily, $font_size, 2)

$text = "GDI+ Demo" & @LF & @LF & _
            "Triangle coded by monoceres" & @LF & @LF & _
            "Vertical scroller by UEZ" & @LF & @LF & @LF & _
            "Greetings to all forum " & @LF  & _
            "Members at " & @LF & @LF & _
            "www.autoitscript.com"
            
$j = $height / 4

_AntiAlias($backbuffer, 4)
$inc = 0

_GDIPlus_GraphicsClear($backbuffer)
Do
    $inc += 0.02
    _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $width, $height, $brush)
    
    $Polygon_X += $Polygon_Xdir
    $Polygon_Y += $Polygon_ydir
    
    $Polygon_Size = 2.5 * (Tan($inc / 1.5) / Cos($inc * $pi / 180) + 1) * 100 + 50 ;triangle size
       
    $red = ((Sin(1 * $inc / 1) + 1) / 2) * 256
    $green = ((Sin(2 * $inc / 1) + 1) / 2) * 256
    $blue = ((Sin(3 * $inc / 1) + 1) / 2) * 256
    
    $Pen = _GDIPlus_PenCreate("0x7F" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2), 6) ;pen format and size
    $x1 = Cos($inc * $Polygon_Speed) * $Polygon_Size + $Polygon_X
    $y1 = Sin($inc * $Polygon_Speed) * $Polygon_Size + $Polygon_Y
    
    $x2 = Cos($inc * $Polygon_Speed + 2 * $pi / 3) * $Polygon_Size + $Polygon_X
    $y2 = Sin($inc * $Polygon_Speed + 2 * $pi / 3) * $Polygon_Size + $Polygon_Y
    
    $x3 = Cos($inc * $Polygon_Speed + 4 * $pi / 3) * $Polygon_Size + $Polygon_X
    $y3 = Sin($inc * $Polygon_Speed + 4 * $pi / 3) * $Polygon_Size + $Polygon_Y

    $aPoints[0][0] = 3
    $aPoints[1][0] = $x1
    $aPoints[1][1] = $y1
    $aPoints[2][0] = $x2
    $aPoints[2][1] = $y2
    $aPoints[3][0] = $x3
    $aPoints[3][1] = $y3
        
    For $i = 1 To $aPoints[0][0]
        If $aPoints[$i][1] >= $height Then
            $Polygon_ydir = -1
        ElseIf $aPoints[$i][1] <= 0 Then
;~             ConsoleWrite("meh!" & @CRLF)
            $Polygon_ydir = 1
        EndIf
        If $aPoints[$i][0] >= $width Then
            $Polygon_Xdir = -1
        ElseIf $aPoints[$i][0] <= 0 Then
            $Polygon_Xdir = 1
        EndIf
    Next

    _GDIPlus_GraphicsDrawPolygon($backbuffer, $aPoints, $Pen)
        
    $tLayout = _GDIPlus_RectFCreate (1 / $width, $height + $j, 0, 0)
    _GDIPlus_GraphicsDrawStringEx ($backbuffer, $text, $hFont, $tLayout, $hFormat, $hBrush)
    $j -= 1
    If $height + $j < 0 - (StringLen($text) * 5) Then $j = $height / 4
    
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
    _GDIPlus_PenDispose($Pen)
    Sleep(1)
Until False

Func Play_Audio()
    $bassdll = DllOpen(@ScriptDir & "\BASSMOD.dll")
    $Init = DllCall($bassdll, "int", "BASSMOD_Init", "int", -1, "int", 44100, "int", 0)
    $string= DllStructCreate("char[255]")
    DllStructSetData($string, 1, @ScriptDir & "\Audio.xm")
    $load = DllCall($bassdll, "int", "BASSMOD_MusicLoad", _
                             "int", 0, _
                             "ptr", DllStructGetPtr($string), _ 
                             "int", 0, _
                             "int", 0, _
                             "int", 4 + 1024)
    $VolLevel = 100
    $Volume = DllCall($BASSDLL, "int", "BASSMOD_SetVolume", "int", $VolLevel)
    DllCall($bassdll, "int", "BASSMOD_MusicPlay")
EndFunc

Func close()
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose($brush)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    DllCall($bassdll, "int", "BASSMOD_MusicFree")
    DllClose($bassdll)
    Exit
EndFunc ;==>close

Func _AntiAlias($hGraphics, $mode)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", $mode)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc ;==>_AntiAlias

The source code, resources and compiled exe can be downloaded from here: <click me>

Don't copy source code from above to editor and press F5 because it will crash when the resources are not in same dir!

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...