Skip to content

Commit

Permalink
同步与整合上游
Browse files Browse the repository at this point in the history
脚本:
uosc 同步至 4.6.0+

着色器:
gaussianBlur_next 和 unsharpMask_next 仅适用于 --vo=gpu-next

nlmeans 暂不与Nvidia显卡完全兼容,不要使用。
依据变体附属关系精简的着色器:
(打勾的是保留的项)
- guided (√) , guided_fast
- guided_s (√) , guided_s_fast
- guided_lgc (√)
- nlmeans (√) , nlmeans_sharpen_denoise , nlmeans_sharpen_only
- nlmeans_hq (√) , nlmeans_hq_medium , nlmeans_hq_heavy , nlmeans_hq_sharpen_denoise , nlmeans_hqx , nlmeans_medium , nlmeans_heavy
- nlmeans_lq (√)
- nlmeans_luma (√)
- nlmeans_lgc (√)
- nlmeans_temporal (√) , nlmeans_temporal_sharpen_denoise
- nlmeans_2x 融合了 FSRCNNX_x2_8_0_4_1
  • Loading branch information
hooke007 committed Apr 4, 2023
1 parent 3eacfc7 commit 54c413d
Show file tree
Hide file tree
Showing 26 changed files with 1,873 additions and 3,015 deletions.
2 changes: 1 addition & 1 deletion portable_config/script-opts/uosc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ stream_quality_options=4320,2160,1440,1080,720,480,360,240,144

# (加载文件/导入视频音频轨时)文件浏览器的扩展名过滤列表。默认值覆盖极广,此预设精简为常见的视频和音频格式
video_types=avi,flv,m2ts,m4v,mkv,mov,mp4,mpeg,mpg,ogv,rm,rmvb,ts,vob,webm,wmv
audio_types=aac,ape,dsf,dts,flac,m4a,mka,mp3,ogg,opus,wav,wma,wv
audio_types=aac,ac3,ape,dsf,dts,flac,m4a,mka,mp3,ogg,opus,wav,wma,wv
image_types=apng,avif,bmp,gif,jfif,jpeg,jpg,jxl,png,svg,tif,tiff,webp
# (导入字幕时)文件浏览器的扩展名过滤列表。默认值覆盖极广,此预设精简为常见的字幕格式
subtitle_types=ass,idx,lrc,mks,pgs,sup,srt,ssa,txt,vtt
Expand Down
10 changes: 5 additions & 5 deletions portable_config/scripts/uosc/elements/Button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ function Button:init(id, props)
end

function Button:on_coordinates() self.font_size = round((self.by - self.ay) * 0.7) end
function Button:on_mbtn_left_down()
-- Don't accept clicks while hidden.
if self:get_visibility() <= 0 then return end
function Button:handle_cursor_down()
-- We delay the callback to next tick, otherwise we are risking race
-- conditions as we are in the middle of event dispatching.
-- For example, handler might add a menu to the end of the element stack, and that
-- than picks up this click even we are in right now, and instantly closes itself.
-- than picks up this click event we are in right now, and instantly closes itself.
mp.add_timeout(0.01, self.on_click)
end

function Button:render()
local visibility = self:get_visibility()
if visibility <= 0 then return end
if self.proximity_raw == 0 then
cursor.on_primary_down = function() self:handle_cursor_down() end
end

local ass = assdraw.ass_new()
local is_hover = self.proximity_raw == 0
Expand All @@ -54,7 +55,6 @@ function Button:render()
-- Tooltip on hover
if is_hover and self.tooltip then ass:tooltip(self, self.tooltip) end


