Jump to content

Smooth Scrolling (Marquee) Text with GDI


Recommended Posts

Hi and Happy New Year everyone :)

Does anyone know a way, how to scroll Text with GDIPlus smoothie with DrawString (_GDIPlus_DrawStringEx)?

I know, I can use the String... commands like StringTrimLeft and so one. But this dont looks smooth, if I use a nonmonospaced Font (like e.g. Arial)

I want to say e.g. he should go every 100ms 2 Pixels left. Dont matter, if the Text is "WWWW" or "IIII" ;-)

This should work on a graphic object.

Would be great, if someone have got an Idea, and sorry again for my bad horrible english.

Thanks :o

Your Spider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

Something like this maybe?

#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)

$hwnd = GUICreate("GDI+ Example", 400, 300)
$label = GUICtrlCreateLabel("", 10, 10, 380, 40)
GUICtrlCreateButton("Start/Stop scrolling",150,50,100,30)
GUICtrlSetOnEvent(-1,"startstop")
GUISetOnEvent(-3, "close")
GUISetBkColor(0xF0F0F0)
GUISetState()

_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($hwnd, "", $label))
$bitmap = _GDIPlus_BitmapCreateFromGraphics(380, 40, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

$ffamily = _GDIPlus_FontFamilyCreate("Arial")
$arial = _GDIPlus_FontCreate($ffamily, 24)

$sformat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($sformat, 1)
$blackbrush = _GDIPlus_BrushCreateSolid()

$pos = 0
$speed=0


Do
    _GDIPlus_GraphicsClear($backbuffer, 0xFFF0F0F0)
    
    $pos -= $speed
    $rectf = _GDIPlus_RectFCreate($pos, 0, 380, 40)
    If $pos < -300 Then $pos = 300
    
    
    _GDIPlus_GraphicsDrawStringEx($backbuffer, "Scrolling text", $arial, $rectf, $sformat, $blackbrush)
    
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 380, 40)
    Sleep(10)
Until False

Func startstop()
    $speed=Not $speed
EndFunc



Func close()
    _GDIPlus_BrushDispose($blackbrush)
    _GDIPlus_StringFormatDispose($sformat)
    _GDIPlus_FontDispose($arial)
    _GDIPlus_FontFamilyDispose($ffamily)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc  ;==>close

:)

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

Link to comment
Share on other sites

Hello

Hey, i like ya dude. Thank you :o

Doesn't looks bad, but there is a problem:

The width don't automatically fits to the Text length if I change the Text (the Text is sometimes 2 chars Len and sometimes 50 chars ;-) )

And i don't can use something like StringLen, because the string can be III or the string can be WWW, so the chars don't have the same width.

Have you an Idea? It's for my G15 ;-)

By the way: In some days I will release a complete new G15 LCD UDF. This UDF connect directly to the Logitech SDK and is so faster and better than the old one with the AvLCD.dll. :)

Spider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

  • Moderators

Would probably be easier to use GUICtrlCreateObj + htm text/javascript for the scroll. No overhead and you don't have to be married to a loop.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hello

Hey, i like ya dude. Thank you :D

Doesn't looks bad, but there is a problem:

The width don't automatically fits to the Text length if I change the Text (the Text is sometimes 2 chars Len and sometimes 50 chars ;-) )

And i don't can use something like StringLen, because the string can be III or the string can be WWW, so the chars don't have the same width.

Have you an Idea? It's for my G15 ;-)

By the way: In some days I will release a complete new G15 LCD UDF. This UDF connect directly to the Logitech SDK and is so faster and better than the old one with the AvLCD.dll. :)

Spider

Ah I see. Well then _GDIPlus_GraphicsMeasureString does the trick :o

#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)

$hwnd = GUICreate("GDI+ Example", 400, 100)
$label = GUICtrlCreateLabel("", 10, 10, 380, 40)
GUICtrlCreateButton("Start/Stop scrolling", 150, 50, 100, 30)
GUICtrlSetOnEvent(-1, "startstop")
GUISetOnEvent(-3, "close")
GUISetBkColor(0xF0F0F0)
GUISetState()

