scon

GDI+ : text with glow (and shadow) effect

22 posts in this topic

Hi

Please help simple example )

Share this post


Link to post
Share on other sites



I made this example some time ago (shadow):

;; Author: monoceres

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

$hWnd = GUICreate("GDI+ Example", 800, 150)
GUISetState()

_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
_GDIPlus_GraphicsClear($hGraphics)
_AntiAlias($hGraphics,4)

$hBrush = _GDIPlus_BrushCreateSolid(0xFF009900)
$hBrush2= _GDIPlus_BrushCreateSolid(0xFF002000)
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 90)
$hLayout = _GDIPlus_RectFCreate(0, 0, 800, 300)
$hStringFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hStringFormat, 1)

_GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush)
For $i=0 To 10
    DllStructSetData($hLayout,"Y",$i)
    DllStructSetData($hLayout,"X",$i)
    _GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush2)
Next
DllStructSetData($hLayout,"Y",0)
DllStructSetData($hLayout,"X",0)
_GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush)


Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE


_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BrushDispose($hBrush2)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_StringFormatDispose($hStringFormat)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()



Func _GDIPlus_StringFormatSetAlign($hStringFormat,$iFlag)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetStringFormatAlign", "ptr", $hStringFormat,"short",$iFlag)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0]=0 Then Return SetError(0,0,1)
    Return SetError(1,0,0)
EndFunc

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

:)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

A stupid suggestion... What about an IE embedded control with a css style applied to some text ?


Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

TNX!

So, i much it is necessary that text glowed, but I did not work with this module

>Josbe

I already was there, but my knowledges do not allow to use this code to do program in Autoit ((

>torels

IE embeded... I tried, but antiviral program bad understand such (

Edited by scon

Share this post


Link to post
Share on other sites

>Valuater

I need beautiful text with effect of the phosphorescence.

I do not know what get this effect from module GDI+

Share this post


Link to post
Share on other sites

In monoceres example, change

_GDIPlus_GraphicsClear($hGraphics)

to

_GDIPlus_GraphicsClear($hGraphics,0xFFFFFFFF)

This will change the background to white instead of the default colour for _GDIPlus_GraphicsClear(), which is black.

The shadow of the text can be seen.

This is a modified monoceres example, with a increasing transparency shadow, or a shadow with reducing opaqueness. And this example uses a gradient line brush to colour the text.

;; A modified monoceres example

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

$hWnd = GUICreate("GDI+ Example", 800, 150)
GUISetState()

_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
_GDIPlus_GraphicsClear($hGraphics,0xffffffE0)
_AntiAlias($hGraphics,4)

$hBrush = _GDIPlus_BrushCreateSolid(0xFF009900)
$hBrush2= _GDIPlus_BrushCreateSolid(0xFF002000)
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 90)
$hLayout = _GDIPlus_RectFCreate(0, 0, 800, 300)
$hStringFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hStringFormat, 1)

_GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush)
For $i=0 To 10
    $hBrush2= _GDIPlus_BrushCreateSolid("0x" & Hex(255-(($i^2)*2.5) ,2) & "306030")
    DllStructSetData($hLayout,"Y",$i)
    DllStructSetData($hLayout,"X",$i)
    _GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush2)
Next
DllStructSetData($hLayout,"Y",0)
DllStructSetData($hLayout,"X",0)
;$hBrush2= _GDIPlus_BrushCreateSolid(0xFF00ff00)
;
$hBrushLin = GDIPlus_CreateLineBrush(0, 0, 800, 300, 0xFF0000ff, 0xFFFFFFFF, 0) ;Blue to White
_GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrushLin)
; Gamma correction is enabled for this linear gradient brush.
GDIPlus_SetLineGammaCorrection($hBrushLin, True)

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BrushDispose($hBrush2)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_StringFormatDispose($hStringFormat)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()


Func _GDIPlus_StringFormatSetAlign($hStringFormat,$iFlag)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetStringFormatAlign", "ptr", $hStringFormat,"short",$iFlag)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0]=0 Then Return SetError(0,0,1)
    Return SetError(1,0,0)
EndFunc

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

