Skip to content

Commit

Permalink
Thumbnail: thumbfast integration
Browse files Browse the repository at this point in the history
cf. #43
  • Loading branch information
po5 committed Oct 29, 2022
1 parent 04171b6 commit 9325845
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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
61 changes: 61 additions & 0 deletions src/Thumbnail.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class Thumbnail extends BarAccent

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

thumbfast = {
width: 0,
height: 0,
disabled: false
}

new: =>
super!

@line = {}
@lastX = -1
@animation = Animation bottomMargin, bottomMargin, @animationDuration, @\animate, nil, 0.5

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
msg.error('thumbfast-info: received json didn\'t produce a table with thumbnail information')
else
thumbfast = data
)

reconfigure: =>
super!
rightMargin = settings['thumbnail-right-margin']
leftMargin = settings['thumbnail-left-margin']
bottomMargin = settings['thumbnail-bottom-margin']
@animation = Animation bottomMargin, bottomMargin, @animationDuration, @\animate, nil, 0.5

animate: ( value ) =>
@needsUpdate = true

if @active and Mouse.x != @lastX
@lastX = Mouse.x
if not thumbfast.disabled and thumbfast.width ~= 0 and thumbfast.height ~= 0
hoverTime = mp.get_property_number( 'duration', 0 )*Mouse.x/Window.w
mp.commandv( 'script-message-to', 'thumbfast', 'thumb',
hoverTime,
math.min(Window.w - thumbfast.width - 10, math.max(10, Mouse.x - thumbfast.width / 2)),
Window.h - bottomMargin - thumbfast.height
)

redraw: =>
if @active
super!
if not thumbfast.disabled and thumbfast.width ~= 0 and thumbfast.height ~= 0
hoverTime = mp.get_property_number( 'duration', 0 )*Mouse.x/Window.w
mp.commandv( 'script-message-to', 'thumbfast', 'thumb',
hoverTime,
math.min(Window.w - thumbfast.width - rightMargin, math.max(leftMargin, Mouse.x - thumbfast.width / 2)),
Window.h - bottomMargin - thumbfast.height
)
elseif thumbfast.width ~= 0 and thumbfast.height ~= 0 then
mp.commandv( 'script-message-to', 'thumbfast', 'clear' )

return @needsUpdate
5 changes: 4 additions & 1 deletion src/main.moon
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ topZone = ActivityZone =>

-- This is kind of ugly but I have gone insane and don't care any more.
-- Watch the rapidly declining quality of this codebase in realtime.
local chapters, progressBar, barCache, barBackground, elapsedTime, remainingTime, hoverTime
local chapters, progressBar, barCache, barBackground, elapsedTime, remainingTime, hoverTime, thumbnail

if settings['enable-bar']
-- this order is recorded and (ab)used by BarBase and
Expand Down Expand Up @@ -59,6 +59,9 @@ if settings['enable-hover-time']
hoverTime = HoverTime!
hoverTimeZone\addUIElement hoverTime

thumbnail = Thumbnail!
bottomZone\addUIElement thumbnail

title = nil
if settings['enable-title']
title = Title!
Expand Down
18 changes: 18 additions & 0 deletions src/settings.moon
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,24 @@ Controls how far above the expanded progress bar the remaining time display is
positioned.
]]

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
12 changes: 12 additions & 0 deletions torque-progressbar.conf
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ hover-time-right-margin=130
# positioned.
hover-time-bottom-margin=0

# 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

0 comments on commit 9325845

Please sign in to comment.