Skip to content

Commit

Permalink
HoverTime: animate position from bottom instead of alpha.
Browse files Browse the repository at this point in the history
I liked the fade-in effect, but it had the problem that it would
override any style-configured opacity for the hover time. Making it pop
up from behind the progress bar is a significantly more straightforward
solution than trying to parse the configured line style for opacity
tags, so the animation has been changed. I think this will work better
with the (eventually) planned chapter title hover effect.
  • Loading branch information
torque committed Oct 28, 2017
1 parent 4b4320b commit 5516493
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
23 changes: 12 additions & 11 deletions src/HoverTime.moon
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,52 @@ class HoverTime extends BarAccent
rightMargin = settings['hover-time-right-margin']
leftMargin = settings['hover-time-left-margin']
bottomMargin = settings['hover-time-bottom-margin']
offScreenPos = settings['hover-time-offscreen-pos']

new: =>
super!

@line = {
[[{%s%s\pos(]]\format settings['default-style'], settings['hover-time-style']
[[-100,0]]
[[)\alpha&H]]
[[FF]]
[[&\an2}]]
[[)\an2}]]
[[????]]
}

@lastTime = 0
@lastX = -1
@position = -100
@animation = Animation 255, 0, @animationDuration, @\animate
@position = offScreenPos
@animation = Animation offScreenPos, bottomMargin, @animationDuration, @\animate, nil, 0.5

reconfigure: =>
super!
rightMargin = settings['hover-time-right-margin']
leftMargin = settings['hover-time-left-margin']
bottomMargin = settings['hover-time-bottom-margin']
@line[2] = ('%g,%g')\format math.min( Window.w - rightMargin, math.max( leftMargin, Mouse.x ) ), @yPos - bottomMargin
offScreenPos = settings['hover-time-offscreen-pos']
@line[2] = ('%g,%g')\format math.min( Window.w - rightMargin, math.max( leftMargin, Mouse.x ) ), @position
@line[1] = ([[{%s%s\pos(]])\format settings['default-style'], settings['hover-time-style']
@animation = Animation 255, 0, @animationDuration, @\animate
@animation = Animation offScreenPos, bottomMargin, @animationDuration, @\animate, nil, 0.5

resize: =>
super!
@line[2] = ("%g,%g")\format math.min( Window.w - rightMargin, math.max( leftMargin, Mouse.x ) ), @yPos - bottomMargin
@line[2] = ("%g,%g")\format math.min( Window.w - rightMargin, math.max( leftMargin, Mouse.x ) ), @yPos - @animation.value

animate: ( value ) =>
@line[4] = ([[%02X]])\format value
@position = @yPos - value
@line[2] = ("%g,%g")\format math.min( Window.w - rightMargin, math.max( leftMargin, Mouse.x ) ), @position
@needsUpdate = true

redraw: =>
if @active
super!
if Mouse.x != @lastX
@line[2] = ("%g,%g")\format math.min( Window.w - rightMargin, math.max( leftMargin, Mouse.x ) ), @yPos - bottomMargin
@line[2] = ("%g,%g")\format math.min( Window.w - rightMargin, math.max( leftMargin, Mouse.x ) ), @position
@lastX = Mouse.x

hoverTime = mp.get_property_number( 'duration', 0 )*Mouse.x/Window.w
if hoverTime != @lastTime
@line[6] = ([[%d:%02d:%02d]])\format math.floor( hoverTime/3600 ), math.floor( (hoverTime/60)%60 ), math.floor( hoverTime%60 )
@line[4] = ([[%d:%02d:%02d]])\format math.floor( hoverTime/3600 ), math.floor( (hoverTime/60)%60 ), math.floor( hoverTime%60 )
@lastTime = hoverTime

@needsUpdate = true
Expand Down
2 changes: 1 addition & 1 deletion src/main.moon
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ if settings['enable-system-time']
-- The order of these is important, because the order that elements are added to
-- eventLoop matters, because that controls how they are layered (first element
-- on the bottom).
eventLoop\addZone bottomZone
eventLoop\addZone hoverTimeZone
eventLoop\addZone bottomZone
eventLoop\addZone topZone

notFrameStepping = false
Expand Down
9 changes: 9 additions & 0 deletions src/settings.moon
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ display will disappear without animating all the way off-screen. Positive values
will cause the display to animate the wrong direction.
]]

settings['hover-time-offscreen-pos'] = -50
helpText['hover-time-offscreen-pos'] = [[
Controls how far off the bottom of the window the mouse hover time display tries
to move when it is inactive. If you use a non-default font, this value may need
to be tweaked. If this value is not far enough off-screen, the elapsed
display will disappear without animating all the way off-screen. Positive values
will cause the display to animate the wrong direction.
]]

settings['system-time-offscreen-pos'] = -100
helpText['system-time-offscreen-pos'] = [[
Controls how far off the left side of the window the system time display tries
Expand Down

0 comments on commit 5516493

Please sign in to comment.