Page 1 of 1

[Crossplatform] Scrolling text marquees using WebGadget

Posted: Thu Jun 25, 2009 7:02 pm
by Arctic Fox
Scrolling text "gadgets" using the WebGadget and the <marquee>-tag in HTML.
It will try to auto-position the vertical scrollbar, but sometimes it fails and you will have to position it manually (for instance it fails with a height of 20 pixels and a font size of 12).
Enhancements and modifications are always welcome :)

Code: Select all

Procedure MarqueeText(GadgetNumber, x, y, w, h, Text$, Direction = 0, Reverse = 0, TextColor = 0, BackColor = #White, Font$ = "Arial", FontSize = 12)
Protected ret, BgCo$, TxCo$, Dir$, html$

ret = WebGadget(GadgetNumber, x, y, w, h, "")
HideGadget(GadgetNumber, 1)

BgCo$ = RSet(Hex(Red(BackColor)), 2, "0") + RSet(Hex(Green(BackColor)), 2, "0") + RSet(Hex(Blue(BackColor)), 2, "0")
TxCo$ = RSet(Hex(Red(TextColor)), 2, "0") + RSet(Hex(Green(TextColor)), 2, "0") + RSet(Hex(Blue(TextColor)), 2, "0")

Select Direction
Case 1
Dir$ = "right"

Case 2
Dir$ = "up"

Case 3
Dir$ = "down"

Default
Dir$ = "left"
EndSelect

html$ = "<html><head>" + #CRLF$
html$ + "<style type=" + #DQUOTE$ + "text/css" + #DQUOTE$ + ">" + #CRLF$
html$ + "body {background-color: #" + BgCo$ + ";}" + #CRLF$
html$ + "body,td,th {" + #CRLF$
html$ + "font-family: " + Font$ + ";" + #CRLF$
html$ + "font-size: " + Str(FontSize) + "px;" + #CRLF$
html$ + "color:#" + TxCo$ + ";" + #CRLF$
html$ + "}" + #CRLF$
html$ + "</style></head>" + #CRLF$
html$ + "<body scroll=" + #DQUOTE$ + "no" + #DQUOTE$ + " style=" + #DQUOTE$ + "vertical-align:text-top" + #DQUOTE$ + ">"
html$ + "<marquee direction=" + #DQUOTE$ + Dir$ + #DQUOTE$
If Reverse : html$ + " behavior=" + #DQUOTE$ + "alternate" + #DQUOTE$ : EndIf
html$ + ">" + Text$ + "</marquee></body></html>"

SetGadgetItemText(GadgetNumber, #PB_Web_HtmlCode, html$)
While WindowEvent() : Wend

SetGadgetAttribute(GadgetNumber, #PB_Web_ScrollY, 0.7 * h)
DisableGadget(GadgetNumber, 1)
HideGadget(GadgetNumber, 0)
ProcedureReturn ret
EndProcedure

OpenWindow(0, 100, 100, 300, 300, "WebGadget Marquees")

CompilerIf #PB_Compiler_OS = #PB_OS_Linux Or #PB_Compiler_OS = #PB_OS_Windows
StartDrawing(WindowOutput(0)) : c = Point(0, 0) : StopDrawing()
CompilerElse
c = #White
CompilerEndIf

MarqueeText(0, 5, 15, 290, 17, "Hello World", 0, 0, #Blue, c)
MarqueeText(1, 5, 50, 290, 20, "Direction >> Right >>", 1, 0, $009900, c)
MarqueeText(2, 5, 95, 290, 45, "White background", 0, 1, 0, #White)
MarqueeText(3, 5, 145, 290, 50, "PureBasic rocks!", 2, 0, #White, #Red)

SetGadgetAttribute(1, #PB_Web_ScrollY, 17)

Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End