-- Badge
local icon_clip
if self.badge then
Expand Down
4 changes: 2 additions & 2 deletions portable_config/scripts/uosc/elements/Element.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Element:init(id, props)
-- Relative proximity from `0` - mouse outside `proximity_max` range, to `1` - mouse within `proximity_min` range.
self.proximity = 0
-- Raw proximity in pixels.
self.proximity_raw = infinity
self.proximity_raw = INFINITY
---@type number `0-1` factor to force min visibility. Used for toggling element's permanent visibility.
self.min_visibility = 0
---@type number `0-1` factor to force a visibility value. Used for flashing, fading out, and other animations
Expand Down Expand Up @@ -44,7 +44,7 @@ function Element:destroy()
Elements:remove(self)
end

function Element:reset_proximity() self.proximity, self.proximity_raw = 0, infinity end
function Element:reset_proximity() self.proximity, self.proximity_raw = 0, INFINITY end

---@param ax number
---@param ay number
Expand Down
45 changes: 2 additions & 43 deletions portable_config/scripts/uosc/elements/Elements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ function Elements:remove(idOrElement)
end

function Elements:update_proximities()
local capture_mbtn_left = false
local capture_wheel = false
local menu_only = Elements.menu ~= nil
local mouse_leave_elements = {}
local mouse_enter_elements = {}
Expand All @@ -42,26 +40,13 @@ function Elements:update_proximities()

-- If menu is open, all other elements have to be disabled
if menu_only then
if element.ignores_menu then
capture_mbtn_left = true
capture_wheel = true
element:update_proximity()
else
element:reset_proximity()
end
if element.ignores_menu then element:update_proximity()
else element:reset_proximity() end
else
element:update_proximity()
end

-- Element has global forced key listeners
if element.on_global_mbtn_left_down then capture_mbtn_left = true end
if element.on_global_wheel_up or element.on_global_wheel_down then capture_wheel = true end

if element.proximity_raw == 0 then
-- Element has local forced key listeners
if element.on_mbtn_left_down then capture_mbtn_left = true end
if element.on_wheel_up or element.on_wheel_up then capture_wheel = true end

