Skip to content

Commit 77135c4

Browse files
committed
ProgressBarCache: fix full bar drawing
This is a hack that injects a newline to force this single component to produce two separate lines for rendering. in order to produce smaller output, the previous implementation baked both drawings into a single line using an interest hack with the way that ASS drawings work. Well, it seems that interesting hack was more with the way that libass works, and at some point the libass behavior changed, which broke the rendering. When a video was fully cached, the bar would become 100% the width of the canvas. This would cause libass's line-wrapping behavior to engage, which would result in the bar being drawn incorrectly. This was fixed by splitting the bar into two separate. Positioned independently, they do not collide with each other and there is no problem.
1 parent dfaa5c6 commit 77135c4

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/ProgressBarCache.moon

+21-17
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,34 @@ class ProgressBarCache extends BarBase
1515
reconfigure: =>
1616
super 'bar-cache-'
1717
@line[6] = 100
18-
@line[8] = @line[8]\format( settings['bar-cache-style'] ) .. 'm 0 0'
19-
@line[10] = [[{\p0%s\p1}]]\format settings['bar-cache-background-style']
20-
@line[11] = [[]]
18+
@line[9] = ''
19+
-- TODO: this is a hack
20+
@line[10] = '\n'
21+
for idx = 1, 9
22+
@line[idx + 10] = @line[idx]
23+
24+
@line[8] = @line[8]\format( settings['bar-cache-style'] )
25+
@line[18] = @line[18]\format( settings['bar-cache-background-style'] )
2126
@fileDuration = mp.get_property_number 'duration', nil
2227

2328
resize: =>
2429
super!
2530
if @fileDuration
2631
@coordinateRemap = Window.w/@fileDuration
32+
33+
-- map position onto background bar
34+
@line[12] = @line[2]
2735
-- undo BarBase size update
28-
@line[9] = [[]]
36+
@clobber!
37+
38+
animate: ( value ) =>
39+
super value
40+
-- map scale onto background bar
41+
@line[14] = @line[4]
2942

3043
clobber: =>
3144
@line[9] = ""
32-
@line[11] = ""
45+
@line[19] = ""
3346

3447
redraw: =>
3548
super!
@@ -75,25 +88,16 @@ class ProgressBarCache extends BarBase
7588
rect = 'm %g 0 l %g 1 %g 1 %g 0'\format rangeStart, rangeStart, rangeEnd, rangeEnd
7689
table.insert barDrawing.past, rect
7790
elseif rangeStart > progressPosition
78-
-- the way ASS handles two drawings in a single line is weird
79-
-- (drawing coordinates are relative to the end of the previous
80-
-- drawing/character on the same line), so we have to offset all
81-
-- future values by the split point. This is handled by bounding the
82-
-- first (past) set of drawings with m 0 0 and m #{progressPosition}
83-
-- 0.
84-
rangeStart -= progressPosition
85-
rangeEnd -= progressPosition
8691
rect = 'm %g 0 l %g 1 %g 1 %g 0'\format rangeStart, rangeStart, rangeEnd, rangeEnd
8792
table.insert barDrawing.future, rect
8893
else
89-
rangeEnd -= progressPosition
9094
rectPast = 'm %g 0 l %g 1 %g 1 %g 0'\format rangeStart, rangeStart, progressPosition, progressPosition
91-
rectFuture = 'm %g 0 l %g 1 %g 1 %g 0'\format 0, 0, rangeEnd, rangeEnd
95+
rectFuture = 'm %g 0 l %g 1 %g 1 %g 0'\format progressPosition, progressPosition, rangeEnd, rangeEnd
9296
table.insert barDrawing.past, rectPast
9397
table.insert barDrawing.future, rectFuture
9498

95-
@line[9] = table.concat( barDrawing.past, ' ' ) .. 'm %g 0'\format progressPosition
96-
@line[11] = table.concat barDrawing.future, ' '
99+
@line[9] = table.concat barDrawing.past, ' '
100+
@line[19] = table.concat barDrawing.future, ' '
97101

98102
@cacheKey = cacheKey
99103
@needsUpdate = true

0 commit comments

Comments
 (0)