Skip to content

Commit

Permalink
feat(mpv): base config
Browse files Browse the repository at this point in the history
  • Loading branch information
0x61nas committed Sep 8, 2024
1 parent 0afa9a9 commit 5c306fe
Show file tree
Hide file tree
Showing 38 changed files with 9,326 additions and 0 deletions.
Binary file added home/.config/mpv/fonts/uosc_icons.otf
Binary file not shown.
Binary file added home/.config/mpv/fonts/uosc_textures.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions home/.config/mpv/script-opts/uosc.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
border=no
Binary file added home/.config/mpv/scripts/uosc/bin/ziggy-darwin
Binary file not shown.
Binary file added home/.config/mpv/scripts/uosc/bin/ziggy-linux
Binary file not shown.
Binary file not shown.
405 changes: 405 additions & 0 deletions home/.config/mpv/scripts/uosc/char-conv/zh.json

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions home/.config/mpv/scripts/uosc/elements/BufferingIndicator.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
local Element = require('elements/Element')

---@class BufferingIndicator : Element
local BufferingIndicator = class(Element)

function BufferingIndicator:new() return Class.new(self) --[[@as BufferingIndicator]] end
function BufferingIndicator:init()
Element.init(self, 'buffering_indicator', {ignores_curtain = true, render_order = 2})
self.enabled = false
self:decide_enabled()
end

function BufferingIndicator:decide_enabled()
local cache = state.cache_underrun or state.cache_buffering and state.cache_buffering < 100
local player = state.core_idle and not state.eof_reached
if self.enabled then
if not player or (state.pause and not cache) then self.enabled = false end
elseif player and cache and state.uncached_ranges then
self.enabled = true
end
end

function BufferingIndicator:on_prop_pause() self:decide_enabled() end
function BufferingIndicator:on_prop_core_idle() self:decide_enabled() end
function BufferingIndicator:on_prop_eof_reached() self:decide_enabled() end
function BufferingIndicator:on_prop_uncached_ranges() self:decide_enabled() end
function BufferingIndicator:on_prop_cache_buffering() self:decide_enabled() end
function BufferingIndicator:on_prop_cache_underrun() self:decide_enabled() end

function BufferingIndicator:render()
local ass = assdraw.ass_new()
ass:rect(0, 0, display.width, display.height, {color = bg, opacity = config.opacity.buffering_indicator})
local size = round(30 + math.min(display.width, display.height) / 10)
local opacity = (Elements.menu and Elements.menu:is_alive()) and 0.3 or 0.8
ass:spinner(display.width / 2, display.height / 2, size, {color = fg, opacity = opacity})
return ass
end

return BufferingIndicator
95 changes: 95 additions & 0 deletions home/.config/mpv/scripts/uosc/elements/Button.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
local Element = require('elements/Element')

---@alias ButtonProps {icon: string; on_click: function; anchor_id?: string; active?: boolean; badge?: string|number; foreground?: string; background?: string; tooltip?: string}

---@class Button : Element
local Button = class(Element)

---@param id string
---@param props ButtonProps
function Button:new(id, props) return Class.new(self, id, props) --[[@as Button]] end
---@param id string
---@param props ButtonProps
function Button:init(id, props)
self.icon = props.icon
self.active = props.active
self.tooltip = props.tooltip
self.badge = props.badge
self.foreground = props.foreground or fg
self.background = props.background or bg
---@type fun()
self.on_click = props.on_click
Element.init(self, id, props)
end

function Button:on_coordinates() self.font_size = round((self.by - self.ay) * 0.7) end
function Button:handle_cursor_click()
-- We delay the callback to next tick, otherwise we are risking race
-- conditions as we are in the middle of event dispatching.
-- For example, handler might add a menu to the end of the element stack, and that
-- than picks up this click event we are in right now, and instantly closes itself.
mp.add_timeout(0.01, self.on_click)
end

function Button:render()
local visibility = self:get_visibility()
if visibility <= 0 then return end
cursor:zone('primary_click', self, function() self:handle_cursor_click() end)

local ass = assdraw.ass_new()
local is_hover = self.proximity_raw == 0
local is_hover_or_active = is_hover or self.active
local foreground = self.active and self.background or self.foreground
local background = self.active and self.foreground or self.background

-- Background
if is_hover_or_active or config.opacity.controls > 0 then
ass:rect(self.ax, self.ay, self.bx, self.by, {
color = (self.active or not is_hover) and background or foreground,
radius = state.radius,
opacity = visibility * (self.active and 1 or (is_hover and 0.3 or config.opacity.controls)),
})
end

-- Tooltip on hover
if is_hover and self.tooltip then ass:tooltip(self, self.tooltip) end

-- Badge
local icon_clip
if self.badge then
local badge_font_size = self.font_size * 0.6
local badge_opts = {size = badge_font_size, color = background, opacity = visibility}
local badge_width = text_width(self.badge, badge_opts)
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 = 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)

local clip_border = math.max(self.font_size / 20, 1)
local clip_path = assdraw.ass_new()
clip_path:round_rect_cw(
math.floor((bx - width) - clip_border), math.floor((by - height) - clip_border), bx, by, 3
)
icon_clip = '\\iclip(' .. clip_path.scale .. ', ' .. clip_path.text .. ')'
end

-- 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 * state.scale,
border_color = background,
opacity = visibility,
clip = icon_clip,
})

return ass
end

return Button
Loading

0 comments on commit 5c306fe

Please sign in to comment.