Sign in to follow this  
Followers 0
CodeTinkerer

GDI+ Moving Text, Fade, Reset

2 posts in this topic

#1 ·  Posted (edited)

Hi again,

Trying to get a handle on GDI Plus. If you would be so kind, how would I go about creating text (either through a label or _GDIPlus_GraphicsDrawString ?), Move the test onto the GUI from the left to the center of the GUI, then Down, then fade out, reset and resume?

Comparing the normal route with standard controls I understand I cant manipulate GDIPlus Items the same way.

Looking in the help, It seems to mesh together rather complex. I will continue to educate myself. But none the less I would appreciate any assistance :)

Edited by CodeTinkerer

Share this post


Link to post
Share on other sites



Here a simple demo how a text can be moved.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("GUIOnEventMode", 1)

_GDIPlus_Startup()
Global Const $iWidth = 640, $iHeight = 480, $iBGColor = 0x404040, $fFontSize = 80, $fSpeed = 1.5
Global Const $hGUI = GUICreate("GDI+ Demo", $iWidth, $iHeight)
GUISetState()
Global Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global Const $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
Global Const $Ctxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($Ctxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
_GDIPlus_GraphicsSetPixelOffsetMode($Ctxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
_GDIPlus_GraphicsSetTextRenderingHint($Ctxt, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT)
_GDIPlus_GraphicsClear($Ctxt, 0xFF000000 + $iBGColor)
Global Const $hPath = _GDIPlus_PathCreate()
Global Const $hPen = _GDIPlus_PenCreate(0xFF000000, 2)
Global Const $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
Global Const $hFamily = _GDIPlus_FontFamilyCreate("Arial")
Global Const $hFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetLineAlign($hFormat, 1)

Global $sText = "GDI+ Demo"
_GDIPlus_PathAddString($hPath, $sText, _GDIPlus_RectFCreate(0, 0, $iWidth, $iHeight), $hFamily, 0, $fFontSize, $hFormat)
Global $aDim = _GDIPlus_PathGetWorldBounds($hPath)
_GDIPlus_PathReset($hPath)
Global $fCenter = ($iWidth - $aDim[2]) / 2, $fPosX = -$aDim[2] - $fFontSize
Global $tLayout = _GDIPlus_RectFCreate($fPosX, 0, $iWidth, $iHeight)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")


For $i = $fPosX To $fCenter Step $fSpeed * 2
    $tLayout.X = $i
    _GDIPlus_GraphicsClear($Ctxt, 0xFF000000 + $iBGColor)
    _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFamily, 0, $fFontSize, $hFormat)
    _GDIPlus_GraphicsFillPath($Ctxt, $hPath, $hBrush)
    _GDIPlus_GraphicsDrawPath($Ctxt, $hPath, $hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)
    _GDIPlus_PathReset($hPath)
    Sleep(10)
Next

Global $fFade = Ceiling(256 / ($iHeight / 2 - $fFontSize)) , $iAlpha = 0xFF

For $i = 0 To $iHeight / 2 + $fFontSize Step $fSpeed
    $tLayout.Y = $i
    _GDIPlus_GraphicsClear($Ctxt, 0xFF000000 + $iBGColor)
    _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFamily, 0, $fFontSize, $hFormat)
    _GDIPlus_GraphicsFillPath($Ctxt, $hPath, $hBrush)
    _GDIPlus_GraphicsDrawPath($Ctxt, $hPath, $hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)
    _GDIPlus_PathReset($hPath)
    _GDIPlus_PenSetColor($hPen, ($iAlpha - $fFade) * 0x1000000)
    _GDIPlus_BrushSetSolidColor($hBrush, ($iAlpha - $fFade) * 0x1000000 + 0xFFFFFF)
    $iAlpha -= $fFade
    $iAlpha = $iAlpha > $fFade ? $iAlpha : $fFade
    Sleep(10)
Next

ConsoleWrite("Done" & @CRLF)
Do
Until Not Sleep(1000)

Func _Exit()
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($Ctxt)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BitmapDispose($hBitmap)
    GUIDelete()
    _GDIPlus_Shutdown()
    Exit
EndFunc

 

If you have any question please ask.


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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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
Sign in to follow this  
Followers 0