diff --git a/Makefile b/Makefile index feb5e0c..4b5e83e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/Thumbnail.moon b/src/Thumbnail.moon new file mode 100644 index 0000000..aefec6e --- /dev/null +++ b/src/Thumbnail.moon @@ -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 diff --git a/src/main.moon b/src/main.moon index 98cb2d6..41603c3 100644 --- a/src/main.moon +++ b/src/main.moon @@ -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 @@ -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! diff --git a/src/settings.moon b/src/settings.moon index 6d393e5..4889a77 100644 --- a/src/settings.moon +++ b/src/settings.moon @@ -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. diff --git a/torque-progressbar.conf b/torque-progressbar.conf index 67d636a..7b0cfa4 100644 --- a/torque-progressbar.conf +++ b/torque-progressbar.conf @@ -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