Skip to content

Commit 54c413d

Browse files
committed
同步与整合上游
脚本: 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
1 parent 3eacfc7 commit 54c413d

26 files changed

+1873
-3015
lines changed

portable_config/script-opts/uosc.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ stream_quality_options=4320,2160,1440,1080,720,480,360,240,144
130130

131131
# (加载文件/导入视频音频轨时)文件浏览器的扩展名过滤列表。默认值覆盖极广,此预设精简为常见的视频和音频格式
132132
video_types=avi,flv,m2ts,m4v,mkv,mov,mp4,mpeg,mpg,ogv,rm,rmvb,ts,vob,webm,wmv
133-
audio_types=aac,ape,dsf,dts,flac,m4a,mka,mp3,ogg,opus,wav,wma,wv
133+
audio_types=aac,ac3,ape,dsf,dts,flac,m4a,mka,mp3,ogg,opus,wav,wma,wv
134134
image_types=apng,avif,bmp,gif,jfif,jpeg,jpg,jxl,png,svg,tif,tiff,webp
135135
# (导入字幕时)文件浏览器的扩展名过滤列表。默认值覆盖极广,此预设精简为常见的字幕格式
136136
subtitle_types=ass,idx,lrc,mks,pgs,sup,srt,ssa,txt,vtt

portable_config/scripts/uosc/elements/Button.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@ function Button:init(id, props)
2323
end
2424

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

3634
function Button:render()
3735
local visibility = self:get_visibility()
3836
if visibility <= 0 then return end
37+
if self.proximity_raw == 0 then
38+
cursor.on_primary_down = function() self:handle_cursor_down() end
39+
end
3940

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

57-
5858
-- Badge
5959
local icon_clip
6060
if self.badge then

portable_config/scripts/uosc/elements/Element.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Element:init(id, props)
1515
-- Relative proximity from `0` - mouse outside `proximity_max` range, to `1` - mouse within `proximity_min` range.
1616
self.proximity = 0
1717
-- Raw proximity in pixels.
18-
self.proximity_raw = infinity
18+
self.proximity_raw = INFINITY
1919
---@type number `0-1` factor to force min visibility. Used for toggling element's permanent visibility.
2020
self.min_visibility = 0
2121
---@type number `0-1` factor to force a visibility value. Used for flashing, fading out, and other animations
@@ -44,7 +44,7 @@ function Element:destroy()
4444
Elements:remove(self)
4545
end
4646

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

4949
---@param ax number
5050
---@param ay number

portable_config/scripts/uosc/elements/Elements.lua

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ function Elements:remove(idOrElement)
2929
end
3030

3131
function Elements:update_proximities()
32-
local capture_mbtn_left = false
33-
local capture_wheel = false
3432
local menu_only = Elements.menu ~= nil
3533
local mouse_leave_elements = {}
3634
local mouse_enter_elements = {}
@@ -42,26 +40,13 @@ function Elements:update_proximities()
4240

4341
-- If menu is open, all other elements have to be disabled
4442
if menu_only then
45-
if element.ignores_menu then
46-
capture_mbtn_left = true
47-
capture_wheel = true
48-
element:update_proximity()
49-
else
50-
element:reset_proximity()
51-
end
43+
if element.ignores_menu then element:update_proximity()
44+
else element:reset_proximity() end
5245
else
5346
element:update_proximity()
5447
end
5548

