Skip to content

Commit

Permalink
console.lua: scale like the OSD and other scripts
Browse files Browse the repository at this point in the history
This makes console.lua consistent with the OSD, osc.lua and stats.lua:

- If --osd-scale-by-window is true it scales with the window height. No
  vidscale option is added so users don't have to configure it in yet
  another script.

- display-hidpi-scale is no longer considered.

- The scale option is removed because you can set font_size and
  border_size to have the same effect.
  • Loading branch information
guidocella committed May 11, 2024
1 parent 552c455 commit 06ae3fb
Show file tree
Hide file tree
Showing 2 changed files with 19 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
32 changes: 15 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 @@ -239,6 +235,17 @@ 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

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 @@ -248,9 +255,7 @@ local function calculate_max_log_lines()
end

-- Subtract 1.5 to account for the input line.
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
- 1.5)
Expand Down Expand Up @@ -451,20 +456,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, aspect = 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 06ae3fb

Please sign in to comment.