mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Utils: refactor GetSceneItemFromItem and get rid of GetSceneItemFromId
This commit is contained in:
parent
dca385ae87
commit
9723147429
@ -173,20 +173,28 @@ obs_data_t* Utils::GetSceneItemData(obs_sceneitem_t* item) {
|
||||
return data;
|
||||
}
|
||||
|
||||
obs_sceneitem_t* Utils::GetSceneItemFromItem(obs_source_t* source, obs_data_t* item) {
|
||||
OBSSceneItem sceneItem;
|
||||
if (obs_data_has_user_value(item, "id")) {
|
||||
sceneItem = GetSceneItemFromId(source, obs_data_get_int(item, "id"));
|
||||
if (obs_data_has_user_value(item, "name") &&
|
||||
(QString)obs_source_get_name(obs_sceneitem_get_source(sceneItem)) !=
|
||||
(QString)obs_data_get_string(item, "name")) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else if (obs_data_has_user_value(item, "name")) {
|
||||
sceneItem = GetSceneItemFromName(source, obs_data_get_string(item, "name"));
|
||||
}
|
||||
return sceneItem;
|
||||
obs_sceneitem_t* Utils::GetSceneItemFromItem(obs_source_t* scene, obs_data_t* itemInfo) {
|
||||
obs_data_item_t* idInfoItem = obs_data_item_byname(itemInfo, "id"); // TODO fix memory leak
|
||||
int id = obs_data_item_get_int(idInfoItem);
|
||||
|
||||
obs_data_item_t* nameInfoItem = obs_data_item_byname(itemInfo, "name"); // TODO fix memory leak
|
||||
const char* name = obs_data_item_get_string(nameInfoItem);
|
||||
|
||||
if (idInfoItem) {
|
||||
obs_sceneitem_t* sceneItem = obs_scene_find_sceneitem_by_id(obs_scene_from_source(scene), id);
|
||||
obs_source_t* sceneItemSource = obs_sceneitem_get_source(sceneItem);
|
||||
|
||||
QString sceneItemName = obs_source_get_name(sceneItemSource);
|
||||
if (nameInfoItem && (QString(name) != sceneItemName)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sceneItem;
|
||||
} else if (nameInfoItem) {
|
||||
return GetSceneItemFromName(scene, name);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
obs_sceneitem_t* Utils::GetSceneItemFromName(obs_source_t* source, QString name) {
|
||||
@ -236,51 +244,6 @@ obs_sceneitem_t* Utils::GetSceneItemFromName(obs_source_t* source, QString name)
|
||||
return search.result;
|
||||
}
|
||||
|
||||
// TODO refactor this to unify it with GetSceneItemFromName
|
||||
obs_sceneitem_t* Utils::GetSceneItemFromId(obs_source_t* source, size_t id) {
|
||||
struct current_search {
|
||||
size_t query;
|
||||
obs_sceneitem_t* result;
|
||||
bool (*enumCallback)(obs_scene_t*, obs_sceneitem_t*, void*);
|
||||
};
|
||||
|
||||
current_search search;
|
||||
search.query = id;
|
||||
search.result = nullptr;
|
||||
search.enumCallback = nullptr;
|
||||
|
||||
OBSScene scene = obs_scene_from_source(source);
|
||||
if (!scene)
|
||||
return nullptr;
|
||||
|
||||
search.enumCallback = [](
|
||||
obs_scene_t* scene,
|
||||
obs_sceneitem_t* currentItem,
|
||||
void* param)
|
||||
{
|
||||
current_search* search = reinterpret_cast<current_search*>(param);
|
||||
|
||||
if (obs_sceneitem_is_group(currentItem)) {
|
||||
obs_sceneitem_group_enum_items(currentItem, search->enumCallback, param);
|
||||
if (search->result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (obs_sceneitem_get_id(currentItem) == search->query) {
|
||||
search->result = currentItem;
|
||||
obs_sceneitem_addref(search->result);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
obs_scene_enum_items(scene, search.enumCallback, &search);
|
||||
|
||||
return search.result;
|
||||
}
|
||||
|
||||
bool Utils::IsValidAlignment(const uint32_t alignment) {
|
||||
switch (alignment) {
|
||||
case OBS_ALIGN_CENTER:
|
||||
|
@ -38,8 +38,7 @@ class Utils {
|
||||
static obs_data_t* GetSceneItemData(obs_sceneitem_t* item);
|
||||
static obs_sceneitem_t* GetSceneItemFromName(
|
||||
obs_source_t* source, QString name);
|
||||
static obs_sceneitem_t* GetSceneItemFromId(obs_source_t* source, size_t id);
|
||||
static obs_sceneitem_t* GetSceneItemFromItem(obs_source_t* source, obs_data_t* item);
|
||||
static obs_sceneitem_t* GetSceneItemFromItem(obs_source_t* scene, obs_data_t* item);
|
||||
static obs_source_t* GetTransitionFromName(QString transitionName);
|
||||
static obs_source_t* GetSceneFromNameOrCurrent(QString sceneName);
|
||||
static obs_data_t* GetSceneItemPropertiesData(obs_sceneitem_t* item);
|
||||
|
Loading…
x
Reference in New Issue
Block a user