Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: reworked config options for fullscreen scale adjustments #664

Merged
merged 13 commits into from
Oct 6, 2023
10 changes: 3 additions & 7 deletions script-opts/uosc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ timeline_style=line
timeline_line_width=2
# Timeline size when fully expanded, in pixels, 0 to disable
timeline_size=40
timeline_size_fullscreen=60
# Comma separated states when element should always be fully visible.
# Available: paused, audio, image, video, idle, windowed, fullscreen
timeline_persistency=paused
Expand Down Expand Up @@ -86,15 +85,13 @@ progress_line_width=20
# toggle:{icon}:{prop} = cycle:{icon}:{prop}:no/yes!
controls=menu,gap,subtitles,<has_many_audio>audio,<has_many_video>video,<has_many_edition>editions,<stream>stream-quality,gap,space,speed,space,shuffle,loop-playlist,loop-file,gap,prev,items,next,gap,fullscreen
controls_size=32
controls_size_fullscreen=40
controls_margin=8
controls_spacing=2
controls_persistency=

# Where to display volume controls: none, left, right
volume=right
volume_size=40
volume_size_fullscreen=52
volume_opacity=0.9
volume_border=1
volume_step=1
Expand All @@ -108,9 +105,7 @@ speed_persistency=

# Controls all menus, such as context menu, subtitle loader/selector, etc
menu_item_height=36
menu_item_height_fullscreen=50
menu_min_width=260
menu_min_width_fullscreen=360
menu_opacity=1
menu_parent_opacity=0.4
# Determines if `/` or `ctrl+f` is required to activate the search, or if typing
Expand All @@ -122,7 +117,6 @@ menu_type_to_search=yes
# Can be: never, no-border, always
top_bar=no-border
top_bar_size=40
top_bar_size_fullscreen=46
top_bar_controls=yes
# Can be: `no` (hide), `yes` (inherit title from mpv.conf), or a custom template string
top_bar_title=yes
Expand Down Expand Up @@ -155,7 +149,9 @@ autoload_types=video,audio,image
shuffle=no

# Scale the interface by this factor
ui_scale=1
scale=1
# Scale in fullscreen
scale_fullscreen=1.3
# Adjust the text scaling to fit your font
font_scale=1
# Border of text and icons when drawn directly on top of video
Expand Down
6 changes: 3 additions & 3 deletions scripts/uosc/elements/Button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Button:render()
-- Background
if is_hover_or_active then
ass:rect(self.ax, self.ay, self.bx, self.by, {
color = self.active and background or foreground, radius = 2,
color = self.active and background or foreground, radius = state.radius,
opacity = visibility * (self.active and 1 or 0.3),
})
end
Expand All @@ -64,7 +64,7 @@ function Button:render()
local width, height = math.ceil(badge_width + (badge_font_size / 7) * 2), math.ceil(badge_font_size * 0.93)
local bx, by = self.bx - 1, self.by - 1
ass:rect(bx - width, by - height, bx, by, {
color = foreground, radius = 2, opacity = visibility,
color = foreground, radius = state.radius, opacity = visibility,
border = self.active and 0 or 1, border_color = background,
})
ass:txt(bx - width / 2, by - height / 2, 5, self.badge, badge_opts)
Expand All @@ -80,7 +80,7 @@ function Button:render()
-- Icon
local x, y = round(self.ax + (self.bx - self.ax) / 2), round(self.ay + (self.by - self.ay) / 2)
ass:icon(x, y, self.font_size, self.icon, {
color = foreground, border = self.active and 0 or options.text_border, border_color = background,
color = foreground, border = self.active and 0 or options.text_border * state.scale, border_color = background,
opacity = visibility, clip = icon_clip,
})

Expand Down
6 changes: 3 additions & 3 deletions scripts/uosc/elements/Controls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ end

function Controls:update_dimensions()
local window_border = Elements.window_border.size
local size = state.fullormaxed and options.controls_size_fullscreen or options.controls_size
local spacing = options.controls_spacing
local margin = options.controls_margin
local size = round(options.controls_size * state.scale)
local spacing = round(options.controls_spacing * state.scale)
local margin = round(options.controls_margin * state.scale)