56-
-- Element has global forced key listeners
57-
if element.on_global_mbtn_left_down then capture_mbtn_left = true end
58-
if element.on_global_wheel_up or element.on_global_wheel_down then capture_wheel = true end
59-
6049
if element.proximity_raw == 0 then
61-
-- Element has local forced key listeners
62-
if element.on_mbtn_left_down then capture_mbtn_left = true end
63-
if element.on_wheel_up or element.on_wheel_up then capture_wheel = true end
64-
6550
-- Mouse entered element area
6651
if previous_proximity_raw ~= 0 then
6752
mouse_enter_elements[#mouse_enter_elements + 1] = element
@@ -75,10 +60,6 @@ function Elements:update_proximities()
7560
end
7661
end
7762

78-
-- Enable key group captures requested by elements
79-
mp[capture_mbtn_left and 'enable_key_bindings' or 'disable_key_bindings']('mbtn_left')
80-
mp[capture_wheel and 'enable_key_bindings' or 'disable_key_bindings']('wheel')
81-
8263
-- Trigger `mouse_leave` and `mouse_enter` events
8364
for _, element in ipairs(mouse_leave_elements) do element:trigger('mouse_leave') end
8465
for _, element in ipairs(mouse_enter_elements) do element:trigger('mouse_enter') end
@@ -142,26 +123,4 @@ end
142123
function Elements:has(id) return self[id] ~= nil end
143124
function Elements:ipairs() return ipairs(self.itable) end
144125

145-
---@param name string Event name.
146-
function Elements:create_proximity_dispatcher(name)
147-
return function(...) self:proximity_trigger(name, ...) end
148-
end
149-
150-
mp.set_key_bindings({
151-
{
152-
'mbtn_left',
153-
Elements:create_proximity_dispatcher('mbtn_left_up'),
154-
function(...)
155-
update_mouse_pos(nil, mp.get_property_native('mouse-pos'))
156-
Elements:proximity_trigger('mbtn_left_down', ...)
157-
end,
158-
},
159-
{'mbtn_left_dbl', 'ignore'},
160-
}, 'mbtn_left', 'force')
161-
162-
mp.set_key_bindings({
163-
{'wheel_up', Elements:create_proximity_dispatcher('wheel_up')},
164-
{'wheel_down', Elements:create_proximity_dispatcher('wheel_down')},
165-
}, 'wheel', 'force')
166-
167126
return Elements

portable_config/scripts/uosc/elements/Menu.lua

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ local Element = require('elements/Element')
44
---@alias MenuData {type?: string; title?: string; hint?: string; keep_open?: boolean; separator?: boolean; items?: MenuDataItem[]; selected_index?: integer;}
55
---@alias MenuDataItem MenuDataValue|MenuData
66
---@alias MenuDataValue {title?: string; hint?: string; icon?: string; value: any; bold?: boolean; italic?: boolean; muted?: boolean; active?: boolean; keep_open?: boolean; separator?: boolean;}
7-
---@alias MenuOptions {mouse_nav?: boolean; on_open?: fun(); on_close?: fun(); on_back?: fun()}
7+
---@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[])}
88

99
-- Internal data structure created from `Menu`.
10-
---@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}
10+
---@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}
1111
---@alias MenuStackItem MenuStackValue|MenuStack
1212
---@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}
1313
---@alias Fling {y: number, distance: number, time: number, easing: fun(x: number), duration: number, update_cursor?: boolean}
@@ -56,6 +56,7 @@ function Menu:close(immediate, callback)
5656
menu.is_closing, menu.stack, menu.current, menu.all, menu.by_id = false, nil, nil, {}, {}
5757
menu:disable_key_bindings()
5858
Elements:update_proximities()
59+
cursor.queue_autohide()
5960
if callback then callback() end
6061
request_render()
6162
end
@@ -135,7 +136,7 @@ end
135136
function Menu:update(data)
136137
self.type = data.type
137138

