Move getSceneItemsWithName() to utility

This commit is contained in:
WarmUpTill 2021-06-16 21:14:38 +02:00 committed by WarmUpTill
parent 1bf2a154e2
commit beec7d5939
3 changed files with 35 additions and 26 deletions

View File

@ -25,6 +25,8 @@ std::string getSourceSettings(OBSWeakSource ws);
void setSourceSettings(obs_source_t *s, const std::string &settings);
bool compareSourceSettings(const OBSWeakSource &source,
const std::string &settings, bool regex);
std::vector<obs_scene_item *> getSceneItemsWithName(OBSScene scene,
std::string &name);
std::string getDataFilePath(const std::string &file);
/**

View File

@ -22,37 +22,14 @@ const static std::map<SceneOrderAction, std::string> actionTypes = {
"AdvSceneSwitcher.action.sceneOrder.type.movePosition"},
};
struct MoveInfo {
std::string name;
std::vector<obs_sceneitem_t *> items = {};
};
static bool getSceneItems(obs_scene_t *, obs_sceneitem_t *item, void *ptr)
{
MoveInfo *moveInfo = reinterpret_cast<MoveInfo *>(ptr);
auto sourceName = obs_source_get_name(obs_sceneitem_get_source(item));
if (moveInfo->name == sourceName) {
obs_sceneitem_addref(item);
moveInfo->items.push_back(item);
}
if (obs_sceneitem_is_group(item)) {
obs_scene_t *scene = obs_sceneitem_group_get_scene(item);
obs_scene_enum_items(scene, getSceneItems, ptr);
}
return true;
}
bool MacroActionSceneOrder::PerformAction()
{
auto s = obs_weak_source_get_source(_scene);
auto scene = obs_scene_from_source(s);
auto sourceName = GetWeakSourceName(_source);
MoveInfo moveInfo = {sourceName};
obs_scene_enum_items(scene, getSceneItems, &moveInfo);
auto name = GetWeakSourceName(_source);
auto items = getSceneItemsWithName(scene, name);
for (auto &i : moveInfo.items) {
for (auto &i : items) {
switch (_action) {
case SceneOrderAction::MOVE_UP:
obs_sceneitem_set_order(i, OBS_ORDER_MOVE_UP);

View File

@ -235,6 +235,36 @@ void setSourceSettings(obs_source_t *s, const std::string &settings)
obs_data_release(data);
}
struct ItemInfo {
std::string name;
std::vector<obs_sceneitem_t *> items = {};
};
static bool getSceneItems(obs_scene_t *, obs_sceneitem_t *item, void *ptr)
{
ItemInfo *moveInfo = reinterpret_cast<ItemInfo *>(ptr);
auto sourceName = obs_source_get_name(obs_sceneitem_get_source(item));
if (moveInfo->name == sourceName) {
obs_sceneitem_addref(item);
moveInfo->items.push_back(item);
}
if (obs_sceneitem_is_group(item)) {
obs_scene_t *scene = obs_sceneitem_group_get_scene(item);
obs_scene_enum_items(scene, getSceneItems, ptr);
}
return true;
}
std::vector<obs_scene_item *> getSceneItemsWithName(OBSScene scene,
std::string &name)
{
ItemInfo itemInfo = {name};
obs_scene_enum_items(scene, getSceneItems, &itemInfo);
return itemInfo.items;
}
bool compareSourceSettings(const OBSWeakSource &source,
const std::string &settings, bool useRegex)
{