Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console.lua: scale with the window height #14114

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/console-scale-with-window.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `console-scale_with_window` script-opt
10 changes: 8 additions & 2 deletions DOCS/man/console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,22 @@ Configurable Options
aligned correctly.

``font_size``
Default: 16
Default: 24

Set the font size used for the REPL and the console. This will be
multiplied by ``display-hidpi-scale``.

``border_size``
Default: 1
Default: 1.5

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``
Default: no on Windows, yes on other platforms.

Expand Down
51 changes: 36 additions & 15 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ local assdraw = require 'mp.assdraw'
-- Default options
local opts = {
font = "",
font_size = 16,
border_size = 1,
font_size = 24,
border_size = 1.5,
scale_with_window = "auto",
case_sensitive = true,
history_dedup = true,
font_hw_ratio = 'auto',
Expand Down Expand Up @@ -230,6 +231,30 @@ local function ass_escape(str)
return mp.command_native({'escape-ass', str})
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()
if not mp.get_property_native('vo-configured')
or not mp.get_property_native('video-osd') then
Expand All @@ -239,8 +264,7 @@ local function calculate_max_log_lines()
select(2, mp.get_property('term-status-msg'):gsub('\\n', ''))
end

return math.floor(mp.get_property_native('osd-height')
/ mp.get_property_native('display-hidpi-scale', 1)
return math.floor(select(2, get_scaled_osd_dimensions())
* (1 - global_margins.t - global_margins.b)
/ opts.font_size
-- Subtract 1 for the input line and 1 for the newline
Expand Down Expand Up @@ -474,10 +498,7 @@ local function update()
return
end

local screenx, screeny = mp.get_osd_size()
local dpi_scale = mp.get_property_native('display-hidpi-scale', 1)
screenx = screenx / dpi_scale
screeny = screeny / dpi_scale
local screenx, screeny = get_scaled_osd_dimensions()

local bottom_left_margin = 6

Expand Down Expand Up @@ -782,16 +803,16 @@ local function handle_enter()
end

local function determine_hovered_item()
local height = mp.get_property_native('osd-height')
if height == 0 then
return
local height = select(2, get_scaled_osd_dimensions())
local y = mp.get_property_native('mouse-pos').y
if should_scale() then
y = y * 720 / mp.get_property_native('osd-height')
end

local y = mp.get_property_native('mouse-pos').y - global_margins.t * height
y = y - global_margins.t * height
-- Calculate how many lines could be printed without decreasing them for
-- the input line and OSC.
local max_lines = height / mp.get_property_native('display-hidpi-scale')
/ opts.font_size
local max_lines = height / mp.get_property_native('display-hidpi-scale', 1)
/ opts.font_size
local clicked_line = math.floor(y / height * max_lines + .5)

local offset = first_match_to_print - 1
Expand Down
Loading