1
mirror of https://github.com/mpv-player/mpv synced 2024-11-18 21:16:10 +01:00

osc: Unify bottom and topbar code

Among the pointless duplication the right timecode label was given some extra space that wasn't needed.

Fixes: #6904
This commit is contained in:
Jan Janssen 2019-10-25 11:30:56 +02:00 committed by wm4
parent 69f7251f32
commit 00c9a6c237
2 changed files with 33 additions and 181 deletions

View File

@ -330,8 +330,8 @@ Configurable Options
user has set them. (It will not overwrite them if all of them are set to
default values.)
Currently, this is supported for the ``bottombar`` layout only. The other
layouts do not change if this option is set.
Currently, this is supported for the ``bottombar`` and ``topbar`` layout
only. The other layouts do not change if this option is set.
The border is static and appears even if the OSC is configured to appear
only on mouse interaction. If the OSC is invisible, the border is simply

View File

@ -1252,11 +1252,13 @@ layouts["slimbox"] = function ()
end
layouts["bottombar"] = function()
function bar_layout(direction)
local y_offset = (direction < 0) and osc_param.playresy or 0
local osc_geo = {
x = -2,
y = osc_param.playresy - 54 - user_opts.barmargin,
an = 7,
y = y_offset + direction * (54 + user_opts.barmargin),
an = (direction < 0) and 7 or 1,
w = osc_param.playresx + 4,
h = 56,
}
@ -1271,12 +1273,12 @@ layouts["bottombar"] = function()
if ((osc_param.display_aspect > 0) and (osc_param.playresx < minW)) then
osc_param.playresy = minW / osc_param.display_aspect
osc_param.playresx = osc_param.playresy * osc_param.display_aspect
osc_geo.y = osc_param.playresy - 54 - user_opts.barmargin
osc_geo.y = y_offset + direction * (54 + user_opts.barmargin)
osc_geo.w = osc_param.playresx + 4
end
local line1 = osc_geo.y + 9 + padY
local line2 = osc_geo.y + 36 + padY
local line1 = osc_geo.y - direction * (9 + padY)
local line2 = osc_geo.y - direction * (36 + padY)
osc_param.areas = {}
@ -1284,9 +1286,18 @@ layouts["bottombar"] = function()
osc_geo.w, osc_geo.h))
local sh_area_y0, sh_area_y1
sh_area_y0 = get_align(-1 + (2*user_opts.deadzonesize),
osc_geo.y - (osc_geo.h / 2), 0, 0)
sh_area_y1 = osc_param.playresy - user_opts.barmargin
if direction > 0 then
-- deadzone below OSC
sh_area_y0 = user_opts.barmargin
sh_area_y1 = (osc_geo.y + (osc_geo.h / 2)) +
get_align(1 - (2*user_opts.deadzonesize),
osc_param.playresy - (osc_geo.y + (osc_geo.h / 2)), 0, 0)
else
-- deadzone above OSC
sh_area_y0 = get_align(-1 + (2*user_opts.deadzonesize),
osc_geo.y - (osc_geo.h / 2), 0, 0)
sh_area_y1 = osc_param.playresy - user_opts.barmargin
end
add_area("showhide", 0, sh_area_y0, osc_param.playresx, sh_area_y1)
local lo, geo
@ -1413,7 +1424,7 @@ layouts["bottombar"] = function()
lo = add_layout("seekbar")
lo.geometry = geo
lo.style = osc_styles.timecodes
lo.style = osc_styles.timecodesBar
lo.slider.border = 0
lo.slider.gap = 2
lo.slider.tooltip_style = osc_styles.timePosBar
@ -1421,178 +1432,19 @@ layouts["bottombar"] = function()
lo.slider.stype = user_opts["seekbarstyle"]
lo.slider.rtype = user_opts["seekrangestyle"]
osc_param.video_margins.b = osc_geo.h / osc_param.playresy
if direction < 0 then
osc_param.video_margins.b = osc_geo.h / osc_param.playresy
else
osc_param.video_margins.t = osc_geo.h / osc_param.playresy
end
end
layouts["bottombar"] = function()
bar_layout(-1)
end
layouts["topbar"] = function()
local osc_geo = {
x = -2,
y = 54 + user_opts.barmargin,
an = 1,
w = osc_param.playresx + 4,
h = 56,
}
local padX = 9
local padY = 3
local buttonW = 27
local tcW = (state.tc_ms) and 170 or 110
local tsW = 90
local minW = (buttonW + padX)*5 + (tcW + padX)*4 + (tsW + padX)*2
if ((osc_param.display_aspect > 0) and (osc_param.playresx < minW)) then
osc_param.playresy = minW / osc_param.display_aspect
osc_param.playresx = osc_param.playresy * osc_param.display_aspect
osc_geo.y = 54 + user_opts.barmargin
osc_geo.w = osc_param.playresx + 4
end
local line1 = osc_geo.y - 36 - padY
local line2 = osc_geo.y - 9 - padY
osc_param.areas = {}
add_area("input", get_hitbox_coords(osc_geo.x, osc_geo.y, osc_geo.an,
osc_geo.w, osc_geo.h))
local sh_area_y0, sh_area_y1
sh_area_y0 = user_opts.barmargin
sh_area_y1 = (osc_geo.y + (osc_geo.h / 2)) +
get_align(1 - (2*user_opts.deadzonesize),
osc_param.playresy - (osc_geo.y + (osc_geo.h / 2)), 0, 0)
add_area("showhide", 0, sh_area_y0, osc_param.playresx, sh_area_y1)
local lo, geo
-- Background bar
new_element("bgbox", "box")
lo = add_layout("bgbox")
lo.geometry = osc_geo
lo.layer = 10
lo.style = osc_styles.box
lo.alpha[1] = user_opts.boxalpha
-- Playback control buttons
geo = { x = osc_geo.x + padX, y = line1, an = 4,
w = buttonW, h = 36 - padY*2 }
lo = add_layout("playpause")
lo.geometry = geo
lo.style = osc_styles.smallButtonsBar
geo = { x = geo.x + geo.w + padX, y = geo.y, an = geo.an, w = geo.w, h = geo.h }
lo = add_layout("ch_prev")
lo.geometry = geo
lo.style = osc_styles.smallButtonsBar
geo = { x = geo.x + geo.w + padX, y = geo.y, an = geo.an, w = geo.w, h = geo.h }
lo = add_layout("ch_next")
lo.geometry = geo
lo.style = osc_styles.smallButtonsBar
-- Left timecode
geo = { x = geo.x + geo.w + padX + tcW, y = geo.y, an = 6,
w = tcW, h = geo.h }
lo = add_layout("tc_left")
lo.geometry = geo
lo.style = osc_styles.timecodesBar
local sb_l = geo.x + padX
-- Fullscreen button
geo = { x = osc_geo.x + osc_geo.w - buttonW - padX, y = geo.y, an = 4,
w = buttonW, h = geo.h }
lo = add_layout("tog_fs")
lo.geometry = geo
lo.style = osc_styles.smallButtonsBar
-- Volume
geo = { x = geo.x - geo.w - padX, y = geo.y, an = geo.an, w = geo.w, h = geo.h }
lo = add_layout("volume")
lo.geometry = geo
lo.style = osc_styles.smallButtonsBar
-- Track selection buttons
geo = { x = geo.x - tsW - padX, y = geo.y, an = geo.an, w = tsW, h = geo.h }
lo = add_layout("cy_sub")
lo.geometry = geo
lo.style = osc_styles.smallButtonsBar
geo = { x = geo.x - geo.w - padX, y = geo.y, an = geo.an, w = geo.w, h = geo.h }
lo = add_layout("cy_audio")
lo.geometry = geo
lo.style = osc_styles.smallButtonsBar
-- Right timecode
geo = { x = geo.x - geo.w - padX - tcW - 10, y = geo.y, an = 4,
w = tcW, h = geo.h }
lo = add_layout("tc_right")
lo.geometry = geo
lo.style = osc_styles.timecodesBar
local sb_r = geo.x - padX
-- Seekbar
geo = { x = sb_l, y = user_opts.barmargin, an = 7,
w = math.max(0, sb_r - sb_l), h = geo.h }
new_element("bgbar1", "box")
lo = add_layout("bgbar1")
lo.geometry = geo
lo.layer = 15
lo.style = osc_styles.timecodesBar
lo.alpha[1] =
math.min(255, user_opts.boxalpha + (255 - user_opts.boxalpha)*0.8)
if not (user_opts["seekbarstyle"] == "bar") then
lo.box.radius = geo.h / 2
lo.box.hexagon = user_opts["seekbarstyle"] == "diamond"
end
lo = add_layout("seekbar")
lo.geometry = geo
lo.style = osc_styles.timecodesBar
lo.slider.border = 0
lo.slider.gap = 2
lo.slider.tooltip_style = osc_styles.timePosBar
lo.slider.stype = user_opts["seekbarstyle"]
lo.slider.rtype = user_opts["seekrangestyle"]
lo.slider.tooltip_an = 5
-- Playlist prev/next
geo = { x = osc_geo.x + padX, y = line2, an = 4, w = 18, h = 18 - padY }
lo = add_layout("pl_prev")
lo.geometry = geo
lo.style = osc_styles.topButtonsBar
geo = { x = geo.x + geo.w + padX, y = geo.y, an = geo.an, w = geo.w, h = geo.h }
lo = add_layout("pl_next")
lo.geometry = geo
lo.style = osc_styles.topButtonsBar
local t_l = geo.x + geo.w + padX
-- Cache
geo = { x = osc_geo.x + osc_geo.w - padX, y = geo.y,
an = 6, w = 150, h = geo.h }
lo = add_layout("cache")
lo.geometry = geo
lo.style = osc_styles.vidtitleBar
local t_r = geo.x - geo.w - padX*2
-- Title
geo = { x = t_l, y = geo.y, an = 4,
w = t_r - t_l, h = geo.h }
lo = add_layout("title")
lo.geometry = geo
lo.style = string.format("%s{\\clip(%f,%f,%f,%f)}",
osc_styles.vidtitleBar,
geo.x, geo.y-geo.h, geo.w, geo.y+geo.h)
bar_layout(1)
end
-- Validate string type user options