-- Mouse entered element area
if previous_proximity_raw ~= 0 then
mouse_enter_elements[#mouse_enter_elements + 1] = element
Expand All @@ -75,10 +60,6 @@ function Elements:update_proximities()
end
end

-- Enable key group captures requested by elements
mp[capture_mbtn_left and 'enable_key_bindings' or 'disable_key_bindings']('mbtn_left')
mp[capture_wheel and 'enable_key_bindings' or 'disable_key_bindings']('wheel')

-- Trigger `mouse_leave` and `mouse_enter` events
for _, element in ipairs(mouse_leave_elements) do element:trigger('mouse_leave') end
for _, element in ipairs(mouse_enter_elements) do element:trigger('mouse_enter') end
Expand Down Expand Up @@ -142,26 +123,4 @@ end
function Elements:has(id) return self[id] ~= nil end
function Elements:ipairs() return ipairs(self.itable) end

---@param name string Event name.
function Elements:create_proximity_dispatcher(name)
return function(...) self:proximity_trigger(name, ...) end
end

mp.set_key_bindings({
{
'mbtn_left',
Elements:create_proximity_dispatcher('mbtn_left_up'),
function(...)
update_mouse_pos(nil, mp.get_property_native('mouse-pos'))
Elements:proximity_trigger('mbtn_left_down', ...)
end,
},
{'mbtn_left_dbl', 'ignore'},
}, 'mbtn_left', 'force')

mp.set_key_bindings({
{'wheel_up', Elements:create_proximity_dispatcher('wheel_up')},
{'wheel_down', Elements:create_proximity_dispatcher('wheel_down')},
}, 'wheel', 'force')

return Elements
100 changes: 71 additions & 29 deletions portable_config/scripts/uosc/elements/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ local Element = require('elements/Element')
---@alias MenuData {type?: string; title?: string; hint?: string; keep_open?: boolean; separator?: boolean; items?: MenuDataItem[]; selected_index?: integer;}
---@alias MenuDataItem MenuDataValue|MenuData
---@alias MenuDataValue {title?: string; hint?: string; icon?: string; value: any; bold?: boolean; italic?: boolean; muted?: boolean; active?: boolean; keep_open?: boolean; separator?: boolean;}
---@alias MenuOptions {mouse_nav?: boolean; on_open?: fun(); on_close?: fun(); on_back?: fun()}
---@alias MenuOptions {mouse_nav?: boolean; on_open?: fun(); on_close?: fun(); on_back?: fun(); on_move_item?: fun(from_index: integer, to_index: integer, submenu_path: integer[]); on_delete_item?: fun(index: integer, submenu_path: integer[])}

-- Internal data structure created from `Menu`.
---@alias MenuStack {id?: string; type?: string; title?: string; hint?: string; selected_index?: number; keep_open?: boolean; separator?: boolean; items: MenuStackItem[]; parent_menu?: MenuStack; active?: boolean; width: number; height: number; top: number; scroll_y: number; scroll_height: number; title_width: number; hint_width: number; max_width: number; is_root?: boolean; fling?: Fling}
---@alias MenuStack {id?: string; type?: string; title?: string; hint?: string; selected_index?: number; keep_open?: boolean; separator?: boolean; items: MenuStackItem[]; parent_menu?: MenuStack; submenu_path: integer[]; active?: boolean; width: number; height: number; top: number; scroll_y: number; scroll_height: number; title_width: number; hint_width: number; max_width: number; is_root?: boolean; fling?: Fling}
---@alias MenuStackItem MenuStackValue|MenuStack
---@alias MenuStackValue {title?: string; hint?: string; icon?: string; value: any; active?: boolean; bold?: boolean; italic?: boolean; muted?: boolean; keep_open?: boolean; separator?: boolean; title_width: number; hint_width: number}
---@alias Fling {y: number, distance: number, time: number, easing: fun(x: number), duration: number, update_cursor?: boolean}
Expand Down Expand Up @@ -56,6 +56,7 @@ function Menu:close(immediate, callback)
menu.is_closing, menu.stack, menu.current, menu.all, menu.by_id = false, nil, nil, {}, {}
menu:disable_key_bindings()
Elements:update_proximities()
cursor.queue_autohide()
if callback then callback() end
request_render()
end
Expand Down Expand Up @@ -135,7 +136,7 @@ end
function Menu:update(data)
self.type = data.type

local new_root = {is_root = true}
local new_root = {is_root = true, submenu_path = {}}
local new_all = {}
local new_by_id = {}
local menus_to_serialize = {{new_root, data}}
Expand Down Expand Up @@ -169,6 +170,7 @@ function Menu:update(data)
-- Submenu
if item_data.items then
item.parent_menu = menu
item.submenu_path = itable_join(menu.submenu_path, {i})
menus_to_serialize[#menus_to_serialize + 1] = {item, item_data}
end

Expand Down Expand Up @@ -210,8 +212,10 @@ function Menu:update_content_dimensions()
local hint_opts = {size = self.font_size_hint}

for _, menu in ipairs(self.all) do
title_opts.bold, title_opts.italic = true, false
local max_width = text_width(menu.title, title_opts) + 2 * self.item_padding

-- Estimate width of a widest item
local max_width = 0
for _, item in ipairs(menu.items) do
local icon_width = item.icon and self.font_size or 0
item.title_width = text_width(item.title, title_opts)
Expand All @@ -223,11 +227,6 @@ function Menu:update_content_dimensions()
if estimated_width > max_width then max_width = estimated_width end
end

-- Also check menu title
title_opts.bold, title_opts.italic = true, false
local menu_title_width = text_width(menu.title, title_opts)
if menu_title_width > max_width then max_width = menu_title_width end

menu.max_width = max_width
end

Expand All @@ -236,8 +235,8 @@ end

function Menu:update_dimensions()
-- Coordinates and sizes are of the scrollable area to make
-- consuming values in rendering and collisions easier. Title drawn above this, so
-- we need to account for that in max_height and ay position.
-- consuming values in rendering and collisions easier. Title is rendered
-- above it, so we need to account for that in max_height and ay position.
local min_width = state.fullormaxed and options.menu_min_width_fullscreen or options.menu_min_width

for _, menu in ipairs(self.all) do
Expand All @@ -252,6 +251,11 @@ function Menu:update_dimensions()
self:scroll_to(menu.scroll_y, menu) -- clamps scroll_y to scroll limits
end

self:update_coordinates()
end

-- Updates element coordinates to match currently open (sub)menu.
function Menu:update_coordinates()
local ax = round((display.width - self.current.width) / 2) + self.offset_x
self:set_coordinates(ax, self.current.top, ax + self.current.width, self.current.top + self.current.height)
end
Expand Down Expand Up @@ -359,7 +363,7 @@ end
function Menu:select_value(value, menu)
menu = menu or self.current
local index = itable_find(menu.items, function(item) return item.value == value end)
self:select_index(index, 5)
self:select_index(index)
end

---@param menu? MenuStack
Expand Down Expand Up @@ -400,16 +404,23 @@ function Menu:activate_one_value(value, menu)
self:activate_one_index(index, menu)
end

---@param id string
function Menu:activate_submenu(id)
local submenu = self.by_id[id]
if submenu then
self.current = submenu
---@param menu MenuStack One of menus in `self.all`.
function Menu:activate_menu(menu)
if itable_index_of(self.all, menu) then
self.current = menu
self:update_coordinates()
self:reset_navigation()
request_render()
else
msg.error(string.format('Requested submenu id "%s" doesn\'t exist', id))
msg.error('Attempt to open a menu not in `self.all` list.')
end
self:reset_navigation()
end

---@param id string
function Menu:activate_submenu(id)
local submenu = self.by_id[id]
if submenu then self:activate_menu(submenu)
else msg.error(string.format('Requested submenu id "%s" doesn\'t exist', id)) end
end

---@param index? integer
Expand Down Expand Up @@ -456,8 +467,7 @@ function Menu:back()

if parent then
menu.selected_index = nil
self.current = parent
self:update_dimensions()
self:activate_menu(parent)
self:tween(self.offset_x - menu.width / 2, 0, function(offset) self:set_offset_x(offset) end)
self.opacity = 1 -- in case tween above canceled fade in animation
else
Expand All @@ -473,11 +483,10 @@ function Menu:open_selected_item(opts)
local item = menu.items[menu.selected_index]
-- Is submenu
if item.items then
self.current = item
if opts.preselect_submenu_item then
item.selected_index = #item.items > 0 and 1 or nil
end
self:update_dimensions()
self:activate_menu(item)
self:tween(self.offset_x + menu.width / 2, 0, function(offset) self:set_offset_x(offset) end)
self.opacity = 1 -- in case tween above canceled fade in animation
else
Expand All @@ -491,10 +500,33 @@ function Menu:open_selected_item_soft() self:open_selected_item({keep_open = tru
function Menu:open_selected_item_preselect() self:open_selected_item({preselect_submenu_item = true}) end
function Menu:select_item_below_cursor() self.current.selected_index = self:get_item_index_below_cursor() end

---@param index integer
function Menu:move_selected_item_to(index)
local from, callback = self.current.selected_index, self.opts.on_move_item
if callback and from and from ~= index and index >= 1 and index <= #self.current.items then
callback(from, index, self.current.submenu_path)
self.current.selected_index = index
request_render()
end
end

function Menu:move_selected_item_up()
if self.current.selected_index then self:move_selected_item_to(self.current.selected_index - 1) end
end

function Menu:move_selected_item_down()
if self.current.selected_index then self:move_selected_item_to(self.current.selected_index + 1) end
end

function Menu:delete_selected_item()
local index, callback = self.current.selected_index, self.opts.on_delete_item
if callback and index then callback(index, self.current.submenu_path) end
end

function Menu:on_display() self:update_dimensions() end
function Menu:on_prop_fullormaxed() self:update_content_dimensions() end

function Menu:on_global_mbtn_left_down()
function Menu:handle_cursor_down()
if self.proximity_raw == 0 then
self.drag_data = {{y = cursor.y, time = mp.get_time()}}
self.current.fling = nil
Expand All @@ -514,7 +546,7 @@ function Menu:fling_distance()
return #self.drag_data < 2 and 0 or ((first.y - last.y) / ((first.time - last.time) / 0.03)) * 10
end

function Menu:on_global_mbtn_left_up()
function Menu:handle_cursor_up()
if self.proximity_raw == 0 and self.drag_data and not self.is_dragging then
self:select_item_below_cursor()
self:open_selected_item({preselect_submenu_item = false, keep_open = self.modifiers and self.modifiers.shift})
Expand Down Expand Up @@ -546,8 +578,8 @@ function Menu:on_global_mouse_move()
request_render()
end

function Menu:on_wheel_up() self:scroll_by(self.scroll_step * -3, nil, {update_cursor = true}) end
function Menu:on_wheel_down() self:scroll_by(self.scroll_step * 3, nil, {update_cursor = true}) end
function Menu:handle_wheel_up() self:scroll_by(self.scroll_step * -3, nil, {update_cursor = true}) end
function Menu:handle_wheel_down() self:scroll_by(self.scroll_step * 3, nil, {update_cursor = true}) end

function Menu:on_pgup()
local menu = self.current
Expand Down Expand Up @@ -585,6 +617,8 @@ function Menu:enable_key_bindings()
-- doesn't support 'repeatable' flag, so we are stuck with this monster.
self:add_key_binding('up', 'menu-prev1', self:create_key_action('prev'), 'repeatable')
self:add_key_binding('down', 'menu-next1', self:create_key_action('next'), 'repeatable')
self:add_key_binding('ctrl+up', 'menu-move-up', self:create_key_action('move_selected_item_up'), 'repeatable')
self:add_key_binding('ctrl+down', 'menu-move-down', self:create_key_action('move_selected_item_down'), 'repeatable')
self:add_key_binding('left', 'menu-back1', self:create_key_action('back'))
self:add_key_binding('right', 'menu-select1', self:create_key_action('open_selected_item_preselect'))
self:add_key_binding('shift+right', 'menu-select-soft1',
Expand All @@ -608,6 +642,7 @@ function Menu:enable_key_bindings()
self:add_key_binding('pgdwn', 'menu-page-down', self:create_key_action('on_pgdwn'), 'repeatable')
self:add_key_binding('home', 'menu-home', self:create_key_action('on_home'))
self:add_key_binding('end', 'menu-end', self:create_key_action('on_end'))
self:add_key_binding('del', 'menu-delete-item', self:create_key_action('delete_selected_item'))
end

function Menu:disable_key_bindings()
Expand All @@ -620,8 +655,8 @@ function Menu:create_modified_mbtn_left_handler(modifiers)
return function()
self.mouse_nav = true
self.modifiers = modifiers
self:on_global_mbtn_left_down()
self:on_global_mbtn_left_up()
self:handle_cursor_down()
self:handle_cursor_up()
self.modifiers = nil
end
end
Expand Down Expand Up @@ -650,6 +685,13 @@ function Menu:render()
end
if update_cursor then self:select_item_below_cursor() end

cursor.on_primary_down = function() self:handle_cursor_down() end
cursor.on_primary_up = function() self:handle_cursor_up() end
if self.proximity_raw == 0 then
cursor.on_wheel_down = function() self:handle_wheel_down() end
cursor.on_wheel_up = function() self:handle_wheel_up() end
end

local ass = assdraw.ass_new()
local opacity = options.menu_opacity * self.opacity
local spacing = self.item_padding
Expand Down
Loading

0 comments on commit 54c413d

Please sign in to comment.