CogentRedTester / mpv-scroll-list

MIT License
36 stars 3 forks source link

[REQUEST] Background dim #6

Open ma-zsola opened 1 year ago

ma-zsola commented 1 year ago

For better text readability a background dim would be great. I can found a sample here: https://github.com/christoph-heinrich/mpv-quality-menu/commit/c5fec0889be71bf0a9cbae5bf2b66ba9167f0570

CogentRedTester commented 1 year ago

Not a bad idea, have you considered making a pull request?

ma-zsola commented 1 year ago

I'm relatively new to GitHub. I don't think I can make a pull request. But in the meantime I can solve this problem with a little help.

Here is the relevant code, feel free to use any part of it:


local scroll_list = {
...
    empty_text = "No entries",
    curtain_opacity = 0.7,
}
--add a curtain behind the list
local curtain = mp.create_osd_overlay("ass-events")
local opacity = math.floor(255 - scroll_list.curtain_opacity * 255)
local osd_w = 1280
local osd_h = 720
curtain.data = string.format("{\\rDefault\\alpha&H%X&\\bord0\\an7\\pos(0,0)\\1c&H000000&}{\\p1}m 0 0 l %d 0 %d %d 0 %d{\\p0}", opacity, osd_w, osd_w, osd_h, osd_h)

--opens the list and sets the hidden flag
function scroll_list:open_list()
...
    curtain:update()
end

--closes the list and sets the hidden flag
function scroll_list:close_list()
...
    curtain:remove()
end

I couldn't get it to work when I tried to get the osd_w and osd_h parameters from the actual OSD size

kaoneko commented 11 months ago

Neat idea, but when I try it the list text ends up behind the overlay as well... is there any way to set the layer, z-index, priority or something like that? Or what could I be doing wrong?

Edit: found it! curtain:update() must (at least on my OS and mpv version) happen at the beginning of the open_list function:

function scroll_list:open_list()
    self.hidden = false
    curtain:update()
    if not self.flag_update then self.ass:update()
    else self.flag_update = false ; self:update_ass() end
end
CogentRedTester commented 11 months ago

In addition, I believe that curtain and scroll_list.ass both have a z value that should control this. I am not sure what version of mpv added that.

kaoneko commented 11 months ago

Ah, indeed. Adding

curtain.z = -1

below the curtain.data = ...-line also works.