-- Disable when not enough space
local available_space = display.height - Elements.window_border.size * 2
Expand Down
39 changes: 24 additions & 15 deletions scripts/uosc/elements/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ function Menu:init(data, callback, opts)
---@type Modifiers|nil
self.modifiers = nil
self.item_height = nil
self.min_width = nil
self.item_spacing = 1
self.item_padding = nil
self.separator_size = nil
self.padding = nil
self.gap = nil
self.font_size = nil
self.font_size_hint = nil
self.scroll_step = nil -- Item height + item spacing.
Expand Down Expand Up @@ -258,7 +262,11 @@ function Menu:update_items(items)
end

function Menu:update_content_dimensions()
self.item_height = state.fullormaxed and options.menu_item_height_fullscreen or options.menu_item_height
self.item_height = round(options.menu_item_height * state.scale)
self.min_width = round(options.menu_min_width * state.scale)
self.separator_size = round(1 * state.scale)
self.padding = round(2 * state.scale)
self.gap = round(2 * state.scale)
self.font_size = round(self.item_height * 0.48 * options.font_scale)
self.font_size_hint = self.font_size - 1
self.item_padding = round((self.item_height - self.font_size) * 0.6)
Expand Down Expand Up @@ -296,10 +304,7 @@ function Menu:update_dimensions()
-- and dumb titles with no search inputs. It could use a refactor.
local margin = round(self.item_height / 2)
local width_available, height_available = display.width - margin * 2, display.height - margin * 2
local min_width = math.min(
state.fullormaxed and options.menu_min_width_fullscreen or options.menu_min_width,
width_available
)
local min_width = math.min(self.min_width, width_available)

for _, menu in ipairs(self.all) do
local width = math.max(menu.search and menu.search.max_width or 0, menu.max_width)
Expand Down Expand Up @@ -1001,7 +1006,6 @@ function Menu:render()
local opacity = options.menu_opacity * self.opacity
local spacing = self.item_padding
local icon_size = self.font_size
local menu_gap, menu_padding = 2, 2

---@param menu MenuStack
---@param x number
Expand All @@ -1016,11 +1020,16 @@ function Menu:render()
local end_index = math.ceil((menu.scroll_y + menu.height) / self.scroll_step)
-- Remove menu_opacity to start off with full, but still decay for parent menus
local text_opacity = menu_opacity / options.menu_opacity
local menu_rect = {ax = ax, ay = ay - (draw_title and self.scroll_step or 0) - 2, bx = bx, by = by + 2}
local menu_rect = {
ax = ax, ay = ay - (draw_title and self.scroll_step or 0) - self.padding,
bx = bx, by = by + self.padding
}
local blur_selected_index = is_current and self.mouse_nav

-- Background
ass:rect(menu_rect.ax, menu_rect.ay, menu_rect.bx, menu_rect.by, {color = bg, opacity = menu_opacity, radius = 4})
ass:rect(menu_rect.ax, menu_rect.ay, menu_rect.bx, menu_rect.by, {
color = bg, opacity = menu_opacity, radius = state.radius + self.padding
})

