Jump to content
Biatu

_GDIPlus_GraphicsDrawLine with gradient

Recommended Posts

Something like that here?

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

_GDIPlus_Startup() ;initialize GDI+
Global Const $iWidth = 600, $iHeight = 300, $iBgColor = 0x303030 ;$iBgColor format RRGGBB

Global $hGUI = GUICreate("GDI+ Test", $iWidth, $iHeight) ;create a test GUI
GUISetBkColor($iBgColor, $hGUI) ;set GUI background color
GUISetState(@SW_SHOW)

Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)

Global Const $fDeg = 180 / ACos(-1), $fRad = ACos(-1) / 180

_GDIPlus_DrawLaserBeam($hGraphics, 10, -10, 300, 310, 10)
_GDIPlus_DrawLaserBeam($hGraphics, -10, 100, 600, 0)
_GDIPlus_DrawLaserBeam($hGraphics, 100, 310, 300, -10, 5)
_GDIPlus_DrawLaserBeam($hGraphics, 280, -50, 620, 300, 50)


Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

;cleanup GDI+ resources
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
GUIDelete($hGUI)

Func _GDIPlus_DrawLaserBeam(ByRef $hGraphics, $iX1, $iY1, $iX2, $iY2, $iSize = 20, $iCInner = 0xFFE0FFFF, $iCOuter = 0x80104030) ;coded by UEZ build 2014-09-05

    Local Const $fAngle = ATan(($iY2 - $iY1) / ($iX2 - $iX1)) * $fDeg ;calculate the angle of the 2 points
    Local Const $iW = Round(Sqrt(($iY2 - $iY1) ^ 2 + ($iX2 - $iX1) ^ 2), 0), $iH = $iW ;length between the 2 points

    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)

    Local Const $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($hMatrix, $iW / 2, $iH / 2)
    _GDIPlus_MatrixRotate($hMatrix, $fAngle + 90)
    _GDIPlus_MatrixTranslate($hMatrix, -$iW / 2, -$iH / 2)
    _GDIPlus_GraphicsSetTransform($hCtxt, $hMatrix)

    Local Const $hBrush = _GDIPlus_LineBrushCreate(($iW - $iSize) / 2, 0, ($iW + $iSize) / 2, 0, 0, 0) ;create gradient brush
    Local $aColorGradient[4][2]
    $aColorGradient[0][0] = 3
    $aColorGradient[1][0] = $iCOuter
    $aColorGradient[1][1] = 0.0
    $aColorGradient[2][0] = $iCInner
    $aColorGradient[2][1] = 0.5
    $aColorGradient[3][0] = $iCOuter
    $aColorGradient[3][1] = 1.0
    _GDIPlus_LineBrushSetPresetBlend($hBrush, $aColorGradient)
    _GDIPlus_GraphicsFillRect($hCtxt, ($iW - $iSize) / 2, 0, $iSize, $iH, $hBrush)

    Local Const $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddRectangle($hPath, ($iW - $iSize) / 2 - $iSize / 2, 0, $iSize * 2, $iH)
    Local Const $hBrush_Glow = _GDIPlus_PathBrushCreateFromPath($hPath) ;create glow brush
    _GDIPlus_PathBrushSetSigmaBlend($hBrush_Glow, 1, 0.75)
    _GDIPlus_PathBrushSetFocusScales($hBrush_Glow, 0, 0.995)
    _GDIPlus_PathBrushSetCenterColor($hBrush_Glow, $iCInner)
    Local $aColor[2] = [1, $iCInner - 0xFF000000]
    _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush_Glow, $aColor)
    _GDIPlus_PathBrushSetWrapMode($hBrush_Glow, 0)
    _GDIPlus_GraphicsFillRect($hCtxt, ($iW - $iSize) / 2 - $iSize / 2, 0, $iSize * 2, $iH, $hBrush_Glow)


    Local $fDX, $fDY
    If $fAngle <= 180 Then  ;adjust position
        $fDX = $iX2 - ($iW / 2 + Cos($fAngle * $fRad) * $iW / 2)
        $fDY = $iY2 - ($iH / 2 + Sin($fAngle * $fRad) * $iH / 2)
    Else
        $fDX = $iX1 - ($iW / 2 + Cos($fAngle * $fRad) * $iW / 2)
        $fDY = $iY1 - ($iH / 2 + Sin($fAngle * $fRad) * $iH / 2)
    EndIf
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, $fDX, $fDY, $iW, $iH)

    _GDIPlus_PathDispose($hPath)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush_Glow)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_BitmapDispose($hBitmap)
EndFunc   ;==>_GDIPlus_DrawLaserBeam

Br,

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

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

×
×
  • Create New...