summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorMiroslav Koskar <mk@mkoskar.com>2016-10-24 19:50:58 +0200
committerRicardo Constantino <wiiaboo@gmail.com>2016-10-25 14:09:48 +0100
commit6953a1ca2f5650025599a6ec9d57214c58d9c9c4 (patch)
tree35d37ba95600355e0e0acb125fcd45a2916e7b10 /player
parentc8e3ee494cc5ca73f54d5ae24bbf03fc3e42d15d (diff)
downloadmpv-6953a1ca2f5650025599a6ec9d57214c58d9c9c4.tar.bz2
mpv-6953a1ca2f5650025599a6ec9d57214c58d9c9c4.tar.xz
osc: Fix and simplify limited_list
* Fixes: when on the end of playlist only half of entries are displayed. * Simplifies the logic of limited_list so it's easy to follow. * limited_list's pos parameter is now 1 based which seem more natural. * Few changes to comply with code style thorough the file. * Small format change: "Playlist: (%d/%d):" -> "Playlist [%d/%d]:" "Chapters: (%d/%d):" -> "Chapters [%d/%d]:"
Diffstat (limited to 'player')
-rw-r--r--player/lua/osc.lua53
1 files changed, 25 insertions, 28 deletions
diff --git a/player/lua/osc.lua b/player/lua/osc.lua
index 7c88c9ca4c..31e7a3a8cd 100644
--- a/player/lua/osc.lua
+++ b/player/lua/osc.lua
@@ -651,47 +651,44 @@ end
-- Message display
--
+-- pos is 1 based
function limited_list(prop, pos)
- local fs = tonumber(mp.get_property('options/osd-font-size'))
- local max_items = math.ceil(720 / fs)
-
local proplist = mp.get_property_native(prop, {})
local count = #proplist
- if (count == 0) then
+ if count == 0 then
return count, proplist
end
- local min, max = 0, count
- local temp = {}
- if (count > max_items - 1) then
- local extra = math.ceil(max_items / 2) - 1
- min = pos - extra
- max = pos + extra
- if (pos < extra) then
- max = max + math.abs(min)
- min = 0
- end
+
+ local fs = tonumber(mp.get_property('options/osd-font-size'))
+ local max = math.ceil(720 / fs)
+ if max % 2 == 0 then
+ max = max - 1
end
+ local delta = math.ceil(max / 2) - 1
+ local begi = math.max(math.min(pos - delta, count - max + 1), 1)
+ local endi = math.min(begi + max - 1, count)
- for i=min+1, math.min(max, count) do
+ local reslist = {}
+ for i=begi, endi do
local item = proplist[i]
- item.current = (i-1 == pos) and true or nil
- table.insert(temp, item)
+ item.current = (i == pos) and true or nil
+ table.insert(reslist, item)
end
- return count, temp
+ return count, reslist
end
function get_playlist()
- local pos = mp.get_property_number('playlist-pos')
+ local pos = mp.get_property_number('playlist-pos') + 1
local count, limlist = limited_list('playlist', pos)
- if (count == 0) then
- return "Empty playlist."
+ if count == 0 then
+ return 'Empty playlist.'
end
- local message = string.format('Playlist: (%d/%d):\n', pos + 1, count)
+ local message = string.format('Playlist [%d/%d]:\n', pos, count)
for i, v in ipairs(limlist) do
local title = v.title
local _, filename = utils.split_path(v.filename)
- if (title == nil) then
+ if title == nil then
title = filename
end
message = string.format('%s %s %s\n', message,
@@ -701,17 +698,17 @@ function get_playlist()
end
function get_chapterlist()
- local pos = mp.get_property_number('chapter')
+ local pos = mp.get_property_number('chapter') + 1
local count, limlist = limited_list('chapter-list', pos)
- if (count == 0) then
- return "No chapters."
+ if count == 0 then
+ return 'No chapters.'
end
- local message = string.format('Chapters: (%d/%d):\n', pos + 1, count)
+ local message = string.format('Chapters [%d/%d]:\n', pos + 1, count)
for i, v in ipairs(limlist) do
local time = mp.format_time(v.time)
local title = v.title
- if (title == nil) then
+ if title == nil then
title = string.format('Chapter %02d', i + 1)
end
message = string.format('%s[%s] %s %s\n', message, time,