Code: Select all
InitSprite()
Structure Marquee
id.i
x.f
y.f
im.i
speed.f
ready.i
bg.i
EndStructure
Global m.Marquee, ev, quit, ret, fn.i
Declare.i SetText(txt.s, Font.i = -1, BckColor.i = $0, FrntColor.i = $FFFFFF, ScrollSpeed.f = 1.0, Transp.i = #False)
Declare.i AButtons()
Declare.i SetButtons()
Declare.i UpdateScroll()
Declare.i MakeBG()
OpenWindow(0, 0, 0, 800, 600, "Scroll", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 800 * DesktopResolutionX(), 100)
SetButtons()
MakeBG()
fn = LoadFont(#PB_Any, "MS Sans Serif", 20, #PB_Font_Bold)
SetText("<<<<<This is a simple example for scrolling text......You can change the speed on the fly, background, fonts e.t.c.......<><><>..Press the close button to end..>>>>>", fn, $0, $01F400, 1.2, #True)
Repeat
ClearScreen($0)
Repeat : ev = WindowEvent() : If ev = #PB_Event_CloseWindow : quit = #True : EndIf : Until ev = 0
If IsSprite(m\bg) : DisplaySprite(m\bg, 0, 0) : EndIf
If IsSprite(m\id) And m\ready = #True
ret = UpdateScroll()
DisplayTransparentSprite(m\id, m\x, m\y)
EndIf
FlipBuffers()
Until quit = #True
Procedure.i AButtons()
Protected ga = EventGadget()
Debug "Button pressed - Number " + Str(EventGadget())
Select ga
Case 0
m\speed = 0.2
Case 1
m\speed = 0.5
Case 2
m\speed = 1.0
Case 3
m\speed = 1.5
EndSelect
EndProcedure
Procedure.i SetText(txt.s, Font.i = -1, BckColor.i = $0, FrntColor.i = $FFFFFF, ScrollSpeed.f = 1.0, Transp.i = #False) ;Since we only can move a pixel at a time we can slow the scroll down by using float
Protected fw, fh
m\ready = #False
m\speed = ScrollSpeed
m\x = ScreenWidth()
If IsImage(m\im) = 0 : m\im = CreateImage(#PB_Any, 10, 10) : EndIf
StartDrawing(ImageOutput(m\im))
If Font <> -1 : DrawingFont(FontID(Font)) : EndIf
fw = TextWidth(txt) : fh = TextHeight("W")
StopDrawing()
If IsSprite(m\id) > 0 : FreeSprite(m\id) : EndIf
m\id = CreateSprite(#PB_Any, fw , fh)
StartDrawing(SpriteOutput(m\id))
Box(0, 0, OutputWidth(), OutputHeight(), BckColor)
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(Font))
DrawText(0, 0, txt, FrntColor)
StopDrawing()
If Transp = #True : TransparentSpriteColor(m\id, BckColor) : EndIf
m\ready = #True
ProcedureReturn #True
EndProcedure
Procedure.i SetButtons()
Protected x
For x = 0 To 7
ButtonGadget(x, x * 100, 560, 100, 50, "Button " + Str(x))
BindGadgetEvent(x, @AButtons())
Next x
ProcedureReturn #True
EndProcedure
Procedure.i UpdateScroll()
If IsSprite(m\id) And m\ready = #True
If m\x < -SpriteWidth(m\id)
m\x = ScreenWidth()
EndIf
m\x - m\speed
EndIf
ProcedureReturn #True
EndProcedure
Procedure.i MakeBG()
Protected x
m\bg = CreateSprite(#PB_Any, ScreenWidth(), ScreenHeight())
StartDrawing(SpriteOutput(m\bg))
DrawingMode(#PB_2DDrawing_Outlined)
For x = 2 To ScreenWidth() / 2 Step 10
Circle(ScreenWidth()/2, ScreenHeight() / 2, x, $01D4FF)
Next x
StopDrawing()
ProcedureReturn #True
EndProcedure