From a54a9a80c1d81ffea65765b2ab8875bdce1ef3c1 Mon Sep 17 00:00:00 2001 From: Eva Date: Sun, 30 Oct 2022 02:27:37 +0200 Subject: [PATCH] fix: render thumbnails on uosc side --- scripts/uosc.lua | 29 +++++++++++++++++++++++ scripts/uosc_shared/elements/Timeline.lua | 10 +++++--- scripts/uosc_shared/lib/utils.lua | 7 ++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/scripts/uosc.lua b/scripts/uosc.lua index d81ab596..7adac550 100644 --- a/scripts/uosc.lua +++ b/scripts/uosc.lua @@ -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') @@ -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 @@ -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) diff --git a/scripts/uosc_shared/elements/Timeline.lua b/scripts/uosc_shared/elements/Timeline.lua index 9b7811b5..0ce7a66e 100644 --- a/scripts/uosc_shared/elements/Timeline.lua +++ b/scripts/uosc_shared/elements/Timeline.lua @@ -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 @@ -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 diff --git a/scripts/uosc_shared/lib/utils.lua b/scripts/uosc_shared/lib/utils.lua index 52cf16d8..1bdebd4c 100644 --- a/scripts/uosc_shared/lib/utils.lua +++ b/scripts/uosc_shared/lib/utils.lua @@ -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