Skip to content

Commit

Permalink
ProgressBar: with progress-bar-width, center marker on current position.
Browse files Browse the repository at this point in the history
Previously, the bar's leading (right) edge sat at the current video
position, mainly because I hadn't realized how easy this would be to
implement. This change will probably look odd with large values of
progress-bar-width; however, that isn't the intended use case, and this
change looks significantly better at small values (say, between 0 and
10).
  • Loading branch information
torque committed Oct 31, 2017
1 parent 4969688 commit d6ded6d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/ProgressBar.moon
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,33 @@ class ProgressBar extends BarBase
seekString = ('absolute-percent+%s')\format settings['seek-precision']

new: =>
-- super calls reconfigure which sets barShift.
super!
@lastPosition = 0

reconfigure: =>
super!
seekString = ('absolute-percent+%s')\format settings['seek-precision']
@barWidth = settings['progress-bar-width']
@barShift = settings['progress-bar-width']/2.0
@resize!
@line[7] = [[]]
@line[8] = @line[8]\format settings['bar-foreground-style']

clickHandler: =>
mp.commandv "seek", Mouse.clickX*100/Window.w, seekString

resize: =>
super!
if @barShift > 0
@line[2] = ('%g,%g')\format @barShift, Window.h

redraw: =>
super!
position = mp.get_property_number 'percent-pos', 0
if position != @lastPosition or @needsUpdate
@line[6] = position
if @barWidth > 0
followingEdge = Window.w*position*1e-2 - @barWidth
if @barShift > 0
followingEdge = Window.w*position*1e-2 - @barShift
@line[7] = [[\clip(m %g 0 l %g 0 %g %g %g %g)]]\format followingEdge, Window.w, Window.w, Window.h, followingEdge, Window.h
@lastPosition = position
@needsUpdate = true
Expand Down

0 comments on commit d6ded6d

Please sign in to comment.