diff --git a/osd_styler.lua b/osd_styler.lua new file mode 100644 index 0000000..be8cb37 --- /dev/null +++ b/osd_styler.lua @@ -0,0 +1,61 @@ +--[[ +A helper class for styling OSD messages +http://docs.aegisub.org/3.2/ASS_Tags/ + +Copyright (C) 2021 Ren Tatsumoto + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +]] + +local OSD = {} +OSD.__index = OSD + +function OSD:new() + return setmetatable({ text = {} }, self) +end + +function OSD:append(s) + table.insert(self.text, s) + return self +end + +function OSD:bold(s) + return self:append(string.format([[{\b1}%s{\b0}]], s)) +end + +function OSD:italics(s) + return self:append('{\\i1}'):append(s):append('{\\i0}') +end + +function OSD:newline() + return self:append([[\N]]) +end + +function OSD:tab() + return self:append([[\h\h\h\h]]) +end + +function OSD:size(size) + return self:append(string.format([[{\fs%s}]], size)) +end + +function OSD:align(number) + return self:append(string.format([[{\an%s}]], number)) +end + +function OSD:get_text() + return table.concat(self.text) +end + +return OSD diff --git a/videoclip.lua b/videoclip.lua index 51f6955..45afa3a 100644 --- a/videoclip.lua +++ b/videoclip.lua @@ -1,6 +1,7 @@ local mp = require('mp') local mpopt = require('mp.options') local utils = require('mp.utils') +local OSD = require('osd_styler') -- Options can be changed here or in a separate config file. -- Config path: ~/.config/mpv/script-opts/videoclip.conf @@ -30,7 +31,6 @@ mpopt.read_options(config, 'videoclip') local main_menu local pref_menu local encoder -local OSD local Timings local allowed_presets = { @@ -469,50 +469,6 @@ function pref_menu:update() self:overlay_draw(osd:get_text()) end ------------------------------------------------------------- --- Helper class for styling OSD messages --- http://docs.aegisub.org/3.2/ASS_Tags/ - -OSD = {} -OSD.__index = OSD - -function OSD:new() - return setmetatable({ text = {} }, self) -end - -function OSD:append(s) - table.insert(self.text, s) - return self -end - -function OSD:bold(s) - return self:append(string.format([[{\b1}%s{\b0}]], s)) -end - -function OSD:italics(s) - return self:append('{\\i1}'):append(s):append('{\\i0}') -end - -function OSD:newline() - return self:append([[\N]]) -end - -function OSD:tab() - return self:append([[\h\h\h\h]]) -end - -function OSD:size(size) - return self:append(string.format([[{\fs%s}]], size)) -end - -function OSD:align(number) - return self:append(string.format([[{\an%s}]], number)) -end - -function OSD:get_text() - return table.concat(self.text) -end - ------------------------------------------------------------ -- Timings class