X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Ftheme.cpp;h=9506294dcea2c11c3d5367a1bed4bd3c7fba45fc;hb=948d715655a84b93d8292e64731ea3c32b45deb7;hp=ec8f43191aefb0f31d3bef4aae0e7c1b588cba81;hpb=efeea7571ab45c6a846208f0554153de549d1711;p=nageru diff --git a/nageru/theme.cpp b/nageru/theme.cpp index ec8f431..9506294 100644 --- a/nageru/theme.cpp +++ b/nageru/theme.cpp @@ -1295,6 +1295,10 @@ int Nageru_set_supports_wb(lua_State *L) Theme::Theme(const string &filename, const vector &search_dirs, ResourcePool *resource_pool, unsigned num_cards) : resource_pool(resource_pool), num_cards(num_cards), signal_to_card_mapping(global_flags.default_stream_mapping) { + // Defaults. + channel_names[0] = "Live"; + channel_names[1] = "Preview"; + L = luaL_newstate(); luaL_openlibs(L); @@ -1412,6 +1416,8 @@ void Theme::register_globals() const vector> num_constants = { { "VIDEO_FORMAT_BGRA", bmusb::PixelFormat_8BitBGRA }, { "VIDEO_FORMAT_YCBCR", bmusb::PixelFormat_8BitYCbCrPlanar }, + { "CHECKABLE", MenuEntry::CHECKABLE }, + { "CHECKED", MenuEntry::CHECKED }, }; const vector> str_constants = { { "THEME_PATH", theme_path }, @@ -1567,6 +1573,12 @@ string Theme::get_channel_name(unsigned channel) { lock_guard lock(m); + // We never ask the legacy channel_name() about live and preview. + // The defaults are set in our constructor. + if (channel == 0 || channel == 1) { + return channel_names[channel]; + } + lua_getglobal(L, "channel_name"); if (lua_isnil(L, -1)) { lua_pop(L, 1); @@ -1802,6 +1814,13 @@ unique_ptr create_theme_menu_entry(lua_State *L, int index) const string text = checkstdstring(L, -1); lua_pop(L, 1); + unsigned flags = 0; + if (lua_objlen(L, -1) > 2) { + lua_rawgeti(L, -1, 3); + flags = luaL_checknumber(L, -1); + lua_pop(L, 1); + } + lua_rawgeti(L, index, 2); if (lua_istable(L, -1)) { vector> submenu = create_recursive_theme_menu(L); @@ -1810,7 +1829,7 @@ unique_ptr create_theme_menu_entry(lua_State *L, int index) } else { luaL_checktype(L, -1, LUA_TFUNCTION); int ref = luaL_ref(L, LUA_REGISTRYINDEX); - entry.reset(new Theme::MenuEntry{ text, L, ref }); + entry.reset(new Theme::MenuEntry{ text, L, ref, flags }); } return entry; } @@ -1859,3 +1878,24 @@ void Theme::theme_menu_entry_clicked(int lua_ref) abort(); } } + +string Theme::format_status_line(const string &disk_space_left_text, double file_length_seconds) +{ + lock_guard lock(m); + lua_getglobal(L, "format_status_line"); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + return disk_space_left_text; + } + + lua_pushstring(L, disk_space_left_text.c_str()); + lua_pushnumber(L, file_length_seconds); + if (lua_pcall(L, 2, 1, 0) != 0) { + fprintf(stderr, "error running function format_status_line(): %s\n", lua_tostring(L, -1)); + abort(); + } + string text = checkstdstring(L, 1); + lua_pop(L, 1); + assert(lua_gettop(L) == 0); + return text; +}