From a54a9a80c1d81ffea65765b2ab8875bdce1ef3c1 Mon Sep 17 00:00:00 2001 From: Eva Date: Sun, 30 Oct 2022 02:27:37 +0200 Subject: [PATCH 1/3] 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 From 74c9a43d5a7e3f965d7665768533a00aaf89b4b6 Mon Sep 17 00:00:00 2001 From: Eva Date: Mon, 31 Oct 2022 13:36:07 +0100 Subject: [PATCH 2/3] fix: better thumbnail clearing --- scripts/uosc.lua | 8 ++++++++ scripts/uosc_shared/elements/Timeline.lua | 15 ++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/uosc.lua b/scripts/uosc.lua index 7adac550..a3e623a7 100644 --- a/scripts/uosc.lua +++ b/scripts/uosc.lua @@ -541,8 +541,16 @@ function update_mouse_pos(_, mouse, ignore_hover) end mp.observe_property('mouse-pos', 'native', update_mouse_pos) mp.observe_property('osc', 'bool', function(name, value) if value == true then mp.set_property('osc', 'no') end end) + +function clear_thumbnail() + if not thumbnail_state.render.thumbnail then return end + mp.commandv('script-message-to', 'thumbfast', 'clear') + thumbnail_state.render.thumbnail = false + thumbnail_state.updated = true +end mp.register_event('file-loaded', function() set_state('path', normalize_path(mp.get_property_native('path'))) + clear_thumbnail() end) mp.register_event('end-file', function(event) if event.reason == 'eof' then diff --git a/scripts/uosc_shared/elements/Timeline.lua b/scripts/uosc_shared/elements/Timeline.lua index 0ce7a66e..3f57da1f 100644 --- a/scripts/uosc_shared/elements/Timeline.lua +++ b/scripts/uosc_shared/elements/Timeline.lua @@ -84,11 +84,6 @@ 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') - thumbnail_state.render.thumbnail = false - thumbnail_state.updated = true -end function Timeline:on_mbtn_left_down() self.pressed = true @@ -101,17 +96,14 @@ function Timeline:on_prop_time() self:decide_enabled() end function Timeline:on_prop_border() self:update_dimensions() end function Timeline:on_prop_fullormaxed() self:update_dimensions() end function Timeline:on_display() self:update_dimensions() end -function Timeline:on_mouse_leave() self:clear_thumbnail() end function Timeline:on_global_mbtn_left_up() if self.pressed then mp.set_property_native('pause', self.pressed_pause) self.pressed = false end - self:clear_thumbnail() end function Timeline:on_global_mouse_leave() self.pressed = false - self:clear_thumbnail() end Timeline.seek_timer = mp.add_timeout(0.05, function() Elements.timeline:set_from_cursor() end) @@ -135,7 +127,10 @@ function Timeline:render() local size = self:get_effective_size() local visibility = self:get_visibility() - if size < 1 then return end + if size < 1 then + clear_thumbnail() + return + end local ass = assdraw.ass_new() @@ -340,6 +335,8 @@ function Timeline:render() }) end end + else + clear_thumbnail() end return ass From 68c23a20775693af3ea2c98955d3bd23073dc13f Mon Sep 17 00:00:00 2001 From: Eva Date: Wed, 2 Nov 2022 22:42:46 +0100 Subject: [PATCH 3/3] remove thumbfast-render --- scripts/uosc.lua | 29 +++++++++-------------- scripts/uosc_shared/elements/Timeline.lua | 2 +- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/scripts/uosc.lua b/scripts/uosc.lua index a3e623a7..f8d29283 100644 --- a/scripts/uosc.lua +++ b/scripts/uosc.lua @@ -328,7 +328,7 @@ 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 = {}} +thumbnail_state = {updated = true, show=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') @@ -543,10 +543,13 @@ mp.observe_property('mouse-pos', 'native', update_mouse_pos) mp.observe_property('osc', 'bool', function(name, value) if value == true then mp.set_property('osc', 'no') end end) function clear_thumbnail() - if not thumbnail_state.render.thumbnail then return end + if not thumbnail_state.show then return end mp.commandv('script-message-to', 'thumbfast', 'clear') - thumbnail_state.render.thumbnail = false thumbnail_state.updated = true + if thumbnail.overlay_id ~= nil then + mp.command_native({"overlay-remove", thumbnail.overlay_id}) + end + thumbnail_state.show = false end mp.register_event('file-loaded', function() set_state('path', normalize_path(mp.get_property_native('path'))) @@ -1056,20 +1059,20 @@ mp.register_script_message('update-menu', function(json) end end) function thumbnail_render() - if not thumbnail_state.updated then return end + if not thumbnail_state.updated or not thumbnail.thumbnail 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 + if not thumbnail_state.show then + if thumbnail.overlay_id ~= nil then mp.command_native( - {name = "overlay-remove", id=thumbnail_state.render.overlay_id} + {name = "overlay-remove", id=thumbnail.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)} + {name = "overlay-add", id=thumbnail.overlay_id, x=thumbnail_state.x, y=thumbnail_state.y, file=thumbnail.thumbnail..".bgra", offset=0, fmt="bgra", w=thumbnail.width, h=thumbnail.height, stride=(4*thumbnail.width)} ) end mp.register_script_message('thumbfast-info', function(json) @@ -1082,16 +1085,6 @@ 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 3f57da1f..332c51e2 100644 --- a/scripts/uosc_shared/elements/Timeline.lua +++ b/scripts/uosc_shared/elements/Timeline.lua @@ -320,7 +320,7 @@ 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 - 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} + thumbnail_state = {updated = true, show=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