Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thumbnail: thumbfast integration #62

Merged
merged 12 commits into from
Nov 6, 2022
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# The order of the sources does matter.
SOURCES := src/log.moon
SOURCES += src/util.moon
SOURCES += src/requires.moon
SOURCES += src/settings.moon
SOURCES += src/Stack.moon
Expand All @@ -21,6 +22,7 @@ SOURCES += src/Chapters.moon
SOURCES += src/TimeElapsed.moon
SOURCES += src/TimeRemaining.moon
SOURCES += src/HoverTime.moon
SOURCES += src/Thumbnail.moon
SOURCES += src/PauseIndicator.moon
SOURCES += src/Title.moon
SOURCES += src/SystemTime.moon
Expand Down
5 changes: 3 additions & 2 deletions src/Animation.moon
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ class Animation

update: ( now ) =>
if @isReversed
@linearProgress = math.max 0, math.min 1, @linearProgress + (@lastUpdate - now)*@durationR
@linearProgress = clamp @linearProgress + (@lastUpdate - now) * @durationR, 0, 1
if @linearProgress == 0
@isFinished = true
else
@linearProgress = math.max 0, math.min 1, @linearProgress + (now - @lastUpdate)*@durationR
@linearProgress = clamp @linearProgress + (now - @lastUpdate) * @durationR, 0, 1
if @linearProgress == 1
@isFinished = true

@lastUpdate = now

progress = math.pow @linearProgress, @accel
Expand Down
10 changes: 5 additions & 5 deletions src/HoverTime.moon
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ class HoverTime extends BarAccent
leftMargin = settings['hover-time-left-margin']
bottomMargin = settings['hover-time-bottom-margin']
offScreenPos = settings['hover-time-offscreen-pos']
@line[2] = ('%g,%g')\format math.min( Window.w - rightMargin, math.max( leftMargin, Mouse.x ) ), @position
@line[2] = ('%g,%g')\format clamp( Mouse.x, leftMargin, Window.w - rightMargin ), @position
@line[1] = ([[{%s%s\pos(]])\format settings['default-style'], settings['hover-time-style']
@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 - @animation.value
@line[2] = ("%g,%g")\format clamp( Mouse.x, leftMargin, Window.w - rightMargin ), @yPos - @animation.value

animate: ( value ) =>
@position = @yPos - value
@line[2] = ("%g,%g")\format math.min( Window.w - rightMargin, math.max( leftMargin, Mouse.x ) ), @position
@line[2] = ("%g,%g")\format clamp( Mouse.x, leftMargin, Window.w - rightMargin ), @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 ) ), @position
@line[2] = ("%g,%g")\format clamp( Mouse.x, leftMargin, Window.w - rightMargin ), @position
@lastX = Mouse.x

hoverTime = mp.get_property_number( 'duration', 0 )*Mouse.x/Window.w
hoverTime = mp.get_property_number( 'duration', 0 ) * Mouse.x / Window.w
if hoverTime != @lastTime
@line[4] = ([[%d:%02d:%02d]])\format math.floor( hoverTime/3600 ), math.floor( (hoverTime/60)%60 ), math.floor( hoverTime%60 )
@lastTime = hoverTime
Expand Down
12 changes: 6 additions & 6 deletions src/Mouse.moon
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
class Mouse
osdScale = settings['display-scale-factor']

@@x, @@y = -1, -1
@@_rawX, @@_rawY = -1, -1
@@inWindow, @@dead = false, true
@@clickX, @@clickY = -1, -1
@@clickPending = false

scaledPosition = ->
scaledPosition = =>
x, y = mp.get_mouse_pos!
return math.floor( x/osdScale ), math.floor( y/osdScale )
@_rawX, @_rawY = x, y
return math.floor( x/Window.osdScale ), math.floor( y/Window.osdScale )

@update: =>
oldX, oldY = @x, @y
@x, @y = scaledPosition!
@x, @y = scaledPosition @
if @dead and (oldX != @x or oldY != @y)
@dead = false
if not @dead and @clickPending
Expand All @@ -22,7 +22,7 @@ class Mouse

@cacheClick: =>
if not @dead
@clickX, @clickY = scaledPosition!
@clickX, @clickY = scaledPosition @
@clickPending = true
else
@dead = false
Expand Down
43 changes: 43 additions & 0 deletions src/Thumbnail.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Thumbnail extends BarAccent

rightMargin = settings['thumbnail-right-margin']
leftMargin = settings['thumbnail-left-margin']
bottomMargin = settings['thumbnail-bottom-margin']

new: ( thumbfastInfo ) =>
super!

@line = {}
@lastX = -1
@thumbfast = thumbfastInfo

reconfigure: =>
super!
rightMargin = settings['thumbnail-right-margin']
leftMargin = settings['thumbnail-left-margin']
bottomMargin = settings['thumbnail-bottom-margin']

activate: ( activate ) =>
super activate
if not activate
mp.commandv( 'script-message-to', 'thumbfast', 'clear' )
@needsUpdate = true

redraw: =>
if @active
super!
if Mouse.x != @lastX and not @thumbfast.disabled and @thumbfast.width >= 0 and @thumbfast.height >= 0
torque marked this conversation as resolved.
Show resolved Hide resolved
@lastX = Mouse.x

hoverTime = mp.get_property_number( 'duration', 0 ) * Mouse.x / Window.w