Func GDIPlus_CreateLineBrush($iPoint1X, $iPoint1Y, $iPoint2X, $iPoint2Y, $iArgb1 = 0xFF0000FF, _
        $iArgb2 = 0xFFFF0000, $WrapMode = 0)

    Local $tPoint1, $pPoint1, $tPoint2, $pPoint2, $aRet, $res

    $tPoint1 = DllStructCreate("float X;float Y")
    $pPoint1 = DllStructGetPtr($tPoint1)
    DllStructSetData($tPoint1, "X", $iPoint1X)
    DllStructSetData($tPoint1, "Y", $iPoint1Y)
    
    $tPoint2 = DllStructCreate("float X;float Y")
    $pPoint2 = DllStructGetPtr($tPoint2)
    DllStructSetData($tPoint2, "X", $iPoint2X)
    DllStructSetData($tPoint2, "Y", $iPoint2Y)
    ;Note: Within _GDIPlus_Startup(), $ghGDIPDll is defined
    $aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrush", "ptr", $pPoint1, "ptr", $pPoint2, "int", $iArgb1, _
            "int", $iArgb2, "int", $WrapMode, "int*", 0)
    ;$res = "GdipCreateLineBrush " & @CRLF
    ;for $x = 0 to 6
    ;$res &= $x & "  " & $aRet[$x] & @CRLF
    ;Next
    ;ConsoleWrite($res & @CRLF)
    Return $aRet[6]
EndFunc   ;==>GDIPlus_CreateLineBrush

Func GDIPlus_SetLineGammaCorrection($hBrush, $useGammaCorrection = True)
    Local $aResult
    
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetLineGammaCorrection", "hwnd", $hBrush, "int", $useGammaCorrection)
    Return $aResult[0]
EndFunc   ;==>GDIPlus_SetLineGammaCorrection

Share this post


Link to post
Share on other sites

This is a glow example.

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
Global $nPI = 3.1415926535897932384626433832795
$hWnd = GUICreate("GDI+ Example", 800, 150)

$iGlow = 2 ; <== Amount of Glow min = 1 Max about 5

_GDIPlus_Startup()
$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics(800, 150, $hGraphicGUI)
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
_GDIPlus_GraphicsClear($hGraphics, 0xff003000)  ; Black-green background
;_GDIPlus_GraphicsClear($hGraphics, 0xffffffff) ; White Background
_AntiAlias($hGraphics, 4)

$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 90)
$hLayout = _GDIPlus_RectFCreate(0, 0, 800, 150)
$hStringFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hStringFormat, 1)

For $i = 1 To 15 Step 3
    $hBrush3 = _GDIPlus_BrushCreateSolid("0x" & hex($iGlow,2) & "00ff00"); <====== Glow (Transparency)
    For $x = 0 To 360 Step 6
        DllStructSetData($hLayout, "Y", ((18 - $i)) * Sin($x * $nPI / 180))
        DllStructSetData($hLayout, "X", ((18 - $i)) * Cos($x * $nPI / 180))
        $hStringFormat = _GDIPlus_StringFormatCreate()
        _GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush3)       
    Next
Next
DllStructSetData($hLayout, "Y", 0)
DllStructSetData($hLayout, "X", 0)
$hStringFormat = _GDIPlus_StringFormatCreate()
$hBrush3 = _GDIPlus_BrushCreateSolid("0xfF00FF00")
_GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush3)
GUISetState()

GUIRegisterMsg(0xF, "MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3)
GUIRegisterMsg(0x85, "MY_PAINT") ; $WM_NCPAINT = 0x0085 (WindowsConstants.au3)Restore after Minimize.
_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

_GDIPlus_BrushDispose($hBrush3)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_StringFormatDispose($hStringFormat)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_GraphicsDispose($hGraphicGUI)
_WinAPI_DeleteObject($hBMPBuff)
_GDIPlus_Shutdown()


Func _GDIPlus_StringFormatSetAlign($hStringFormat, $iFlag)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetStringFormatAlign", "ptr", $hStringFormat, "short", $iFlag)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] = 0 Then Return SetError(0, 0, 1)
    Return SetError(1, 0, 0)
EndFunc   ;==>_GDIPlus_StringFormatSetAlign

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

;Func to redraw on PAINT MSG
Func MY_PAINT($hWnd, $msg, $wParam, $lParam)    
    _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
    _WinAPI_RedrawWindow($hWnd, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)) ; , $RDW_ALLCHILDREN
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_PAINT

Share this post


Link to post
Share on other sites

Mmmm.. Nice examples Malkey.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Yeah, really good examples. As usual from you :)

I really would like to see a full-blown GDI+ app from you. Would rock my world Posted Image


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Nice example. I get a weird result on Vista though, if the font size drops below 67 (weird arbitrary number). Try the above example with these changes -