_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($hwnd, "", $label))
$bitmap = _GDIPlus_BitmapCreateFromGraphics(380, 40, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

$ffamily = _GDIPlus_FontFamilyCreate("Arial")
$arial = _GDIPlus_FontCreate($ffamily, 24)

$sformat = _GDIPlus_StringFormatCreate()
;~ _GDIPlus_StringFormatSetAlign($sformat, 1)
$blackbrush = _GDIPlus_BrushCreateSolid()

$pos = 0
$speed = 1

$text = "This is a string"

Do
    _GDIPlus_GraphicsClear($backbuffer, 0xFFF0F0F0)


    $pos -= $speed
    $rectf = _GDIPlus_RectFCreate($pos, 0, 380, 40)
    $arr = _GDIPlus_GraphicsMeasureString($graphics, $text, $arial, $rectf, $sformat)
    $stringwidth = DllStructGetData($arr[0], "Width")
    If $pos < -$stringwidth Then $pos = $stringwidth*2


    _GDIPlus_GraphicsDrawStringEx($backbuffer, $text, $arial, $rectf, $sformat, $blackbrush)

    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 380, 40)
    Sleep(10)
Until False

Func startstop()
    $speed = Not $speed
EndFunc  ;==>startstop



Func close()
    _GDIPlus_BrushDispose($blackbrush)
    _GDIPlus_StringFormatDispose($sformat)
    _GDIPlus_FontDispose($arial)
    _GDIPlus_FontFamilyDispose($ffamily)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc  ;==>close

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

Link to comment
Share on other sites

  • 1 year later...

Thank you very much for this useful script monoceres. I'm unable to get it to work with longer strings. Any suggestions?

-Regards, Joe

#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)

$hwnd = GUICreate("GDI+ Example", 400, 100)
$label = GUICtrlCreateLabel("", 10, 10, 380, 40)
GUICtrlCreateButton("Start/Stop scrolling", 150, 50, 100, 30)
GUICtrlSetOnEvent(-1, "startstop")
GUISetOnEvent(-3, "close")
GUISetBkColor(0xF0F0F0)
GUISetState()

_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($hwnd, "", $label))
$bitmap = _GDIPlus_BitmapCreateFromGraphics(380, 40, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

$ffamily = _GDIPlus_FontFamilyCreate("Arial")
$arial = _GDIPlus_FontCreate($ffamily, 24)

$sformat = _GDIPlus_StringFormatCreate()
;~ _GDIPlus_StringFormatSetAlign($sformat, 1)
$blackbrush = _GDIPlus_BrushCreateSolid()

$pos = 0
$speed = 1

$text = "This is a string that is too long to scroll right."

Do
    _GDIPlus_GraphicsClear($backbuffer, 0xFFF0F0F0)


    $pos -= $speed
    $rectf = _GDIPlus_RectFCreate($pos, 0, 380, 40)
    $arr = _GDIPlus_GraphicsMeasureString($graphics, $text, $arial, $rectf, $sformat)
    $stringwidth = DllStructGetData($arr[0], "Width")
    If $pos < -$stringwidth Then $pos = $stringwidth*2


    _GDIPlus_GraphicsDrawStringEx($backbuffer, $text, $arial, $rectf, $sformat, $blackbrush)

    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 380, 40)
    Sleep(10)
Until False

Func startstop()
    $speed = Not $speed
EndFunc  ;==>startstop



Func close()
    _GDIPlus_BrushDispose($blackbrush)
    _GDIPlus_StringFormatDispose($sformat)
    _GDIPlus_FontDispose($arial)
    _GDIPlus_FontFamilyDispose($ffamily)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc  ;==>close

Are you experienced?

Link to comment
Share on other sites

  • Moderators

Hi,

If anyone is interested, Marquee.au3 can be found here. :idea:

M23

Edit: The board did not like the first link!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 1 month later...

Hi,

If anyone is interested, Marquee.au3 can be found here. :mellow:

M23

Edit: The board did not like the first link!

Hi Melba23 and thank you! Pardon me for not providing a link myself. Got so darned tied up trying to hurdle my own programming deficiencies that I neglected not only to acknowledge you for your excellent script but to offer an easy way for others to benefit from it.

All the best,

Joe

Are you experienced?

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...