Progress bar without pixel jumps

You can post your code snippets here for others to use and learn from
Post Reply
Flinx
Posts: 361
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Progress bar without pixel jumps

Post by Flinx »

Some time ago, I learned that Hollywood’s graphics system can set the position and size of graphic objects only to integer pixel positions. Now I’ve noticed that the function for scaling vector brushes can handle floating-point numbers to achieve the anti-aliasing effect.
This makes it possible to display a progress bar that appears to grow continuously, without any tricks.
The top bar in the example has no anti-aliasing, while the bottom one does:

Code: Select all

@DISPLAY {Width = 400, Height = 150, Layers=True}

SetFillStyle(#FILLCOLOR)
lineWidth=380
lineHeight=15
StartPath(1)
MoveTo(1, 0, 0)
AddBoxToPath(1, 0, 0, lineWidth, lineHeight)
ClosePath(1)

SetFormStyle(#ANTIALIAS)
StartPath(2)
MoveTo(2, 0, 0)
AddBoxToPath(2, 0, 0, lineWidth, lineHeight)
ClosePath(2)

Local id=PathToBrush(Nil, {{ID=1, Color=#WHITE}, {ID=2, Color=#WHITE, X=0, Y=50}})
FreePath(1)
FreePath(2)

xpos=10
ypos=40
TextOut(xpos, 10, "0%", {Name="%"})
DisplayBrush(id, xpos, ypos, {Name="A", Transparency=0})
FreeBrush(id)
For i=0.0001 To 1 Step 0.0003
	BeginRefresh()
	SetLayerStyle("%", {Text=FormatStr("%.2f%%", 100*i)})
	SetLayerStyle("A", {ScaleX=i})
	EndRefresh()
	Sleep(40)
Next

Sleep(5000)
Ralf
User avatar
Juan Carlos
Posts: 960
Joined: Mon Sep 06, 2010 1:02 pm

Re: Progress bar without pixel jumps

Post by Juan Carlos »

It is a beautiful visual effect, but to make a real progress bar, there are other variables to evaluate, for example, it's to copy a file, the file size, copy ratios, etc., but your visual effect will may to be for a demo, etc.
Flinx
Posts: 361
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Progress bar without pixel jumps

Post by Flinx »

Juan Carlos wrote: Fri Apr 03, 2026 5:29 pm there are other variables to evaluate, for example, it's to copy a file, the file size, copy ratios
Take a look at my for loop — there’s a reason it goes from (almost) zero to one. So all you need is a division, for example, the current copy progress divided by the file size.
User avatar
Juan Carlos
Posts: 960
Joined: Mon Sep 06, 2010 1:02 pm

Re: Progress bar without pixel jumps

Post by Juan Carlos »

Flinx wrote: Fri Apr 03, 2026 7:12 pm
Juan Carlos wrote: Fri Apr 03, 2026 5:29 pm there are other variables to evaluate, for example, it's to copy a file, the file size, copy ratios
Take a look at my for loop — there’s a reason it goes from (almost) zero to one. So all you need is a division, for example, the current copy progress divided by the file size.
Thank you, interesting solution, for the progress bar, I though that it is necessary several variables to have factors to consider include file size, data bus speed, source and destination drive speed, memory buffer size, etc.
Post Reply