From 0b0e0a6d49fa67edccdb0f3f7fea5f8b432b15fa Mon Sep 17 00:00:00 2001 From: hooke007 Date: Wed, 10 Apr 2024 01:54:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=84=9A=E6=9C=AC=EF=BC=9A=20=E5=9F=BA?= =?UTF-8?q?=E4=BA=8E=E4=B8=8A=E6=B8=B8dpi=E7=89=B9=E6=80=A7=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E8=B0=83=E8=8A=82ui=E7=BC=A9=E6=94=BE=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- portable_config/script-opts.conf | 4 +-- portable_config/script-opts/uosc.conf | 6 ++--- portable_config/scripts/uosc/main.lua | 38 +++++++++++---------------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/portable_config/script-opts.conf b/portable_config/script-opts.conf index 75c86c98..bff61d70 100644 --- a/portable_config/script-opts.conf +++ b/portable_config/script-opts.conf @@ -519,8 +519,8 @@ # 多个值用半角逗号分隔,默认 video 可用的其它值 audio image subtitle script-opts-append = uosc-shuffle=no # 启用播放列表/当前目录的乱序播放,默认 no - script-opts-append = uosc-scale=0 # 界面元素的缩放率,使用小于等于0的数值即自动计算,默认 0 - script-opts-append = uosc-scale_fullscreen=0 # 界面元素的在全屏时的缩放倍率,默认 0 (采用上一项自动计算出的数值) + script-opts-append = uosc-scale=0 # 界面元素的缩放率,0为自动计算,负值则表示采用自动dpi缩放,默认 0 + script-opts-append = uosc-scale_fullscreen=1 # 界面元素的在全屏时的缩放补偿,默认 1 script-opts-append = uosc-font_scale=1 # 字体缩放率,默认 1 script-opts-append = uosc-font_bold=no # 仅使用字体的Bold字重,默认 no script-opts-append = uosc-text_border=1.2 # 控件元素的边框,默认 1.2 diff --git a/portable_config/script-opts/uosc.conf b/portable_config/script-opts/uosc.conf index 2cf18690..6066275b 100644 --- a/portable_config/script-opts/uosc.conf +++ b/portable_config/script-opts/uosc.conf @@ -76,10 +76,10 @@ autoload_types=video # 启用播放列表/当前目录的乱序播放,默认 no shuffle=no -# 界面元素的缩放率,默认 0 (即自动计算) +# 界面元素的缩放率,默认 0 (即自动计算),负值则表示采用自动dpi缩放 scale=0 -# 界面元素的在全屏时的缩放倍率,默认 0 (采用上一项自动计算出的数值) -scale_fullscreen=0 +# 界面元素的在全屏时的缩放补偿,默认 1 +scale_fullscreen=1 # 字体缩放率,默认 1 font_scale=1 # 仅使用字体的Bold字重,默认 no diff --git a/portable_config/scripts/uosc/main.lua b/portable_config/scripts/uosc/main.lua index 8fbe276d..98bdb91d 100644 --- a/portable_config/scripts/uosc/main.lua +++ b/portable_config/scripts/uosc/main.lua @@ -71,7 +71,7 @@ defaults = { shuffle = false, scale = 0, - scale_fullscreen = 0, + scale_fullscreen = 1, font_scale = 1, font_bold = false, text_border = 1.2, @@ -130,25 +130,17 @@ options.proximity_out = math.max(options.proximity_out, options.proximity_in + 1 if options.chapter_ranges:sub(1, 4) == '^op|' then options.chapter_ranges = defaults.chapter_ranges end -- Ensure required environment configuration if options.autoload then mp.commandv('set', 'keep-open-pause', 'no') end --- 禁用DPI探测时的UI倍率自动计算 +-- 用于UI倍率计算 function auto_ui_scale() local display_w, display_h = mp.get_property_number('display-width', 0), mp.get_property_number('display-height', 0) local display_aspect = display_w / display_h or 0 - if display_aspect <= 1 then - options.scale = 1 - msg.warn('检测到异常的显示器分辨率,回退选项 scale 为1') - return - end - if display_aspect >=2 then - options.scale = tonumber(string.format('%.2f', display_h / 1080)) - msg.info('检测到超宽显示器,建议手动指定选项 scale') - return - end - if display_w * display_h > 2304000 then - options.scale = tonumber(string.format('%.2f', math.sqrt(display_w * display_h / 2073600))) + local factor = 1 + if display_aspect >= 1 then + factor = tonumber(string.format('%.2f', display_h / 1080)) else - options.scale = 1 + factor = tonumber(string.format('%.2f', display_w / 1080)) end + return factor end -- 设置脚本属性 mp.set_property_native('user-data/osc', { idlescreen = options.idlescreen }) @@ -429,16 +421,16 @@ function update_display_dimensions() if real_width <= 0 then return end -- 此处起才能获取到显示分辨率的信息 - if options.scale <= 0 then - if mp.get_property_native('hidpi-window-scale') then - options.scale = 1 - else - auto_ui_scale() - end + local dpi, scale_fom = state.hidpi_scale, options.scale_fullscreen + if scale_fom <= 0 then scale_fom = 1 end + if options.scale < 0 then + state.scale = (dpi or 1) * (state.fullormaxed and scale_fom or 1) + elseif options.scale == 0 then + state.scale = auto_ui_scale() * (state.fullormaxed and scale_fom or 1) + else + state.scale = options.scale * (state.fullormaxed and scale_fom or 1) end - if options.scale_fullscreen <= 0 then options.scale_fullscreen = options.scale end - state.scale = (state.hidpi_scale or 1) * (state.fullormaxed and options.scale_fullscreen or options.scale) state.radius = round(options.border_radius * state.scale) display.width, display.height = real_width, real_height display.initialized = true