Skip to content

Commit

Permalink
console.lua: fix the hovered line calculation without scale with window
Browse files Browse the repository at this point in the history
If not scaling with the window the hidpi scale needs to be factored into
mouse-pos. Follow up to a670f75 and a210639.
  • Loading branch information
guidocella committed Oct 28, 2024
1 parent a210639 commit 8e43478
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,24 @@ local function should_scale()
(opts.scale_with_window == "auto" and mp.get_property_native("osd-scale-by-window"))
end

local function scale_factor()
local height = mp.get_property_native('osd-height')

if should_scale() and height > 0 then
return height / 720
end

return mp.get_property_native('display-hidpi-scale', 1)
end

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

if w == 0 then
return 0, 0
end

local scale = mp.get_property_native('display-hidpi-scale')
if should_scale() then
h = 720
w = 720 * aspect
scale = 1
end

local scale = scale_factor()
w = w / scale
h = h / scale

Expand Down Expand Up @@ -807,11 +811,8 @@ end

local function determine_hovered_item()
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
y = y - global_margins.t * height
local y = mp.get_property_native('mouse-pos').y / scale_factor()
- global_margins.t * height
-- Calculate how many lines could be printed without decreasing them for
-- the input line and OSC.
local max_lines = height / opts.font_size
Expand Down

0 comments on commit 8e43478

Please sign in to comment.