Skip to content

Commit

Permalink
console.lua: scale with the window height
Browse files Browse the repository at this point in the history
This makes console.lua consistent with the OSD, osc.lua and stats.lua.
This reads --osd-scale-by-window so users don't have to configure
vidscale in yet another script.
  • Loading branch information
guidocella committed May 11, 2024
1 parent 552c455 commit c7ed931
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
7 changes: 4 additions & 3 deletions DOCS/man/console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,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 is multiplied by ``scale`` and
``display-hidpi-scale``, and will also scale 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 like ``font_size``.

``case_sensitive``
Default: no on Windows, yes on other platforms.
Expand Down
30 changes: 18 additions & 12 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,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) * opts.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') then
-- Subtract 1 for the input line and for each line in the status line.
Expand All @@ -248,9 +263,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 +464,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 c7ed931

Please sign in to comment.