mp.commandv(
'script-message-to', 'thumbfast', 'thumb',
hoverTime,
clamp( Mouse._rawX - @thumbfast.width / 2, leftMargin, Window._rawW - @thumbfast.width - rightMargin ),
Window._rawH - bottomMargin*Window.osdScale - @thumbfast.height
)

@needsUpdate = true

return @needsUpdate
11 changes: 8 additions & 3 deletions src/UIElement.moon
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ class UIElement

activate: ( activate ) =>
if activate == true
@animation\interrupt false
if @animation
@animation\interrupt false

@active = true
else
@animation\interrupt true
@animation.finishedCb = ->
if @animation
@animation\interrupt true
@animation.finishedCb = ->
@active = false
else
@active = false

reconfigure: =>
Expand Down
11 changes: 8 additions & 3 deletions src/Window.moon
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
class Window
osdScale = settings['display-scale-factor']
@@osdScale = mp.get_property_number("display-hidpi-scale", 1)

@@w, @@h = 0, 0
@@_rawW, @@_rawH = 0, 0

@update: =>
w, h = mp.get_osd_size!
osdScale = mp.get_property_number("display-hidpi-scale", 1)

@_rawW, @_rawH = w, h
w, h = math.floor( w/osdScale ), math.floor( h/osdScale )
if w != @w or h != @h
@w, @h = w, h

if w != @w or h != @h or osdScale != @osdScale
@w, @h, @osdScale = w, h, osdScale
return true
else
return false
15 changes: 15 additions & 0 deletions src/main.moon
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ if settings['enable-hover-time']
hoverTime = HoverTime!
hoverTimeZone\addUIElement hoverTime

if settings['enable-thumbnail']
mp.register_script_message 'thumbfast-info', ( json ) ->
data = utils.parse_json json
if type(data) != 'table' or not data.width or not data.height then
log.warn 'thumbfast did not respond with proper thumbnail information. Thumbnails are disabled.'
else
thumbnail = Thumbnail data
bottomZone\addUIElement thumbnail

-- a bit of a weird hack, but since this resolves asynchronously, it
-- may be called after initDraw has been called. In that case, we
-- have to call generateUIFromZones to actually make the thumbnail
-- get redrawn by the event loop.
eventLoop\generateUIFromZones!

title = nil
if settings['enable-title']
title = Title!
Expand Down
31 changes: 24 additions & 7 deletions src/settings.moon
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ Sets the height of the rectangular area at the top of the screen that shows the
file name and system time when the mouse is hovered over it.
]]

settings['display-scale-factor'] = 1
helpText['display-scale-factor'] = [[
Acts as a multiplier to increase the size of every UI element. Useful for high-
DPI displays that cause the UI to be rendered too small (happens at least on
macOS).
]]

settings['default-style'] = [[\fnSource Sans Pro\b1\bord2\shad0\fs30\c&HFC799E&\3c&H2D2D2D&]]
helpText['default-style'] = [[
Default style that is applied to all UI elements. A string of ASS override tags.
Expand Down Expand Up @@ -246,6 +239,30 @@ Controls how far above the expanded progress bar the remaining time display is
positioned.
]]

settings['enable-thumbnail'] = true
helpText['enable-thumbnail'] = [[
Sets whether or not thumbnails are displayed at all. Note: thumbnail display
requires use of the thumbfast script (See: https://github.com/po5/thumbfast).
]]

settings['thumbnail-left-margin'] = 10
helpText['thumbnail-left-margin'] = [[
Controls how close to the left edge of the window the thumbnail display can
get.
]]

settings['thumbnail-right-margin'] = 10
helpText['thumbnail-right-margin'] = [[
Controls how close to the right edge of the window the thumbnail display can
get.
]]

settings['thumbnail-bottom-margin'] = 40
helpText['thumbnail-bottom-margin'] = [[
Controls how far above the expanded progress bar the thumbnail display is
positioned.
]]

settings['enable-title'] = true
helpText['enable-title'] = [[
Sets whether or not the video title is displayed at all.
Expand Down
5 changes: 5 additions & 0 deletions src/util.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_mathmin = math.min
_mathmax = math.max

clamp = ( value, min, max ) ->
return _mathmin( max, _mathmax( value, min ) )
21 changes: 16 additions & 5 deletions torque-progressbar.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ hover-zone-height=40
# file name and system time when the mouse is hovered over it.
top-hover-zone-height=40

# Acts as a multiplier to increase the size of every UI element. Useful for high-
# DPI displays that cause the UI to be rendered too small (happens at least on
# macOS).
display-scale-factor=1

# Default style that is applied to all UI elements. A string of ASS override tags.
# Individual elements have their own style settings which override the tags here.
# Changing the font will likely require changing the hover-time margin settings
Expand Down Expand Up @@ -180,6 +175,22 @@ hover-time-right-margin=130
# positioned.
hover-time-bottom-margin=0

# Sets whether or not thumbnails are displayed at all. Note: thumbnail display
# requires use of the thumbfast script (See: https://github.com/po5/thumbfast).
enable-thumbnail=yes

# Controls how close to the left edge of the window the thumbnail display can
# get.
thumbnail-left-margin=10

# Controls how close to the right edge of the window the thumbnail display can
# get.
thumbnail-right-margin=10

# Controls how far above the expanded progress bar the thumbnail display is
# positioned.
thumbnail-bottom-margin=40

# Sets whether or not the video title is displayed at all.
enable-title=yes

Expand Down