From 7b1c56877eefac2bb682282755c429f770798a68 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 22 Jul 2023 23:07:44 +0200 Subject: [PATCH] Add GetMacroSegmentDescription() and IsValidMacroSegmentIndex() --- src/utils/utility.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++ src/utils/utility.hpp | 3 +++ 2 files changed, 58 insertions(+) diff --git a/src/utils/utility.cpp b/src/utils/utility.cpp index a8827cc1..d6ff1947 100644 --- a/src/utils/utility.cpp +++ b/src/utils/utility.cpp @@ -5,6 +5,9 @@ #include "scene-group.hpp" #include "non-modal-dialog.hpp" #include "obs-module-helper.hpp" +#include "macro.hpp" +#include "macro-action-edit.hpp" +#include "macro-condition-edit.hpp" #include #include @@ -595,6 +598,58 @@ QStringList GetMonitorNames() return monitorNames; } +bool IsValidMacroSegmentIndex(Macro *m, const int idx, bool isCondition) +{ + if (!m || idx < 0) { + return false; + } + if (isCondition) { + if (idx >= m->Conditions().size()) { + return false; + } + } else { + if (idx >= m->Actions().size()) { + return false; + } + } + return true; +} + +QString GetMacroSegmentDescription(Macro *macro, int idx, bool isCondition) +{ + if (!macro) { + return ""; + } + if (!IsValidMacroSegmentIndex(macro, idx, isCondition)) { + return ""; + } + + MacroSegment *segment; + if (isCondition) { + segment = macro->Conditions().at(idx).get(); + } else { + segment = macro->Actions().at(idx).get(); + } + + QString description = QString::fromStdString(segment->GetShortDesc()); + QString type; + if (isCondition) { + type = obs_module_text(MacroConditionFactory::GetConditionName( + segment->GetId()) + .c_str()); + } else { + type = obs_module_text( + MacroActionFactory::GetActionName(segment->GetId()) + .c_str()); + } + + QString result = type; + if (!description.isEmpty()) { + result += ": " + description; + } + return result; +} + QStringList GetSourceNames() { auto sourceEnum = [](void *param, obs_source_t *source) -> bool /* -- */ diff --git a/src/utils/utility.hpp b/src/utils/utility.hpp index 33234402..0c6a44f7 100644 --- a/src/utils/utility.hpp +++ b/src/utils/utility.hpp @@ -17,6 +17,7 @@ namespace advss { class SceneSelection; class RegexConfig; struct SceneGroup; +class Macro; /* Source helpers */ @@ -126,6 +127,8 @@ void ReplaceAll(std::string &str, const std::string &from, QString GetDefaultSettingsSaveLocation(); std::string GetPathInProfileDir(const char *filePath); QStringList GetMonitorNames(); +bool IsValidMacroSegmentIndex(Macro *m, const int idx, bool isCondition); +QString GetMacroSegmentDescription(Macro *, int idx, bool isCondition); /* Legacy helpers */