Line 14 -> _GDIPlus_GraphicsClear($hGraphics, 0x00000000) ; transparent background

Line 19 -> $hFont = _GDIPlus_FontCreate($hFamily, 40) ; font size 40

Why is there a black border around the text now? As soon as the font size reaches 67+, the black border goes away, and it's transparent like it should be. Ideas?

Edited by wraithdu

Share this post


Link to post
Share on other sites

Nice example. I get a weird result on Vista though, if the font size drops below 67 (weird arbitrary number). Try the above example with these changes -

Line 14 -> _GDIPlus_GraphicsClear($hGraphics, 0x00000000) ; transparent background

Line 19 -> $hFont = _GDIPlus_FontCreate($hFamily, 40) ; font size 40

Why is there a black border around the text now? As soon as the font size reaches 67+, the black border goes away, and it's transparent like it should be. Ideas?

No ideas here.

I can not reproduce your black border around the text on XP.

Share this post


Link to post
Share on other sites

Tested on my XP SP3 no black border either.


Giggity

Share this post


Link to post
Share on other sites

Figures it's a Vista problem....damn.

Share this post


Link to post
Share on other sites

Find me a Vista solution, then I'll be shocked :)


Giggity

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Just so you know what I mean, here's what I'm talking about. This happens when there's transparency in the GraphicsClear function and the font is <= 66.

_GDIPlus_GraphicsClear($hGraphics, 0x50FFFFFF)

Edited by wraithdu

Share this post


Link to post
Share on other sites

I can't reproduce on Vista...


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

I wish I could explain it then. I mean, the proof is in the screenshot. Video card issue maybe? It's a laptop w/ Nvidia GeForce Go 7400. HP hasn't updated their drivers in forever, so who knows. But I'm inclined to think otherwise. Just to be sure, you tried with a smaller font size, like 40 or whatever? Could you post a screenshot?

EDIT -

I get the same result in an XP virtual machine (VirtualBox) with this code. I removed the StringFormatSetAlign() function since it's now included in the .12 beta.

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
Global $nPI = 3.1415926535897932384626433832795
$hWnd = GUICreate("GDI+ Example", 800, 150)

$iGlow = 2 ; <== Amount of Glow min = 1 Max about 5

_GDIPlus_Startup()
$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics(800, 150, $hGraphicGUI)
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
_GDIPlus_GraphicsClear($hGraphics, 0x00003000)  ; Black-green background
;_GDIPlus_GraphicsClear($hGraphics, 0xffffffff) ; White Background
_AntiAlias($hGraphics, 4)

$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 50)
$hLayout = _GDIPlus_RectFCreate(0, 0, 800, 150)
$hStringFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hStringFormat, 1)

For $i = 1 To 15 Step 3
    $hBrush3 = _GDIPlus_BrushCreateSolid("0x" & hex($iGlow,2) & "00ff00"); <====== Glow (Transparency)
    For $x = 0 To 360 Step 6
        DllStructSetData($hLayout, "Y", ((5 - $i)) * Sin($x * $nPI / 180))
        DllStructSetData($hLayout, "X", ((5 - $i)) * Cos($x * $nPI / 180))
;~         $hStringFormat = _GDIPlus_StringFormatCreate()
        _GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush3)      
    Next
Next
DllStructSetData($hLayout, "Y", 0)
DllStructSetData($hLayout, "X", 0)
;~ $hStringFormat = _GDIPlus_StringFormatCreate()
$hBrush3 = _GDIPlus_BrushCreateSolid("0xfF00FF00")
_GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush3)
GUISetState()

GUIRegisterMsg(0xF, "MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3)
GUIRegisterMsg(0x85, "MY_PAINT") ; $WM_NCPAINT = 0x0085 (WindowsConstants.au3)Restore after Minimize.
_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

_GDIPlus_BrushDispose($hBrush3)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_StringFormatDispose($hStringFormat)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_GraphicsDispose($hGraphicGUI)
_WinAPI_DeleteObject($hBMPBuff)
_GDIPlus_Shutdown()

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

;Func to redraw on PAINT MSG
Func MY_PAINT($hWnd, $msg, $wParam, $lParam)   
    _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
    _WinAPI_RedrawWindow($hWnd, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)) ; , $RDW_ALLCHILDREN
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_PAINT
Edited by wraithdu

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