Skip to content

Commit

Permalink
fix: render thumbnails on uosc side
Browse files Browse the repository at this point in the history
  • Loading branch information
po5 committed Oct 31, 2022
1 parent 5f5bf4b commit a54a9a8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
29 changes: 29 additions & 0 deletions scripts/uosc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ state = {
hidpi_scale = 1,
}
thumbnail = {width = 0, height = 0, disabled = false}
thumbnail_state = {updated = true, x = 0, y = 0, ax = 0, ay = 0, bx = 0, by = 0, color = '000000', border_color = 'ffffff', render = {}}
script_name = mp.get_script_name()
external = {} -- Properties set by external scripts
Elements = require('uosc_shared/elements/Elements')
Menu = require('uosc_shared/elements/Menu')
Expand Down Expand Up @@ -1045,6 +1047,23 @@ mp.register_script_message('update-menu', function(json)
else open_command_menu(data) end
end
end)
function thumbnail_render()
if not thumbnail_state.updated then return end
thumbnail_state.updated = false
thumbnail_ass = assdraw.ass_new()
if not thumbnail_state.render.thumbnail then
if thumbnail_state.render.overlay_id ~= nil then
mp.command_native(
{name = "overlay-remove", id=thumbnail_state.render.overlay_id}
)
end
return
end
thumbnail_ass:rect(thumbnail_state.ax, thumbnail_state.ay, thumbnail_state.bx, thumbnail_state.by, {color = thumbnail_state.color, border = 1, border_color = thumbnail_state.border_color, border_opacity = 0.08, radius = 2})
mp.command_native(
{name = "overlay-add", id=thumbnail_state.render.overlay_id, x=thumbnail_state.x, y=thumbnail_state.y, file=thumbnail_state.render.thumbnail..".bgra", offset=0, fmt="bgra", w=thumbnail_state.render.width, h=thumbnail_state.render.height, stride=(4*thumbnail_state.render.width)}
)
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
Expand All @@ -1055,6 +1074,16 @@ mp.register_script_message('thumbfast-info', function(json)
request_render()
end
end)
mp.register_script_message('thumbfast-render', function(json)
local data = utils.parse_json(json)
if type(data) ~= 'table' or not data.width or not data.height then
thumbnail.disabled = true
msg.error('thumbfast-render: received json didn\'t produce a table with thumbnail information')
else
thumbnail_state.render = data
thumbnail_render()
end
end)
mp.register_script_message('set', function(name, value)
external[name] = value
Elements:trigger('external_prop_' .. name, value)
Expand Down
10 changes: 7 additions & 3 deletions scripts/uosc_shared/elements/Timeline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ function Timeline:set_from_cursor(fast)
mp.commandv('seek', self:get_time_at_x(cursor.x), fast and 'absolute+keyframes' or 'absolute+exact')
end
end
function Timeline:clear_thumbnail() mp.commandv('script-message-to', 'thumbfast', 'clear') end
function Timeline:clear_thumbnail()
mp.commandv('script-message-to', 'thumbfast', 'clear')
thumbnail_state.render.thumbnail = false
thumbnail_state.updated = true
end

function Timeline:on_mbtn_left_down()
self.pressed = true
Expand Down Expand Up @@ -321,8 +325,8 @@ function Timeline:render()
local thumb_y = round(tooltip_anchor.ay * scale_y - thumb_y_margin - thumb_height)
local ax, ay = (thumb_x - border) / scale_x, (thumb_y - border) / scale_y
local bx, by = (thumb_x + thumb_width + border) / scale_x, (thumb_y + thumb_height + border) / scale_y
ass:rect(ax, ay, bx, by, {color = bg, border = 1, border_color = fg, border_opacity = 0.08, radius = 2})
mp.commandv('script-message-to', 'thumbfast', 'thumb', hovered_seconds, thumb_x, thumb_y)
thumbnail_state = {updated = true, x = thumb_x, y = thumb_y, ax = ax, ay = ay, bx = bx, by = by, color = bg, border_color = fg, render = thumbnail_state.render}
mp.commandv('script-message-to', 'thumbfast', 'thumb', hovered_seconds, "", "", script_name)
tooltip_anchor.ax, tooltip_anchor.bx, tooltip_anchor.ay = ax, bx, ay
end

Expand Down
7 changes: 7 additions & 0 deletions scripts/uosc_shared/lib/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,13 @@ function render()
end
end

thumbnail_render()

if thumbnail_ass then
ass:new_event()
ass:merge(thumbnail_ass)
end

-- submit
if osd.res_x == display.width and osd.res_y == display.height and osd.data == ass.text then
return
Expand Down

0 comments on commit a54a9a8

Please sign in to comment.