Scroll starts to bump/flicker

Just starting out? Need help? Post your questions and find answers here.
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Scroll starts to bump/flicker

Post 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
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
Desert Polar Bear
User
User
Posts: 25
Joined: Thu Feb 04, 2021 9:27 pm
Location: Nowhere Special, Arizona, USA

Re: Scroll starts to bump/flicker

Post 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.

Image
Last edited by Desert Polar Bear on Sat Feb 20, 2021 11:55 pm, edited 1 time in total.
"You should never judge a book by its cover."
"A picture is worth a thousand words."

Well, which...? Shuddup!
Image
- Desert Polar Bear • Nowhere Special • Arizona, USA
ProphetOfDoom
User
User
Posts: 84
Joined: Mon Jun 30, 2008 4:36 pm
Location: UK

Re: Scroll starts to bump/flicker

Post 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.
Last edited by ProphetOfDoom on Sat Feb 13, 2021 11:34 pm, edited 2 times in total.
ProphetOfDoom
User
User
Posts: 84
Joined: Mon Jun 30, 2008 4:36 pm
Location: UK

Re: Scroll starts to bump/flicker

Post 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.
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: Scroll starts to bump/flicker

Post 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
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: Scroll starts to bump/flicker

Post 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.
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: Scroll starts to bump/flicker

Post by StarWarsFan »

Desert Polar Bear wrote:Image
^^^Cool, how did you do that animation?
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: Scroll starts to bump/flicker

Post 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
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Scroll starts to bump/flicker

Post 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
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: Scroll starts to bump/flicker

Post by StarWarsFan »

@DK_PETER

Nice, but not helpful. I need a solution with TOOLTIPS, your example has none.
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Scroll starts to bump/flicker

Post 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
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
ProphetOfDoom
User
User
Posts: 84
Joined: Mon Jun 30, 2008 4:36 pm
Location: UK

Re: Scroll starts to bump/flicker

Post 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.
Desert Polar Bear
User
User
Posts: 25
Joined: Thu Feb 04, 2021 9:27 pm
Location: Nowhere Special, Arizona, USA

Re: Scroll starts to bump/flicker

Post by Desert Polar Bear »

StarWarsFan wrote:^^^Cool, how did you do that animation?
Snagit video capture saved as gif.
"You should never judge a book by its cover."
"A picture is worth a thousand words."

Well, which...? Shuddup!
Image
- Desert Polar Bear • Nowhere Special • Arizona, USA
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: Scroll starts to bump/flicker

Post 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.
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: Scroll starts to bump/flicker

Post 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.
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
Post Reply