Page 1 of 2
Scroll starts to bump/flicker
Posted: Sat Feb 13, 2021 2:02 pm
by StarWarsFan
Hey #PB-friends
I got a problem with my example code. The scrolltext does not run smoothly anymore as soon as you move your mouse over the example button and the tool-tip is displayed.
My question: How can I improve or even fix that? Can someone help me?
Code: Select all
`Declare Marquee(image,width,text$,speed.f)
Declare MyDelay(VERZ)
InitSprite() : ExamineDesktops()
w1= OpenWindow(#PB_Any,0,0,400,100,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu )
OpenWindowedScreen(WindowID(W1),000,10,400,20)
b1= ButtonGadget(#PB_Any,000,050,200,020,"A simple test-button with a tool-tip")
GadgetToolTip(b1,"As soon as you read this text, the scroll flickers!")
text$=" ...TEST SCROLL starts to bump/flicker when mouse is over a button..."
CreateImage(0,400,60)
scrollstart:
scrcnt=0 : Repeat
mydelay(2)
Marquee(0,400,text$,1)
StartDrawing(ScreenOutput())
DrawImage(ImageID(0),0,0)
StopDrawing()
FlipBuffers()
scrcnt+1
Until scrcnt=900
Goto scrollstart
Procedure Marquee(image,width,text$,speed.f)
Global x.f
x.f-speed
StartDrawing(ImageOutput(image))
Box(0,0,width,20,0)
FrontColor($CC6600)
If x<-TextWidth(text$):x=width:EndIf
DrawText(x,0,text$)
StopDrawing()
EndProcedure
Procedure MyDelay(VERZ)
Timer= ElapsedMilliseconds() : Repeat : WaitWindowEvent(1) : Until ElapsedMilliseconds()-Timer >= VERZ
EndProcedure
Re: Scroll starts to bump/flicker
Posted: Sat Feb 13, 2021 5:13 pm
by Desert Polar Bear
I'm not sure if this is any help at all, but running this on a Mac shows a rapidly flickering red bar with very smooth blue text. The gif below doesn't capture just how fast the red bar is flickering. I suspect it's a timing issue with the video capture software.

Re: Scroll starts to bump/flicker
Posted: Sat Feb 13, 2021 7:08 pm
by ProphetOfDoom
Hi StarWarsFan,
Unfortunately your marquee doesn't flicker much here so it's hard to debug!
Does this improve things at all? I've changed it so there's no timeout for the window event, no busy wait for (ElapsedMilliseconds()-Timer) to reach a certain threshold, and x is now calculated newly each time rather than being based on its previous value,
Code: Select all
Declare Marquee(image,width,text$,speed.f)
Declare MyDelay(VERZ)
InitSprite() : ExamineDesktops()
w1= OpenWindow(#PB_Any,0,0,400,100,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu )
OpenWindowedScreen(WindowID(W1),000,10,400,20)
b1= ButtonGadget(#PB_Any,000,050,200,020,"A simple test-button with a tool-tip")
GadgetToolTip(b1,"As soon as you read this text, the scroll flickers!")
text$=" ...TEST SCROLL starts to bump/flicker when mouse is over a button..."
CreateImage(0,400,60)
Global x.f
Global t.f = ElapsedMilliseconds() ; current time
Global nt.f = t ; new time (elapsed)
Global tt.f = 0 ; total time for one iteration
Global l = t
scrollstart:
scrcnt=0 : Repeat
;mydelay(2)
WindowEvent()
Marquee(0,400,text$,0.1)
StartDrawing(ScreenOutput())
DrawImage(ImageID(0),0,0)
StopDrawing()
FlipBuffers()
scrcnt+1
Until scrcnt=900
Goto scrollstart
Procedure Marquee(image,width,text$,speed.f)
StartDrawing(ImageOutput(image))
ClearScreen(0)
Box(0,0,width,20,0)
FrontColor($CC6600)
tt = 1000 / speed
nt = ElapsedMilliseconds()
x = -TextWidth(text$) + (1.0 - ((nt - t) / tt)) * (TextWidth(text$) + width)
If (nt - t) > tt
t = nt
EndIf
DrawText(x,0,text$)
StopDrawing()
EndProcedure
Edit: fixed a bug.
Re: Scroll starts to bump/flicker
Posted: Sat Feb 13, 2021 8:09 pm
by ProphetOfDoom
That comment I wrote in the code "0.1 pixels per second" is wrong, I meant 0.1 complete cycles per second. So if you put 1 the text would return to its starting position in one second.
Re: Scroll starts to bump/flicker
Posted: Sun Feb 14, 2021 10:13 am
by StarWarsFan
ProphetOfDoom wrote:...doesn't flicker much
And still it does!
Move your mouse over and away from the button to see it.
This gets worse the more buttons with tooltips you have
Re: Scroll starts to bump/flicker
Posted: Sun Feb 14, 2021 10:32 am
by Mijikai
Calling WaitWindowEvents() multiple times in a loop is bad.
Only call it once and if that doesnt work out try WindowEvent().
WindowEvent() on the other hand should be called multiple times until there is no more event in the queue.
ProphetOfDoom example doesnt do that.
The screen itself has different options check them out they might be useful aswell.
Good luck.
Re: Scroll starts to bump/flicker
Posted: Sun Feb 14, 2021 10:41 am
by StarWarsFan
Desert Polar Bear wrote:
^^^Cool, how did you do that animation?
Re: Scroll starts to bump/flicker
Posted: Sun Feb 14, 2021 10:45 am
by StarWarsFan
Mijikai wrote:Calling WaitWindowEvents() multiple times in a loop is bad.
Only call it once and if that doesnt work out try WindowEvent().
WindowEvent() on the other hand should be called multiple times until there is no more event in the queue.
The screen itself has different options check them out they might be useful aswell.
Tried that. Did not help the problem.
Even tried Repeat : Until WindowEvent()=0
Does not help either.
The scroll keeps doing a bump as soon as you hover your mouse over or move it away the button
Re: Scroll starts to bump/flicker
Posted: Sun Feb 14, 2021 12:40 pm
by DK_PETER
Try this
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
Re: Scroll starts to bump/flicker
Posted: Sun Feb 14, 2021 12:56 pm
by StarWarsFan
@DK_PETER
Nice, but not helpful. I need a solution with TOOLTIPS, your example has none.
Re: Scroll starts to bump/flicker
Posted: Sun Feb 14, 2021 1:04 pm
by DK_PETER
Then just add the tooltips....
Code: Select all
Procedure.i SetButtons()
Protected x
For x = 0 To 7
ButtonGadget(x, x * 100, 560, 100, 50, "Button " + Str(x))
BindGadgetEvent(x, @AButtons())
GadgetToolTip(x, "This is tooltip for number " + Str(x))
Next x
ProcedureReturn #True
EndProcedure
Re: Scroll starts to bump/flicker
Posted: Sun Feb 14, 2021 4:07 pm
by ProphetOfDoom
I had a book once about Windows programming, I think the author’s name was Charles Petzold. He presented a “bouncing ball” demo which flickered like heck on my laptop. Maybe it’s a hardware or software issue completely separate from your program? I also have a Thinkpad with Ubuntu on it that flickers rather a lot.
Re: Scroll starts to bump/flicker
Posted: Sun Feb 14, 2021 4:35 pm
by Desert Polar Bear
StarWarsFan wrote:^^^Cool, how did you do that animation?
Snagit video capture saved as gif.
Re: Scroll starts to bump/flicker
Posted: Sun Feb 14, 2021 4:43 pm
by StarWarsFan
DK_PETER wrote:Then just add the tooltips....
I did try that, too.
I even removed the background that irritated away from the problem.
Did not help.
Re: Scroll starts to bump/flicker
Posted: Sun Feb 14, 2021 4:44 pm
by StarWarsFan
ProphetOfDoom wrote:I had a book once about Windows programming, I think the author’s name was Charles Petzold. He presented a “bouncing ball” demo which flickered like heck on my laptop. Maybe it’s a hardware or software issue completely separate from your program? I also have a Thinkpad with Ubuntu on it that flickers rather a lot.
No. I have tested this on all my 4 computers.
It is definitely a software issue that must be solved here.