feat: thumbfast intergration (#213)

* feat: thumbfast intergration

* fix: respect ui scale, hidpi scale, support wrapped chapter titles
This commit is contained in:
Eva
2022-09-21 09:19:37 +02:00
committed by GitHub
parent cabe84daf9
commit b3b5b15406

View File

@@ -435,6 +435,11 @@ local state = {
margin_top = 0,
margin_bottom = 0,
}
local thumbfast = {
width = 0,
height = 0,
disabled = false
}
--[[ HELPERS ]]
@@ -629,7 +634,7 @@ function wrap_text(text, target_line_length)
lines[#lines + 1] = string.sub(text, line_start)
if line_length > max_length then max_length = line_length end
end
return table.concat(lines, '\n'), max_length
return table.concat(lines, '\n'), max_length, #lines
end
-- Escape a string for verbatim display on the OSD
@@ -889,7 +894,7 @@ function serialize_chapters(chapters)
if not chapters then return end
for index, chapter in ipairs(chapters) do
chapter.index = index
chapter.title_wrapped, chapter.title_wrapped_width = wrap_text(chapter.title, 25)
chapter.title_wrapped, chapter.title_wrapped_width, chapter.title_wrapped_lines = wrap_text(chapter.title, 25)
chapter.title_wrapped = ass_escape(chapter.title_wrapped)
end
return chapters
@@ -2876,6 +2881,7 @@ function Timeline:render()
if chapter and not chapter.is_end_only then
chapter_title = chapter.title_wrapped
chapter_title_width = chapter.title_wrapped_width
chapter_title_lines = chapter.title_wrapped_lines
end
end
@@ -2896,6 +2902,21 @@ function Timeline:render()
text_length_override = chapter_title_width,
})
end
-- Thumbnail
if not thumbfast.disabled and thumbfast.width ~= 0 and thumbfast.height ~= 0 then
local final_scale = options.ui_scale * state.hidpi_scale
mp.commandv("script-message-to", "thumbfast", "thumb",
hovered_seconds,
math.min(display.width * final_scale - thumbfast.width - 10 * final_scale, math.max(10 * final_scale, cursor.x * final_scale - thumbfast.width / 2)),
fay * final_scale - thumbfast.height - (2 + self.font_size * (chapter_title and 1.8 or 1.4) +
(chapter_title_lines and self.font_size * chapter_title_lines or 0)) * final_scale
)
end
else
if thumbfast.width ~= 0 and thumbfast.height ~= 0 then
mp.commandv("script-message-to", "thumbfast", "clear")
end
end
return ass
@@ -4173,7 +4194,7 @@ mp.observe_property('osd-dimensions', 'native', function(name, val)
update_display_dimensions()
request_render()
end)
mp.observe_property('display-hidpi-scale', 'native', update_display_dimensions)
mp.observe_property('display-hidpi-scale', 'native', create_state_setter('hidpi_scale', function() update_display_dimensions() end))
mp.observe_property('demuxer-via-network', 'native', create_state_setter('is_stream', function()
set_state('uncached_ranges', state.is_stream and state.duration and {0, state.duration} or nil)
Elements:trigger('dispositions')
@@ -4597,3 +4618,11 @@ mp.register_script_message('update-menu', function(json)
else open_command_menu(data) end
end
end)
mp.register_script_message('thumbfast-info', function(json)
local 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
end
end)