Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libobs,UI: Replace and deprecate obs_scene_sceneitem_from_source #11251

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions UI/window-basic-source-select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
#include "obs-app.hpp"

struct AddSourceData {
/* Input data */
obs_source_t *source;
bool visible;
obs_transform_info *transform = nullptr;
obs_sceneitem_crop *crop = nullptr;
obs_blending_method *blend_method = nullptr;
obs_blending_type *blend_mode = nullptr;

/* Return data */
obs_sceneitem_t *scene_item = nullptr;
};

bool OBSBasicSourceSelect::EnumSources(void *data, obs_source_t *source)
Expand Down Expand Up @@ -132,6 +136,8 @@ static void AddSource(void *_data, obs_scene_t *scene)
obs_sceneitem_set_blending_mode(sceneitem, *data->blend_mode);

obs_sceneitem_set_visible(sceneitem, data->visible);

data->scene_item = sceneitem;
}

char *get_new_source_name(const char *name, const char *format)
Expand Down Expand Up @@ -201,7 +207,8 @@ static void AddExisting(const char *name, bool visible, bool duplicate,
}

bool AddNew(QWidget *parent, const char *id, const char *name,
const bool visible, OBSSource &newSource)
const bool visible, OBSSource &newSource,
OBSSceneItem &newSceneItem)
{
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSScene scene = main->GetCurrentScene();
Expand All @@ -228,6 +235,7 @@ bool AddNew(QWidget *parent, const char *id, const char *name,
obs_leave_graphics();

newSource = source;
newSceneItem = data.scene_item;

/* set monitoring if source monitors by default */
uint32_t flags = obs_source_get_output_flags(source);
Expand Down Expand Up @@ -304,12 +312,12 @@ void OBSBasicSourceSelect::on_buttonBox_accepted()
return;
}

OBSSceneItem item;
if (!AddNew(this, id, QT_TO_UTF8(ui->sourceName->text()),
visible, newSource))
visible, newSource, item))
return;

OBSBasic *main =
reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
std::string scene_name =
obs_source_get_name(main->GetCurrentSceneSource());
auto undo = [scene_name, main](const std::string &data) {
Expand All @@ -323,8 +331,6 @@ void OBSBasicSourceSelect::on_buttonBox_accepted()
};
OBSDataAutoRelease wrapper = obs_data_create();
obs_data_set_string(wrapper, "id", id);
OBSSceneItemAutoRelease item = obs_scene_sceneitem_from_source(
main->GetCurrentScene(), newSource);
obs_data_set_int(wrapper, "item_id",
obs_sceneitem_get_id(item));
obs_data_set_string(
Expand All @@ -340,12 +346,10 @@ void OBSBasicSourceSelect::on_buttonBox_accepted()
OBSDataAutoRelease dat =
obs_data_create_from_json(data.c_str());
OBSSource source;
OBSSceneItem item;
AddNew(NULL, obs_data_get_string(dat, "id"),
obs_data_get_string(dat, "name"),
obs_data_get_bool(dat, "visible"), source);
OBSSceneItemAutoRelease item =
obs_scene_sceneitem_from_source(
main->GetCurrentScene(), source);
obs_data_get_bool(dat, "visible"), source, item);
Lain-B marked this conversation as resolved.
Show resolved Hide resolved
obs_sceneitem_set_id(item, (int64_t)obs_data_get_int(
dat, "item_id"));
};
Expand Down
5 changes: 5 additions & 0 deletions docs/sphinx/reference-scenes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ Scene Item Functions

:return: The sceneitem associated with a source in a scene. Returns NULL if not found.

.. deprecated:: 31.0
This function is problematic because there can be multiple items of the same source in a scene.
In that case, which of those this function will return is undefined.
If this is the behavior you need, manually use :c:func:`obs_scene_enum_items` instead.

---------------------

.. function:: void obs_sceneitem_set_id(obs_sceneitem_t *item);
Expand Down
4 changes: 2 additions & 2 deletions libobs/obs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1806,8 +1806,8 @@ EXPORT void obs_sceneitem_save(obs_sceneitem_t *item, obs_data_array_t *arr);
EXPORT void obs_sceneitem_set_id(obs_sceneitem_t *sceneitem, int64_t id);

/** Tries to find the sceneitem of the source in a given scene. Returns NULL if not found */
EXPORT obs_sceneitem_t *obs_scene_sceneitem_from_source(obs_scene_t *scene,
obs_source_t *source);
OBS_DEPRECATED EXPORT obs_sceneitem_t *
obs_scene_sceneitem_from_source(obs_scene_t *scene, obs_source_t *source);

/** Save all the transform states for a current scene's sceneitems */
EXPORT obs_data_t *obs_scene_save_transform_states(obs_scene_t *scene,
Expand Down