diff --git a/scripts/uosc.lua b/scripts/uosc.lua index d81ab596..f8d29283 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, 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') Menu = require('uosc_shared/elements/Menu') @@ -539,8 +541,19 @@ 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.show then return end + mp.commandv('script-message-to', 'thumbfast', 'clear') + 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'))) + clear_thumbnail() end) mp.register_event('end-file', function(event) if event.reason == 'eof' then @@ -1045,6 +1058,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 or not thumbnail.thumbnail then return end + thumbnail_state.updated = false + thumbnail_ass = assdraw.ass_new() + if not thumbnail_state.show then + if thumbnail.overlay_id ~= nil then + mp.command_native( + {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.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) local data = utils.parse_json(json) if type(data) ~= 'table' or not data.width or not data.height then diff --git a/scripts/uosc_shared/elements/Timeline.lua b/scripts/uosc_shared/elements/Timeline.lua index 9b7811b5..332c51e2 100644 --- a/scripts/uosc_shared/elements/Timeline.lua +++ b/scripts/uosc_shared/elements/Timeline.lua @@ -84,7 +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') end function Timeline:on_mbtn_left_down() self.pressed = true @@ -97,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) @@ -131,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() @@ -321,8 +320,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, 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 @@ -336,6 +335,8 @@ function Timeline:render() }) end end + else + clear_thumbnail() end return ass 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