Procházet zdrojové kódy

libobs: Add group functions that can signal refresh

Adds API:
obs_scene_add_group2
obs_scene_insert_group2
obs_sceneitem_group_ungroup2

These functions should be used by plugins if they need to use these
functions and need to send a refresh signal.  If a major API rework ever
happens the old functions should be removed.  The old functions should
eventually be deprecated.

The reason why specifying a 'signal' parameter is useful is because it's
a bit more seamless for the user interface to be able to have custom
handling of these specific cases.  It looks better and doesn't require
completely erasing/recreating the entire list, which is visually
unappealing.
jp9000 před 5 roky
rodič
revize
99e639015f
3 změnil soubory, kde provedl 76 přidání a 2 odebrání
  1. 43 2
      docs/sphinx/reference-scenes.rst
  2. 25 0
      libobs/obs-scene.c
  3. 8 0
      libobs/obs.h

+ 43 - 2
docs/sphinx/reference-scenes.rst

@@ -478,7 +478,8 @@ Scene Item Group Functions
 
 .. function:: obs_sceneitem_t *obs_scene_add_group(obs_scene_t *scene, const char *name)
 
-   Adds a group with the specified name.
+   Adds a group with the specified name.  Does not signal the scene with
+   the *refresh* signal.
 
    :param scene: Scene to add the group to
    :param name:  Name of the group
@@ -486,10 +487,23 @@ Scene Item Group Functions
 
 ---------------------
 
+.. function:: obs_sceneitem_t *obs_scene_add_group2(obs_scene_t *scene, const char *name)
+
+   Adds a group with the specified name.
+
+   :param scene:  Scene to add the group to
+   :param name:   Name of the group
+   :param signal: If *true*, signals the scene with the *refresh*
+                  signal
+   :return:       The new group's scene item
+
+---------------------
+
 .. function:: obs_sceneitem_t *obs_scene_insert_group(obs_scene_t *scene, const char *name, obs_sceneitem_t **items, size_t count)
 
    Creates a group out of the specified scene items.  The group will be
-   inserted at the top scene item.
+   inserted at the top scene item.  Does not signal the scene with the
+   *refresh* signal.
 
    :param scene: Scene to add the group to
    :param name:  Name of the group
@@ -499,6 +513,21 @@ Scene Item Group Functions
 
 ---------------------
 
+.. function:: obs_sceneitem_t *obs_scene_insert_group2(obs_scene_t *scene, const char *name, obs_sceneitem_t **items, size_t count, bool signal)
+
+   Creates a group out of the specified scene items.  The group will be
+   inserted at the top scene item.  Does not signal a refresh.
+
+   :param scene: Scene to add the group to
+   :param name:  Name of the group
+   :param items: Array of scene items to put in a group
+   :param count: Number of scene items in the array
+   :param signal: If *true*, signals the scene with the *refresh*
+                  signal
+   :return:      The new group's scene item
+
+---------------------
+
 .. function:: obs_sceneitem_t *obs_scene_get_group(obs_scene_t *scene, const char *name)
 
    Finds a group within a scene by its name.
@@ -532,9 +561,21 @@ Scene Item Group Functions
 
 .. function:: void obs_sceneitem_group_ungroup(obs_sceneitem_t *group)
 
+   Ungroups the specified group.  Scene items within the group will be
+   placed where the group was.  Does not signal the scene with the
+   *refresh* signal.
+
+---------------------
+
+.. function:: void obs_sceneitem_group_ungroup2(obs_sceneitem_t *group, bool signal)
+
    Ungroups the specified group.  Scene items within the group will be
    placed where the group was.
 
+   :param group: Group scene item
+   :param signal: If *true*, signals the scene with the *refresh*
+                  signal
+
 ---------------------
 
 .. function:: void obs_sceneitem_group_add_item(obs_sceneitem_t *group, obs_sceneitem_t *item)

+ 25 - 0
libobs/obs-scene.c

@@ -2571,6 +2571,12 @@ obs_sceneitem_t *obs_scene_add_group(obs_scene_t *scene, const char *name)
 	return obs_scene_insert_group(scene, name, NULL, 0);
 }
 
+obs_sceneitem_t *obs_scene_add_group2(obs_scene_t *scene, const char *name,
+				      bool signal)
+{
+	return obs_scene_insert_group2(scene, name, NULL, 0, signal);
+}
+
 obs_sceneitem_t *obs_scene_insert_group(obs_scene_t *scene, const char *name,
 					obs_sceneitem_t **items, size_t count)
 {
@@ -2628,6 +2634,17 @@ obs_sceneitem_t *obs_scene_insert_group(obs_scene_t *scene, const char *name,
 	return item;
 }
 
+obs_sceneitem_t *obs_scene_insert_group2(obs_scene_t *scene, const char *name,
+					 obs_sceneitem_t **items, size_t count,
+					 bool signal)
+{
+	obs_sceneitem_t *item =
+		obs_scene_insert_group(scene, name, items, count);
+	if (signal && item)
+		signal_refresh(scene);
+	return item;
+}
+
 obs_sceneitem_t *obs_scene_get_group(obs_scene_t *scene, const char *name)
 {
 	if (!scene || !name || !*name) {
@@ -2708,6 +2725,14 @@ void obs_sceneitem_group_ungroup(obs_sceneitem_t *item)
 	obs_sceneitem_release(item);
 }
 
+void obs_sceneitem_group_ungroup2(obs_sceneitem_t *item, bool signal)
+{
+	obs_scene_t *scene = item->parent;
+	obs_sceneitem_group_ungroup(item);
+	if (signal)
+		signal_refresh(scene);
+}
+
 void obs_sceneitem_group_add_item(obs_sceneitem_t *group, obs_sceneitem_t *item)
 {
 	if (!group || !group->is_group || !item)

+ 8 - 0
libobs/obs.h

@@ -1598,6 +1598,13 @@ EXPORT obs_sceneitem_t *obs_scene_insert_group(obs_scene_t *scene,
 					       obs_sceneitem_t **items,
 					       size_t count);
 
+EXPORT obs_sceneitem_t *obs_scene_add_group2(obs_scene_t *scene,
+					     const char *name, bool signal);
+EXPORT obs_sceneitem_t *obs_scene_insert_group2(obs_scene_t *scene,
+						const char *name,
+						obs_sceneitem_t **items,
+						size_t count, bool signal);
+
 EXPORT obs_sceneitem_t *obs_scene_get_group(obs_scene_t *scene,
 					    const char *name);
 
@@ -1606,6 +1613,7 @@ EXPORT bool obs_sceneitem_is_group(obs_sceneitem_t *item);
 EXPORT obs_scene_t *obs_sceneitem_group_get_scene(const obs_sceneitem_t *group);
 
 EXPORT void obs_sceneitem_group_ungroup(obs_sceneitem_t *group);
+EXPORT void obs_sceneitem_group_ungroup2(obs_sceneitem_t *group, bool signal);
 
 EXPORT void obs_sceneitem_group_add_item(obs_sceneitem_t *group,
 					 obs_sceneitem_t *item);