osd_styler.lua (2108B)
1 --[[ 2 A helper class for styling OSD messages 3 http://docs.aegisub.org/3.2/ASS_Tags/ 4 5 Copyright (C) 2021 Ren Tatsumoto 6 7 This program is free software: you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation, either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <https://www.gnu.org/licenses/>. 19 ]] 20 21 local OSD = {} 22 OSD.__index = OSD 23 24 function OSD:new() 25 return setmetatable({ messages = {} }, self) 26 end 27 28 function OSD:append(s) 29 table.insert(self.messages, tostring(s)) 30 return self 31 end 32 33 function OSD:newline() 34 return self:append([[\N]]) 35 end 36 37 function OSD:tab() 38 return self:append([[\h\h\h\h]]) 39 end 40 41 function OSD:size(size) 42 return self:append('{\\fs'):append(size):append('}') 43 end 44 45 function OSD:align(number) 46 return self:append('{\\an'):append(number):append('}') 47 end 48 49 function OSD:get_text() 50 return table.concat(self.messages) 51 end 52 53 function OSD:color(code) 54 return self:append('{\\1c&H') 55 :append(code:sub(5, 6)) 56 :append(code:sub(3, 4)) 57 :append(code:sub(1, 2)) 58 :append('&}') 59 end 60 61 function OSD:text(text) 62 return self:append(text) 63 end 64 65 function OSD:bold(s) 66 return self:append('{\\b1}'):append(s):append('{\\b0}') 67 end 68 69 function OSD:italics(s) 70 return self:append('{\\i1}'):append(s):append('{\\i0}') 71 end 72 73 function OSD:submenu(text) 74 return self:color('ffe1d0'):bold(text):color('ffffff') 75 end 76 77 function OSD:item(text) 78 return self:color('fef6dd'):bold(text):color('ffffff') 79 end 80 81 function OSD:selected(text) 82 return self:color('48a868'):bold(text):color('ffffff') 83 end 84 85 function OSD:red(text) 86 return self:color('ff0000'):bold(text):color('ffffff') 87 end 88 89 return OSD