Pixel based scrolling text?
Pixel based scrolling text?
How can I program a pixel based scrolling text? (like in famous media players, for example WinAmp)
Do you have any ideas? I'm very thankful for replies!!!
P.S.: I hope you can understand what I mean. ;D
Do you have any ideas? I'm very thankful for replies!!!
P.S.: I hope you can understand what I mean. ;D
Last edited by Snoop0304 on Mon Jul 24, 2006 7:26 am, edited 1 time in total.
did you mean something like this? (sorry it's a bit messy - I'm sure some of the older hands around here could optimise it)
Cheers,
Matt
Code: Select all
;- Scrolling Demo
; Matt Speight
; www.novaseer.net
#width=1 ; Change the width to change the speed of the scroll
CreateImage(0, 110, 20) ; Main scrolling image
CreateImage(1, #width, 20) ; Slice of main image
CreateImage(2, 110-#width, 20) ; Remainder of image after slice
Procedure initImage()
scrolltext$ = "Scroll Me" ; change this to whatever you like
StartDrawing(ImageOutput(0))
Box(0, 0, 110, 20, RGB(0,0,0))
DrawText(0, 0, scrolltext$, RGB(255,255,255),0)
StopDrawing()
EndProcedure
Procedure scrollImage()
GrabImage(0, 1, 0, 0, #width, 20) ; grab the leftmost slice
GrabImage(0, 2, #width, 0, 110-#width, 20); grab the remainder
StartDrawing(ImageOutput(0))
DrawImage(ImageID(1), 110-#width, 0) ; reverse the positions
DrawImage(ImageID(2), 0, 0) ; of the slices
StopDrawing()
EndProcedure
initImage()
If OpenWindow(0, 0, 0, 110, 20, "Scrolling", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
ImageGadget(1, 0, 0, 110, 20, ImageID(0))
Repeat
scrollImage()
SetGadgetState(1,ImageID(0))
Delay(1)
Until WindowEvent() = #PB_Event_CloseWindow
EndIf
Matt
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Cool - I just did some changes in timing and text output...
Code: Select all
;- Scrolling Demo
; Matt Speight
; www.novaseer.net
#width=1 ; Change the width to change the speed of the scroll
#Waitress=15
Global WaitingPoint
CreateImage(0, 110, 20) ; Main scrolling image
CreateImage(1, #width, 20) ; Slice of main image
CreateImage(2, 110-#width, 20) ; Remainder of image after slice
Procedure initImage(mode)
Protected x,y,color
If mode=1
color=#Gray
Else
color=#White
EndIf
scrolltext$ = "Scroll Me" ; change this to whatever you like
StartDrawing(ImageOutput(0))
Box(0, 0, 110, 20,#Black)
DrawText(0,0,scrolltext$,color,0)
Select mode
Case 1
For x=0 To 110 Step 2
For y =0 To 20 Step 2
If Point(x,y)=0
Plot(x,y,#Gray)
Else
Plot(x,y,#White)
EndIf
Next y
Next x
Case 2
For x=1 To 110 Step 2
LineXY(x,0,x,20,#Black)
Next x
For y=0 To 20 Step 2
LineXY(0,y,110,y,#Black)
Next y
EndSelect
StopDrawing()
EndProcedure
Procedure scrollImage()
GrabImage(0, 1, 0, 0, #width, 20) ; grab the leftmost slice
GrabImage(0, 2, #width, 0, 110-#width, 20); grab the remainder
StartDrawing(ImageOutput(0))
DrawImage(ImageID(1), 110-#width, 0) ; reverse the positions
DrawImage(ImageID(2), 0, 0) ; of the slices
StopDrawing()
EndProcedure
Procedure Waiter()
While GetTickCount_()<WaitingPoint
Delay(1)
Wend
EndProcedure
initImage(1)
If OpenWindow(0, 0, 0, 110, 20, "Scrolling", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
ImageGadget(1, 0, 0, 110, 20, ImageID(0))
Repeat
WaitingPoint=GetTickCount_()+#Waitress
scrollImage()
SetGadgetState(1,ImageID(0))
Waiter()
Until WindowEvent() = #PB_Event_CloseWindow
EndIf
-
- Enthusiast
- Posts: 537
- Joined: Wed Oct 29, 2003 10:35 am
Did you search and find this ?
http://www.purebasic.fr/english/viewtop ... lling+text
This is a great example of scrolling text
http://www.purebasic.fr/english/viewtop ... lling+text
This is a great example of scrolling text

Paid up PB User !
Here you go. I updated my code quickly to work under PB 4.0. Read that original link from dontmailme for info on it.
I'll update it in a little bit to be more user friendly but for now you can test this and see what you think
I'll update it in a little bit to be more user friendly but for now you can test this and see what you think

Code: Select all
; Notes
; - Coded by Xombie 11/18/2005
Enumeration
#WindowMain
EndEnumeration
Enumeration
#ImageScroll
EndEnumeration
#ScrollWidth = 400
;- Global Variables
Global Dim ArrayScroll.s(3)
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
;
lImage = StartDrawing(ImageOutput(HandleImage))
;
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(#WindowMain) : 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(3)) : 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,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)
;
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(HandleImage))
;
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) = "here"
ArrayScroll(2) = " and be happy!"
ArrayScroll(3) = "http://www.seijin.net/"
;
If OpenWindow(#WindowMain, 0, 0, 650, 310, "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))
;
HandleImage = CreateImage(#PB_Any, #ScrollWidth - 1, 40)
;
ImageGadget(#ImageScroll, 0, 0, #ScrollWidth - 1, 100, ImageID(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 EventGadget() = #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
;
Use any length string now
Using Michael V's funky LED-like display too
Enjoy
Code: Select all
;- Scrolling Demo
; Matt Speight
; www.novaseer.net
#width=1 ; Change the width to change the speed of the scroll
#Waitress=15
Global WaitingPoint
Global Length
Global scrolltext$ = "scroll a really really really long, overly long really, text line"
CreateImage(0, 1000, 20)
StartDrawing(ImageOutput(0))
Length = TextWidth(scrolltext$)
StopDrawing()
If Length < 110: Length = 110: EndIf
ResizeImage(0, Length, 20) ; Main scrolling image
CreateImage(1, #width, 20) ; Slice of main image
CreateImage(2, Length-#width, 20) ; Remainder of image after slice
Procedure initImage(mode)
Protected x,y,color
If mode=1
color=#Gray
Else
color=#White
EndIf
StartDrawing(ImageOutput(0))
Box(0, 0, 110, 20,#Black)
DrawText(0, 0, scrolltext$, color, 0)
Select mode
Case 1
For x=0 To Length Step 2
For y =0 To 20 Step 2
If Point(x,y)=0
Plot(x, y, #Gray)
Else
Plot(x, y, #White)
EndIf
Next y
Next x
Case 2
For x=1 To Length Step 2
LineXY(x, 0, x, 20, #Black)
Next x
For y=0 To 20 Step 2
LineXY(0, y, Length, y, #Black)
Next y
EndSelect
StopDrawing()
EndProcedure
Procedure scrollImage()
GrabImage(0, 1, 0, 0, #width, 20) ; grab the leftmost slice
GrabImage(0, 2, #width, 0, Length-#width, 20); grab the remainder
StartDrawing(ImageOutput(0))
DrawImage(ImageID(1), Length-#width, 0) ; reverse the positions
DrawImage(ImageID(2), 0, 0) ; of the slices
StopDrawing()
EndProcedure
Procedure Waiter()
While GetTickCount_()<WaitingPoint
Delay(1)
Wend
EndProcedure
initImage(1)
If OpenWindow(0, 0, 0, 110, 20, "Scrolling", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
ImageGadget(1, 0, 0, 110, 20, ImageID(0))
Repeat
WaitingPoint=GetTickCount_()+#Waitress
scrollImage()
SetGadgetState(1,ImageID(0))
Waiter()
Until WindowEvent() = #PB_Event_CloseWindow
EndIf
Enjoy
Last edited by citystate on Mon Jul 24, 2006 10:51 pm, edited 2 times in total.
I updated my code @ http://www.purebasic.fr/english/viewtopic.php?p=154371 to make it a little more user friendly for you, Snoop0304