Skip to content

Commit

Permalink
Merge pull request #29 from po5/thumbfast
Browse files Browse the repository at this point in the history
Add thumbfast integration
  • Loading branch information
cyl0 authored Nov 6, 2022
2 parents dc79a75 + 814d538 commit a65bb7b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ border = no # Optional, but recommended

edit osc.conf in "\~\~/script-opts/" folder, however many options are changed, so refer to the user_opts variable in the script file for details.

# Thumbnails

To enable thumbnails in timeline, install [thumbfast](https://github.com/po5/thumbfast). No other step necessary.

# Buttons

like the built-in script, some buttons may accept multiple mouse actions, here is a list:
Expand Down
85 changes: 77 additions & 8 deletions mordenx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ local state = {
chapter_list = {}, -- sorted by time
}

local thumbfast = {
width = 0,
height = 0,
disabled = true,
available = false
}

local window_control_box_width = 138
local tick_delay = 0.03

Expand Down Expand Up @@ -666,14 +673,16 @@ function render_elements(master_ass)
-- then we use it instead of the normal title. we calculate it before the
-- render iterations because the title may be rendered before the slider.
state.forced_title = nil
local se, ae = state.slider_element, elements[state.active_element]
if user_opts.chapter_fmt ~= "no" and se and (ae == se or (not ae and mouse_hit(se))) then
local dur = mp.get_property_number("duration", 0)
if dur > 0 then
local possec = get_slider_value(se) * dur / 100 -- of mouse pos
local ch = get_chapter(possec)
if ch and ch.title and ch.title ~= "" then
state.forced_title = string.format(user_opts.chapter_fmt, ch.title)
if thumbfast.disabled then
local se, ae = state.slider_element, elements[state.active_element]
if user_opts.chapter_fmt ~= "no" and se and (ae == se or (not ae and mouse_hit(se))) then
local dur = mp.get_property_number("duration", 0)
if dur > 0 then
local possec = get_slider_value(se) * dur / 100 -- of mouse pos
local ch = get_chapter(possec)
if ch and ch.title and ch.title ~= "" then
state.forced_title = string.format(user_opts.chapter_fmt, ch.title)
end
end
end
end
Expand Down Expand Up @@ -784,6 +793,57 @@ function render_elements(master_ass)
elem_ass:append(slider_lo.tooltip_style)
ass_append_alpha(elem_ass, slider_lo.alpha, 0)
elem_ass:append(tooltiplabel)

-- thumbnail
if not thumbfast.disabled then
local osd_w = mp.get_property_number("osd-width")
if osd_w then
local r_w, r_h = get_virt_scale_factor()

local tooltip_font_size = 18
local thumbPad = 4
local thumbMarginX = 18 / r_w
local thumbMarginY = tooltip_font_size + thumbPad + 2 / r_h
local tooltipBgColor = "FFFFFF"
local tooltipBgAlpha = 80
local thumbX = math.min(osd_w - thumbfast.width - thumbMarginX, math.max(thumbMarginX, tx / r_w - thumbfast.width / 2))
local thumbY = (ty - thumbMarginY) / r_h - thumbfast.height

elem_ass:new_event()
elem_ass:pos(thumbX * r_w, ty - thumbMarginY - thumbfast.height * r_h)
elem_ass:append(osc_styles.Tooltip)
elem_ass:draw_start()
elem_ass:rect_cw(-thumbPad * r_h, -thumbPad * r_h, (thumbfast.width + thumbPad) * r_w, (thumbfast.height + thumbPad) * r_h)
elem_ass:draw_stop()

mp.commandv("script-message-to", "thumbfast", "thumb",
mp.get_property_number("duration", 0) * (sliderpos / 100),
thumbX,
thumbY
)

local se, ae = state.slider_element, elements[state.active_element]
if user_opts.chapter_fmt ~= "no" and se and (ae == se or (not ae and mouse_hit(se))) then
local dur = mp.get_property_number("duration", 0)
if dur > 0 then
local possec = get_slider_value(se) * dur / 100 -- of mouse pos
local ch = get_chapter(possec)
if ch and ch.title and ch.title ~= "" then
elem_ass:new_event()
elem_ass:pos((thumbX + thumbfast.width / 2) * r_w, thumbY * r_h - tooltip_font_size)
elem_ass:an(an)
elem_ass:append(slider_lo.tooltip_style)
ass_append_alpha(elem_ass, slider_lo.alpha, 0)
elem_ass:append(string.format(user_opts.chapter_fmt, ch.title))
end
end
end
end
end
else
if thumbfast.available then
mp.commandv("script-message-to", "thumbfast", "clear")
end
end
end

Expand Down Expand Up @@ -2553,5 +2613,14 @@ visibility_mode(user_opts.visibility, true)
mp.register_script_message('osc-visibility', visibility_mode)
mp.add_key_binding(nil, 'visibility', function() visibility_mode('cycle') end)

mp.register_script_message("thumbfast-info", function(json)
local data = utils.parse_json(json)
if type(data) ~= "table" or not data.width or not data.height then
msg.error("thumbfast-info: received json didn't produce a table with thumbnail information")
else
thumbfast = data
end
end)

set_virt_mouse_area(0, 0, 0, 0, 'input')
set_virt_mouse_area(0, 0, 0, 0, 'window-controls')

0 comments on commit a65bb7b

Please sign in to comment.