Page 1 of 1

Scrolling Text Thingie

Posted: Sat Nov 12, 2005 9:09 am
by Xombie
I built this for Pantcho really quickly (from the IRC channel) when he was trying to put together a scrolling text thing. I was kinda tired but thought it might not be too horrible a challenge. It's nothing special but maybe someone can use it as an example for something else.

Code: Select all

Enumeration
   #WindowMain 
EndEnumeration

Enumeration
   #ImageScroll
EndEnumeration

;- Global Variables
Global HandleImage.l
Global HandleTimer.l
Global PositionText.l
Global IsFinishedDrawing.b
;- Procedures
Procedure.l ScrollCallback(HandleWindow.l, Message.l, EventID.l, dwTime.l)
   ;
   lImage.l
   ;
   lBrush.l
   ;
   BrushProperties.LOGBRUSH
   ; Brush properties - color, brush type.
   HoldRect.RECT
   ; Rectangular coordinates used to fill shapes.
   FontSize.l
   ;
   CellFont.l
   ;
   CellText.s
   ;
   If IsFinishedDrawing
      ;
      IsFinishedDrawing = #False
      ;
      UseImage(HandleImage)
      ;
      lImage = StartDrawing(ImageOutput())
      ;
      BrushProperties\lbStyle = #BS_SOLID
      BrushProperties\lbColor = RGB(0, 0, 0)
      ;
      lBrush = CreateBrushIndirect_(BrushProperties)
      ;
      SelectObject_(lImage, lBrush)
      ;
      HoldRect\Left = 0 : HoldRect\Top = 0 : HoldRect\Right = WindowWidth() : HoldRect\Bottom = 100
      ;
      FillRect_(lImage, HoldRect, lBrush)
      ;
      DeleteObject_(lBrush) : lBrush = 0
      ;
      SetTextColor_(lImage, RGB(255, 0, 0)) : SetBkMode_(lImage, #TRANSPARENT)
      ;
      CellText = "From Xombie!"
      ;
      FontSize = -Int((28 * GetDeviceCaps_(lImage, #LOGPIXELSY)) / 72)
      ; Using 28 as the height.
      CellFont = CreateFont_(FontSize,0,0,0,0,0,0,0,#ANSI_CHARSET,#OUT_DEFAULT_PRECIS,#CLIP_DEFAULT_PRECIS,#PROOF_QUALITY,0,"Arial")
      ; Set any font formatting here.  Italics, bold, whatever.
      SelectObject_(lImage, CellFont)
      ;
      DrawText_(lImage, @CellText, Len(CellText), @HoldRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE | #DT_CALCRECT) 
      ;
      MoveToEx_(lImage, PositionText, Int((GadgetHeight(#ImageScroll) - HoldRect\Bottom) / 2), 0)
      ;
      DrawText_(lImage, @CellText, Len(CellText), @HoldRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE)
      ; Draw the column header. 
      DeleteObject_(CellFont)
      ;
      StopDrawing()
      ;
      SetGadgetState(#ImageScroll, ImageID())
      ;
      If PositionText + HoldRect\Right >= 0 : PositionText - 1 : Else : PositionText = WindowWidth() : EndIf
      ; Move the text to the left for the next call.
      IsFinishedDrawing = #True
      ;
   EndIf
   ;
EndProcedure
;
;- Main Code
;
EventID.l
; Variable to hold the window message.
DoQuit.b
; Variable to control whether we quit the window or not.  Automatically set to #False.
lHold.l
;
HoldString.s
;
If OpenWindow(#WindowMain, 0, 0, 650, 310, #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_SizeGadget, "xGrid")
   ; Create the main window.
   If CreateGadgetList(WindowID())
      ;
      AdvancedGadgetEvents(#True)
      ; Enable advanced gadget events.
      HandleImage = CreateImage(#PB_Any, WindowWidth() - 1, 100)
      ;
      ImageGadget(#ImageScroll, 0, 0, WindowWidth() - 1, 100, UseImage(HandleImage), #PB_Image_Border)
      ;
   EndIf
   ;
   IsFinishedDrawing = #True
   ;
   PositionText = WindowWidth()
   ;
   HandleTimer = SetTimer_(0, 0, 10, @ScrollCallback())
   ;
   Repeat
      ;
      ;{ Event Loop
      EventID = WaitWindowEvent()
      ;
      If EventID = #PB_Event_CloseWindow
         ; Close the program.
         DoQuit = #True
         ;
      ElseIf EventID = #PB_Event_SizeWindow
         ;
         ;
      ElseIf EventID = #PB_Event_Menu
         ; Menu Events
         ;
      ElseIf EventID = #PB_Event_Gadget
         ; Control Events
         ;
      EndIf
      ;}
      ;
   Until DoQuit = #True
   ;
   KillTimer_(0, HandleTimer)
   ;
EndIf
Feel free to laugh at my sleepy code ^_^

Posted: Sat Nov 12, 2005 2:59 pm
by rsts
Allright! Another "cool" one.

Another lesson from the Tricks 'n' Tips tutorials.

Thanks

Posted: Sat Nov 12, 2005 7:44 pm
by Straker
Very nice as usual, Xombie!
:D

Posted: Sun Nov 13, 2005 12:24 pm
by Psychophanta
Good API lesson :wink:

Posted: Mon Nov 14, 2005 1:53 pm
by Pantcho!!
Thanks! and he did it really fast! amazing! :)

Posted: Fri Nov 18, 2005 9:55 am
by Xombie
Was working on my main project when Pantcho(!!) had a few more questions on this code. So... being naturally curious about programming, I added and changed a few things. This was all done quickly so it's not as elegant as it could be. Please forgive me :)

Code: Select all

Enumeration
   #WindowMain 
EndEnumeration

Enumeration
   #ImageScroll
EndEnumeration

#ScrollWidth = 400

;- Global Variables
Dim ArrayScroll.s(2)
Global HandleImage.l
Global HandleTimer.l
Global PositionText.l
Global DoBounce.b
Global BounceDirection.b
Global PauseScroll.b
Global ScrollClick.POINT
Global IsFinishedDrawing.b
;- Procedures
Procedure.l ScrollCallback(HandleWindow.l, Message.l, EventID.l, dwTime.l)
   ;
   lImage.l
   ;
   lBrush.l
   ;
   IsMouseOver.b
   ;
   LastPosition.l
   ;
   HoldPosition.POINT
   ;
   BrushProperties.LOGBRUSH
   ; Brush properties - color, brush type.
   HoldRect.RECT
   ; Rectangular coordinates used to fill shapes.
   HyperRect.RECT
   ;
   FontSize.l
   ;
   CellFont.l
   ;
   CellText.s
   ;
   If IsFinishedDrawing
      ;
      GetCursorPos_(@HoldPosition)
      ;
      lHold = WindowFromPoint_(HoldPosition\X, HoldPosition\Y)
      ;
      MapWindowPoints_(0, GadgetID(#ImageScroll), @HoldPosition, 1)
      ;
      If lHold = GadgetID(#ImageScroll) : IsMouseOver = #True : EndIf
      ;
      If PauseScroll : ProcedureReturn : EndIf
      ;
      IsFinishedDrawing = #False
      ;
      UseImage(HandleImage)
      ;
      lImage = StartDrawing(ImageOutput())
      ;
      BrushProperties\lbStyle = #BS_SOLID
      BrushProperties\lbColor = RGB(0, 0, 0)
      ;
      lBrush = CreateBrushIndirect_(BrushProperties)
      ;
      SelectObject_(lImage, lBrush)
      ;
      HoldRect\Left = 0 : HoldRect\Top = 0 : HoldRect\Right = WindowWidth() : HoldRect\Bottom = 100
      ;
      FillRect_(lImage, HoldRect, lBrush)
      ;
      DeleteObject_(lBrush) : lBrush = 0
      ;
      SetTextColor_(lImage, RGB(255, 0, 0)) : SetBkMode_(lImage, #TRANSPARENT)
      ;
      CellText = ArrayScroll(0)
      ;
      FontSize = -Int((16 * GetDeviceCaps_(lImage, #LOGPIXELSY)) / 72)
      ; Using 28 as the height.
      CellFont = CreateFont_(FontSize,0,0,0,0,0,0,0,#ANSI_CHARSET,#OUT_DEFAULT_PRECIS,#CLIP_DEFAULT_PRECIS,#PROOF_QUALITY,0,"Arial")
      ; Set any font formatting here.  Italics, bold, whatever.
      SelectObject_(lImage, CellFont)
      ;
      DrawText_(lImage, @CellText, Len(CellText), @HoldRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE | #DT_CALCRECT) 
      ;
      MoveToEx_(lImage, PositionText, Int((GadgetHeight(#ImageScroll) - HoldRect\Bottom) / 2), 0)
      ;
      DrawText_(lImage, @CellText, Len(CellText), @HoldRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE)
      ; Draw the column header. 
      DeleteObject_(CellFont)
      ;
      LastPosition = PositionText + HoldRect\Right
      ;
      SetRect_(@HoldRect, 0, 0, 0, 0)
      ;
      ;- Begin Hyperlink Drawing
      If IsMouseOver And ArrayScroll(0) <> ""
         ;
         SetTextColor_(lImage, RGB(0, 0, 255)) : SetBkMode_(lImage, #TRANSPARENT)
         ;
         CellText = ArrayScroll(1)
         ;
         CellFont = CreateFont_(FontSize,0,0,0,0,1,1,0,#ANSI_CHARSET,#OUT_DEFAULT_PRECIS,#CLIP_DEFAULT_PRECIS,#PROOF_QUALITY,0,"Arial")
         ; Set any font formatting here.  Italics, bold, whatever.
         SelectObject_(lImage, CellFont)
         ;
         DrawText_(lImage, @CellText, Len(CellText), @HyperRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE | #DT_CALCRECT) 
         ;
         If (HoldPosition\X > LastPosition And HoldPosition\X < LastPosition + HyperRect\Right)
            ;
            MoveToEx_(lImage, LastPosition, Int((GadgetHeight(#ImageScroll) - HyperRect\Bottom) / 2), 0)
            ;
            DrawText_(lImage, @CellText, Len(CellText), @HyperRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE)
            ; Draw the column header.
            If ScrollClick\X <> -1 And ScrollClick\Y <> -1 : RunProgram(ArrayScroll(1)) : EndIf
            ;
         Else
            ;
            IsMouseOver = #False
            ;
         EndIf
         ;
         DeleteObject_(CellFont)
         ;
      EndIf
      ;
      If IsMouseOver = #False Or ArrayScroll(0) = ""
         ;
         SetTextColor_(lImage, RGB(255, 0, 0)) : SetBkMode_(lImage, #TRANSPARENT)
         ;
         CellText = ArrayScroll(1)
         ;
         CellFont = CreateFont_(FontSize,0,0,0,0,0,0,0,#ANSI_CHARSET,#OUT_DEFAULT_PRECIS,#CLIP_DEFAULT_PRECIS,#PROOF_QUALITY,0,"Arial")
         ; Set any font formatting here.  Italics, bold, whatever.
         SelectObject_(lImage, CellFont)
         ;
         DrawText_(lImage, @CellText, Len(CellText), @HyperRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE | #DT_CALCRECT) 
         ;
         MoveToEx_(lImage, LastPosition, Int((GadgetHeight(#ImageScroll) - HyperRect\Bottom) / 2), 0)
         ;
         DrawText_(lImage, @CellText, Len(CellText), @HyperRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE)
         ; Draw the column header. 
         DeleteObject_(CellFont)
         ;
      EndIf
      ;
      LastPosition + HyperRect\Right
      ;-
      If ArrayScroll(2) <> ""
         ;
         SetTextColor_(lImage, RGB(255, 0, 0)) : SetBkMode_(lImage, #TRANSPARENT)
         ;
         CellText = ArrayScroll(2)
         ;
         CellFont = CreateFont_(FontSize,0,0,0,0,0,0,0,#ANSI_CHARSET,#OUT_DEFAULT_PRECIS,#CLIP_DEFAULT_PRECIS,#PROOF_QUALITY,0,"Arial")
         ; Set any font formatting here.  Italics, bold, whatever.
         SelectObject_(lImage, CellFont)
         ;
         DrawText_(lImage, @CellText, Len(CellText), @HoldRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE | #DT_CALCRECT) 
         ;
         MoveToEx_(lImage, LastPosition, Int((GadgetHeight(#ImageScroll) - HoldRect\Bottom) / 2), 0)
         ;
         DrawText_(lImage, @CellText, Len(CellText), @HoldRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE)
         ; Draw the column header. 
         DeleteObject_(CellFont)
         ;
      EndIf
      ;
      LastPosition + HoldRect\Right
      ;
      StopDrawing()
      ;
      SetGadgetState(#ImageScroll, ImageID())
      ;
      If DoBounce
         ; Bouncing between boundaries.
         If BounceDirection
            ; Scrolling left.
            If LastPosition = 0 : PositionText + 1 : BounceDirection = 0 : Else : PositionText -1 : EndIf
            ;
         Else
            ; Scrolling light.
            If LastPosition >= GadgetWidth(#ImageScroll) : PositionText - 1 : BounceDirection = 1 : Else : PositionText + 1 : EndIf
            ;
         EndIf
         ;
      Else
         ; Wrapping.
         If LastPosition >= 0 : PositionText - 1 : Else : PositionText = GadgetWidth(#ImageScroll) : EndIf
         ; Move the text to the left for the next call.
      EndIf
      ;
      ScrollClick\X = -1 : ScrollClick\Y = -1
      ;
      IsFinishedDrawing = #True
      ;
   EndIf
   ;
EndProcedure
;
;- Main Code
;
EventID.l
; Variable to hold the window message.
DoQuit.b
; Variable to control whether we quit the window or not.  Automatically set to #False.
lHold.l
;
HoldString.s
;
ArrayScroll(0) = "From Xombie! - Go to "
ArrayScroll(1) = "http://www.seijin.net/"
ArrayScroll(2) = " and be happy!"
;
If OpenWindow(#WindowMain, 0, 0, 650, 310, #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_SizeGadget, "xGrid")
   ; Create the main window.
   If CreateGadgetList(WindowID())
      ;
      AdvancedGadgetEvents(#True)
      ; Enable advanced gadget events.
      HandleImage = CreateImage(#PB_Any, #ScrollWidth - 1, 40)
      ;
      ImageGadget(#ImageScroll, 0, 0, #ScrollWidth - 1, 100, UseImage(HandleImage), #PB_Image_Border)
      ;
   EndIf
   ;
   IsFinishedDrawing = #True
   ;
   PositionText = GadgetWidth(#ImageScroll)
   ;
   HandleTimer = SetTimer_(0, 0, 1, @ScrollCallback())
   ;
   Repeat
      ;
      ;{ Event Loop
      EventID = WaitWindowEvent()
      ;
      If EventID = #PB_Event_CloseWindow
         ; Close the program.
         DoQuit = #True
         ;
      ElseIf EventID = #PB_Event_SizeWindow
         ;
         ;
      ElseIf EventID = #PB_Event_Menu
         ; Menu Events
         ;
      ElseIf EventID = #PB_Event_Gadget
         ; Control Events
         If EventGadgetID() = #ImageScroll
            ;
            If EventType() = #PB_EventType_LeftClick
               ;
               GetCursorPos_(@ScrollClick) : MapWindowPoints_(0, GadgetID(#ImageScroll), @ScrollClick, 1)
               ;
               ; If PauseScroll : PauseScroll = #False : Else : PauseScroll = #True : EndIf 
               ;
            ElseIf EventType() = #PB_EventType_RightClick
               ;
               Hold01.s = InputRequester("Scroll Test", "Please enter the first part of the message.  This will either be the whole message or the message before the hyperlink.  If using a hyperlink, please leave a space after this string.", "")
               ;
               Hold02.s = InputRequester("Scroll Test", "Please enter the web address.  Leave blank if no web address is needed.", "http://www.seijin.net/")
               ;
               Hold03.s = InputRequester("Scroll Test", "Please enter the text that follows the web address.  Leave blank if no web address was used.  If using a hyperlink, please use a space at the beginning of this string.", "")
               ;
               ArrayScroll(0) = Hold01 : ArrayScroll(1) = Hold02 : ArrayScroll(2) = Hold03
               ;
               ; If DoBounce : DoBounce = #False : Else : DoBounce = #True : BounceDirection = #True : EndIf
               ;
            EndIf
            ;
         EndIf
         ;
      EndIf
      ;}
      ;
   Until DoQuit = #True
   ;
   KillTimer_(0, HandleTimer)
   ;
EndIf
Now move the mouse over the "http://www.seijin.net/" part and it should pretend to be a kind of hyperlink. Click it and it should launch the link. There is an array to control what text is displayed - ArrayScroll(). ArrayScroll(0) is the text before the hyperlink. ArrayScroll(1) is the hyperlink. ArrayScroll(2) is the text after the hyperlink. Be sure to put a space at the end of ArrayScroll(0) and before in ArrayScroll(2) or it will look weird :)

There are two other behaviors that you can turn on. Look for these lines...

Code: Select all

            If EventType() = #PB_EventType_LeftClick
               ;
               GetCursorPos_(@ScrollClick) : MapWindowPoints_(0, GadgetID(#ImageScroll), @ScrollClick, 1)
               ;
               ; If PauseScroll : PauseScroll = #False : Else : PauseScroll = #True : EndIf 
               ;
            ElseIf EventType() = #PB_EventType_RightClick
               ;
               Hold01.s = InputRequester("Scroll Test", "Please enter the first part of the message.  This will either be the whole message or the message before the hyperlink.  If using a hyperlink, please leave a space after this string.", "")
               ;
               Hold02.s = InputRequester("Scroll Test", "Please enter the web address.  Leave blank if no web address is needed.", "http://www.seijin.net/")
               ;
               Hold03.s = InputRequester("Scroll Test", "Please enter the text that follows the web address.  Leave blank if no web address was used.  If using a hyperlink, please use a space at the beginning of this string.", "")
               ;
               ArrayScroll(0) = Hold01 : ArrayScroll(1) = Hold02 : ArrayScroll(2) = Hold03
               ;
               ; If DoBounce : DoBounce = #False : Else : DoBounce = #True : BounceDirection = #True : EndIf
               ;
            EndIf
The commented DoBounce line will make the text bounce between the boundary when it is enabled (not tested with the hyperlink code, sorry). The commented PauseScroll line will pause the display when enabled. I have not tested the pause or bounce functions with the hyperlink because the hyperlink stuff was added on after Pantcho requested it :) The greedy fella :D So to test the bounce and pause functions, comment the hyperlink functions in the left and right click events. You can test changing the displayed text by right-clicking in the image gadget.

Maybe this is useful for someone else as well?

And remember - this was a quick & dirty thing I slapped together for Mr. Pantcho(!!!!!!) so it's kinda ugly and could use some clean up. However, it's 1am and I have work tomorrow so... :)

EDIT: Made a really quick modification that you can grab here...

http://www.seijin.net/Storage/ScrollThingie.pb

... basically it adds an ArrayScroll(3) that you can use to store the actual website address. ArrayScroll(1) can now contain something more friendly if you want to hide the full website address. Also, the hyperlink is now always underlined so they know to click on it.

Oh, and you can always change #ScrollWidth if you want a different width for the scrolling text thingie.

Posted: Fri Nov 18, 2005 10:00 am
by Pantcho!!
I was Greedy i admit!
This code is perfect!

Xombie thanks alot for helping and spending your time to do this
i really need this for my project and i guess meny other peple will find a good use for this.

great code!

Thank you very much.

Posted: Mon Jul 24, 2006 9:55 pm
by Xombie
Here's a quick update to make it more like a 'gadget'.

Code: Select all

;-
#PB_ScrollText_Bounces = 2
#PB_ScrollText_MousePauses = 4
#PB_ScrollText_Border = 8
;-
Enumeration ; Window Enumeration
   #WindowMain 
EndEnumeration
Enumeration ; Gadget Enumeration
   #ScrollMain
   #ScrollTwo
   #ButtonTest
EndEnumeration
;-
Structure s_ScrollText_Main
   ;
   Gadget.l
   ;
   GadgetImage.l
   ;
   HandleImage.l
   ;
   Text.s
   ;
   FontName.s
   FontSize.l
   ;
   ColorBack.l
   ColorFront.l
   ;
   DelayAmount.l
   LastDrawn.l
   ;
   HandleTimer.l
   ; The handle to the callback timer.
   IsFinishedDrawing.b
   ;
   PositionText.l
   ;
   BounceText.b
   ;
   BounceDirection.b
   ;
   MousePauses.b
   ;
   Paused.b
   ;
EndStructure
;-
Global NewList __s_ScrollText_Main.s_ScrollText_Main()
;-
EnableExplicit
;-
Procedure st_RemoveAll()
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      KillTimer_(0, __s_ScrollText_Main()\HandleTimer) 
      ;
      FreeImage(__s_ScrollText_Main()\HandleImage)
      ;
      FreeGadget(__s_ScrollText_Main()\GadgetImage)
      ;
      DeleteElement(__s_ScrollText_Main())
      ;
   Wend
   ;
EndProcedure
Procedure st_Remove(Gadget.l)
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\Gadget = Gadget
         ;
         KillTimer_(0, __s_ScrollText_Main()\HandleTimer) 
         ;
         FreeImage(__s_ScrollText_Main()\HandleImage)
         ;
         FreeGadget(__s_ScrollText_Main()\GadgetImage)
         ;
         DeleteElement(__s_ScrollText_Main())
         ;
         Break
         ;
      EndIf
      ;
   Wend
   ;
EndProcedure
Procedure st_ChangeFont(Gadget.l, FontName.s, FontSize.l)
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\Gadget = Gadget
         ;
         __s_ScrollText_Main()\FontName = FontName
         __s_ScrollText_Main()\FontSize = FontSize
         ;
         Break
         ;
      EndIf
      ;
   Wend
   ;
EndProcedure
Procedure st_ChangeColor(Gadget.l, ColorBack.l, ColorFront.l)
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\Gadget = Gadget
         ;
         __s_ScrollText_Main()\ColorBack = ColorBack
         __s_ScrollText_Main()\ColorFront = ColorFront
         ;
         Break
         ;
      EndIf
      ;
   Wend
   ;
EndProcedure
Procedure st_ChangeDelay(Gadget.l, DelayAmount.l) ; In Milliseconds.
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\Gadget = Gadget
         ;
         __s_ScrollText_Main()\DelayAmount = DelayAmount
         ;
         __s_ScrollText_Main()\LastDrawn = ElapsedMilliseconds()
         ;
         Break
         ;
      EndIf
      ;
   Wend
   ;
EndProcedure
Procedure.l st_GetX(Gadget.l)
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\Gadget = Gadget
         ;
         ProcedureReturn GadgetX(__s_ScrollText_Main()\GadgetImage)
         ;
      EndIf
      ;
   Wend
   ;
EndProcedure
Procedure.l st_GetY(Gadget.l)
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\Gadget = Gadget
         ;
         ProcedureReturn Gadgety(__s_ScrollText_Main()\GadgetImage)
         ;
      EndIf
      ;
   Wend
   ;
EndProcedure
Procedure.l st_GetWidth(Gadget.l)
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\Gadget = Gadget
         ;
         ProcedureReturn GadgetWidth(__s_ScrollText_Main()\GadgetImage)
         ;
      EndIf
      ;
   Wend
   ;
EndProcedure
Procedure.l st_GetHeight(Gadget.l)
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\Gadget = Gadget
         ;
         ProcedureReturn GadgetHeight(__s_ScrollText_Main()\GadgetImage)
         ;
      EndIf
      ;
   Wend
   ;
EndProcedure
Procedure.l st_Resize(Gadget.l, X.l, Y.l, Width.l, Height.l)
   ;
   Define.b ChangedState
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      With __s_ScrollText_Main()
         ;
         If \Gadget = Gadget
            ;
            If \IsFinishedDrawing : ChangedState = #True : EndIf
            ;
            \IsFinishedDrawing = #False 
            ;
            FreeImage(\HandleImage)
            ;
            ResizeGadget(\GadgetImage, X, Y, Width, Height)
            ;
            \HandleImage = CreateImage(#PB_Any, GadgetWidth(\GadgetImage), GadgetHeight(\GadgetImage))
            ;
            If ChangedState : \IsFinishedDrawing = #True : EndIf
            ;
            Break
            ;
         EndIf
         ;
      EndWith
      ;
   Wend
   ;
EndProcedure
Procedure st_Pause(Gadget.l, Pause.b)
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\Gadget = Gadget
         ;
         __s_ScrollText_Main()\Paused = Pause
         ;
         Break
         ;
      EndIf
      ;
   Wend
   ;
EndProcedure
Procedure.b st_IsPaused(Gadget.l)
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\Gadget = Gadget
         ;
         ProcedureReturn __s_ScrollText_Main()\Paused
         ;
      EndIf
      ;
   Wend
   ;
EndProcedure
Procedure.l ScrollCallback(HandleWindow.l, message.l, EventID.l, dwTime.l)
   ;
   Define.l hdc
   ;
   Define.l lBrush
   ;
   Define.b IsMouseOver
   ;
   Define.l LastPosition
   ;
   Define.POINT HoldPosition
   ;
   Define.LOGBRUSH BrushProperties
   ; Brush properties - color, brush type.
   Define.RECT HoldRect
   ; Rectangular coordinates used to fill shapes.
   Define.l FontSize
   ;
   Define.l HoldFont
   ;
   Define.s CellText
   ;
   Define.b CaughtMatch
   ;
   Define.l HandleWindow
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\HandleTimer = EventID : CaughtMatch = #True : Break : EndIf
      ;
   Wend
   ;
   If CaughtMatch = #False : ProcedureReturn : EndIf
   ;
   If __s_ScrollText_Main()\Paused : ProcedureReturn : EndIf
   ;
   If __s_ScrollText_Main()\IsFinishedDrawing
      ;
      If __s_ScrollText_Main()\DelayAmount And ElapsedMilliseconds() - __s_ScrollText_Main()\LastDrawn < __s_ScrollText_Main()\DelayAmount : ProcedureReturn : EndIf
      ;
      GetCursorPos_(@HoldPosition)
      ;
      HandleWindow = WindowFromPoint_(HoldPosition\X, HoldPosition\Y)
      ;
      MapWindowPoints_(0, GadgetID(__s_ScrollText_Main()\GadgetImage), @HoldPosition, 1)
      ;
      If HandleWindow = GadgetID(__s_ScrollText_Main()\GadgetImage) : IsMouseOver = #True : EndIf
      ;
      If __s_ScrollText_Main()\MousePauses And IsMouseOver : ProcedureReturn : EndIf
      ;
      __s_ScrollText_Main()\IsFinishedDrawing = #False
      ;
      hdc = StartDrawing(ImageOutput(__s_ScrollText_Main()\HandleImage))
         ;
         BrushProperties\lbStyle = #BS_SOLID
         BrushProperties\lbColor = __s_ScrollText_Main()\ColorBack
         ;
         lBrush = CreateBrushIndirect_(BrushProperties)
         ;
         SelectObject_(hdc, lBrush)
         ;
         HoldRect\left = 0 : HoldRect\top = 0 : HoldRect\right = GadgetWidth(__s_ScrollText_Main()\GadgetImage) : HoldRect\bottom = GadgetHeight(__s_ScrollText_Main()\GadgetImage)
         ;
         FillRect_(hdc, HoldRect, lBrush)
         ;
         DeleteObject_(lBrush) : lBrush = 0
         ;
         SetTextColor_(hdc, __s_ScrollText_Main()\ColorFront) : SetBkMode_(hdc, #TRANSPARENT)
         ;
         FontSize = -Int((__s_ScrollText_Main()\FontSize * GetDeviceCaps_(hdc, #LOGPIXELSY)) / 72)
         ; Using 28 as the height.
         HoldFont = CreateFont_(FontSize,0,0,0,0,0,0,0,#ANSI_CHARSET,#OUT_DEFAULT_PRECIS,#CLIP_DEFAULT_PRECIS,#PROOF_QUALITY,0,__s_ScrollText_Main()\FontName)
         ; Set any font formatting here.  Italics, bold, whatever.
         SelectObject_(hdc, HoldFont)
         ;
         DrawText_(hdc, @__s_ScrollText_Main()\Text, Len(__s_ScrollText_Main()\Text), @HoldRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE | #DT_CALCRECT) 
         ;
         MoveToEx_(hdc, __s_ScrollText_Main()\PositionText, Int((GadgetHeight(__s_ScrollText_Main()\GadgetImage) - HoldRect\bottom) / 2), 0)
         ;
         DrawText_(hdc, @__s_ScrollText_Main()\Text, Len(__s_ScrollText_Main()\Text), @HoldRect, #DT_NOCLIP | #DT_NOPREFIX | #DT_SINGLELINE)
         ; Draw the column header. 
         DeleteObject_(HoldFont)
         ;
         LastPosition = __s_ScrollText_Main()\PositionText + HoldRect\right
         ;
         SetRect_(@HoldRect, 0, 0, 0, 0)
         ;
      StopDrawing()
      ;
      SetGadgetState(__s_ScrollText_Main()\GadgetImage, ImageID(__s_ScrollText_Main()\HandleImage))
      ;
      If __s_ScrollText_Main()\BounceText
         ; Bouncing between boundaries.
         If __s_ScrollText_Main()\BounceDirection
            ; Scrolling left.
            If LastPosition = 0 : __s_ScrollText_Main()\PositionText + 1 : __s_ScrollText_Main()\BounceDirection = 0 : Else : __s_ScrollText_Main()\PositionText -1 : EndIf
            ;
         Else
            ; Scrolling right.
            If LastPosition >= GadgetWidth(__s_ScrollText_Main()\GadgetImage) : __s_ScrollText_Main()\PositionText - 1 : __s_ScrollText_Main()\BounceDirection = 1 : Else : __s_ScrollText_Main()\PositionText + 1 : EndIf
            ;
         EndIf
         ;
      Else
         ; Wrapping.
         If LastPosition >= 0 : __s_ScrollText_Main()\PositionText - 1 : Else : __s_ScrollText_Main()\PositionText = GadgetWidth(__s_ScrollText_Main()\GadgetImage) : EndIf
         ; Move the text to the left for the next call.
      EndIf
      ;
      __s_ScrollText_Main()\IsFinishedDrawing = #True
      ;
      __s_ScrollText_Main()\LastDrawn = ElapsedMilliseconds()
      ;
   EndIf
   ;
EndProcedure
Procedure ScrollTextGadget(Gadget.l, X.l, Y.l, Width.l, Height.l, Text.s, FontName.s, FontSize.l, flags.l = 0)
   ;
   Define.b Border
   ;
   ResetList(__s_ScrollText_Main())
   While NextElement(__s_ScrollText_Main())
      ;
      If __s_ScrollText_Main()\Gadget = Gadget : ProcedureReturn : EndIf
      ;
   Wend
   ;
   AddElement(__s_ScrollText_Main())
   ;
   With __s_ScrollText_Main()
      ;
      If flags & #PB_ScrollText_Border : \GadgetImage = ImageGadget(#PB_Any, X, Y, Width, Height, #Null, #PB_Image_Border) : Else : \GadgetImage = ImageGadget(#PB_Any, X, Y, Width, Height, #Null) : EndIf
      ;
      \HandleImage = CreateImage(#PB_Any, GadgetWidth(\GadgetImage), GadgetHeight(\GadgetImage))
      ;
      \Gadget = Gadget
      \Text = Text
      ;
      \FontName = FontName
      \FontSize = FontSize
      ;
      \ColorBack = RGB(0, 0, 0)
      \ColorFront = RGB(255, 0, 0)
      ;
      \DelayAmount = 0
      ;
      \IsFinishedDrawing = #True
      ;
      \PositionText = GadgetWidth(\GadgetImage)
      ;
      If flags & #PB_ScrollText_Bounces : \BounceText = #True : EndIf
      ;
      If flags & #PB_ScrollText_MousePauses : \MousePauses = #True : EndIf
      ;
      \HandleTimer = SetTimer_(0, 0, 1, @ScrollCallback())
      ;
   EndWith
   ;
EndProcedure
;-
Define.l EventID
; Variable to hold the window message.
Define.b DoQuit
; Variable to control whether we quit the window or not.  Automatically set to #False.
If OpenWindow(#WindowMain, 0, 0, 300, 150, "Test", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_SizeGadget)
   ; Create the main window.
   If CreateGadgetList(WindowID(#WindowMain))
      ;
      ScrollTextGadget(#ScrollMain, 0, 0, 300 - 1, 20, "Test Scroll", "Arial", 12, #PB_ScrollText_Border | #PB_ScrollText_MousePauses)
      ScrollTextGadget(#ScrollTwo, 0, 25, 300 - 1, 20, "Second Scroller", "Garamond", 12, #PB_ScrollText_Bounces | #PB_ScrollText_Border)
      ;
      ButtonGadget(#ButtonTest, 0, 50, 80, 20, "Pause State")
      ;
   EndIf
   ;
   st_ChangeDelay(#ScrollMain, 20)
   st_ChangeColor(#ScrollTwo, RGB(255, 255, 255), RGB(0, 0, 0))
   ;
   Repeat
      ;
      ;{ Event Loop
      EventID = WaitWindowEvent()
      ;
      If EventID = #PB_Event_CloseWindow
         ; Close the program.
         DoQuit = #True
         ;
      ElseIf EventID = #PB_Event_SizeWindow
         ;
         ;
      ElseIf EventID = #PB_Event_Menu
         ; Menu Events
         ;
      ElseIf EventID = #PB_Event_Gadget
         ; Control Events
         If EventGadget() = #ButtonTest
            ;
            If EventType() = #PB_EventType_LeftClick
               ;
               If st_IsPaused(#ScrollTwo)
                  ;
                  st_Pause(#ScrollTwo, #False)
                  ;
               Else
                  ;
                  st_Pause(#ScrollTwo, #True)
                  ;
               EndIf
               ;
            EndIf
            ;
         EndIf
         ;
      EndIf
      ;}
      ;
   Until DoQuit = #True
   ;
EndIf
;-
st_RemoveAll()
;-
End
;-
I removed the HTML link stuff in this one but may add it in if enough interest. Sorry for not posting a file to download but I don't have access to my ftp at the moment :)

Posted: Tue Jul 25, 2006 8:12 am
by Pantcho!!
Thanks man 8)