From 3351a785be94ec1d489ac07507671f09c88fdf3f Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Fri, 10 Dec 2021 16:56:27 +0000 Subject: [PATCH] src/Viewer/viewmgr.cxx: enable/disable video encoding menu items. It doesn't look like menubar items can be enabled/disabled using or , so instead we write to the File menu's items tree /sim/menubar/default/menu[]/name[]/enabled. We also set /sim/video/encoding-path to '' or path of video file that we are encoding to. --- src/Viewer/viewmgr.cxx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Viewer/viewmgr.cxx b/src/Viewer/viewmgr.cxx index 1f3a4096e..6dffb6f48 100644 --- a/src/Viewer/viewmgr.cxx +++ b/src/Viewer/viewmgr.cxx @@ -175,9 +175,40 @@ static void videoEncodingPopup(const std::string& message, int delay) globals->get_commands()->execute("show-message", args); } +static void vidoEncodingUpdateStatus(const std::string& path) +{ + fgSetString("/sim/video/encoding-path", path); + bool encoding = (path != ""); + SGPropertyNode* node = fgGetNode("/sim/menubar/default"); + + /* Enable/disable menu items 'File/Video encode start' and 'File/Video + encode stop'. */ + for (auto a: node->getChildren("menu")) + { + std::string name = a->getStringValue("name"); + if (name == "file") + { + for (auto b: a->getChildren("item")) + { + std::string name = b->getStringValue("name"); + if (name == "video-start") + { + b->setBoolValue("enabled", !encoding); + } + if (name == "video-stop") + { + b->setBoolValue("enabled", encoding); + } + } + break; + } + } +} + static void videoEncodingError(const std::string& message) { globals->get_props()->setIntValue("/sim/video/error", 1); + vidoEncodingUpdateStatus(""); videoEncodingPopup(message, 15); } @@ -471,6 +502,8 @@ bool FGViewMgr::video_start( videoEncodingError(e.what()); return false; } + + vidoEncodingUpdateStatus(path.str()); return true; } @@ -479,6 +512,7 @@ void FGViewMgr::video_stop() if (_video_encoder) { _video_encoder.reset(); + vidoEncodingUpdateStatus(""); videoEncodingPopup("Video encoding stopped", 5); } else