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 authored and kasper93 committed Oct 28, 2024
1 parent 940ab99 commit bf3382b
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,24 +236,21 @@ local function should_scale()
(opts.scale_with_window == "auto" and mp.get_property_native("osd-scale-by-window"))
end

local function get_scaled_osd_dimensions()
local w, h, aspect = mp.get_osd_size()
local function scale_factor()
local height = mp.get_property_native('osd-height')

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

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

w = w / scale
h = h / scale
local function get_scaled_osd_dimensions()
local dims = mp.get_property_native('osd-dimensions')
local scale = scale_factor()

return w, h
return dims.w / scale, dims.h /scale
end

local function calculate_max_log_lines()
Expand Down Expand Up @@ -807,11 +804,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 bf3382b

Please sign in to comment.