138-
local new_root = {is_root = true}
139+
local new_root = {is_root = true, submenu_path = {}}
139140
local new_all = {}
140141
local new_by_id = {}
141142
local menus_to_serialize = {{new_root, data}}
@@ -169,6 +170,7 @@ function Menu:update(data)
169170
-- Submenu
170171
if item_data.items then
171172
item.parent_menu = menu
173+
item.submenu_path = itable_join(menu.submenu_path, {i})
172174
menus_to_serialize[#menus_to_serialize + 1] = {item, item_data}
173175
end
174176

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

212214
for _, menu in ipairs(self.all) do
215+
title_opts.bold, title_opts.italic = true, false
216+
local max_width = text_width(menu.title, title_opts) + 2 * self.item_padding
217+
213218
-- Estimate width of a widest item
214-
local max_width = 0
215219
for _, item in ipairs(menu.items) do
216220
local icon_width = item.icon and self.font_size or 0
217221
item.title_width = text_width(item.title, title_opts)
@@ -223,11 +227,6 @@ function Menu:update_content_dimensions()
223227
if estimated_width > max_width then max_width = estimated_width end
224228
end
225229

226-
-- Also check menu title
227-
title_opts.bold, title_opts.italic = true, false
228-
local menu_title_width = text_width(menu.title, title_opts)
229-
if menu_title_width > max_width then max_width = menu_title_width end
230-
231230
menu.max_width = max_width
232231
end
233232

@@ -236,8 +235,8 @@ end
236235

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

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

254+
self:update_coordinates()
255+
end
256+
257+
-- Updates element coordinates to match currently open (sub)menu.
258+
function Menu:update_coordinates()
255259
local ax = round((display.width - self.current.width) / 2) + self.offset_x
256260
self:set_coordinates(ax, self.current.top, ax + self.current.width, self.current.top + self.current.height)
257261
end
@@ -359,7 +363,7 @@ end
359363
function Menu:select_value(value, menu)
360364
menu = menu or self.current
361365
local index = itable_find(menu.items, function(item) return item.value == value end)
362-
self:select_index(index, 5)
366+
self:select_index(index)
363367
end
364368

365369
---@param menu? MenuStack
@@ -400,16 +404,23 @@ function Menu:activate_one_value(value, menu)
400404
self:activate_one_index(index, menu)
401405
end
402406

403-
---@param id string
404-
function Menu:activate_submenu(id)
405-
local submenu = self.by_id[id]
406-
if submenu then
407-
self.current = submenu
407+
---@param menu MenuStack One of menus in `self.all`.
408+
function Menu:activate_menu(menu)
409+
if itable_index_of(self.all, menu) then
410+
self.current = menu
411+
self:update_coordinates()
412+
self:reset_navigation()
408413
request_render()
409414
else
410-
msg.error(string.format('Requested submenu id "%s" doesn\'t exist', id))
415+
msg.error('Attempt to open a menu not in `self.all` list.')
411416
end
412-
self:reset_navigation()
417+
end
418+
419+
---@param id string
420+
function Menu:activate_submenu(id)
421+
local submenu = self.by_id[id]
422+
if submenu then self:activate_menu(submenu)
423+
else msg.error(string.format('Requested submenu id "%s" doesn\'t exist', id)) end
413424
end
414425

415426
---@param index? integer
@@ -456,8 +467,7 @@ function Menu:back()
456467

457468
if parent then
458469
menu.selected_index = nil
459-
self.current = parent
460-
self:update_dimensions()
470+
self:activate_menu(parent)
461471
self:tween(self.offset_x - menu.width / 2, 0, function(offset) self:set_offset_x(offset) end)
462472
self.opacity = 1 -- in case tween above canceled fade in animation
463473
else
@@ -473,11 +483,10 @@ function Menu:open_selected_item(opts)
473483
local item = menu.items[menu.selected_index]
474484
-- Is submenu
475485
if item.items then
476-
self.current = item
477486
if opts.preselect_submenu_item then
478487
item.selected_index = #item.items > 0 and 1 or nil
479488
end
480-
self:update_dimensions()
489+
self:activate_menu(item)
481490
self:tween(self.offset_x + menu.width / 2, 0, function(offset) self:set_offset_x(offset) end)
482491
self.opacity = 1 -- in case tween above canceled fade in animation
483492
else
@@ -491,10 +500,33 @@ function Menu:open_selected_item_soft() self:open_selected_item({keep_open = tru
491500
function Menu:open_selected_item_preselect() self:open_selected_item({preselect_submenu_item = true}) end
492501
function Menu:select_item_below_cursor() self.current.selected_index = self:get_item_index_below_cursor() end
493502

503+
---@param index integer
504+
function Menu:move_selected_item_to(index)
505+
local from, callback = self.current.selected_index, self.opts.on_move_item
506+
if callback and from and from ~= index and index >= 1 and index <= #self.current.items then
507+
callback(from, index, self.current.submenu_path)
508+
self.current.selected_index = index
509+
request_render()
510+
end
511+
end
512+
513+
function Menu:move_selected_item_up()
514+
if self.current.selected_index then self:move_selected_item_to(self.current.selected_index - 1) end
515+
end
516+
517+
function Menu:move_selected_item_down()
518+
if self.current.selected_index then self:move_selected_item_to(self.current.selected_index + 1) end
519+
end
520+
521+
function Menu:delete_selected_item()
522+
local index, callback = self.current.selected_index, self.opts.on_delete_item
523+
if callback and index then callback(index, self.current.submenu_path) end
524+
end
525+
494526
function Menu:on_display() self:update_dimensions() end
495527
function Menu:on_prop_fullormaxed() self:update_content_dimensions() end
496528

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

517-
function Menu:on_global_mbtn_left_up()
549+
function Menu:handle_cursor_up()
518550
if self.proximity_raw == 0 and self.drag_data and not self.is_dragging then
519551
self:select_item_below_cursor()
520552
self:open_selected_item({preselect_submenu_item = false, keep_open = self.modifiers and self.modifiers.shift})
@@ -546,8 +578,8 @@ function Menu:on_global_mouse_move()
546578
request_render()
547579
end
548580

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

552584
function Menu:on_pgup()
553585
local menu = self.current
@@ -585,6 +617,8 @@ function Menu:enable_key_bindings()
585617
-- doesn't support 'repeatable' flag, so we are stuck with this monster.
586618
self:add_key_binding('up', 'menu-prev1', self:create_key_action('prev'), 'repeatable')
587619
self:add_key_binding('down', 'menu-next1', self:create_key_action('next'), 'repeatable')
620+
self:add_key_binding('ctrl+up', 'menu-move-up', self:create_key_action('move_selected_item_up'), 'repeatable')
621+
self:add_key_binding('ctrl+down', 'menu-move-down', self:create_key_action('move_selected_item_down'), 'repeatable')
588622
self:add_key_binding('left', 'menu-back1', self:create_key_action('back'))
589623
self:add_key_binding('right', 'menu-select1', self:create_key_action('open_selected_item_preselect'))
590624
self:add_key_binding('shift+right', 'menu-select-soft1',
@@ -608,6 +642,7 @@ function Menu:enable_key_bindings()
608642
self:add_key_binding('pgdwn', 'menu-page-down', self:create_key_action('on_pgdwn'), 'repeatable')
609643
self:add_key_binding('home', 'menu-home', self:create_key_action('on_home'))
610644
self:add_key_binding('end', 'menu-end', self:create_key_action('on_end'))
645+
self:add_key_binding('del', 'menu-delete-item', self:create_key_action('delete_selected_item'))
611646
end
612647

613648
function Menu:disable_key_bindings()
@@ -620,8 +655,8 @@ function Menu:create_modified_mbtn_left_handler(modifiers)
620655
return function()
621656
self.mouse_nav = true
622657
self.modifiers = modifiers
623-
self:on_global_mbtn_left_down()
624-
self:on_global_mbtn_left_up()
658+
self:handle_cursor_down()
659+
self:handle_cursor_up()
625660
self.modifiers = nil
626661
end
627662
end
@@ -650,6 +685,13 @@ function Menu:render()
650685
end
651686
if update_cursor then self:select_item_below_cursor() end
652687

688+
cursor.on_primary_down = function() self:handle_cursor_down() end
689+
cursor.on_primary_up = function() self:handle_cursor_up() end
690+
if self.proximity_raw == 0 then
691+
cursor.on_wheel_down = function() self:handle_wheel_down() end
692+
cursor.on_wheel_up = function() self:handle_wheel_up() end
693+
end
694+
653695
local ass = assdraw.ass_new()
654696
local opacity = options.menu_opacity * self.opacity
655697
local spacing = self.item_padding

0 commit comments

Comments
 (0)