mirror of https://github.com/mpv-player/mpv
console.lua: add scale_with_window script-opt
If this is set to yes or auto and --osd-scale-by-window is true, console scales with the window height like everything else in mpv. Defaults to auto.
This commit is contained in:
parent
fbf869584c
commit
e00d8dcb03
|
@ -0,0 +1 @@
|
||||||
|
add `console-scale_with_window` script-opt
|
|
@ -164,6 +164,12 @@ Configurable Options
|
||||||
|
|
||||||
Set the font border size used for the REPL and the console.
|
Set the font border size used for the REPL and the console.
|
||||||
|
|
||||||
|
``scale_with_window``
|
||||||
|
Default: ``auto``
|
||||||
|
|
||||||
|
Whether to scale the console with the window height. Can be ``yes``, ``no``,
|
||||||
|
or ``auto``, which follows the value of ``--osd-scale-by-window``.
|
||||||
|
|
||||||
``case_sensitive``
|
``case_sensitive``
|
||||||
Default: no on Windows, yes on other platforms.
|
Default: no on Windows, yes on other platforms.
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ local opts = {
|
||||||
font = "",
|
font = "",
|
||||||
font_size = 16,
|
font_size = 16,
|
||||||
border_size = 1,
|
border_size = 1,
|
||||||
|
scale_with_window = "auto",
|
||||||
case_sensitive = true,
|
case_sensitive = true,
|
||||||
history_dedup = true,
|
history_dedup = true,
|
||||||
font_hw_ratio = 'auto',
|
font_hw_ratio = 'auto',
|
||||||
|
@ -230,6 +231,30 @@ local function ass_escape(str)
|
||||||
return mp.command_native({'escape-ass', str})
|
return mp.command_native({'escape-ass', str})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function should_scale()
|
||||||
|
return opts.scale_with_window == "yes" or
|
||||||
|
(opts.scale_with_window == "auto" and mp.get_property_native("osd-scale-by-window"))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_scaled_osd_dimensions()
|
||||||
|
local w, h, aspect = mp.get_osd_size()
|
||||||
|
|
||||||
|
if w == 0 then
|
||||||
|
return 0, 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if should_scale() then
|
||||||
|
h = 720
|
||||||
|
w = 720 * aspect
|
||||||
|
end
|
||||||
|
|
||||||
|
local scale = mp.get_property_native('display-hidpi-scale')
|
||||||
|
w = w / scale
|
||||||
|
h = h / scale
|
||||||
|
|
||||||
|
return w, h
|
||||||
|
end
|
||||||
|
|
||||||
local function calculate_max_log_lines()
|
local function calculate_max_log_lines()
|
||||||
if not mp.get_property_native('vo-configured')
|
if not mp.get_property_native('vo-configured')
|
||||||
or not mp.get_property_native('video-osd') then
|
or not mp.get_property_native('video-osd') then
|
||||||
|
@ -239,8 +264,7 @@ local function calculate_max_log_lines()
|
||||||
select(2, mp.get_property('term-status-msg'):gsub('\\n', ''))
|
select(2, mp.get_property('term-status-msg'):gsub('\\n', ''))
|
||||||
end
|
end
|
||||||
|
|
||||||
return math.floor(mp.get_property_native('osd-height')
|
return math.floor(select(2, get_scaled_osd_dimensions())
|
||||||
/ mp.get_property_native('display-hidpi-scale', 1)
|
|
||||||
* (1 - global_margins.t - global_margins.b)
|
* (1 - global_margins.t - global_margins.b)
|
||||||
/ opts.font_size
|
/ opts.font_size
|
||||||
-- Subtract 1 for the input line and 1 for the newline
|
-- Subtract 1 for the input line and 1 for the newline
|
||||||
|
@ -476,10 +500,7 @@ local function update()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local screenx, screeny = mp.get_osd_size()
|
local screenx, screeny = get_scaled_osd_dimensions()
|
||||||
local dpi_scale = mp.get_property_native('display-hidpi-scale', 1)
|
|
||||||
screenx = screenx / dpi_scale
|
|
||||||
screeny = screeny / dpi_scale
|
|
||||||
|
|
||||||
local bottom_left_margin = 6
|
local bottom_left_margin = 6
|
||||||
|
|
||||||
|
@ -784,16 +805,16 @@ local function handle_enter()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function determine_hovered_item()
|
local function determine_hovered_item()
|
||||||
local height = mp.get_property_native('osd-height')
|
local height = select(2, get_scaled_osd_dimensions())
|
||||||
if height == 0 then
|
local y = mp.get_property_native('mouse-pos').y
|
||||||
return
|
if should_scale() then
|
||||||
|
y = y * 720 / mp.get_property_native('osd-height')
|
||||||
end
|
end
|
||||||
|
y = y - global_margins.t * height
|
||||||
local y = mp.get_property_native('mouse-pos').y - global_margins.t * height
|
|
||||||
-- Calculate how many lines could be printed without decreasing them for
|
-- Calculate how many lines could be printed without decreasing them for
|
||||||
-- the input line and OSC.
|
-- the input line and OSC.
|
||||||
local max_lines = height / mp.get_property_native('display-hidpi-scale')
|
local max_lines = height / mp.get_property_native('display-hidpi-scale', 1)
|
||||||
/ opts.font_size
|
/ opts.font_size
|
||||||
local clicked_line = math.floor(y / height * max_lines + .5)
|
local clicked_line = math.floor(y / height * max_lines + .5)
|
||||||
|
|
||||||
local offset = first_match_to_print - 1
|
local offset = first_match_to_print - 1
|
||||||
|
|
Loading…
Reference in New Issue