Skip to content

Commit

Permalink
console.lua: scale with the window height
Browse files Browse the repository at this point in the history
If --osd-scale-by-window is true scale console.lua with the window
height to be consistent with the OSD, osc.lua and stats.lua.

Also remove the scale option because you can set font_size and
border_size to have the same effect.

display-hidpi-scale is still used and it may make sense to also multiple
other mpv text sizes by it.
  • Loading branch information
guidocella committed May 20, 2024
1 parent c3bf2c7 commit 53bcc46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
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

0 comments on commit 53bcc46

Please sign in to comment.