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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 4 additions & 12 deletions DOCS/man/console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,6 @@ documentation.
Configurable Options
~~~~~~~~~~~~~~~~~~~~

``scale``
Default: 1

All drawing is scaled by this value, including the text borders and the
cursor.

If the VO backend in use has HiDPI scale reporting implemented, the option
value is scaled with the reported HiDPI scale.

``font``
Default: unset (picks a hardcoded font depending on detected platform)

Expand All @@ -150,13 +141,14 @@ Configurable Options
``font_size``
Default: 16

Set the font size used for the REPL and the console. This will be
multiplied by "scale".
Set the font size. This scales with the window height when
``--osd-scale-by-window`` is enabled.

``border_size``
Default: 1

Set the font border size used for the REPL and the console.
Set the font border size. This scales with the window height when
``--osd-scale-by-window`` is enabled.

``case_sensitive``
Default: no on Windows, yes on other platforms.
Expand Down
36 changes: 19 additions & 17 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ local assdraw = require 'mp.assdraw'

-- Default options
local opts = {
-- All drawing is scaled by this value, including the text borders and the
-- cursor. Change it if you have a high-DPI display.
scale = 1,
-- Set the font used for the REPL and the console.
-- This has to be a monospaced font.
font = "",
-- Set the font size used for the REPL and the console. This will be
-- multiplied by "scale".
-- Set the font size used for the REPL and the console.
font_size = 16,
border_size = 1,
case_sensitive = true,
Expand Down Expand Up @@ -243,6 +239,21 @@ function ass_escape(str)
return mp.command_native({'escape-ass', str})
end

local function get_scaled_osd_dimensions()
local w, h, aspect = mp.get_osd_size()

if mp.get_property_native('osd-scale-by-window') then
h = 720
w = 720 * aspect
end

local scale = mp.get_property_native('display-hidpi-scale', 1)
w = w / scale
h = h / scale

return w, h
end

local function calculate_max_log_lines()
if not mp.get_property_native('vo-configured') then
-- Subtract 1 for the input line and for each line in the status line.
Expand All @@ -251,9 +262,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)
/ opts.scale
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 @@ -494,20 +503,13 @@ function update()
return
end

local dpi_scale = mp.get_property_native("display-hidpi-scale", 1.0)

dpi_scale = dpi_scale * opts.scale

local screenx, screeny = mp.get_osd_size()
screenx = screenx / dpi_scale
screeny = screeny / dpi_scale

-- Clear the OSD if the REPL is not active
if not repl_active then
mp.set_osd_ass(screenx, screeny, '')
mp.set_osd_ass(0, 0, '')
return
end

local screenx, screeny = get_scaled_osd_dimensions()
local coordinate_top = math.floor(global_margins.t * screeny + 0.5)
local clipping_coordinates = '0,' .. coordinate_top .. ',' ..
screenx .. ',' .. screeny
Expand Down