Skip to content

Commit fb64f9b

Browse files
committed
Add thumbnail offset + background padding
Allows user to make the thumbnail look a bit nicer.
1 parent 8254930 commit fb64f9b

File tree

2 files changed

+83
-25
lines changed

2 files changed

+83
-25
lines changed

src/options.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@ local thumbnailer_options = {
3838
-- Disable the built-in keybind ("T") to add your own
3939
disable_keybinds = false,
4040

41+
-- Move the thumbnail up or down
42+
-- For example:
43+
-- topbar/bottombar: 24
44+
-- rest: 0
45+
vertical_offset = 24,
46+
47+
-- Adjust background padding
48+
-- Examples:
49+
-- topbar: 0, 10, 10, 10
50+
-- bottombar: 10, 0, 10, 10
51+
-- slimbox/box: 10, 10, 10, 10
52+
pad_top = 10,
53+
pad_bot = 0,
54+
pad_left = 10,
55+
pad_right = 10,
56+
57+
-- If true, pad values are screen-pixels. If false, video-pixels.
58+
pad_in_screenspace = true,
59+
-- Calculate pad into the offset
60+
offset_by_pad = true,
61+
62+
-- Background color in BBGGRR
63+
background_color = "000000",
64+
-- Alpha: 0 - fully opaque, 255 - transparent
65+
background_alpha = 80,
66+
4167
-- The maximum dimensions of the thumbnails (pixels)
4268
thumbnail_width = 200,
4369
thumbnail_height = 200,

src/patched_osc.lua

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,37 +123,69 @@ function display_thumbnail(pos, value, ass)
123123
local thumbs_total = Thumbnailer.state.thumbnail_count
124124
local perc = math.floor((thumbs_ready / thumbs_total) * 100)
125125

126-
if thumbs_ready ~= thumbs_total then
127-
local ass_w = thumb_size.w * msx
128-
local ass_h = thumb_size.h * msy
129-
local y_offset = get_thumbnail_y_offset(thumb_size, 1)
126+
local display_progress = thumbs_ready ~= thumbs_total
127+
128+
local vertical_offset = thumbnailer_options.vertical_offset
129+
local padding = thumbnailer_options.background_padding
130+
131+
local pad = {
132+
l = thumbnailer_options.pad_left, r = thumbnailer_options.pad_right,
133+
t = thumbnailer_options.pad_top, b = thumbnailer_options.pad_bot
134+
}
135+
if thumbnailer_options.pad_in_screenspace then
136+
pad.l = pad.l * msx
137+
pad.r = pad.r * msx
138+
pad.t = pad.t * msy
139+
pad.b = pad.b * msy
140+
end
141+
142+
if thumbnailer_options.offset_by_pad then
143+
vertical_offset = vertical_offset + (user_opts.layout == "topbar" and pad.t or pad.b)
144+
end
145+
146+
local ass_w = thumb_size.w * msx
147+
local ass_h = thumb_size.h * msy
148+
local y_offset = get_thumbnail_y_offset(thumb_size, 1)
130149

131-
local bg_h = ass_h + 30 * msy
132-
local bg_left = pos.x - ass_w/2
133-
local framegraph_h = 10 * msy
150+
local text_h = 30 * msy
151+
local bg_h = ass_h + (display_progress and text_h or 0)
152+
local bg_left = pos.x - ass_w/2
153+
local framegraph_h = 10 * msy
134154

135-
local bg_top = nil
136-
local text_top = nil
137-
local framegraph_top = nil
155+
local bg_top = nil
156+
local text_top = nil
157+
local framegraph_top = nil
158+
159+
if user_opts.layout == "topbar" then
160+
bg_top = pos.y - ( y_offset + thumb_size.h ) + vertical_offset
161+
text_top = bg_top + ass_h + framegraph_h
162+
framegraph_top = bg_top + ass_h
163+
vertical_offset = -vertical_offset
164+
else
165+
bg_top = pos.y - y_offset - bg_h - vertical_offset
166+
text_top = bg_top
167+
framegraph_top = bg_top + 20 * msy
168+
end
138169

170+
if display_progress then
139171
if user_opts.layout == "topbar" then
140-
bg_top = pos.y - ( y_offset + thumb_size.h )
141-
text_top = bg_top + ass_h + framegraph_h
142-
framegraph_top = bg_top + ass_h
172+
pad.b = math.max(0, pad.b - 30)
143173
else
144-
bg_top = pos.y - y_offset - bg_h
145-
text_top = bg_top
146-
framegraph_top = bg_top + 20 * msy
174+
pad.t = math.max(0, pad.t - 30)
147175
end
176+
end
148177

149-
-- Draw background
150-
ass:new_event()
151-
ass:pos(bg_left, bg_top)
152-
ass:append(("{\\bord0\\1c&H000000&\\1a&H%X&"):format(80))
153-
ass:draw_start()
154-
-- ass:round_rect_cw(0, 0, ass_w, bg_h, 5)
155-
ass:rect_cw(0, 0, ass_w, bg_h)
156-
ass:draw_stop()
178+
179+
180+
-- Draw background
181+
ass:new_event()
182+
ass:pos(bg_left, bg_top)
183+
ass:append(("{\\bord0\\1c&H%s&\\1a&H%X&}"):format(thumbnailer_options.background_color, thumbnailer_options.background_alpha))
184+
ass:draw_start()
185+
ass:rect_cw(-pad.l, -pad.t, ass_w+pad.r, bg_h+pad.b)
186+
ass:draw_stop()
187+
188+
if display_progress then
157189

158190
ass:new_event()
159191
ass:pos(pos.x, text_top)
@@ -204,7 +236,7 @@ function display_thumbnail(pos, value, ass)
204236
local overlay_y_offset = get_thumbnail_y_offset(thumb_size, msy)
205237

206238
local thumb_x = math.floor(pos.x / msx - thumb_size.w/2)
207-
local thumb_y = math.floor(pos.y / msy - thumb_size.h - overlay_y_offset)
239+
local thumb_y = math.floor(pos.y / msy - thumb_size.h - overlay_y_offset - vertical_offset/msy)
208240

209241
osc_thumb_state.visible = true
210242
if not (osc_thumb_state.last_path == thumb_path and osc_thumb_state.last_x == thumb_x and osc_thumb_state.last_y == thumb_y) then

0 commit comments

Comments
 (0)