Scrolling Text Thingie
Posted: Sat Nov 12, 2005 9:09 am
				
				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.
Feel free to laugh at my sleepy code ^_^
			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