Modified code above to use a rounded box instead. Clipping routine adapted from
Neuro Fuzzy's code.
It's pretty slow, but I believe that's due to my drawing routines.
type vector2
x as float
y as float
endtype
boxX = 100
boxY = 100
boxWidth = 400
boxHeight = 20
radius = boxHeight/2
thickness = 16
spacing = 16
point1 as vector2
point2 as vector2
p# = 0.35
sync on
do
cls
Rem Width for loaded percent of box
width = boxWidth*p#
Rem background
ink 0xFFEEEEEE,0
roundedBoxFill(boxX, boxY, boxX+boxWidth, boxY+boxHeight-1, radius)
Rem base stripes
ink 0xFF6AD1FC, 0
`box boxX, boxY, boxX+width, boxY+boxHeight
roundedBoxFill(boxX, boxY, boxX+width, boxY+boxHeight-1, radius)
Rem diagonal lines
ink 0xFF3E7890,0
for i = -boxHeight-spacing to width step thickness+spacing
for x = 0 to thickness-1
ox = x + i + scrollOffset
point1.x = boxX + ox
point1.y = boxY
point2.x = boxX + ox + boxHeight
point2.y = boxY + boxHeight
clipLineToCapsule(point1,point2, boxX, boxY, boxX+width-2, boxY+boxHeight, radius)
next x
next i
Rem highlight
c1 = 0xCCFFFFFF
c2 = 0x33FFFFFF
`box boxX, boxY, boxX+boxWidth, boxY+boxHeight*0.5, c2,c1,c2,c1
rem outlines/borders
`E2DC_Rounded_Box_AA_Alpha_Outline(boxX, boxY, boxX+width, boxY+boxHeight, radius, 0xFF6AD1FC)
E2DC_Rounded_Box_AA_Alpha_Outline(boxX, boxY, boxX+boxWidth, boxY+boxHeight, radius, 0xFFCCCCCC)
E2DC_Rounded_Box_AA_Alpha_Outline(boxX+1, boxY+1, boxX+boxWidth-1, boxY+boxHeight-1, radius-2, 0xFFCCCCCC)
E2DC_Rounded_Box_AA_Alpha_Outline(boxX-1, boxY-1, boxX+boxWidth+1, boxY+boxHeight+1, radius+2, 0xFFCCCCCC)
Rem percentage text
ink 0xFFCCCCCC,0
center text boxX+boxWidth/2, boxY+boxHeight, str$(int(p#*100))+"%"
Rem animate/scroll stripes
if timestamp+20 < timer()
inc scrollOffset
if scrollOffset > spacing*2 then scrollOffset = 0
timestamp = timer()
endif
Rem Controls percent loaded
if rightkey()
p# = p# + 0.01
if p# > 1 then p# = 1
endif
if leftkey()
p# = p# - 0.01
if p# < 0.15 then p# = 0.15
endif
ink rgb(255,0,0),0
print screen fps()
print p#
sync
loop
end
function clipLineToCapsule(p1 as vector2, p2 as vector2, rbx1, rby1, rbx2, rby2, radius)
ax = p1.x
ay = p1.y
bx = p2.x
by = p2.y
if p1.x < rbx1+radius or p2.x > rbx2-radius
c as vector2
c.y = rby1 + (rby2-rby1)/2
if p2.x > rbx2-radius
c.x = rbx2-radius
else
c.x = rbx1+radius
endif
x21 as float
y21 as float
y1c as float
x1c as float
quad_a as float
quad_b as float
quad_c as float
x21 = p2.x - p1.x
x1c = p1.x - C.x
y21 = p2.y - p1.y
y1c = p1.y - C.y
quad_a = x21*x21 + y21*y21
quad_b = 2*(x21*x1c + y21*y1c)
quad_c = y1c*y1c + x1c*x1c - radius*radius
d# = sqrt(quad_b*quad_b - 4*quad_a*quad_c)
if d# <= 0 then exitfunction
t1# = (-quad_b+d#) / (2*quad_a)
t2# = (-quad_b-d#) / (2*quad_a)
t#=0
if t1# >= 0 and t1# <= 1.0
if t2# >= 0 and t2# <= 1.0
t# = t1#
if t# > t2# then t# = t2#
else
t# = t1#
endif
else
if t2# >= 0 and t2# <= 1.0
t# = t2#
else
t# = 1.0
endif
endif
if p1.x < rbx1+radius or p1.x > rbx2-radius
ax = (p2.x-p1.x)*t2#+p1.x
ay = (p2.y-p1.y)*t2#+p1.y
endif
if p2.x > rbx2-radius or p2.x < rbx1+radius
bx = (p2.x-p1.x)*t1#+p1.x+1
by = (p2.y-p1.y)*t1#+p1.y+1
endif
endif
line ax, ay, bx, by
endfunction
REM **************************************************
REM Draws an anti-aliased circle with alpha values
REM Based on Xiaolin Wu method
REM **************************************************
function E2DC_Rounded_Box_AA_Alpha_Outline(cx as integer, cy as integer, x2 as integer, y2 as integer, r as integer, color as dword)
local alpha1 as dword
local alpha2 as dword
cx = cx+r
cy = cy+r
ow = x2-cx-r-1
oh = y2-cy-r-1
x = r
xx = r
y = -1
yy = -1
t# = 0
red = rgbr(color)
green = rgbg(color)
blue = rgbb(color)
box cx, cy-r, x2-r, cy-r+1, color, color, color, color
box cx, y2-1, x2-r, y2, color, color, color, color
box cx-r, cy, cx-r+1, y2-r, color, color, color, color
box x2-1, cy, x2, y2-r, color, color, color, color
while x > y
inc y
cur_dist# = E2DC_Distance#(r, y)
if cur_dist# < t# then dec x
c = 127*cur_dist# : alpha1 = E2DC_ARGB(c,red, green, blue)
c = 127 - c : alpha2 = E2DC_ARGB(c,red, green, blue)
rem octant 1
box cx-y, cy-x, cx-y+1, cy-x+1, color, color, color, color
if cy-x > cy-r then box cx-y, cy-x-1, cx-y+1, cy-x, alpha2, alpha2, alpha2, alpha2
box cx-y, cy-x+1, cx-y+1, cy-x+2, alpha1, alpha1, alpha1, alpha1
rem octant 2
box cx-x, cy-y, cx-x+1, cy-y+1, color, color, color, color
if cx-x > cx-r then box cx-x-1, cy-y, cx-x, cy-y+1, alpha2, alpha2, alpha2, alpha2
box cx-x+1, cy-y, cx-x+2, cy-y+1, alpha1, alpha1, alpha1, alpha1
rem octant 3
box cx-x, cy+y+oh, cx-x+1, cy+y+oh+1, color, color, color, color
if cx-x > cx-r then box cx-x-1, cy+y+oh, cx-x, cy+y+oh+1, alpha2, alpha2, alpha2, alpha2
box cx-x+1, cy+y+oh, cx-x+2, cy+y+oh+1, alpha1, alpha1, alpha1, alpha1
rem octant 4
box cx-y, cy+x+oh, cx-y+1, cy+x+oh+1, color, color, color, color
if cy+x+oh < y2-1 then box cx-y, cy+x+1+oh, cx-y+1, cy+x+2+oh, alpha2, alpha2, alpha2, alpha2
box cx-y, cy+x-1+oh, cx-y+1, cy+x+oh, alpha1, alpha1, alpha1, alpha1
rem octant 5
box cx+y+ow, cy+x+oh, cx+y+1+ow, cy+x+1+oh, color, color, color, color
box cx+y+ow, cy+x-1+oh, cx+y+1+ow, cy+x+oh, alpha1, alpha1, alpha1, alpha1
if cy+x+oh < y2-1 then box cx+y+ow, cy+x+1+oh, cx+y+1+ow, cy+x+2+oh, alpha2, alpha2, alpha2, alpha2
rem octant 6
box cx+x+ow, cy+y+oh, cx+x+1+ow, cy+y+1+oh, color, color, color, color
box cx+x-1+ow, cy+y+oh, cx+x+ow, cy+y+1+oh, alpha1, alpha1, alpha1, alpha1
if cx+x+ow < x2-1 then box cx+x+1+ow, cy+y+oh, cx+x+2+ow, cy+y+1+oh, alpha2, alpha2, alpha2, alpha2
rem octant 7
box cx+x+ow, cy-y, cx+x+1+ow, cy-y+1, color, color, color, color
box cx+x-1+ow, cy-y, cx+x+ow, cy-y+1, alpha1, alpha1, alpha1, alpha1
if cx+x+ow < x2-1 then box cx+x+1+ow, cy-y, cx+x+2+ow, cy-y+1, alpha2, alpha2, alpha2, alpha2
rem octant 8
box cx+y+ow, cy-x, cx+y+1+ow, cy-x+1, color, color, color, color
if cy-x > cy-r then box cx+y+ow, cy-x-1, cx+y+1+ow, cy-x, alpha2, alpha2, alpha2, alpha2
box cx+y+ow, cy-x+1, cx+y+1+ow, cy-x+2, alpha1, alpha1, alpha1, alpha1
t# = cur_dist#
endwhile
endfunction
REM **************************************************
REM Original function: OBese87 [Aug. 19 2009]
REM Edited: Phaelax [June 11 2010]
REM Draws a box with rounded corners and filled with
REM the current drawing color
REM **************************************************
function roundedBoxFill(ax,ay,bx,by,r)
dots = r*6.28
deg2dot# = 360 / (dots*1.0)
dotsperqtr# = dots / 4.0
L = abs(bx-ax)-r*2
H = abs(by-ay)
for corner = 2 to 3
select corner
case 0:x=bx-r:y=by-r:endcase
case 1:x=bx-r:y=ay+r:endcase
case 2:x=ax+r:y=ay+r:endcase
case 3:x=ax+r:y=by-r:endcase
endselect
qtr = corner*dotsperqtr#
for o=qtr to qtr+dotsperqtr#
u = sin(o*deg2dot#)*r
v = cos(o*deg2dot#)*r
x2 = L - u*2
box x+u, y+v, x+u+x2, y+v+1
next o
next corner
box ax, ay+r, bx, by-r
endfunction
REM **************************************************
REM Returns a linear interpolated color between base
REM color and target color. Percent ranges from 0 to 1
REM **************************************************
function E2DC_Get_LO_Color(base as dword, target as dword, percent# as float)
br = rgbr(base)
bg = rgbg(base)
bb = rgbb(base)
ba = base >> 24
tr = rgbr(target)
tg = rgbg(target)
tb = rgbb(target)
ta = target >> 24
tr = br + (tr-br)*percent#
tg = bg + (tg-bg)*percent#
tb = bb + (tb-bb)*percent#
ta = ba + (ta-ba)*percent#
color = E2DC_ARGB(ta,tr,tg,tb)
endfunction color
REM **************************************************
REM Returns a color with an alpha value
REM **************************************************
function E2DC_ARGB(a,r,g,b)
local c as dword
c = (a*16777216)+(r*65536)+(g*256)+b
endfunction c
REM **************************************************
REM Draws a point to screen
REM **************************************************
function E2DC_Dot(x as integer, y as integer, color as dword )
if x > 0 and x < screen width() and y > 0 and y < screen height()
offset = get pixels pointer()
pitch = get pixels pitch()
bitsPerPixel = bitmap depth(0)/8
pointer = offset + y*pitch + x*bitsPerPixel
*pointer = color
endif
endfunction
REM **************************************************
REM Returns fractional part of distance
REM * Needed for Xiaolin Wu functions
REM **************************************************
function E2DC_Distance#(a, b)
real# = sqrt(a^2 - b^2)
d# = ceil(real#) - real#
endfunction d#