Skip to content

Commit

Permalink
Move GetSceneItemCount() to utility
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmUpTill committed Sep 16, 2023
1 parent fc1460e commit 569f794
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
31 changes: 3 additions & 28 deletions src/utils/scene-item-selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,6 @@ static bool getSceneItemAtIdx(obs_scene_t *, obs_sceneitem_t *item, void *ptr)
return true;
}

static bool getTotalSceneItemCountHelper(obs_scene_t *, obs_sceneitem_t *item,
void *ptr)
{
auto count = reinterpret_cast<int *>(ptr);

if (obs_sceneitem_is_group(item)) {
obs_scene_t *scene = obs_sceneitem_group_get_scene(item);
obs_scene_enum_items(scene, getTotalSceneItemCountHelper, ptr);
}
*count = *count + 1;
return true;
}

static int getTotalSceneItemCountOnScene(const OBSWeakSource &sceneWeakSource)
{
auto s = obs_weak_source_get_source(sceneWeakSource);
auto scene = obs_scene_from_source(s);
int count = 0;
obs_scene_enum_items(scene, getTotalSceneItemCountHelper, &count);
obs_source_release(s);
return count;
}

struct GroupData {
std::string type;
std::vector<OBSSceneItem> items = {};
Expand Down Expand Up @@ -408,7 +385,7 @@ std::vector<OBSSceneItem> SceneItemSelection::GetSceneItemsByIdx(
}

auto sceneWeakSource = sceneSelection.GetScene(false);
int count = getTotalSceneItemCountOnScene(sceneWeakSource);
int count = GetSceneItemCount(sceneWeakSource);
if (count == 0) {
return {};
}
Expand Down Expand Up @@ -750,8 +727,7 @@ void SceneItemSelectionWidget::SetNameConflictVisibility()

case SceneItemSelection::Type::SOURCE_NAME_PATTERN:
case SceneItemSelection::Type::SOURCE_GROUP:
sceneItemCount =
getTotalSceneItemCountOnScene(_scene.GetScene(false));
sceneItemCount = GetSceneItemCount(_scene.GetScene(false));
break;
case SceneItemSelection::Type::INDEX:
case SceneItemSelection::Type::INDEX_RANGE:
Expand All @@ -761,8 +737,7 @@ void SceneItemSelectionWidget::SetNameConflictVisibility()

if (_currentSelection._type ==
SceneItemSelection::Type::SOURCE_NAME_PATTERN) {
int sceneItemCount =
getTotalSceneItemCountOnScene(_scene.GetScene(false));
int sceneItemCount = GetSceneItemCount(_scene.GetScene(false));
if (sceneItemCount == 0) {
_nameConflictIndex->hide();
return;
Expand Down
23 changes: 23 additions & 0 deletions src/utils/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,29 @@ bool SaveTransformState(obs_data_t *obj, const struct obs_transform_info &info,
return true;
}

static bool getTotalSceneItemCountHelper(obs_scene_t *, obs_sceneitem_t *item,
void *ptr)
{
auto count = reinterpret_cast<int *>(ptr);

if (obs_sceneitem_is_group(item)) {
obs_scene_t *scene = obs_sceneitem_group_get_scene(item);
obs_scene_enum_items(scene, getTotalSceneItemCountHelper, ptr);
}
*count = *count + 1;
return true;
}

int GetSceneItemCount(const OBSWeakSource &sceneWeakSource)
{
auto s = obs_weak_source_get_source(sceneWeakSource);
auto scene = obs_scene_from_source(s);
int count = 0;
obs_scene_enum_items(scene, getTotalSceneItemCountHelper, &count);
obs_source_release(s);
return count;
}

bool DisplayMessage(const QString &msg, bool question, bool modal)
{
if (!modal) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void LoadTransformState(obs_data_t *obj, struct obs_transform_info &info,
struct obs_sceneitem_crop &crop);
bool SaveTransformState(obs_data_t *obj, const struct obs_transform_info &info,
const struct obs_sceneitem_crop &crop);
int GetSceneItemCount(const OBSWeakSource &);

/* Scene item helpers */

Expand Down

0 comments on commit 569f794

Please sign in to comment.