if is_parent and get_point_to_rectangle_proximity(cursor, menu_rect) == 0 then
cursor.on_primary_down = self:create_action(function() self:slide_in_menu(menu, x) end)
Expand All @@ -1030,7 +1039,7 @@ function Menu:render()
local submenu_rect, current_item = nil, is_current and menu.selected_index and menu.items[menu.selected_index]
local submenu_is_hovered = false
if current_item and current_item.items then
submenu_rect = draw_menu(current_item, menu_rect.bx + menu_gap, 1)
submenu_rect = draw_menu(current_item, menu_rect.bx + self.gap, 1)
submenu_is_hovered = get_point_to_rectangle_proximity(cursor, submenu_rect) == 0
if submenu_is_hovered then
cursor.on_primary_down = self:create_action(function()
Expand All @@ -1057,9 +1066,9 @@ function Menu:render()
blur_selected_index = false
else
local item_rect_hitbox = {
ax = menu_rect.ax + menu_padding,
ax = menu_rect.ax + self.padding,
ay = item_ay,
bx = menu_rect.bx + (item.items and menu_gap or -menu_padding), -- to bridge the gap with cursor
bx = menu_rect.bx + (item.items and self.gap or -self.padding), -- to bridge the gap with cursor
by = item_by
}
if submenu_is_hovered or get_point_to_rectangle_proximity(cursor, item_rect_hitbox) == 0 then
Expand Down Expand Up @@ -1089,8 +1098,8 @@ function Menu:render()
-- Highlight
local highlight_opacity = 0 + (item.active and 0.8 or 0) + (menu.selected_index == index and 0.15 or 0)
if not is_submenu and highlight_opacity > 0 then
ass:rect(ax + menu_padding, item_ay, bx - menu_padding, item_by, {
radius = 2, color = fg, opacity = highlight_opacity * text_opacity,
ass:rect(ax + self.padding, item_ay, bx - self.padding, item_by, {
radius = state.radius, color = fg, opacity = highlight_opacity * text_opacity,
clip = item_clip,
})
end
Expand Down Expand Up @@ -1159,7 +1168,7 @@ function Menu:render()
end

-- Bottom border
ass:rect(ax, rect.by - 1, bx, rect.by, {color = fg, opacity = menu_opacity * 0.2})
ass:rect(ax, rect.by - self.separator_size, bx, rect.by, {color = fg, opacity = menu_opacity * 0.2})

-- Title
if menu.search then
Expand Down Expand Up @@ -1240,7 +1249,7 @@ function Menu:render()
local parent_offset_x, parent_horizontal_index = self.ax, -1

while parent_menu do
parent_offset_x = parent_offset_x - parent_menu.width - menu_gap
parent_offset_x = parent_offset_x - parent_menu.width - self.gap
draw_menu(parent_menu, parent_offset_x, parent_horizontal_index)
parent_horizontal_index = parent_horizontal_index - 1
parent_menu = parent_menu.parent_menu
Expand Down
7 changes: 5 additions & 2 deletions scripts/uosc/elements/Speed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ function Speed:render()
local ass = assdraw.ass_new()

-- Background
ass:rect(self.ax, self.ay, self.bx, self.by, {color = bg, radius = 2, opacity = opacity * options.speed_opacity})
ass:rect(self.ax, self.ay, self.bx, self.by, {
color = bg, radius = state.radius, opacity = opacity * options.speed_opacity
})

-- Coordinates
local ax, ay = self.ax, self.ay
Expand Down Expand Up @@ -184,7 +186,8 @@ function Speed:render()
-- Speed value
local speed_text = (round(state.speed * 100) / 100) .. 'x'
ass:txt(half_x, ay + (notch_ay_big - ay) / 2, 5, speed_text, {
size = self.font_size, color = bgt, border = options.text_border, border_color = bg, opacity = opacity,
size = self.font_size, color = bgt, border = options.text_border * state.scale, border_color = bg,
opacity = opacity,
})

return ass
Expand Down
53 changes: 27 additions & 26 deletions scripts/uosc/elements/Timeline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ function Timeline:init()
self.size = 0
self.progress_size = 0
self.font_size = 0
self.top_border = options.timeline_border
self.top_border = 0
self.line_width = 0
self.progress_line_width = 0
self.is_hovered = false
self.has_thumbnail = false

Expand All @@ -38,14 +40,13 @@ function Timeline:get_effective_size()
return self.progress_size + math.ceil((self.size - self.progress_size) * self:get_visibility())
end

function Timeline:get_effective_line_width()
return state.fullormaxed and options.timeline_line_width_fullscreen or options.timeline_line_width
end

function Timeline:get_is_hovered() return self.enabled and self.is_hovered end

function Timeline:update_dimensions()
self.size = state.fullormaxed and options.timeline_size_fullscreen or options.timeline_size
self.size = round(options.timeline_size * state.scale)
self.top_border = round(options.timeline_border * state.scale)
self.line_width = round(options.timeline_line_width * state.scale)
self.progress_line_width = round(options.progress_line_width * state.scale)
self.font_size = math.floor(math.min((self.size + 60) * 0.2, self.size * 0.96) * options.font_scale)
self.ax = Elements.window_border.size
self.ay = display.height - Elements.window_border.size - self.size - self.top_border
Expand Down Expand Up @@ -76,7 +77,7 @@ function Timeline:toggle_progress()
end

function Timeline:get_time_at_x(x)
local line_width = (options.timeline_style == 'line' and options.timeline_line_width - 1 or 0)
local line_width = (options.timeline_style == 'line' and self.line_width - 1 or 0)
local time_width = self.width - line_width - 1
local fax = (time_width) * state.time / state.duration
local fbx = fax + line_width
Expand Down Expand Up @@ -115,10 +116,7 @@ function Timeline:on_prop_fullormaxed()
self:update_dimensions()
end
function Timeline:on_display() self:update_dimensions() end
function Timeline:on_options()
self.top_border = options.timeline_border
self:update_dimensions()
end
function Timeline:on_options() self:update_dimensions() end
function Timeline:handle_cursor_up()
if self.pressed then
mp.set_property_native('pause', self.pressed.pause)
Expand Down Expand Up @@ -171,8 +169,8 @@ function Timeline:render()
local hide_text_ramp = hide_text_below / 2
local text_opacity = clamp(0, size - hide_text_below, hide_text_ramp) / hide_text_ramp

local tooltip_gap = 2
local tooltip_margin = 10
local tooltip_gap = round(2 * state.scale)
local tooltip_margin = round(10 * state.scale)
local timestamp_gap = tooltip_gap

local spacing = math.max(math.floor((self.size - self.font_size) / 2.5), 4)
Expand All @@ -188,9 +186,8 @@ function Timeline:render()

if is_line then
local minimized_fraction = 1 - math.min((size - self.progress_size) / ((self.size - self.progress_size) / 8), 1)
local line_width_normal = self:get_effective_line_width()
local progress_delta = self.progress_size > 0 and options.progress_line_width - line_width_normal or 0
line_width = line_width_normal + (progress_delta * minimized_fraction)
local progress_delta = self.progress_size > 0 and self.progress_line_width - self.line_width or 0
line_width = self.line_width + (progress_delta * minimized_fraction)
fax = bax + (self.width - line_width) * progress
fbx = fax + line_width
line_width = line_width - 1
Expand Down Expand Up @@ -353,7 +350,9 @@ function Timeline:render()
if buffered_playtime and options.buffered_time_threshold > 0
and buffered_playtime < options.buffered_time_threshold then
local x, align = fbx + 5, 4
local cache_opts = {size = self.font_size * 0.8, opacity = text_opacity * 0.6, border = 1}
local cache_opts = {
size = self.font_size * 0.8, opacity = text_opacity * 0.6, border = options.text_border * state.scale
}
local human = round(math.max(buffered_playtime, 0)) .. 's'
local width = text_width(human, cache_opts)
local time_width = timestamp_width(state.time_human, time_opts)
Expand Down Expand Up @@ -400,19 +399,21 @@ function Timeline:render()
and thumbnail.width ~= 0
and thumbnail.height ~= 0
then
local scale_x, scale_y = display.scale_x, display.scale_y
local border = math.ceil(2 * scale_x)
local margin_x, margin_y = round(tooltip_margin * scale_x), round(tooltip_gap * scale_y)
local border = math.ceil(math.max(2, state.radius / 2) * state.scale)
local margin_x, margin_y = tooltip_margin, tooltip_gap
local thumb_x_margin, thumb_y_margin = border + margin_x + bax, border + margin_y
local thumb_width, thumb_height = thumbnail.width, thumbnail.height
local thumb_x = round(clamp(
thumb_x_margin, cursor_x * scale_x - thumb_width / 2,
display.width * scale_x - thumb_width - thumb_x_margin
thumb_x_margin,
cursor_x - thumb_width / 2,
display.width - thumb_width - thumb_x_margin
))
local thumb_y = round(tooltip_anchor.ay * scale_y - thumb_y_margin - thumb_height)
local ax, ay = (thumb_x - border) / scale_x, (thumb_y - border) / scale_y
local bx, by = (thumb_x + thumb_width + border) / scale_x, (thumb_y + thumb_height + border) / scale_y
ass:rect(ax, ay, bx, by, {color = bg, border = 1, border_color = fg, border_opacity = 0.08, radius = 2})
local thumb_y = round(tooltip_anchor.ay - thumb_y_margin - thumb_height)
local ax, ay = (thumb_x - border), (thumb_y - border)
local bx, by = (thumb_x + thumb_width + border), (thumb_y + thumb_height + border)
ass:rect(ax, ay, bx, by, {
color = bg, border = 1, border_color = fg, border_opacity = 0.08, radius = state.radius
})
mp.commandv('script-message-to', 'thumbfast', 'thumb', hovered_seconds, thumb_x, thumb_y)
self.has_thumbnail, rendered_thumbnail = true, true
tooltip_anchor.ay = ay
Expand Down
Loading